Skip to content

Commit ad340a4

Browse files
committed
release 2.0.0 init
1 parent 6655fc4 commit ad340a4

File tree

21 files changed

+226
-181
lines changed

21 files changed

+226
-181
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,36 @@ $ npm install
2525
```
2626

2727
### Development
28-
Development Environment using gulp-nodemon, gulp-livereload and gulp-jshint.
28+
Development Environment using gulp-nodemon, [browser-sync](https://www.browsersync.io/) and gulp-jshint.
2929
1. Make sure <strong>isDevMode</strong> configuration is <strong>true</strong> in <strong>locals.js</strong>
30-
2. Install [livereload chrome extension](http://livereload.com/extensions/)
31-
3. Start the server with `gulp start-develop`
30+
2. Start development mode with `gulp --development`
31+
3. Input `http://localhost:devPort` with browsers
3232

3333
### Production
3434
1. Make sure <strong>isDevMode</strong> configuration is <strong>false</strong> in <strong>locals.js</strong>
35-
2. Compile and build with `gulp`
35+
2. Compile and build with `gulp --production`
3636
3. Start the server with node or pm2 or others
37+
4. Input `http://localhost:port` with browsers
3738

3839
### Configuration
3940
System configuration are stored in the <strong>locals.js</strong> file.
4041

4142
### Samples Page
42-
Start the server and input `http://localhost:8099/samples` with browsers.
43+
Start the server and input `URL/samples` with browsers.
44+
45+
## Gulp
46+
Show task list with `gulp help`.
4347

4448
## Test
4549
Test using karma and jasmine, run the test with `npm test` or `karma start`. Unit and coverage test report are stored in report directory.
4650

4751
## Changelog
52+
### 2.1.0
53+
- replace gulp-livereload with browser-sync
54+
- add gulp-help, gulp-size and others gulp components
55+
- remove less.js<br>
56+
10.01.2016
57+
4858
### 2.0.0
4959
- adjust directory and code of project
5060
- add angular samples page

bower.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angularjs-requirejs-boilerplate",
33
"description": "An complete angularjs requirejs boilerplate for node.",
4-
"version": "2.0.0",
4+
"version": "2.1.0",
55
"authors": "Pluser <[email protected]>",
66
"main": "app.js",
77
"keywords": [
@@ -17,7 +17,6 @@
1717
"angular": "~1.4.7",
1818
"bootstrap": "~3.3.5",
1919
"jquery": "~2.1.4",
20-
"less": "~2.5.1",
2120
"requirejs": "~2.1.20",
2221
"angular-mocks": "~1.4.7",
2322
"github-markdown-css": "~2.1.1"

gulp/common/env-util.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var argv = require('yargs').argv;
2+
3+
var env = {};
4+
5+
env.isProduction = function () {
6+
return argv.production ? true : false;
7+
};
8+
9+
env.isDevelopment = function () {
10+
return argv.development ? true : false;
11+
};
12+
13+
module.exports = env;

gulp/desktop/build-scripts.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
var gulp = require('gulp'),
1+
var gulp = require('gulp-help')(require('gulp')),
22
gutil = require('gulp-util'),
33
concat = require('gulp-concat'),
44
uglify = require('gulp-uglify'),
55
size = require('gulp-size'),
6+
gulpif = require('gulp-if'),
67
requirejs = require('requirejs'),
78
vp = require('vinyl-paths'),
89
del = require('del');
910

10-
var locals = require('../../node-app/config/locals');
11+
var envUtil = require('../common/env-util');
1112

1213
var paths = {
1314
origin: 'public/scripts/desktop',
@@ -23,7 +24,7 @@ gulp.task('desktop-build-libs-no-clean', function () {
2324
optimize: 'uglify2',
2425
removeCombined: true
2526
}, function (files) {
26-
if (locals.isDevMode) {
27+
if (!envUtil.isProduction()) {
2728
gutil.log('modules of build libs in desktop', files);
2829
}
2930
}, function (err) {
@@ -37,13 +38,9 @@ gulp.task('desktop-build-custom-scripts-no-clean', function () {
3738
'!' + paths.origin + '/optimize-main.js',
3839
'!' + paths.origin + '/optimize-require-config.js'
3940
]).pipe(concat('apps.min.js').on('error', gutil.log))
40-
.pipe(size({
41-
title: 'size of custom scripts in desktop'
42-
}))
41+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of custom scripts in desktop'})))
4342
.pipe(uglify().on('error', gutil.log))
44-
.pipe(size({
45-
title: 'size of uglify custom scripts in desktop'
46-
}))
43+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of uglify custom scripts in desktop'})))
4744
.pipe(gulp.dest(paths.compiled));
4845
});
4946

gulp/desktop/build-styles.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
var gulp = require('gulp'),
1+
var gulp = require('gulp-help')(require('gulp')),
22
gutil = require('gulp-util'),
33
less = require('gulp-less'),
44
minifycss = require('gulp-minify-css'),
55
size = require('gulp-size'),
6+
gulpif = require('gulp-if'),
7+
plumber = require('gulp-plumber'),
68
vp = require('vinyl-paths'),
79
del = require('del');
810

11+
var envUtil = require('../common/env-util'),
12+
browserSync = require('../develop/build-browser-sync');
13+
914
var paths = {
1015
origin: 'public/styles/desktop',
1116
compiled: 'public/compiled/desktop/styles'
1217
};
1318

1419
gulp.task('desktop-build-styles-no-clean', function () {
1520
return gulp.src(paths.origin + '/**/*.less')
16-
.pipe(size({
17-
title: 'size of less in desktop'
18-
}))
21+
.pipe(plumber())
22+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of less in desktop'})))
1923
.pipe(less().on('error', gutil.log))
20-
.pipe(size({
21-
title: 'size of css in desktop, after less2css'
22-
}))
24+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of css in desktop, after less2css'})))
2325
.pipe(minifycss().on('error', gutil.log))
24-
.pipe(size({
25-
title: 'size of css in desktop, after minify css'
26-
}))
27-
.pipe(gulp.dest(paths.compiled));
26+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of css in desktop, after minify css'})))
27+
.pipe(gulp.dest(paths.compiled))
28+
.pipe(gulpif(envUtil.isDevelopment(), browserSync.stream()));
2829
});
2930

3031
gulp.task('desktop-clean-styles', function () {

gulp/desktop/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var gulp = require('gulp');
1+
var gulp = require('gulp-help')(require('gulp'));
22

33
require('./build-scripts.js');
44
require('./build-styles.js');

gulp/develop/build-browser-sync.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var browserSync = require("browser-sync");
2+
3+
var envUtil = require('../common/env-util');
4+
5+
if (envUtil.isDevelopment()) {
6+
var browserSyncServer = browserSync.create(),
7+
locals = require('../../node-app/config/locals');
8+
9+
browserSyncServer.init({
10+
proxy: 'localhost:' + locals.port,
11+
port: locals.devPort
12+
});
13+
14+
module.exports = browserSyncServer;
15+
} else {
16+
module.exports = browserSync;
17+
}

gulp/develop/build.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var gulp = require('gulp-help')(require('gulp')),
2+
gutil = require('gulp-util'),
3+
nodemon = require('gulp-nodemon'),
4+
jshint = require('gulp-jshint'),
5+
stylish = require('jshint-stylish'),
6+
karmaServer = require('karma').Server;
7+
8+
var envUtil = require('../common/env-util'),
9+
browserSync = require('./build-browser-sync');
10+
11+
var resources = {
12+
styles: 'public/styles/**/*.less',
13+
scripts: 'public/scripts/**/*.js',
14+
libs: 'public/libs/**/*.js',
15+
jshint: [
16+
'public/scripts/**/*.js',
17+
'node-app/**/*.js',
18+
'middleware/**/*.js',
19+
'test/**/*.js'
20+
],
21+
views: 'views/**/*.html',
22+
images: 'public/images/**/*'
23+
};
24+
25+
gulp.task('develop-watch', [
26+
'develop-watch-node',
27+
'build-styles'
28+
], function () {
29+
gulp.watch(resources.styles, ['build-styles']);
30+
gulp.watch(resources.scripts, ['browsersync-reload']);
31+
gulp.watch(resources.libs, ['browsersync-reload']);
32+
gulp.watch(resources.jshint, ['develop-jshint']);
33+
gulp.watch(resources.views, ['browsersync-reload']);
34+
gulp.watch(resources.images, ['browsersync-reload']);
35+
});
36+
37+
gulp.task('develop-watch-node', function () {
38+
nodemon({
39+
scripts: 'app.js',
40+
env: {
41+
'NODE_ENV': 'development'
42+
},
43+
ext: 'js',
44+
watch: [
45+
'middleware',
46+
'node-app',
47+
'app.js'
48+
]
49+
}).on('restart', function (files) {
50+
gutil.log('Node server restarted due to: ', files);
51+
});
52+
});
53+
54+
gulp.task('browsersync-reload', function () {
55+
if (envUtil.isDevelopment()) {
56+
browserSync.reload();
57+
}
58+
});
59+
60+
gulp.task('develop-jshint', function () {
61+
return gulp.src(resources.jshint)
62+
.pipe(jshint())
63+
.pipe(jshint.reporter(stylish));
64+
});
65+
66+
gulp.task('develop-tests', function () {
67+
new karmaServer({
68+
configFile: process.cwd() + '/karma.conf.js'
69+
}).start();
70+
});

gulp/gulp-docker.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
var gulp = require('gulp');
1+
var gulp = require('gulp-help')(require('gulp'));
2+
3+
var envUtil = require('./common/env-util');
24

35
require('./desktop/build.js');
46
require('./mobile/build.js');
57

8+
if (!envUtil.isProduction()) {
9+
require('./develop/build.js');
10+
}
11+
612
gulp.task('clean-scripts', function () {
713
gulp.start('desktop-clean-scripts', 'mobile-clean-scripts');
814
});
@@ -39,6 +45,15 @@ gulp.task('build', function () {
3945
gulp.start('desktop-build', 'mobile-build');
4046
});
4147

42-
gulp.task('default', function () {
43-
gulp.start('desktop-build', 'mobile-build');
48+
gulp.task('default', 'compile and build by production mode and it show more information', function () {
49+
if (envUtil.isDevelopment()) {
50+
gulp.start('develop-watch');
51+
} else {
52+
gulp.start('desktop-build', 'mobile-build');
53+
}
54+
}, {
55+
options: {
56+
'production': 'compile and build in production env',
57+
'development': 'development mode for developer'
58+
}
4459
});

gulp/mobile/build-scripts.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
var gulp = require('gulp'),
1+
var gulp = require('gulp-help')(require('gulp')),
22
gutil = require('gulp-util'),
33
concat = require('gulp-concat'),
44
uglify = require('gulp-uglify'),
55
size = require('gulp-size'),
6+
gulpif = require('gulp-if'),
67
requirejs = require('requirejs'),
78
vp = require('vinyl-paths'),
89
del = require('del');
910

10-
var locals = require('../../node-app/config/locals');
11+
var envUtil = require('../common/env-util');
1112

1213
var paths = {
1314
origin: 'public/scripts/mobile',
@@ -23,8 +24,8 @@ gulp.task('mobile-build-libs-no-clean', function () {
2324
optimize: 'uglify2',
2425
removeCombined: true
2526
}, function (data) {
26-
if (locals.isDevMode) {
27-
gutil.log('modules of build libs in mobile', data);
27+
if (!envUtil.isProduction()) {
28+
gutil.log('modules of build libs in desktop', files);
2829
}
2930
}, function (err) {
3031
gutil.log('build libs error in mobile', err);
@@ -37,13 +38,9 @@ gulp.task('mobile-build-custom-scripts-no-clean', function () {
3738
'!' + paths.origin + '/optimize-main.js',
3839
'!' + paths.origin + '/optimize-require-config.js'
3940
]).pipe(concat('apps.min.js').on('error', gutil.log))
40-
.pipe(size({
41-
title: 'size of custom scripts in mobile'
42-
}))
41+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of custom scripts in mobile'})))
4342
.pipe(uglify().on('error', gutil.log))
44-
.pipe(size({
45-
title: 'size of uglify custom scripts in mobile'
46-
}))
43+
.pipe(gulpif(!envUtil.isProduction(), size({title: 'size of uglify custom scripts in mobile'})))
4744
.pipe(gulp.dest(paths.compiled));
4845
});
4946

0 commit comments

Comments
 (0)