11'use strict' ;
22
3- var path = require ( 'path' ) ,
4- fs = require ( 'fs' ) ;
3+ var path = require ( 'path' ) ,
4+ fs = require ( 'fs' ) ;
55
6- var gulp = require ( 'gulp' ) ,
7- jshint = require ( 'gulp-jshint' ) ,
8- rimraf = require ( 'gulp-rimraf' ) ,
9- runSequence = require ( 'run-sequence' ) ,
10- combined = require ( 'combined-stream' ) ,
11- semiflat = require ( 'gulp-semiflat' ) ,
12- to5ify = require ( '6to5ify' ) ,
13- stringify = require ( 'stringify' ) ,
14- wordwrap = require ( 'wordwrap' ) ,
15- ngAnnotate = require ( 'browserify-ngannotate' ) ;
6+ var gulp = require ( 'gulp' ) ,
7+ jshint = require ( 'gulp-jshint' ) ,
8+ rimraf = require ( 'gulp-rimraf' ) ,
9+ runSequence = require ( 'run-sequence' ) ,
10+ combined = require ( 'combined-stream' ) ,
11+ semiflat = require ( 'gulp-semiflat' ) ,
12+ to5ify = require ( '6to5ify' ) ,
13+ stringify = require ( 'stringify' ) ,
14+ wordwrap = require ( 'wordwrap' ) ,
15+ ngAnnotate = require ( 'browserify-ngannotate' ) ;
1616
1717var karma = require ( '../lib/test/karma' ) ,
1818 browserify = require ( '../lib/build/browserify' ) ,
@@ -22,10 +22,10 @@ var karma = require('../lib/test/karma'),
2222 jshintReporter = require ( '../lib/util/jshint-reporter' ) ;
2323
2424var cliArgs ;
25- var transforms ;
2625
2726yargs . getInstance ( 'javascript' )
28- . usage ( wordwrap ( 2 , 80 ) ( 'The "javascript" task performs a one time build of the javascript composition root(s).' ) )
27+ . usage ( wordwrap ( 2 , 80 ) ( 'The "javascript" task performs a one time build of the javascript composition root(s) ' +
28+ 'and also bundles of all .spec.js files in the project.' ) )
2929 . example ( 'angularity javascript' , 'Run this task' )
3030 . example ( 'angularity javascript -u' , 'Run this task but do not minify javascript' )
3131 . options ( 'help' , {
@@ -52,39 +52,12 @@ yargs.getInstance('javascript')
5252//Proper solution would be to have yargs.getInstance modified to
5353//mixin options and checks from dependent/ prequisite yargs instances
5454
55- yargs . getInstance ( 'test' )
56- . usage ( wordwrap ( 2 , 80 ) ( 'The "test" task performs a one time build and ' +
57- 'karma test of all .spec.js files in the project.' ) )
58- . example ( 'angularity test' , 'Run this task' )
59- . options ( 'help' , {
60- describe : 'This help message' ,
61- alias : [ 'h' , '?' ] ,
62- boolean : true
63- } )
64- . options ( jshintReporter . yargsOption . key , jshintReporter . yargsOption . value )
65- . options ( karma . yargsOption . key , karma . yargsOption . value )
66- . strict ( )
67- . check ( yargs . subCommandCheck )
68- . check ( jshintReporter . yargsCheck )
69- . check ( karma . yargsCheck )
70- . wrap ( 80 ) ;
71-
7255gulp . task ( 'javascript' , function ( done ) {
7356 console . log ( hr ( '-' , 80 , 'javascript' ) ) ;
74- init ( ) ;
75- runSequence (
76- [ 'javascript:cleanbuild' , 'javascript:lint' ] ,
77- [ 'javascript:build' ] ,
78- done
79- ) ;
80- } ) ;
81-
82- gulp . task ( 'test' , function ( done ) {
83- console . log ( hr ( '-' , 80 , 'test' ) ) ;
84- init ( true ) ;
57+ cliArgs = cliArgs || yargs . resolveArgv ( ) ;
8558 runSequence (
86- [ 'javascript:cleanunit' , 'javascript:lint' ] ,
87- 'javascript:unit' ,
59+ [ 'javascript:cleanbuild' , 'javascript: cleanunit', 'javascript:lint' ] ,
60+ [ 'javascript:build' , 'javascript: unit'] ,
8861 done
8962 ) ;
9063} ) ;
@@ -96,8 +69,9 @@ gulp.task('javascript:cleanbuild', function () {
9669} ) ;
9770
9871// clean javascript from the test directory
72+ // don't remove the karma conf or Webstorm ide will have problems
9973gulp . task ( 'javascript:cleanunit' , function ( ) {
100- return gulp . src ( streams . TEST + '/**/*.js*' , { read : false } )
74+ return gulp . src ( [ streams . TEST + '/**/*.js*' , '!**/karma.conf.js' ] , { read : false } ) // keep configuration
10175 . pipe ( rimraf ( ) ) ;
10276} ) ;
10377
@@ -114,9 +88,7 @@ gulp.task('javascript:lint', function () {
11488// karma unit tests in local library only
11589gulp . task ( 'javascript:unit' , function ( ) {
11690 var reporters = [ ] . concat ( cliArgs [ karma . yargsOption . key ] )
117- . filter ( function isString ( value ) {
118- return ( typeof value === 'string' ) ;
119- } ) ;
91+ . filter ( Boolean ) ;
12092 return combined . create ( )
12193 . append (
12294 streams
@@ -129,35 +101,34 @@ gulp.task('javascript:unit', function () {
129101 streams
130102 . jsSpec ( )
131103 . pipe ( browserify
132- . compile ( 80 , transforms . concat ( browserify . jasmineTransform ( '@' ) ) )
104+ . compile ( 80 , getTransforms ( ) . concat ( browserify . jasmineTransform ( '@' ) ) )
133105 . all ( 'index.js' , false , '/base' ) )
134106 . pipe ( gulp . dest ( streams . TEST ) )
135107 )
136108 . pipe ( semiflat ( process . cwd ( ) ) )
137109 . pipe ( karma . createConfig ( reporters ) )
138110 . pipe ( gulp . dest ( streams . TEST ) )
139- . pipe ( karma . run ( reporters , 80 ) ) ;
140111} ) ;
141112
142113// give a single optimised javascript file in the build directory with source map for each
143114gulp . task ( 'javascript:build' , function ( ) {
144115 return streams . jsApp ( { read : false } )
145116 . pipe ( browserify
146- . compile ( 80 , transforms )
117+ . compile ( 80 , getTransforms ( ! cliArgs . unminified ) )
147118 . each ( ! cliArgs . unminified ) )
148119 . pipe ( gulp . dest ( streams . BUILD ) ) ;
149120} ) ;
150121
151122/**
152- * Initialisation must be deferred until a task actually starts
123+ * Retrieve the transform list
124+ * @param {boolean } isMinify Indicates whether minification will be used
153125 */
154- function init ( unminified ) {
155- cliArgs = cliArgs || yargs . resolveArgv ( ) ;
156- transforms = [
157- to5ify . configure ( { ignoreRegex : / (? ! ) / } ) , // convert any es6 to es5 (degenerate regex)
158- stringify ( { minify : false } ) , // allow import of html to a string
159- ! cliArgs . unminified && ! unminified && ngAnnotate , { sourcemap : true } // @ngInject for angular injection points
160- ] ;
126+ function getTransforms ( isMinify ) {
127+ return [
128+ to5ify . configure ( { ignoreRegex : / (? ! ) / } ) , // convert any es6 to es5 (degenerate regex)
129+ stringify ( { minify : false } ) , // allow import of html to a string
130+ isMinify && ngAnnotate , { sourcemap : true } // @ngInject for angular injection points
131+ ] . filter ( Boolean ) ;
161132 // TODO @bholloway fix stringify({ minify: true }) throwing error on badly formed html so that we can minify
162133 // TODO @bholloway fix sourcemaps in ngAnnotate so that it may be included even when not minifying
163- }
134+ }
0 commit comments