forked from linnovate/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c7b2a
commit a077d36
Showing
8 changed files
with
217 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,134 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'), | ||
gulpLoadPlugins = require('gulp-load-plugins'), | ||
through = require('through'), | ||
gutil = require('gulp-util'), | ||
plugins = gulpLoadPlugins(), | ||
paths = { | ||
js: ['./*.js', 'config/**/*.js', 'gulp/**/*.js', 'tools/**/*.js', 'packages/**/*.js', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**', '!packages/**/assets/**/js/**'], | ||
html: ['packages/**/*.html', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
css: ['packages/**/*.css', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**', '!packages/core/**/public/assets/css/*.css'], | ||
less: ['packages/**/*.less', '!packages/**/_*.less', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
sass: ['packages/**/*.scss', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
webpack: ['./app.js', 'packages/**/public/**/*.css', 'packages/**/public/**/*.js', '!packages/**/public/assets/lib/**', '!packages/**/node_modules/**'] | ||
}; | ||
var webpack = require("webpack"); | ||
var webpackConfig = require("../webpack.config.js"); | ||
gulpLoadPlugins = require('gulp-load-plugins'), | ||
through = require('through'), | ||
gutil = require('gulp-util'), | ||
plugins = gulpLoadPlugins(), | ||
paths = { | ||
js: ['./*.js', 'config/**/*.js', 'gulp/**/*.js', 'tools/**/*.js', 'packages/**/*.js', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**', '!packages/**/assets/**/js/**'], | ||
html: ['packages/**/*.html', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
css: ['packages/**/*.css', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**', '!packages/core/**/public/assets/css/*.css'], | ||
less: ['packages/**/*.less', '!packages/**/_*.less', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
sass: ['packages/**/*.scss', '!packages/**/node_modules/**', '!packages/**/assets/**/lib/**'], | ||
webpack: ['./app.js', 'packages/**/public/**/*.css', 'packages/**/public/**/*.js', '!packages/**/public/assets/lib/**', '!packages/**/node_modules/**'] | ||
}; | ||
var webpack = require('webpack'); | ||
var webpackConfig = require('../webpack.config.js'); | ||
|
||
/*var defaultTasks = ['clean', 'jshint', 'less', 'csslint', 'devServe', 'watch'];*/ | ||
var defaultTasks = ['webpack:build-dev','clean', 'less', 'sass', 'csslint', 'devServe', 'watch']; | ||
var defaultTasks = ['webpack:build-dev', 'clean', 'less', 'sass', 'csslint', 'devServe', 'watch']; | ||
|
||
gulp.task('env:development', function () { | ||
process.env.NODE_ENV = 'development'; | ||
gulp.task('env:development', function() { | ||
process.env.NODE_ENV = 'development'; | ||
}); | ||
|
||
gulp.task('jshint', function () { | ||
return gulp.src(paths.js) | ||
.pipe(plugins.jshint()) | ||
.pipe(plugins.jshint.reporter('jshint-stylish')) | ||
// .pipe(plugins.jshint.reporter('fail')) to avoid shutdown gulp by warnings | ||
.pipe(count('jshint', 'files lint free')); | ||
function count(taskName, message) { | ||
var fileCount = 0; | ||
|
||
function countFiles(file) { | ||
fileCount++; // jshint ignore:line | ||
} | ||
|
||
function endStream() { | ||
gutil.log(gutil.colors.cyan(taskName + ': ') + fileCount + ' ' + message || 'files processed.'); | ||
this.emit('end'); // jshint ignore:line | ||
} | ||
|
||
return through(countFiles, endStream); | ||
} | ||
|
||
gulp.task('jshint', function() { | ||
return gulp.src(paths.js) | ||
.pipe(plugins.jshint()) | ||
.pipe(plugins.jshint.reporter('jshint-stylish')) | ||
// .pipe(plugins.jshint.reporter('fail')) to avoid shutdown gulp by warnings | ||
.pipe(count('jshint', 'files lint free')); | ||
}); | ||
|
||
gulp.task('csslint', function () { | ||
return gulp.src(paths.css) | ||
.pipe(plugins.csslint('.csslintrc')) | ||
.pipe(plugins.csslint.reporter()) | ||
.pipe(count('csslint', 'files lint free')); | ||
gulp.task('csslint', function() { | ||
return gulp.src(paths.css) | ||
.pipe(plugins.csslint('.csslintrc')) | ||
.pipe(plugins.csslint.reporter()) | ||
.pipe(count('csslint', 'files lint free')); | ||
}); | ||
|
||
gulp.task('less', function () { | ||
return gulp.src(paths.less) | ||
.pipe(plugins.less()) | ||
.pipe(gulp.dest('./packages')); | ||
gulp.task('less', function() { | ||
return gulp.src(paths.less) | ||
.pipe(plugins.less()) | ||
.pipe(gulp.dest('./packages')); | ||
}); | ||
|
||
gulp.task('sass', function () { | ||
return gulp.src(paths.sass) | ||
.pipe(plugins.sass().on('error', plugins.sass.logError)) | ||
.pipe(gulp.dest('./packages')); | ||
gulp.task('sass', function() { | ||
return gulp.src(paths.sass) | ||
.pipe(plugins.sass().on('error', plugins.sass.logError)) | ||
.pipe(gulp.dest('./packages')); | ||
}); | ||
|
||
gulp.task('devServe', ['env:development'], function () { | ||
|
||
plugins.nodemon({ | ||
script: 'server.js', | ||
ext: 'html js', | ||
env: {'NODE_ENV': 'development'}, | ||
ignore: [ | ||
'node_modules/', | ||
'bower_components/', | ||
'logs/', | ||
'packages/*/*/public/assets/lib/', | ||
'packages/*/*/node_modules/', | ||
'.DS_Store', '**/.DS_Store', | ||
'.bower-*', | ||
'**/.bower-*', | ||
'**/tests' | ||
], | ||
nodeArgs: ['--debug'], | ||
stdout: false | ||
}).on('readable', function () { | ||
this.stdout.on('data', function (chunk) { | ||
if (/Mean app started/.test(chunk)) { | ||
setTimeout(function () { | ||
plugins.livereload.reload(); | ||
}, 500); | ||
} | ||
process.stdout.write(chunk); | ||
}); | ||
this.stderr.pipe(process.stderr); | ||
gulp.task('devServe', ['env:development'], function() { | ||
|
||
plugins.nodemon({ | ||
script: 'server.js', | ||
ext: 'html js', | ||
env: { | ||
'NODE_ENV': 'development' | ||
}, | ||
ignore: [ | ||
'node_modules/', | ||
'bower_components/', | ||
'logs/', | ||
'packages/*/*/public/assets/lib/', | ||
'packages/*/*/node_modules/', | ||
'.DS_Store', '**/.DS_Store', | ||
'.bower-*', | ||
'**/.bower-*', | ||
'**/tests' | ||
], | ||
nodeArgs: ['--debug'], | ||
stdout: false | ||
}).on('readable', function() { | ||
this.stdout.on('data', function(chunk) { | ||
if (/Mean app started/.test(chunk)) { | ||
setTimeout(function() { | ||
plugins.livereload.reload(); | ||
}, 500); | ||
} | ||
process.stdout.write(chunk); | ||
}); | ||
this.stderr.pipe(process.stderr); | ||
}); | ||
}); | ||
|
||
|
||
// modify some webpack config options | ||
var myDevConfig = Object.create(webpackConfig); | ||
myDevConfig.devtool = "sourcemap"; | ||
myDevConfig.devtool = 'sourcemap'; | ||
myDevConfig.debug = true; | ||
// create a single instance of the compiler to allow caching | ||
var devCompiler = webpack(myDevConfig); | ||
gulp.task('webpack:build-dev', function(callback) { | ||
// run webpack | ||
devCompiler.run(function(err, stats) { | ||
if(err) throw new gutil.PluginError("webpack:build-dev", err); | ||
gutil.log("[webpack:build-dev]", stats.toString({ | ||
colors: true | ||
})); | ||
callback(); | ||
}); | ||
// run webpack | ||
devCompiler.run(function(err, stats) { | ||
if (err) throw new gutil.PluginError('webpack:build-dev', err); | ||
gutil.log('[webpack:build-dev]', stats.toString({ | ||
colors: true | ||
})); | ||
callback(); | ||
}); | ||
}); | ||
|
||
gulp.task('watch', function () { | ||
plugins.livereload.listen({interval: 500}); | ||
gulp.task('watch', function() { | ||
plugins.livereload.listen({ | ||
interval: 500 | ||
}); | ||
|
||
gulp.watch(paths.js, ['jshint']); | ||
gulp.watch(paths.css, ['csslint']).on('change', plugins.livereload.changed); | ||
gulp.watch(paths.less, ['less']); | ||
gulp.watch(paths.sass, ['sass']); | ||
gulp.watch(paths.webpack, ['webpack:build-dev']); | ||
gulp.watch(paths.js, ['jshint']); | ||
gulp.watch(paths.css, ['csslint']).on('change', plugins.livereload.changed); | ||
gulp.watch(paths.less, ['less']); | ||
gulp.watch(paths.sass, ['sass']); | ||
gulp.watch(paths.webpack, ['webpack:build-dev']); | ||
}); | ||
|
||
function count(taskName, message) { | ||
var fileCount = 0; | ||
|
||
function countFiles(file) { | ||
fileCount++; // jshint ignore:line | ||
} | ||
|
||
function endStream() { | ||
gutil.log(gutil.colors.cyan(taskName + ': ') + fileCount + ' ' + message || 'files processed.'); | ||
this.emit('end'); // jshint ignore:line | ||
} | ||
|
||
return through(countFiles, endStream); | ||
} | ||
|
||
gulp.task('development', defaultTasks); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.