From 91c2a9a0864cd2b5fe89b8ce288a952c373306b6 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 13:10:55 -0800 Subject: [PATCH 01/20] First draft of common gulp tasks --- tasks/dev.js | 118 +++++++++++++++++++++++++++++++++++++++++++++++ tasks/release.js | 34 ++++++++++++++ tasks/test.js | 15 ++++++ 3 files changed, 167 insertions(+) create mode 100644 tasks/dev.js create mode 100644 tasks/release.js create mode 100644 tasks/test.js diff --git a/tasks/dev.js b/tasks/dev.js new file mode 100644 index 0000000..cbdd032 --- /dev/null +++ b/tasks/dev.js @@ -0,0 +1,118 @@ +'use strict'; + +var gulp = require('gulp'); +var onejsCompiler = require('gulp-onejs-compiler'); +var tsc = require('gulp-typescript'); +var uglify = require('gulp-uglifyjs'); +var del = require('del'); +var less = require('gulp-less'); +var cssMinify = require('gulp-minify-css'); +var csstojs = require('gulp-csstojs'); +var postcss = require('gulp-postcss'); +var autoprefixer = require('autoprefixer-core'); + +/** + * The common directory structure OneJS uses + * along with some helpful glob patterns + */ +var paths = { + app: { + root: 'app/', + jsGlob: 'app/**/*.js', + min: { + root: 'app-min/' + } + }, + dist: { + root: 'dist/', + amd: 'dist/amd/', + commonjs: 'dist/commonjs/' + }, + src: { + root: 'src/', + htmlGlob: 'src/**/*.html', + lessGlob: 'src/**/*.less', + tsGlob: 'src/**/*.ts', + glob: 'src/**/*' + }, + staticFiles: [ + 'node_modules/requirejs/require.js' + ], + temp: { + root: 'temp/', + ts: 'temp/ts/', + test: 'temp/ts/test/', + tsGlob: 'temp/ts/**/*.ts' + }, + test: { + root: 'test/', + glob: 'test/**/*' + } +}; + +/** Cleans the temporary folders */ +gulp.task('clean', function(cb) { + del([paths.temp], cb); +}); + +/** Runs LESS compiler, auto-prefixer, and uglify, then creates js modules and outputs to temp folder */ +gulp.task('less-to-js', function() { + return gulp.src(paths.src.lessGlob) + .pipe(less()) + .pipe(postcss([autoprefixer()])) + .pipe(cssMinify()) + .pipe(csstojs({ + typeScript: true + })) + .pipe(gulp.dest(paths.temp.ts)) +}); + +/** Compiles OneJS html templates */ +gulp.task('onejs-html', function() { + return gulp.src(paths.src.htmlGlob) + .pipe(onejsCompiler()) + .pipe(gulp.dest(paths.temp.ts)); +}); + +/** Copies OneJS TypeScript files to temp directory for futher compilation */ +gulp.task('onejs-ts', function() { + return gulp.src(paths.src.tsGlob) + .pipe(gulp.dest(paths.temp.ts)); +}) + +/** Runs the basic pre-processing steps before compilation */ +gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js']); + +/** Runs the TypeScript amd compiler over your application .ts files */ +gulp.task('tsc-amd', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'amd' + })) + .pipe(gulp.dest(paths.app.root)) + .pipe(gulp.dest(paths.dist.amd)); +}); + +/** Runs the TypeScript commonjs compiler over your application .ts files */ +gulp.task('tsc-commonjs', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'commonjs' + })) + .pipe(gulp.dest(paths.app.root)) + .pipe(gulp.dest(paths.dist.commonjs)); +}); + +/** Copies the static files to your application path */ +gulp.task('copy-static-files', function() { + return gulp.src(paths.staticFiles) + .pipe(gulp.dest(paths.app.root)) +}); + +/** Watches your src folder for changes, and runs the default build task */ +gulp.task('watch', function() { + gulp.watch(paths.src.glob, ['build']); +}); + +/** Default dev task for building */ +gulp.task('build', ['tsc-amd', 'copy-static-files']); diff --git a/tasks/release.js b/tasks/release.js new file mode 100644 index 0000000..684f648 --- /dev/null +++ b/tasks/release.js @@ -0,0 +1,34 @@ +'use strict'; + +var size = require('gulp-size'); + +gulp.task('minify', ['tsc-amd'], function() { + return gulp.src([paths.app.jsGlob]) + .pipe(uglify()) + .pipe(size({ + gzip: true + })) + .pipe(gulp.dest(paths.app.min.root)); +}); + +gulp.task('minify-dist', ['minify'], function() { + return gulp.src([paths.app.jsGlob]) + .pipe(uglify()) + .pipe(size({ + gzip: true + })) + .pipe(gulp.dest(paths.dist.amd)); +}); + +/** Copies the minified static files to your application path */ +gulp.task('copy-static-files-minified', function() { + return gulp.src(paths.staticFiles) + .pipe(uglify()) + .pipe(gulp.dest(paths.app.min.root)); +}); + +/** Builds the minified version of your app */ +gulp.task('build-minify', ['minify', 'copy-static-files-minified']); + +/** Builds the distributable version of your app */ +gulp.task('build-dist', ['minify-dist']); diff --git a/tasks/test.js b/tasks/test.js new file mode 100644 index 0000000..c7b18a4 --- /dev/null +++ b/tasks/test.js @@ -0,0 +1,15 @@ +'use strict'; + +var karma = require('karma').server; + +gulp.task('test-preprocess', ['copy-deps'], function() { + return gulp.src(paths.test.glob) + .pipe(gulp.dest(paths.temp.test)); +}); + +gulp.task('test', ['tsc-commonjs', 'copy-static-files'], function (done) { + karma.start({ + configFile: __dirname + '/karma.conf.js', + singleRun: true + }, done); +}); From 67fcca785f0ed0838134d1fcda0982288040ffc8 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 14:50:35 -0800 Subject: [PATCH 02/20] Working on exposing all of the tasks --- index.js | 98 ++++++++++++---------- package.json | 19 ++++- tasks/dev.js | 209 ++++++++++++++++++++++++----------------------- tasks/release.js | 56 +++++++------ tasks/test.js | 24 +++--- 5 files changed, 219 insertions(+), 187 deletions(-) diff --git a/index.js b/index.js index 9ea0061..71c268a 100644 --- a/index.js +++ b/index.js @@ -5,58 +5,74 @@ var gutil = require('gulp-util'); var path = require('path'); var typeScriptGenerator = require('onejs-compiler').TypeScriptGenerator; var typeScriptViewModelGenerator = require('onejs-compiler').TypeScriptViewModelGenerator; +var devTasks = require('./tasks/dev.js'); +var releaseTasks = require('./tasks/release.js'); +var testTasks = require('./tasks/test.js'); -module.exports = function(options) { +module.exports = { - options = options || { - typeScriptViewFileFormat: '{{templateName}}.ts', - typeScriptViewModelFileFormat: 'I{{templateName}}Model.ts' - }; + compiler: function(options) { + options = options || { + typeScriptViewFileFormat: '{{templateName}}.ts', + typeScriptViewModelFileFormat: 'I{{templateName}}Model.ts' + }; - function getFileName(nameMatch, templateName) { - return nameMatch.replace('{{templateName}}', templateName); - } - - function generate(generatorType, templateContent, fileNameFormat, file) { - var generator = new generatorType(); - var outputFile = file.clone(); + function getFileName(nameMatch, templateName) { + return nameMatch.replace('{{templateName}}', templateName); + } - try { - outputFile.contents = new Buffer(generator.generate(templateContent)); - outputFile.path = file.path.replace(path.basename(file.path), getFileName(fileNameFormat, generator.template.name)); + function generate(generatorType, templateContent, fileNameFormat, file) { + var generator = new generatorType(); + var outputFile = file.clone(); - } catch (e) { - throw new gutil.PluginError({ - plugin: 'gulp-onejs-compiler', - message: 'Error parsing template: ' + file.path + '\n' + e - }); - } + try { + outputFile.contents = new Buffer(generator.generate(templateContent)); + outputFile.path = file.path.replace(path.basename(file.path), getFileName(fileNameFormat, generator.template.name)); - return outputFile; - } + } catch (e) { + throw new gutil.PluginError({ + plugin: 'gulp-onejs-compiler', + message: 'Error parsing template: ' + file.path + '\n' + e + }); + } - var stream = through.obj(function(file, enc, callback) { - if (file.isNull() || !file.contents || path.extname(file.path).toLowerCase() !== '.html') { - this.push(file); - callback(); - return; + return outputFile; } - var fileContent = file.contents.toString('utf8'); - var outputFile; + var stream = through.obj(function(file, enc, callback) { + if (file.isNull() || !file.contents || path.extname(file.path).toLowerCase() !== '.html') { + this.push(file); + callback(); + return; + } - // Build typescript view class. - if (options.typeScriptViewFileFormat) { - this.push(generate(typeScriptGenerator, fileContent, options.typeScriptViewFileFormat, file)); - } + var fileContent = file.contents.toString('utf8'); + var outputFile; - // Build typescript view model interface. - if (options.typeScriptViewModelFileFormat) { - this.push(generate(typeScriptViewModelGenerator, fileContent, options.typeScriptViewModelFileFormat, file)); - } + // Build typescript view class. + if (options.typeScriptViewFileFormat) { + this.push(generate(typeScriptGenerator, fileContent, options.typeScriptViewFileFormat, file)); + } + + // Build typescript view model interface. + if (options.typeScriptViewModelFileFormat) { + this.push(generate(typeScriptViewModelGenerator, fileContent, options.typeScriptViewModelFileFormat, file)); + } - callback(); - }); + callback(); + }); - return stream; + return stream; + }, + gulpTasks: { + dev: function(gulp) { + devTasks(gulp) + }, + release: function(gulp) { + releaseTasks(gulp); + }, + test: function(gulp) { + testTasks(gulp); + } + } }; \ No newline at end of file diff --git a/package.json b/package.json index 25d9abc..bfe04cd 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,23 @@ "gulpplugin" ], "dependencies": { - "through2": "^0.4.2", - "xmldom": "^0.1.19", + "autoprefixer-core": "^3.1.1", + "del": "^0.1.3", + "gulp": "^3.6.0", + "gulp-csstojs": "^1.0.1", + "gulp-less": "^1.3.2", + "gulp-minify-css": "^0.3.7", + "gulp-postcss": "^2.0.0", + "gulp-size": "^1.0.0", + "gulp-typescript": "^2.0.0", + "gulp-uglifyjs": "^0.4.2", "gulp-util": "~2.2.14", - "onejs-compiler": "^1.1.6" + "karma": "~0.12.24", + "onejs-compiler": "^1.1.6", + "require-dir": "^0.1.0", + "through2": "^0.4.2", + "xmldom": "^0.1.19" }, "devDependencies": { - "gulp": "^3.6.0" } } \ No newline at end of file diff --git a/tasks/dev.js b/tasks/dev.js index cbdd032..d0e1dd8 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -1,118 +1,119 @@ 'use strict'; -var gulp = require('gulp'); -var onejsCompiler = require('gulp-onejs-compiler'); -var tsc = require('gulp-typescript'); -var uglify = require('gulp-uglifyjs'); -var del = require('del'); -var less = require('gulp-less'); -var cssMinify = require('gulp-minify-css'); -var csstojs = require('gulp-csstojs'); -var postcss = require('gulp-postcss'); -var autoprefixer = require('autoprefixer-core'); +module.exports = function(gulp) { + var onejsCompiler = require('gulp-onejs-compiler').compiler; + var tsc = require('gulp-typescript'); + var uglify = require('gulp-uglifyjs'); + var del = require('del'); + var less = require('gulp-less'); + var cssMinify = require('gulp-minify-css'); + var csstojs = require('gulp-csstojs'); + var postcss = require('gulp-postcss'); + var autoprefixer = require('autoprefixer-core'); -/** - * The common directory structure OneJS uses - * along with some helpful glob patterns - */ -var paths = { - app: { - root: 'app/', - jsGlob: 'app/**/*.js', - min: { - root: 'app-min/' + /** + * The common directory structure OneJS uses + * along with some helpful glob patterns + */ + var paths = { + app: { + root: 'app/', + jsGlob: 'app/**/*.js', + min: { + root: 'app-min/' + } + }, + dist: { + root: 'dist/', + amd: 'dist/amd/', + commonjs: 'dist/commonjs/' + }, + src: { + root: 'src/', + htmlGlob: 'src/**/*.html', + lessGlob: 'src/**/*.less', + tsGlob: 'src/**/*.ts', + glob: 'src/**/*' + }, + staticFiles: [ + 'node_modules/requirejs/require.js' + ], + temp: { + root: 'temp/', + ts: 'temp/ts/', + test: 'temp/ts/test/', + tsGlob: 'temp/ts/**/*.ts' + }, + test: { + root: 'test/', + glob: 'test/**/*' } - }, - dist: { - root: 'dist/', - amd: 'dist/amd/', - commonjs: 'dist/commonjs/' - }, - src: { - root: 'src/', - htmlGlob: 'src/**/*.html', - lessGlob: 'src/**/*.less', - tsGlob: 'src/**/*.ts', - glob: 'src/**/*' - }, - staticFiles: [ - 'node_modules/requirejs/require.js' - ], - temp: { - root: 'temp/', - ts: 'temp/ts/', - test: 'temp/ts/test/', - tsGlob: 'temp/ts/**/*.ts' - }, - test: { - root: 'test/', - glob: 'test/**/*' - } -}; + }; -/** Cleans the temporary folders */ -gulp.task('clean', function(cb) { - del([paths.temp], cb); -}); + /** Cleans the temporary folders */ + gulp.task('clean', function(cb) { + del([paths.temp.root], cb); + }); -/** Runs LESS compiler, auto-prefixer, and uglify, then creates js modules and outputs to temp folder */ -gulp.task('less-to-js', function() { - return gulp.src(paths.src.lessGlob) - .pipe(less()) - .pipe(postcss([autoprefixer()])) - .pipe(cssMinify()) - .pipe(csstojs({ - typeScript: true - })) - .pipe(gulp.dest(paths.temp.ts)) -}); + /** Runs LESS compiler, auto-prefixer, and uglify, then creates js modules and outputs to temp folder */ + gulp.task('less-to-js', function() { + return gulp.src(paths.src.lessGlob) + .pipe(less()) + .pipe(postcss([autoprefixer()])) + .pipe(cssMinify()) + .pipe(csstojs({ + typeScript: true + })) + .pipe(gulp.dest(paths.temp.ts)) + }); -/** Compiles OneJS html templates */ -gulp.task('onejs-html', function() { - return gulp.src(paths.src.htmlGlob) - .pipe(onejsCompiler()) - .pipe(gulp.dest(paths.temp.ts)); -}); + /** Compiles OneJS html templates */ + gulp.task('onejs-html', function() { + return gulp.src(paths.src.htmlGlob) + .pipe(onejsCompiler()) + .pipe(gulp.dest(paths.temp.ts)); + }); -/** Copies OneJS TypeScript files to temp directory for futher compilation */ -gulp.task('onejs-ts', function() { - return gulp.src(paths.src.tsGlob) - .pipe(gulp.dest(paths.temp.ts)); -}) + /** Copies OneJS TypeScript files to temp directory for futher compilation */ + gulp.task('onejs-ts', function() { + return gulp.src(paths.src.tsGlob) + .pipe(gulp.dest(paths.temp.ts)); + }) -/** Runs the basic pre-processing steps before compilation */ -gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js']); + /** Runs the basic pre-processing steps before compilation */ + gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js']); -/** Runs the TypeScript amd compiler over your application .ts files */ -gulp.task('tsc-amd', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'amd' - })) - .pipe(gulp.dest(paths.app.root)) - .pipe(gulp.dest(paths.dist.amd)); -}); + /** Runs the TypeScript amd compiler over your application .ts files */ + gulp.task('tsc-amd', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'amd' + })) + .pipe(gulp.dest(paths.app.root)) + .pipe(gulp.dest(paths.dist.amd)); + }); -/** Runs the TypeScript commonjs compiler over your application .ts files */ -gulp.task('tsc-commonjs', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'commonjs' - })) - .pipe(gulp.dest(paths.app.root)) - .pipe(gulp.dest(paths.dist.commonjs)); -}); + /** Runs the TypeScript commonjs compiler over your application .ts files */ + gulp.task('tsc-commonjs', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'commonjs' + })) + .pipe(gulp.dest(paths.app.root)) + .pipe(gulp.dest(paths.dist.commonjs)); + }); -/** Copies the static files to your application path */ -gulp.task('copy-static-files', function() { - return gulp.src(paths.staticFiles) - .pipe(gulp.dest(paths.app.root)) -}); + /** Copies the static files to your application path */ + gulp.task('copy-static-files', function() { + return gulp.src(paths.staticFiles) + .pipe(gulp.dest(paths.app.root)) + }); -/** Watches your src folder for changes, and runs the default build task */ -gulp.task('watch', function() { - gulp.watch(paths.src.glob, ['build']); -}); + /** Watches your src folder for changes, and runs the default build task */ + gulp.task('watch', function() { + gulp.watch(paths.src.glob, ['build']); + }); -/** Default dev task for building */ -gulp.task('build', ['tsc-amd', 'copy-static-files']); + /** Default dev task for building */ + gulp.task('build', ['tsc-amd', 'copy-static-files']); +}; \ No newline at end of file diff --git a/tasks/release.js b/tasks/release.js index 684f648..a45972f 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -1,34 +1,36 @@ 'use strict'; -var size = require('gulp-size'); +module.exports = function(gulp) { + var size = require('gulp-size'); -gulp.task('minify', ['tsc-amd'], function() { - return gulp.src([paths.app.jsGlob]) - .pipe(uglify()) - .pipe(size({ - gzip: true - })) - .pipe(gulp.dest(paths.app.min.root)); -}); + gulp.task('minify', ['tsc-amd'], function() { + return gulp.src([paths.app.jsGlob]) + .pipe(uglify()) + .pipe(size({ + gzip: true + })) + .pipe(gulp.dest(paths.app.min.root)); + }); -gulp.task('minify-dist', ['minify'], function() { - return gulp.src([paths.app.jsGlob]) - .pipe(uglify()) - .pipe(size({ - gzip: true - })) - .pipe(gulp.dest(paths.dist.amd)); -}); + gulp.task('minify-dist', ['minify'], function() { + return gulp.src([paths.app.jsGlob]) + .pipe(uglify()) + .pipe(size({ + gzip: true + })) + .pipe(gulp.dest(paths.dist.amd)); + }); -/** Copies the minified static files to your application path */ -gulp.task('copy-static-files-minified', function() { - return gulp.src(paths.staticFiles) - .pipe(uglify()) - .pipe(gulp.dest(paths.app.min.root)); -}); + /** Copies the minified static files to your application path */ + gulp.task('copy-static-files-minified', function() { + return gulp.src(paths.staticFiles) + .pipe(uglify()) + .pipe(gulp.dest(paths.app.min.root)); + }); -/** Builds the minified version of your app */ -gulp.task('build-minify', ['minify', 'copy-static-files-minified']); + /** Builds the minified version of your app */ + gulp.task('build-minify', ['minify', 'copy-static-files-minified']); -/** Builds the distributable version of your app */ -gulp.task('build-dist', ['minify-dist']); + /** Builds the distributable version of your app */ + gulp.task('build-dist', ['minify-dist']); +}; \ No newline at end of file diff --git a/tasks/test.js b/tasks/test.js index c7b18a4..91b383b 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -1,15 +1,17 @@ 'use strict'; -var karma = require('karma').server; +module.exports = function(gulp) { + var karma = require('karma').server; -gulp.task('test-preprocess', ['copy-deps'], function() { - return gulp.src(paths.test.glob) - .pipe(gulp.dest(paths.temp.test)); -}); + gulp.task('test-preprocess', ['copy-deps'], function() { + return gulp.src(paths.test.glob) + .pipe(gulp.dest(paths.temp.test)); + }); -gulp.task('test', ['tsc-commonjs', 'copy-static-files'], function (done) { - karma.start({ - configFile: __dirname + '/karma.conf.js', - singleRun: true - }, done); -}); + gulp.task('test', ['tsc-commonjs', 'copy-static-files'], function (done) { + karma.start({ + configFile: __dirname + '/karma.conf.js', + singleRun: true + }, done); + }); +} \ No newline at end of file From ba10da438c2eb5dc2217e66a7afe9517d08bec74 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 14:55:41 -0800 Subject: [PATCH 03/20] Add gulp nuke and add a way to register all tasks at once --- index.js | 7 ++++++- tasks/dev.js | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 71c268a..d67ea4a 100644 --- a/index.js +++ b/index.js @@ -66,13 +66,18 @@ module.exports = { }, gulpTasks: { dev: function(gulp) { - devTasks(gulp) + devTasks(gulp); }, release: function(gulp) { releaseTasks(gulp); }, test: function(gulp) { testTasks(gulp); + }, + all: function(gulp) { + devTasks(gulp); + releaseTasks(gulp); + testTasks(gulp); } } }; \ No newline at end of file diff --git a/tasks/dev.js b/tasks/dev.js index d0e1dd8..8c65994 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -50,6 +50,11 @@ module.exports = function(gulp) { } }; + /** Removes all built files, keeping only source */ + gulp.task('nuke', function(cb) { + del([paths.temp.root, paths.app.root, paths.app.min.root], cb); + }); + /** Cleans the temporary folders */ gulp.task('clean', function(cb) { del([paths.temp.root], cb); From 7ccf16f77b3228be07b246d7bd6eb599c657ea70 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 14:59:08 -0800 Subject: [PATCH 04/20] Move around paths obj, added some comments --- index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++------ tasks/dev.js | 41 +---------------------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/index.js b/index.js index d67ea4a..8d1f073 100644 --- a/index.js +++ b/index.js @@ -65,19 +65,58 @@ module.exports = { return stream; }, gulpTasks: { + paths: { + //The common directory structure OneJS uses along with some helpful glob patterns + app: { + root: 'app/', + jsGlob: 'app/**/*.js', + min: { + root: 'app-min/' + } + }, + dist: { + root: 'dist/', + amd: 'dist/amd/', + commonjs: 'dist/commonjs/' + }, + src: { + root: 'src/', + htmlGlob: 'src/**/*.html', + lessGlob: 'src/**/*.less', + tsGlob: 'src/**/*.ts', + glob: 'src/**/*' + }, + staticFiles: [ + 'node_modules/requirejs/require.js' + ], + temp: { + root: 'temp/', + ts: 'temp/ts/', + test: 'temp/ts/test/', + tsGlob: 'temp/ts/**/*.ts' + }, + test: { + root: 'test/', + glob: 'test/**/*' + } + }, dev: function(gulp) { - devTasks(gulp); + // Registers the gulp tasks found in tasks/dev.js + devTasks(gulp, this.paths); }, release: function(gulp) { - releaseTasks(gulp); + // Registers the gulp tasks found in tasks/release.js + releaseTasks(gulp, this.paths); }, test: function(gulp) { - testTasks(gulp); + // Registers the gulp tasks found in tasks/test.js + testTasks(gulp, this.paths); }, all: function(gulp) { - devTasks(gulp); - releaseTasks(gulp); - testTasks(gulp); + // Registers all the gulp tasks found in tasks/*.js + this.dev(gulp); + this.release(gulp); + this.test(gulp); } } }; \ No newline at end of file diff --git a/tasks/dev.js b/tasks/dev.js index 8c65994..af1453a 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(gulp) { +module.exports = function(gulp, paths) { var onejsCompiler = require('gulp-onejs-compiler').compiler; var tsc = require('gulp-typescript'); var uglify = require('gulp-uglifyjs'); @@ -11,45 +11,6 @@ module.exports = function(gulp) { var postcss = require('gulp-postcss'); var autoprefixer = require('autoprefixer-core'); - /** - * The common directory structure OneJS uses - * along with some helpful glob patterns - */ - var paths = { - app: { - root: 'app/', - jsGlob: 'app/**/*.js', - min: { - root: 'app-min/' - } - }, - dist: { - root: 'dist/', - amd: 'dist/amd/', - commonjs: 'dist/commonjs/' - }, - src: { - root: 'src/', - htmlGlob: 'src/**/*.html', - lessGlob: 'src/**/*.less', - tsGlob: 'src/**/*.ts', - glob: 'src/**/*' - }, - staticFiles: [ - 'node_modules/requirejs/require.js' - ], - temp: { - root: 'temp/', - ts: 'temp/ts/', - test: 'temp/ts/test/', - tsGlob: 'temp/ts/**/*.ts' - }, - test: { - root: 'test/', - glob: 'test/**/*' - } - }; - /** Removes all built files, keeping only source */ gulp.task('nuke', function(cb) { del([paths.temp.root, paths.app.root, paths.app.min.root], cb); From 44d5470c147cb05ebeced124f6d20e05d3bd2b66 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 16:00:18 -0800 Subject: [PATCH 05/20] Basic OneJS app building works --- index.js | 16 +++++++++++----- tasks/dev.js | 30 +++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 8d1f073..79501a2 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ module.exports = { }, gulpTasks: { paths: { - //The common directory structure OneJS uses along with some helpful glob patterns + // The common directory structure OneJS uses along with some helpful glob patterns app: { root: 'app/', jsGlob: 'app/**/*.js', @@ -86,14 +86,20 @@ module.exports = { tsGlob: 'src/**/*.ts', glob: 'src/**/*' }, - staticFiles: [ - 'node_modules/requirejs/require.js' - ], + staticFiles: { + js: [ + 'node_modules/requirejs/require.js' + ], + }, + onejsFiles: { + dts: 'bower_components/onejs/dist/amd/*.ts', + js: 'bower_components/onejs/dist/amd/*.js' + }, temp: { root: 'temp/', ts: 'temp/ts/', test: 'temp/ts/test/', - tsGlob: 'temp/ts/**/*.ts' + tsGlob: 'temp/ts/**/!(*.d.ts)' }, test: { root: 'test/', diff --git a/tasks/dev.js b/tasks/dev.js index af1453a..7cf5c15 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -13,7 +13,7 @@ module.exports = function(gulp, paths) { /** Removes all built files, keeping only source */ gulp.task('nuke', function(cb) { - del([paths.temp.root, paths.app.root, paths.app.min.root], cb); + del([paths.temp.root, paths.app.root, paths.app.min.root, paths.dist.root], cb); }); /** Cleans the temporary folders */ @@ -21,6 +21,24 @@ module.exports = function(gulp, paths) { del([paths.temp.root], cb); }); + /** Copies static (non-OneJS) js files to app path */ + gulp.task('copy-static-js-files', function() { + return gulp.src(paths.staticFiles.js) + .pipe(gulp.dest(paths.app.root)); + }); + + /** Copies .d.ts files from OneJS to temp path to compile against */ + gulp.task('copy-onejs-dts-files', function() { + return gulp.src(paths.onejsFiles.dts) + .pipe(gulp.dest(paths.temp.ts + 'onejs/')); + }); + + /** Cupies static OneJS js files to app path */ + gulp.task('copy-onejs-js-files', function() { + return gulp.src(paths.onejsFiles.js) + .pipe(gulp.dest(paths.app.root + 'onejs/')); + }); + /** Runs LESS compiler, auto-prefixer, and uglify, then creates js modules and outputs to temp folder */ gulp.task('less-to-js', function() { return gulp.src(paths.src.lessGlob) @@ -47,7 +65,7 @@ module.exports = function(gulp, paths) { }) /** Runs the basic pre-processing steps before compilation */ - gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js']); + gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js', 'copy-onejs-dts-files']); /** Runs the TypeScript amd compiler over your application .ts files */ gulp.task('tsc-amd', ['tsc-preprocess'], function() { @@ -69,17 +87,11 @@ module.exports = function(gulp, paths) { .pipe(gulp.dest(paths.dist.commonjs)); }); - /** Copies the static files to your application path */ - gulp.task('copy-static-files', function() { - return gulp.src(paths.staticFiles) - .pipe(gulp.dest(paths.app.root)) - }); - /** Watches your src folder for changes, and runs the default build task */ gulp.task('watch', function() { gulp.watch(paths.src.glob, ['build']); }); /** Default dev task for building */ - gulp.task('build', ['tsc-amd', 'copy-static-files']); + gulp.task('build', ['tsc-amd', 'copy-static-js-files', 'copy-onejs-js-files']); }; \ No newline at end of file From 6cebc91a6e6c6dbaf1bdcff0bba21de84e1922ef Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 17:21:21 -0800 Subject: [PATCH 06/20] Basic release works --- index.js | 3 ++- package.json | 1 + tasks/dev.js | 4 ++-- tasks/release.js | 20 ++++++-------------- tasks/test.js | 6 +++--- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 79501a2..f25facc 100644 --- a/index.js +++ b/index.js @@ -103,7 +103,8 @@ module.exports = { }, test: { root: 'test/', - glob: 'test/**/*' + glob: 'test/**/*', + karmaConf: 'test/karma.conf.js' } }, dev: function(gulp) { diff --git a/package.json b/package.json index bfe04cd..11f7897 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "gulp-less": "^1.3.2", "gulp-minify-css": "^0.3.7", "gulp-postcss": "^2.0.0", + "gulp-rename": "^1.2.0", "gulp-size": "^1.0.0", "gulp-typescript": "^2.0.0", "gulp-uglifyjs": "^0.4.2", diff --git a/tasks/dev.js b/tasks/dev.js index 7cf5c15..e2d0d67 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -74,7 +74,7 @@ module.exports = function(gulp, paths) { module: 'amd' })) .pipe(gulp.dest(paths.app.root)) - .pipe(gulp.dest(paths.dist.amd)); + //.pipe(gulp.dest(paths.dist.amd)); }); /** Runs the TypeScript commonjs compiler over your application .ts files */ @@ -84,7 +84,7 @@ module.exports = function(gulp, paths) { module: 'commonjs' })) .pipe(gulp.dest(paths.app.root)) - .pipe(gulp.dest(paths.dist.commonjs)); + //.pipe(gulp.dest(paths.dist.commonjs)); }); /** Watches your src folder for changes, and runs the default build task */ diff --git a/tasks/release.js b/tasks/release.js index a45972f..2c561fb 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -1,36 +1,28 @@ 'use strict'; -module.exports = function(gulp) { +module.exports = function(gulp, paths) { var size = require('gulp-size'); + var uglify = require('gulp-uglifyjs'); + var rename = require('gulp-rename'); + /** Creates a minified version of your application */ gulp.task('minify', ['tsc-amd'], function() { return gulp.src([paths.app.jsGlob]) .pipe(uglify()) .pipe(size({ gzip: true })) + .pipe(rename('app.min.js')) .pipe(gulp.dest(paths.app.min.root)); }); - gulp.task('minify-dist', ['minify'], function() { - return gulp.src([paths.app.jsGlob]) - .pipe(uglify()) - .pipe(size({ - gzip: true - })) - .pipe(gulp.dest(paths.dist.amd)); - }); - /** Copies the minified static files to your application path */ gulp.task('copy-static-files-minified', function() { - return gulp.src(paths.staticFiles) + return gulp.src(paths.staticFiles.js) .pipe(uglify()) .pipe(gulp.dest(paths.app.min.root)); }); /** Builds the minified version of your app */ gulp.task('build-minify', ['minify', 'copy-static-files-minified']); - - /** Builds the distributable version of your app */ - gulp.task('build-dist', ['minify-dist']); }; \ No newline at end of file diff --git a/tasks/test.js b/tasks/test.js index 91b383b..4a8effc 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(gulp) { +module.exports = function(gulp, paths) { var karma = require('karma').server; gulp.task('test-preprocess', ['copy-deps'], function() { @@ -8,9 +8,9 @@ module.exports = function(gulp) { .pipe(gulp.dest(paths.temp.test)); }); - gulp.task('test', ['tsc-commonjs', 'copy-static-files'], function (done) { + gulp.task('test', ['tsc-commonjs'], function (done) { karma.start({ - configFile: __dirname + '/karma.conf.js', + configFile: paths.test.karmaConf, singleRun: true }, done); }); From 6a072c01f21375d4e50de0db6626ea2275f2412d Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Thu, 20 Nov 2014 17:45:35 -0800 Subject: [PATCH 07/20] Mix in options, update test task --- index.js | 28 ++++++++++++++++++---------- tasks/dev.js | 5 ++++- tasks/release.js | 5 ++++- tasks/test.js | 13 ++++++++----- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index f25facc..f6aa8d5 100644 --- a/index.js +++ b/index.js @@ -107,23 +107,31 @@ module.exports = { karmaConf: 'test/karma.conf.js' } }, - dev: function(gulp) { + dev: function(options) { // Registers the gulp tasks found in tasks/dev.js - devTasks(gulp, this.paths); + devTasks(this.mixOptions(options)); }, - release: function(gulp) { + release: function(options) { // Registers the gulp tasks found in tasks/release.js - releaseTasks(gulp, this.paths); + releaseTasks(this.mixOptions(options)); }, - test: function(gulp) { + test: function(options) { // Registers the gulp tasks found in tasks/test.js - testTasks(gulp, this.paths); + testTasks(this.mixOptions(options)); }, - all: function(gulp) { + all: function(options) { // Registers all the gulp tasks found in tasks/*.js - this.dev(gulp); - this.release(gulp); - this.test(gulp); + this.dev(options); + this.release(options); + this.test(options); + }, + mixOptions: function(options) { + return { + gulp: options.gulp, + rootDir: options.rootDir || __dirname, + paths: options.paths || this.paths, + karma: options.karma + } } } }; \ No newline at end of file diff --git a/tasks/dev.js b/tasks/dev.js index e2d0d67..d909d52 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(gulp, paths) { +module.exports = function(options) { var onejsCompiler = require('gulp-onejs-compiler').compiler; var tsc = require('gulp-typescript'); var uglify = require('gulp-uglifyjs'); @@ -11,6 +11,9 @@ module.exports = function(gulp, paths) { var postcss = require('gulp-postcss'); var autoprefixer = require('autoprefixer-core'); + var gulp = options.gulp; + var paths = options.paths; + /** Removes all built files, keeping only source */ gulp.task('nuke', function(cb) { del([paths.temp.root, paths.app.root, paths.app.min.root, paths.dist.root], cb); diff --git a/tasks/release.js b/tasks/release.js index 2c561fb..0256b5e 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -1,10 +1,13 @@ 'use strict'; -module.exports = function(gulp, paths) { +module.exports = function(options) { var size = require('gulp-size'); var uglify = require('gulp-uglifyjs'); var rename = require('gulp-rename'); + var gulp = options.gulp; + var paths = options.paths; + /** Creates a minified version of your application */ gulp.task('minify', ['tsc-amd'], function() { return gulp.src([paths.app.jsGlob]) diff --git a/tasks/test.js b/tasks/test.js index 4a8effc..f837692 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -1,16 +1,19 @@ 'use strict'; -module.exports = function(gulp, paths) { - var karma = require('karma').server; +module.exports = function(options) { + var karma = options.karma; + var gulp = options.gulp; + var paths = options.paths; + var rootDir = options.rootDir; - gulp.task('test-preprocess', ['copy-deps'], function() { + gulp.task('test-preprocess', ['build'], function() { return gulp.src(paths.test.glob) .pipe(gulp.dest(paths.temp.test)); }); - gulp.task('test', ['tsc-commonjs'], function (done) { + gulp.task('test', ['test-preprocess'], function (done) { karma.start({ - configFile: paths.test.karmaConf, + configFile: rootDir + '/karma.conf.js', singleRun: true }, done); }); From a8b7ad9f49c6772ed64a3368dccba58b7a9297c3 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 10:02:44 -0800 Subject: [PATCH 08/20] Dist tasks working --- tasks/dev.js | 6 ++---- tasks/release.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tasks/dev.js b/tasks/dev.js index d909d52..47fd7b1 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -76,8 +76,7 @@ module.exports = function(options) { .pipe(tsc({ module: 'amd' })) - .pipe(gulp.dest(paths.app.root)) - //.pipe(gulp.dest(paths.dist.amd)); + .pipe(gulp.dest(paths.app.root)); }); /** Runs the TypeScript commonjs compiler over your application .ts files */ @@ -86,8 +85,7 @@ module.exports = function(options) { .pipe(tsc({ module: 'commonjs' })) - .pipe(gulp.dest(paths.app.root)) - //.pipe(gulp.dest(paths.dist.commonjs)); + .pipe(gulp.dest(paths.app.root)); }); /** Watches your src folder for changes, and runs the default build task */ diff --git a/tasks/release.js b/tasks/release.js index 0256b5e..3303498 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -4,6 +4,7 @@ module.exports = function(options) { var size = require('gulp-size'); var uglify = require('gulp-uglifyjs'); var rename = require('gulp-rename'); + var tsc = require('gulp-typescript'); var gulp = options.gulp; var paths = options.paths; @@ -26,6 +27,27 @@ module.exports = function(options) { .pipe(gulp.dest(paths.app.min.root)); }); + /** Creates the amd distributable directory */ + gulp.task('dist-amd', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'amd' + })) + .pipe(gulp.dest(paths.dist.amd)) + }); + + /** Creates the commonjs distributable directory */ + gulp.task('dist-commonjs', ['tsc-preprocess'], function() { + return gulp.src(paths.temp.tsGlob) + .pipe(tsc({ + module: 'commonjs' + })) + .pipe(gulp.dest(paths.dist.commonjs)) + }); + + /** Creates both dist flavors */ + gulp.task('dist', ['dist-commonjs', 'dist-amd']); + /** Builds the minified version of your app */ gulp.task('build-minify', ['minify', 'copy-static-files-minified']); }; \ No newline at end of file From 9a89f471d851a9bfbc842d8cc8877f7d72f80c6a Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 11:00:35 -0800 Subject: [PATCH 09/20] Working on release tasks for version bumping --- index.js | 1 + package.json | 75 +++++++++++++++++++++++++----------------------- tasks/dev.js | 3 ++ tasks/release.js | 44 ++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index f6aa8d5..c617474 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,7 @@ module.exports = { dts: 'bower_components/onejs/dist/amd/*.ts', js: 'bower_components/onejs/dist/amd/*.js' }, + release: 'releaseTemp/', temp: { root: 'temp/', ts: 'temp/ts/', diff --git a/package.json b/package.json index 11f7897..6fe7316 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,40 @@ { - "name": "gulp-onejs-compiler", - "version": "1.1.60", - "description": "Compiles OneJS html templates and generates a variety of output.", - "license": "MIT", - "repository": "http://github.com/onejstoolkit/gulp-onejs-compiler", - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "mocha" - }, - "keywords": [ - "gulpplugin" - ], - "dependencies": { - "autoprefixer-core": "^3.1.1", - "del": "^0.1.3", - "gulp": "^3.6.0", - "gulp-csstojs": "^1.0.1", - "gulp-less": "^1.3.2", - "gulp-minify-css": "^0.3.7", - "gulp-postcss": "^2.0.0", - "gulp-rename": "^1.2.0", - "gulp-size": "^1.0.0", - "gulp-typescript": "^2.0.0", - "gulp-uglifyjs": "^0.4.2", - "gulp-util": "~2.2.14", - "karma": "~0.12.24", - "onejs-compiler": "^1.1.6", - "require-dir": "^0.1.0", - "through2": "^0.4.2", - "xmldom": "^0.1.19" - }, - "devDependencies": { - } -} \ No newline at end of file + "name": "gulp-onejs-compiler", + "version": "1.1.60", + "description": "Compiles OneJS html templates and generates a variety of output.", + "license": "MIT", + "repository": "http://github.com/onejstoolkit/gulp-onejs-compiler", + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha" + }, + "keywords": [ + "gulpplugin" + ], + "dependencies": { + "autoprefixer-core": "^3.1.1", + "del": "^0.1.3", + "gulp": "^3.6.0", + "gulp-csstojs": "^1.0.1", + "gulp-git": "^0.5.4", + "gulp-less": "^1.3.2", + "gulp-minify-css": "^0.3.7", + "gulp-postcss": "^2.0.0", + "gulp-prompt": "^0.1.1", + "gulp-rename": "^1.2.0", + "gulp-size": "^1.0.0", + "gulp-typescript": "^2.0.0", + "gulp-uglifyjs": "^0.4.2", + "gulp-util": "~2.2.14", + "inquirer": "^0.8.0", + "karma": "~0.12.24", + "onejs-compiler": "^1.1.6", + "require-dir": "^0.1.0", + "semver": "^4.1.0", + "through2": "^0.4.2", + "xmldom": "^0.1.19" + }, + "devDependencies": {} +} diff --git a/tasks/dev.js b/tasks/dev.js index 47fd7b1..ab86052 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -95,4 +95,7 @@ module.exports = function(options) { /** Default dev task for building */ gulp.task('build', ['tsc-amd', 'copy-static-js-files', 'copy-onejs-js-files']); + + /** Our default task, but can be overridden by the users gulp file */ + gulp.task('default', ['build']); }; \ No newline at end of file diff --git a/tasks/release.js b/tasks/release.js index 3303498..243b0e0 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -5,9 +5,15 @@ module.exports = function(options) { var uglify = require('gulp-uglifyjs'); var rename = require('gulp-rename'); var tsc = require('gulp-typescript'); + var git = require('gulp-git'); + var inquirer = require('inquirer'); + var semver = require('semver'); + var prompt = require('gulp-prompt'); + var fs = require('fs'); var gulp = options.gulp; var paths = options.paths; + var rootDir = options.rootDir; /** Creates a minified version of your application */ gulp.task('minify', ['tsc-amd'], function() { @@ -48,6 +54,44 @@ module.exports = function(options) { /** Creates both dist flavors */ gulp.task('dist', ['dist-commonjs', 'dist-amd']); + gulp.task('release', ['dist'], function() { + var questions = [ + { + type: 'list', + name: 'bumpType', + message: 'What type of version bump is this?', + choices: ['Major', 'Minor', 'Patch'] + }, + { + type: 'input', + name: 'message', + message: 'What is your git tag message?', + validate: function(input) { + // Do not allow empty git tag messages + return !(input.replace(/ /g,'') === ""); + } + } + ]; + + return gulp.src(rootDir + '/package.json') + .pipe(prompt.prompt(questions, function(answers) { + var packageJson = JSON.parse(fs.readFileSync(rootDir + '/package.json', 'utf8')); + var bowerJson = JSON.parse(fs.readFileSync(rootDir + '/bower.json', 'utf8')); + var newVersion = semver.inc(packageJson.version, answers.bumpType.toLowerCase()); + + git.tag('v' + newVersion, answers.message, function(err) { + if (err) { throw err; } + }); + + packageJson.version = newVersion; + bowerJson.version = newVersion; + + fs.writeFileSync(rootDir + '/package.json', JSON.stringify(packageJson, null, 4)); + + fs.writeFileSync(rootDir + '/bower.json', JSON.stringify(bowerJson, null, 4)); + })); + }); + /** Builds the minified version of your app */ gulp.task('build-minify', ['minify', 'copy-static-files-minified']); }; \ No newline at end of file From 0c15d112f4d1f6278742f7a39db4bc838bedb373 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 12:45:20 -0800 Subject: [PATCH 10/20] Release with automatic version bumping based on user input works --- index.js | 8 +++- tasks/release.js | 101 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 82 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index c617474..27d441f 100644 --- a/index.js +++ b/index.js @@ -77,7 +77,8 @@ module.exports = { dist: { root: 'dist/', amd: 'dist/amd/', - commonjs: 'dist/commonjs/' + commonjs: 'dist/commonjs/', + glob: 'dist/**/**/*' }, src: { root: 'src/', @@ -95,7 +96,10 @@ module.exports = { dts: 'bower_components/onejs/dist/amd/*.ts', js: 'bower_components/onejs/dist/amd/*.js' }, - release: 'releaseTemp/', + release: { + root: 'releaseTemp/', + glob: 'releaseTemp/**/**/*' + }, temp: { root: 'temp/', ts: 'temp/ts/', diff --git a/tasks/release.js b/tasks/release.js index 243b0e0..8905a4a 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -10,11 +10,15 @@ module.exports = function(options) { var semver = require('semver'); var prompt = require('gulp-prompt'); var fs = require('fs'); + var del = require('del'); var gulp = options.gulp; var paths = options.paths; var rootDir = options.rootDir; + var bumpType; + var newVersion; + /** Creates a minified version of your application */ gulp.task('minify', ['tsc-amd'], function() { return gulp.src([paths.app.jsGlob]) @@ -39,7 +43,7 @@ module.exports = function(options) { .pipe(tsc({ module: 'amd' })) - .pipe(gulp.dest(paths.dist.amd)) + .pipe(gulp.dest(paths.dist.amd)); }); /** Creates the commonjs distributable directory */ @@ -48,50 +52,97 @@ module.exports = function(options) { .pipe(tsc({ module: 'commonjs' })) - .pipe(gulp.dest(paths.dist.commonjs)) + .pipe(gulp.dest(paths.dist.commonjs)); }); /** Creates both dist flavors */ gulp.task('dist', ['dist-commonjs', 'dist-amd']); - gulp.task('release', ['dist'], function() { + gulp.task('pre-release', ['dist'], function() { + return gulp.src(paths.dist.glob) + .pipe(gulp.dest(paths.release.root)); + }); + + gulp.task('prompt-release', ['pre-release'], function() { var questions = [ { type: 'list', name: 'bumpType', message: 'What type of version bump is this?', choices: ['Major', 'Minor', 'Patch'] - }, - { - type: 'input', - name: 'message', - message: 'What is your git tag message?', - validate: function(input) { - // Do not allow empty git tag messages - return !(input.replace(/ /g,'') === ""); - } } ]; - return gulp.src(rootDir + '/package.json') + return gulp.src('package.json') .pipe(prompt.prompt(questions, function(answers) { - var packageJson = JSON.parse(fs.readFileSync(rootDir + '/package.json', 'utf8')); - var bowerJson = JSON.parse(fs.readFileSync(rootDir + '/bower.json', 'utf8')); - var newVersion = semver.inc(packageJson.version, answers.bumpType.toLowerCase()); + bumpType = answers.bumpType; + writeUpdatedVersionNumbers(); + })); + }); - git.tag('v' + newVersion, answers.message, function(err) { - if (err) { throw err; } - }); + var writeUpdatedVersionNumbers = function() { + var packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + var bowerJson = JSON.parse(fs.readFileSync('bower.json', 'utf8')); + newVersion = semver.inc(packageJson.version, bumpType.toLowerCase()); - packageJson.version = newVersion; - bowerJson.version = newVersion; + packageJson.version = newVersion; + bowerJson.version = newVersion; - fs.writeFileSync(rootDir + '/package.json', JSON.stringify(packageJson, null, 4)); + fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 4)); - fs.writeFileSync(rootDir + '/bower.json', JSON.stringify(bowerJson, null, 4)); - })); + fs.writeFileSync('bower.json', JSON.stringify(bowerJson, null, 4)); + } + + var generateBumpMessage = function() { + return 'Version bump to ' + newVersion; + } + + gulp.task('commit-master', ['prompt-release'], function() { + return gulp.src([rootDir + '/package.json', rootDir + '/bower.json']) + .pipe(git.commit(generateBumpMessage())); + }); + + gulp.task('checkout-dist', ['commit-master'], function(cb) { + git.checkout('dist', function(err) { + if (err) { return cb(err); } + cb(); + }); + }); + + gulp.task('copy-dist-bits', ['checkout-dist'], function() { + return gulp.src(paths.release.glob) + .pipe(gulp.dest(paths.dist.root)); + }); + + gulp.task('clean-temp-bits', ['copy-dist-bits'], function(cb) { + del([paths.release.root], cb); + }); + + gulp.task('write-version-updates', ['clean-temp-bits'], function() { + return writeUpdatedVersionNumbers(); + }); + + gulp.task('commit-dist', ['write-version-updates'], function() { + return gulp.src(['package.json', 'bower.json', 'dist/*']) + .pipe(git.commit(generateBumpMessage())); + }); + + gulp.task('write-dist-tag', ['commit-dist'], function(cb) { + return git.tag('v' + newVersion, generateBumpMessage(), function(err) { + if (err) { return cb(err); } + cb(); + }); }); + gulp.task('checkout-master', ['write-dist-tag'], function(cb) { + return git.checkout('master', function(err) { + if (err) { return cb(err); } + cb(); + }); + }); + + gulp.task('release', ['checkout-master']); + /** Builds the minified version of your app */ gulp.task('build-minify', ['minify', 'copy-static-files-minified']); -}; \ No newline at end of file +}; From 6be7ea716fef034fc0b83f0903f35f0a5b93a63a Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 12:47:33 -0800 Subject: [PATCH 11/20] Watch will run default task --- tasks/dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/dev.js b/tasks/dev.js index ab86052..75bc199 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -90,7 +90,7 @@ module.exports = function(options) { /** Watches your src folder for changes, and runs the default build task */ gulp.task('watch', function() { - gulp.watch(paths.src.glob, ['build']); + gulp.watch(paths.src.glob, ['default']); }); /** Default dev task for building */ From b13cf155b942e96ff39e67f8df03b4e6c5c80ac1 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 13:43:27 -0800 Subject: [PATCH 12/20] Add some comments and a blurb at the end of release --- index.js | 2 ++ tasks/release.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 27d441f..57b8ae9 100644 --- a/index.js +++ b/index.js @@ -97,6 +97,8 @@ module.exports = { js: 'bower_components/onejs/dist/amd/*.js' }, release: { + // These are temp directories that are only used when + // publishing to a dist branch root: 'releaseTemp/', glob: 'releaseTemp/**/**/*' }, diff --git a/tasks/release.js b/tasks/release.js index 8905a4a..fa26e6f 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -58,6 +58,13 @@ module.exports = function(options) { /** Creates both dist flavors */ gulp.task('dist', ['dist-commonjs', 'dist-amd']); + /** + * This next section of tasks are intentionally a bunch of small tasks + * so they can play nicely with Gulp's build system. + * Taks dealing with git, or writing back the package/bower.json files + * need to be synchronous, ergo the callback usage or sync versions + * of the node fs methods. + */ gulp.task('pre-release', ['dist'], function() { return gulp.src(paths.dist.glob) .pipe(gulp.dest(paths.release.root)); @@ -141,7 +148,10 @@ module.exports = function(options) { }); }); - gulp.task('release', ['checkout-master']); + /** The master task for bumping versions and publishing to dist branch */ + gulp.task('release', ['checkout-master'], function() { + console.log('Version bumped, please run `git push --tags` and `npm/bower publish` to make updates available.'); + });; /** Builds the minified version of your app */ gulp.task('build-minify', ['minify', 'copy-static-files-minified']); From f2cca7b9de300a5b468f25dcb7b7e517f13e41c8 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 13:59:09 -0800 Subject: [PATCH 13/20] Put bower and npm json files in paths, use references to that. Wrote a bunch of comments for the small gulp release tasks --- index.js | 5 ++++- tasks/release.js | 30 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 57b8ae9..6362e58 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,8 @@ module.exports = { root: 'dist/', amd: 'dist/amd/', commonjs: 'dist/commonjs/', - glob: 'dist/**/**/*' + glob: 'dist/**/**/*', + gitGlob: 'dist/*' }, src: { root: 'src/', @@ -91,6 +92,8 @@ module.exports = { js: [ 'node_modules/requirejs/require.js' ], + npmPackage: 'package.json', + bowerPackage: 'bower.json' }, onejsFiles: { dts: 'bower_components/onejs/dist/amd/*.ts', diff --git a/tasks/release.js b/tasks/release.js index fa26e6f..1da2607 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -65,11 +65,15 @@ module.exports = function(options) { * need to be synchronous, ergo the callback usage or sync versions * of the node fs methods. */ + + /** Temporarily copies the built folder to a temp dir so it will persist + when switching git branches that have different gitignores */ gulp.task('pre-release', ['dist'], function() { return gulp.src(paths.dist.glob) .pipe(gulp.dest(paths.release.root)); }); + /** Prompts the user for info about the version */ gulp.task('prompt-release', ['pre-release'], function() { var questions = [ { @@ -80,35 +84,39 @@ module.exports = function(options) { } ]; - return gulp.src('package.json') + return gulp.src(paths.staticFiles.npmPackage) .pipe(prompt.prompt(questions, function(answers) { bumpType = answers.bumpType; writeUpdatedVersionNumbers(); })); }); + /** Helper function to bump the version number and write it to the npm package and bower files */ var writeUpdatedVersionNumbers = function() { - var packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); - var bowerJson = JSON.parse(fs.readFileSync('bower.json', 'utf8')); + var packageJson = JSON.parse(fs.readFileSync(paths.staticFiles.npmPackage, 'utf8')); + var bowerJson = JSON.parse(fs.readFileSync(paths.staticFiles.bowerPackage, 'utf8')); newVersion = semver.inc(packageJson.version, bumpType.toLowerCase()); packageJson.version = newVersion; bowerJson.version = newVersion; - fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 4)); + fs.writeFileSync(paths.staticFiles.npmPackage, JSON.stringify(packageJson, null, 4)); - fs.writeFileSync('bower.json', JSON.stringify(bowerJson, null, 4)); + fs.writeFileSync(paths.staticFiles.bowerPackage, JSON.stringify(bowerJson, null, 4)); } + /** Helper function to generate a git message based on version */ var generateBumpMessage = function() { return 'Version bump to ' + newVersion; } + /** Commits the npm and bower packages on master */ gulp.task('commit-master', ['prompt-release'], function() { - return gulp.src([rootDir + '/package.json', rootDir + '/bower.json']) + return gulp.src([rootDir + '/' + paths.staticFiles.npmPackage, rootDir + '/' + paths.staticFiles.bowerPackage]) .pipe(git.commit(generateBumpMessage())); }); + /** Checks out the git dist branch */ gulp.task('checkout-dist', ['commit-master'], function(cb) { git.checkout('dist', function(err) { if (err) { return cb(err); } @@ -116,24 +124,29 @@ module.exports = function(options) { }); }); + /** Copies the dist files to their rightful location */ gulp.task('copy-dist-bits', ['checkout-dist'], function() { return gulp.src(paths.release.glob) .pipe(gulp.dest(paths.dist.root)); }); + /** Removes the temporary dist files */ gulp.task('clean-temp-bits', ['copy-dist-bits'], function(cb) { del([paths.release.root], cb); }); + /** Writes the bower and npm package files with new version number */ gulp.task('write-version-updates', ['clean-temp-bits'], function() { return writeUpdatedVersionNumbers(); }); + /** Commits the bower/npm package files and the dist folder */ gulp.task('commit-dist', ['write-version-updates'], function() { - return gulp.src(['package.json', 'bower.json', 'dist/*']) + return gulp.src([paths.staticFiles.npmPackage, paths.staticFiles.bowerPackage, paths.dist.gitGlob]) .pipe(git.commit(generateBumpMessage())); }); + /** Creates a git tag with the new version number */ gulp.task('write-dist-tag', ['commit-dist'], function(cb) { return git.tag('v' + newVersion, generateBumpMessage(), function(err) { if (err) { return cb(err); } @@ -141,6 +154,7 @@ module.exports = function(options) { }); }); + /** Checks out back to master branch */ gulp.task('checkout-master', ['write-dist-tag'], function(cb) { return git.checkout('master', function(err) { if (err) { return cb(err); } @@ -148,7 +162,7 @@ module.exports = function(options) { }); }); - /** The master task for bumping versions and publishing to dist branch */ + /** The main task for bumping versions and publishing to dist branch */ gulp.task('release', ['checkout-master'], function() { console.log('Version bumped, please run `git push --tags` and `npm/bower publish` to make updates available.'); });; From 6bec19757c150b31db801d1ffc20680610d2994d Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Fri, 21 Nov 2014 14:44:09 -0800 Subject: [PATCH 14/20] Don't copy test files to dist. Update with more comments --- index.js | 16 +++++++++++++++- tasks/dev.js | 11 ++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6362e58..868f478 100644 --- a/index.js +++ b/index.js @@ -68,6 +68,7 @@ module.exports = { paths: { // The common directory structure OneJS uses along with some helpful glob patterns app: { + // A website would consume files in this dir root: 'app/', jsGlob: 'app/**/*.js', min: { @@ -75,6 +76,7 @@ module.exports = { } }, dist: { + // Distributable structure root: 'dist/', amd: 'dist/amd/', commonjs: 'dist/commonjs/', @@ -82,6 +84,7 @@ module.exports = { gitGlob: 'dist/*' }, src: { + // The (non-test) source will live here root: 'src/', htmlGlob: 'src/**/*.html', lessGlob: 'src/**/*.less', @@ -89,6 +92,7 @@ module.exports = { glob: 'src/**/*' }, staticFiles: { + // Static files that may need to be copied/referenced js: [ 'node_modules/requirejs/require.js' ], @@ -96,6 +100,7 @@ module.exports = { bowerPackage: 'bower.json' }, onejsFiles: { + // OneJS files that will need to be copied during build process dts: 'bower_components/onejs/dist/amd/*.ts', js: 'bower_components/onejs/dist/amd/*.js' }, @@ -106,15 +111,24 @@ module.exports = { glob: 'releaseTemp/**/**/*' }, temp: { + // Temp staging dir for building root: 'temp/', ts: 'temp/ts/', test: 'temp/ts/test/', - tsGlob: 'temp/ts/**/!(*.d.ts)' + typings: 'temp/ts/typings/', + typingsGlob: 'temp/ts/typings/**/*.d.ts', + tsGlob: 'temp/ts/**/!(*.d.ts|*.test.ts)' }, test: { + // Test files will live here root: 'test/', glob: 'test/**/*', karmaConf: 'test/karma.conf.js' + }, + typings: { + // This dir is to match up with the structure of tsd: https://github.com/DefinitelyTyped/tsd + root: 'typings/', + glob: 'typings/**/*.d.ts' } }, dev: function(options) { diff --git a/tasks/dev.js b/tasks/dev.js index 75bc199..f0d7c08 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -30,13 +30,18 @@ module.exports = function(options) { .pipe(gulp.dest(paths.app.root)); }); + gulp.task('copy-static-dts-files', function() { + return gulp.src(paths.typings.glob) + .pipe(gulp.dest(paths.temp.typings)); + }); + /** Copies .d.ts files from OneJS to temp path to compile against */ gulp.task('copy-onejs-dts-files', function() { return gulp.src(paths.onejsFiles.dts) .pipe(gulp.dest(paths.temp.ts + 'onejs/')); }); - /** Cupies static OneJS js files to app path */ + /** Copies static OneJS js files to app path */ gulp.task('copy-onejs-js-files', function() { return gulp.src(paths.onejsFiles.js) .pipe(gulp.dest(paths.app.root + 'onejs/')); @@ -65,10 +70,10 @@ module.exports = function(options) { gulp.task('onejs-ts', function() { return gulp.src(paths.src.tsGlob) .pipe(gulp.dest(paths.temp.ts)); - }) + }); /** Runs the basic pre-processing steps before compilation */ - gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js', 'copy-onejs-dts-files']); + gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js', 'copy-onejs-dts-files', 'copy-static-dts-files']); /** Runs the TypeScript amd compiler over your application .ts files */ gulp.task('tsc-amd', ['tsc-preprocess'], function() { From 43d6300ff4b46ade496c0f3cb1551279eaddcae5 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Mon, 24 Nov 2014 09:51:10 -0800 Subject: [PATCH 15/20] Also include dev tasks for release and test since they require tasks from there --- index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 868f478..6312d90 100644 --- a/index.js +++ b/index.js @@ -136,12 +136,16 @@ module.exports = { devTasks(this.mixOptions(options)); }, release: function(options) { - // Registers the gulp tasks found in tasks/release.js - releaseTasks(this.mixOptions(options)); + // Registers the gulp tasks found in tasks/release.js and dev.js + var mixedOptions = this.mixOptions(options); + devTasks(mixedOptions); + releaseTasks(mixedOptions); }, test: function(options) { - // Registers the gulp tasks found in tasks/test.js - testTasks(this.mixOptions(options)); + // Registers the gulp tasks found in tasks/test.js and dev.js + var mixedOptions = this.mixOptions(options); + devTasks(mixedOptions); + testTasks(mixedOptions); }, all: function(options) { // Registers all the gulp tasks found in tasks/*.js @@ -158,4 +162,4 @@ module.exports = { } } } -}; \ No newline at end of file +}; From eea95d80c7ab09a7496e040815bffec37727a635 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Mon, 24 Nov 2014 11:49:09 -0800 Subject: [PATCH 16/20] Allow for user to pass in plugin options that get mixed in with our defaults. Fix a mac bug in require statement --- index.js | 6 +++++- package.json | 1 + tasks/dev.js | 19 ++++++++++--------- tasks/release.js | 16 ++++++++-------- tasks/test.js | 10 +++++++--- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 6312d90..41de853 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var typeScriptViewModelGenerator = require('onejs-compiler').TypeScriptViewModel var devTasks = require('./tasks/dev.js'); var releaseTasks = require('./tasks/release.js'); var testTasks = require('./tasks/test.js'); +var _ = require('lodash'); module.exports = { @@ -158,7 +159,10 @@ module.exports = { gulp: options.gulp, rootDir: options.rootDir || __dirname, paths: options.paths || this.paths, - karma: options.karma + karma: options.karma, + autoprefixerOptions: options.autoprefixerOptions || {}, + // Set our default to target ES5, but allow overrides from the user + tscOptions: _.merge({target: 'ES5'}, options.tscOptions) } } } diff --git a/package.json b/package.json index 6fe7316..cfd9820 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "gulp-util": "~2.2.14", "inquirer": "^0.8.0", "karma": "~0.12.24", + "lodash": "^2.4.1", "onejs-compiler": "^1.1.6", "require-dir": "^0.1.0", "semver": "^4.1.0", diff --git a/tasks/dev.js b/tasks/dev.js index f0d7c08..f2ab604 100644 --- a/tasks/dev.js +++ b/tasks/dev.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function(options) { - var onejsCompiler = require('gulp-onejs-compiler').compiler; + var onejsCompiler = require('../index.js').compiler; var tsc = require('gulp-typescript'); var uglify = require('gulp-uglifyjs'); var del = require('del'); @@ -10,9 +10,12 @@ module.exports = function(options) { var csstojs = require('gulp-csstojs'); var postcss = require('gulp-postcss'); var autoprefixer = require('autoprefixer-core'); + var _ = require('lodash'); var gulp = options.gulp; var paths = options.paths; + var autoprefixerOptions = options.autoprefixerOptions; + var tscOptions = options.tscOptions; /** Removes all built files, keeping only source */ gulp.task('nuke', function(cb) { @@ -51,7 +54,7 @@ module.exports = function(options) { gulp.task('less-to-js', function() { return gulp.src(paths.src.lessGlob) .pipe(less()) - .pipe(postcss([autoprefixer()])) + .pipe(postcss([autoprefixer(autoprefixerOptions)])) .pipe(cssMinify()) .pipe(csstojs({ typeScript: true @@ -78,18 +81,16 @@ module.exports = function(options) { /** Runs the TypeScript amd compiler over your application .ts files */ gulp.task('tsc-amd', ['tsc-preprocess'], function() { return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'amd' - })) + // Allow tscOption overrides, but ensure that we're targeting amd + .pipe(tsc(_.merge(tscOptions, {module: 'amd'}))) .pipe(gulp.dest(paths.app.root)); }); /** Runs the TypeScript commonjs compiler over your application .ts files */ gulp.task('tsc-commonjs', ['tsc-preprocess'], function() { return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'commonjs' - })) + // Allow tscOption overrides, but ensure that we're targeting commonjs + .pipe(tsc(_.merge(tscOptions, {module: 'commonjs'}))) .pipe(gulp.dest(paths.app.root)); }); @@ -103,4 +104,4 @@ module.exports = function(options) { /** Our default task, but can be overridden by the users gulp file */ gulp.task('default', ['build']); -}; \ No newline at end of file +}; diff --git a/tasks/release.js b/tasks/release.js index 1da2607..0c89602 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -11,10 +11,12 @@ module.exports = function(options) { var prompt = require('gulp-prompt'); var fs = require('fs'); var del = require('del'); + var _ = require('lodash'); var gulp = options.gulp; var paths = options.paths; var rootDir = options.rootDir; + var tscOptions = options.tscOptions; var bumpType; var newVersion; @@ -40,18 +42,16 @@ module.exports = function(options) { /** Creates the amd distributable directory */ gulp.task('dist-amd', ['tsc-preprocess'], function() { return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'amd' - })) + // Allow tscOption overrides, but ensure that we're targeting amd + .pipe(tsc(_.merge(tscOptions, {module: 'amd'}))) .pipe(gulp.dest(paths.dist.amd)); }); /** Creates the commonjs distributable directory */ gulp.task('dist-commonjs', ['tsc-preprocess'], function() { return gulp.src(paths.temp.tsGlob) - .pipe(tsc({ - module: 'commonjs' - })) + // Allow tscOption overrides, but ensure that we're targeting commonjs + .pipe(tsc(_.merge(tscOptions, {module: 'commonjs'}))) .pipe(gulp.dest(paths.dist.commonjs)); }); @@ -100,9 +100,9 @@ module.exports = function(options) { packageJson.version = newVersion; bowerJson.version = newVersion; - fs.writeFileSync(paths.staticFiles.npmPackage, JSON.stringify(packageJson, null, 4)); + fs.writeFileSync(paths.staticFiles.npmPackage, JSON.stringify(packageJson, null, 2)); - fs.writeFileSync(paths.staticFiles.bowerPackage, JSON.stringify(bowerJson, null, 4)); + fs.writeFileSync(paths.staticFiles.bowerPackage, JSON.stringify(bowerJson, null, 2)); } /** Helper function to generate a git message based on version */ diff --git a/tasks/test.js b/tasks/test.js index f837692..3364a1d 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -1,20 +1,24 @@ 'use strict'; module.exports = function(options) { + var _ = require('lodash'); + var karma = options.karma; var gulp = options.gulp; var paths = options.paths; var rootDir = options.rootDir; + var karmaOptions = options.karmaOptions; + gulp.task('test-preprocess', ['build'], function() { return gulp.src(paths.test.glob) .pipe(gulp.dest(paths.temp.test)); }); gulp.task('test', ['test-preprocess'], function (done) { - karma.start({ + karma.start(_.merge({ configFile: rootDir + '/karma.conf.js', singleRun: true - }, done); + }, karmaOptions), done); }); -} \ No newline at end of file +} From 020cb144bbe54e91cf5f4085567c719811dddbd3 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Tue, 25 Nov 2014 14:14:41 -0800 Subject: [PATCH 17/20] Fix up some test issues --- index.js | 2 +- tasks/test.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 41de853..4b7fe7f 100644 --- a/index.js +++ b/index.js @@ -118,7 +118,7 @@ module.exports = { test: 'temp/ts/test/', typings: 'temp/ts/typings/', typingsGlob: 'temp/ts/typings/**/*.d.ts', - tsGlob: 'temp/ts/**/!(*.d.ts|*.test.ts)' + tsGlob: 'temp/ts/**/**/*.ts' }, test: { // Test files will live here diff --git a/tasks/test.js b/tasks/test.js index 3364a1d..5b00a70 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -10,12 +10,14 @@ module.exports = function(options) { var karmaOptions = options.karmaOptions; - gulp.task('test-preprocess', ['build'], function() { + gulp.task('test-preprocess', function() { return gulp.src(paths.test.glob) .pipe(gulp.dest(paths.temp.test)); }); - gulp.task('test', ['test-preprocess'], function (done) { + gulp.task('test-build', ['test-preprocess', 'tsc-amd', 'copy-static-js-files', 'copy-onejs-js-files']); + + gulp.task('test', ['test-build', 'build'], function (done) { karma.start(_.merge({ configFile: rootDir + '/karma.conf.js', singleRun: true From 8df52dbedd0b746e60d5ec1cc73da61072bf2e27 Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Tue, 25 Nov 2014 15:12:35 -0800 Subject: [PATCH 18/20] Remove unneeded gulp file --- gulpfile.js | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index cd77af5..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); - -var paths = { - scripts: ['./*.js', '!./gulpfile.js'] -}; - -gulp.task('default', []); From 4e95430619e757674bbbffe3ce2b2f09bf0ef8df Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Wed, 26 Nov 2014 09:38:03 -0800 Subject: [PATCH 19/20] Only expose the compiler yet again --- index.js | 192 +++++++++++------------------------------------ package.json | 21 +----- tasks/dev.js | 107 -------------------------- tasks/release.js | 172 ------------------------------------------ tasks/test.js | 26 ------- 5 files changed, 43 insertions(+), 475 deletions(-) delete mode 100644 tasks/dev.js delete mode 100644 tasks/release.js delete mode 100644 tasks/test.js diff --git a/index.js b/index.js index 4b7fe7f..aeda49c 100644 --- a/index.js +++ b/index.js @@ -3,167 +3,59 @@ var through = require('through2'); var gutil = require('gulp-util'); var path = require('path'); -var typeScriptGenerator = require('onejs-compiler').TypeScriptGenerator; -var typeScriptViewModelGenerator = require('onejs-compiler').TypeScriptViewModelGenerator; -var devTasks = require('./tasks/dev.js'); -var releaseTasks = require('./tasks/release.js'); -var testTasks = require('./tasks/test.js'); -var _ = require('lodash'); +var typeScriptGenerator = require('onejs').TypeScriptGenerator; +var typeScriptViewModelGenerator = require('onejs').TypeScriptViewModelGenerator; -module.exports = { +module.exports = function(options) { + options = options || { + typeScriptViewFileFormat: '{{templateName}}.ts', + typeScriptViewModelFileFormat: 'I{{templateName}}Model.ts' + }; - compiler: function(options) { - options = options || { - typeScriptViewFileFormat: '{{templateName}}.ts', - typeScriptViewModelFileFormat: 'I{{templateName}}Model.ts' - }; + function getFileName(nameMatch, templateName) { + return nameMatch.replace('{{templateName}}', templateName); + } - function getFileName(nameMatch, templateName) { - return nameMatch.replace('{{templateName}}', templateName); - } + function generate(generatorType, templateContent, fileNameFormat, file) { + var generator = new generatorType(); + var outputFile = file.clone(); - function generate(generatorType, templateContent, fileNameFormat, file) { - var generator = new generatorType(); - var outputFile = file.clone(); + try { + outputFile.contents = new Buffer(generator.generate(templateContent)); + outputFile.path = file.path.replace(path.basename(file.path), getFileName(fileNameFormat, generator.template.name)); - try { - outputFile.contents = new Buffer(generator.generate(templateContent)); - outputFile.path = file.path.replace(path.basename(file.path), getFileName(fileNameFormat, generator.template.name)); + } catch (e) { + throw new gutil.PluginError({ + plugin: 'gulp-onejs-compiler', + message: 'Error parsing template: ' + file.path + '\n' + e + }); + } - } catch (e) { - throw new gutil.PluginError({ - plugin: 'gulp-onejs-compiler', - message: 'Error parsing template: ' + file.path + '\n' + e - }); - } + return outputFile; + } - return outputFile; + var stream = through.obj(function(file, enc, callback) { + if (file.isNull() || !file.contents || path.extname(file.path).toLowerCase() !== '.html') { + this.push(file); + callback(); + return; } - var stream = through.obj(function(file, enc, callback) { - if (file.isNull() || !file.contents || path.extname(file.path).toLowerCase() !== '.html') { - this.push(file); - callback(); - return; - } - - var fileContent = file.contents.toString('utf8'); - var outputFile; + var fileContent = file.contents.toString('utf8'); + var outputFile; - // Build typescript view class. - if (options.typeScriptViewFileFormat) { - this.push(generate(typeScriptGenerator, fileContent, options.typeScriptViewFileFormat, file)); - } + // Build typescript view class. + if (options.typeScriptViewFileFormat) { + this.push(generate(typeScriptGenerator, fileContent, options.typeScriptViewFileFormat, file)); + } - // Build typescript view model interface. - if (options.typeScriptViewModelFileFormat) { - this.push(generate(typeScriptViewModelGenerator, fileContent, options.typeScriptViewModelFileFormat, file)); - } + // Build typescript view model interface. + if (options.typeScriptViewModelFileFormat) { + this.push(generate(typeScriptViewModelGenerator, fileContent, options.typeScriptViewModelFileFormat, file)); + } - callback(); - }); + callback(); + }); - return stream; - }, - gulpTasks: { - paths: { - // The common directory structure OneJS uses along with some helpful glob patterns - app: { - // A website would consume files in this dir - root: 'app/', - jsGlob: 'app/**/*.js', - min: { - root: 'app-min/' - } - }, - dist: { - // Distributable structure - root: 'dist/', - amd: 'dist/amd/', - commonjs: 'dist/commonjs/', - glob: 'dist/**/**/*', - gitGlob: 'dist/*' - }, - src: { - // The (non-test) source will live here - root: 'src/', - htmlGlob: 'src/**/*.html', - lessGlob: 'src/**/*.less', - tsGlob: 'src/**/*.ts', - glob: 'src/**/*' - }, - staticFiles: { - // Static files that may need to be copied/referenced - js: [ - 'node_modules/requirejs/require.js' - ], - npmPackage: 'package.json', - bowerPackage: 'bower.json' - }, - onejsFiles: { - // OneJS files that will need to be copied during build process - dts: 'bower_components/onejs/dist/amd/*.ts', - js: 'bower_components/onejs/dist/amd/*.js' - }, - release: { - // These are temp directories that are only used when - // publishing to a dist branch - root: 'releaseTemp/', - glob: 'releaseTemp/**/**/*' - }, - temp: { - // Temp staging dir for building - root: 'temp/', - ts: 'temp/ts/', - test: 'temp/ts/test/', - typings: 'temp/ts/typings/', - typingsGlob: 'temp/ts/typings/**/*.d.ts', - tsGlob: 'temp/ts/**/**/*.ts' - }, - test: { - // Test files will live here - root: 'test/', - glob: 'test/**/*', - karmaConf: 'test/karma.conf.js' - }, - typings: { - // This dir is to match up with the structure of tsd: https://github.com/DefinitelyTyped/tsd - root: 'typings/', - glob: 'typings/**/*.d.ts' - } - }, - dev: function(options) { - // Registers the gulp tasks found in tasks/dev.js - devTasks(this.mixOptions(options)); - }, - release: function(options) { - // Registers the gulp tasks found in tasks/release.js and dev.js - var mixedOptions = this.mixOptions(options); - devTasks(mixedOptions); - releaseTasks(mixedOptions); - }, - test: function(options) { - // Registers the gulp tasks found in tasks/test.js and dev.js - var mixedOptions = this.mixOptions(options); - devTasks(mixedOptions); - testTasks(mixedOptions); - }, - all: function(options) { - // Registers all the gulp tasks found in tasks/*.js - this.dev(options); - this.release(options); - this.test(options); - }, - mixOptions: function(options) { - return { - gulp: options.gulp, - rootDir: options.rootDir || __dirname, - paths: options.paths || this.paths, - karma: options.karma, - autoprefixerOptions: options.autoprefixerOptions || {}, - // Set our default to target ES5, but allow overrides from the user - tscOptions: _.merge({target: 'ES5'}, options.tscOptions) - } - } - } + return stream; }; diff --git a/package.json b/package.json index cfd9820..73d895c 100644 --- a/package.json +++ b/package.json @@ -14,28 +14,9 @@ "gulpplugin" ], "dependencies": { - "autoprefixer-core": "^3.1.1", - "del": "^0.1.3", - "gulp": "^3.6.0", - "gulp-csstojs": "^1.0.1", - "gulp-git": "^0.5.4", - "gulp-less": "^1.3.2", - "gulp-minify-css": "^0.3.7", - "gulp-postcss": "^2.0.0", - "gulp-prompt": "^0.1.1", - "gulp-rename": "^1.2.0", - "gulp-size": "^1.0.0", - "gulp-typescript": "^2.0.0", - "gulp-uglifyjs": "^0.4.2", "gulp-util": "~2.2.14", - "inquirer": "^0.8.0", - "karma": "~0.12.24", - "lodash": "^2.4.1", - "onejs-compiler": "^1.1.6", - "require-dir": "^0.1.0", - "semver": "^4.1.0", + "onejs": "^1.1.66", "through2": "^0.4.2", - "xmldom": "^0.1.19" }, "devDependencies": {} } diff --git a/tasks/dev.js b/tasks/dev.js deleted file mode 100644 index f2ab604..0000000 --- a/tasks/dev.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -module.exports = function(options) { - var onejsCompiler = require('../index.js').compiler; - var tsc = require('gulp-typescript'); - var uglify = require('gulp-uglifyjs'); - var del = require('del'); - var less = require('gulp-less'); - var cssMinify = require('gulp-minify-css'); - var csstojs = require('gulp-csstojs'); - var postcss = require('gulp-postcss'); - var autoprefixer = require('autoprefixer-core'); - var _ = require('lodash'); - - var gulp = options.gulp; - var paths = options.paths; - var autoprefixerOptions = options.autoprefixerOptions; - var tscOptions = options.tscOptions; - - /** Removes all built files, keeping only source */ - gulp.task('nuke', function(cb) { - del([paths.temp.root, paths.app.root, paths.app.min.root, paths.dist.root], cb); - }); - - /** Cleans the temporary folders */ - gulp.task('clean', function(cb) { - del([paths.temp.root], cb); - }); - - /** Copies static (non-OneJS) js files to app path */ - gulp.task('copy-static-js-files', function() { - return gulp.src(paths.staticFiles.js) - .pipe(gulp.dest(paths.app.root)); - }); - - gulp.task('copy-static-dts-files', function() { - return gulp.src(paths.typings.glob) - .pipe(gulp.dest(paths.temp.typings)); - }); - - /** Copies .d.ts files from OneJS to temp path to compile against */ - gulp.task('copy-onejs-dts-files', function() { - return gulp.src(paths.onejsFiles.dts) - .pipe(gulp.dest(paths.temp.ts + 'onejs/')); - }); - - /** Copies static OneJS js files to app path */ - gulp.task('copy-onejs-js-files', function() { - return gulp.src(paths.onejsFiles.js) - .pipe(gulp.dest(paths.app.root + 'onejs/')); - }); - - /** Runs LESS compiler, auto-prefixer, and uglify, then creates js modules and outputs to temp folder */ - gulp.task('less-to-js', function() { - return gulp.src(paths.src.lessGlob) - .pipe(less()) - .pipe(postcss([autoprefixer(autoprefixerOptions)])) - .pipe(cssMinify()) - .pipe(csstojs({ - typeScript: true - })) - .pipe(gulp.dest(paths.temp.ts)) - }); - - /** Compiles OneJS html templates */ - gulp.task('onejs-html', function() { - return gulp.src(paths.src.htmlGlob) - .pipe(onejsCompiler()) - .pipe(gulp.dest(paths.temp.ts)); - }); - - /** Copies OneJS TypeScript files to temp directory for futher compilation */ - gulp.task('onejs-ts', function() { - return gulp.src(paths.src.tsGlob) - .pipe(gulp.dest(paths.temp.ts)); - }); - - /** Runs the basic pre-processing steps before compilation */ - gulp.task('tsc-preprocess', ['onejs-html', 'onejs-ts', 'less-to-js', 'copy-onejs-dts-files', 'copy-static-dts-files']); - - /** Runs the TypeScript amd compiler over your application .ts files */ - gulp.task('tsc-amd', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - // Allow tscOption overrides, but ensure that we're targeting amd - .pipe(tsc(_.merge(tscOptions, {module: 'amd'}))) - .pipe(gulp.dest(paths.app.root)); - }); - - /** Runs the TypeScript commonjs compiler over your application .ts files */ - gulp.task('tsc-commonjs', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - // Allow tscOption overrides, but ensure that we're targeting commonjs - .pipe(tsc(_.merge(tscOptions, {module: 'commonjs'}))) - .pipe(gulp.dest(paths.app.root)); - }); - - /** Watches your src folder for changes, and runs the default build task */ - gulp.task('watch', function() { - gulp.watch(paths.src.glob, ['default']); - }); - - /** Default dev task for building */ - gulp.task('build', ['tsc-amd', 'copy-static-js-files', 'copy-onejs-js-files']); - - /** Our default task, but can be overridden by the users gulp file */ - gulp.task('default', ['build']); -}; diff --git a/tasks/release.js b/tasks/release.js deleted file mode 100644 index 0c89602..0000000 --- a/tasks/release.js +++ /dev/null @@ -1,172 +0,0 @@ -'use strict'; - -module.exports = function(options) { - var size = require('gulp-size'); - var uglify = require('gulp-uglifyjs'); - var rename = require('gulp-rename'); - var tsc = require('gulp-typescript'); - var git = require('gulp-git'); - var inquirer = require('inquirer'); - var semver = require('semver'); - var prompt = require('gulp-prompt'); - var fs = require('fs'); - var del = require('del'); - var _ = require('lodash'); - - var gulp = options.gulp; - var paths = options.paths; - var rootDir = options.rootDir; - var tscOptions = options.tscOptions; - - var bumpType; - var newVersion; - - /** Creates a minified version of your application */ - gulp.task('minify', ['tsc-amd'], function() { - return gulp.src([paths.app.jsGlob]) - .pipe(uglify()) - .pipe(size({ - gzip: true - })) - .pipe(rename('app.min.js')) - .pipe(gulp.dest(paths.app.min.root)); - }); - - /** Copies the minified static files to your application path */ - gulp.task('copy-static-files-minified', function() { - return gulp.src(paths.staticFiles.js) - .pipe(uglify()) - .pipe(gulp.dest(paths.app.min.root)); - }); - - /** Creates the amd distributable directory */ - gulp.task('dist-amd', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - // Allow tscOption overrides, but ensure that we're targeting amd - .pipe(tsc(_.merge(tscOptions, {module: 'amd'}))) - .pipe(gulp.dest(paths.dist.amd)); - }); - - /** Creates the commonjs distributable directory */ - gulp.task('dist-commonjs', ['tsc-preprocess'], function() { - return gulp.src(paths.temp.tsGlob) - // Allow tscOption overrides, but ensure that we're targeting commonjs - .pipe(tsc(_.merge(tscOptions, {module: 'commonjs'}))) - .pipe(gulp.dest(paths.dist.commonjs)); - }); - - /** Creates both dist flavors */ - gulp.task('dist', ['dist-commonjs', 'dist-amd']); - - /** - * This next section of tasks are intentionally a bunch of small tasks - * so they can play nicely with Gulp's build system. - * Taks dealing with git, or writing back the package/bower.json files - * need to be synchronous, ergo the callback usage or sync versions - * of the node fs methods. - */ - - /** Temporarily copies the built folder to a temp dir so it will persist - when switching git branches that have different gitignores */ - gulp.task('pre-release', ['dist'], function() { - return gulp.src(paths.dist.glob) - .pipe(gulp.dest(paths.release.root)); - }); - - /** Prompts the user for info about the version */ - gulp.task('prompt-release', ['pre-release'], function() { - var questions = [ - { - type: 'list', - name: 'bumpType', - message: 'What type of version bump is this?', - choices: ['Major', 'Minor', 'Patch'] - } - ]; - - return gulp.src(paths.staticFiles.npmPackage) - .pipe(prompt.prompt(questions, function(answers) { - bumpType = answers.bumpType; - writeUpdatedVersionNumbers(); - })); - }); - - /** Helper function to bump the version number and write it to the npm package and bower files */ - var writeUpdatedVersionNumbers = function() { - var packageJson = JSON.parse(fs.readFileSync(paths.staticFiles.npmPackage, 'utf8')); - var bowerJson = JSON.parse(fs.readFileSync(paths.staticFiles.bowerPackage, 'utf8')); - newVersion = semver.inc(packageJson.version, bumpType.toLowerCase()); - - packageJson.version = newVersion; - bowerJson.version = newVersion; - - fs.writeFileSync(paths.staticFiles.npmPackage, JSON.stringify(packageJson, null, 2)); - - fs.writeFileSync(paths.staticFiles.bowerPackage, JSON.stringify(bowerJson, null, 2)); - } - - /** Helper function to generate a git message based on version */ - var generateBumpMessage = function() { - return 'Version bump to ' + newVersion; - } - - /** Commits the npm and bower packages on master */ - gulp.task('commit-master', ['prompt-release'], function() { - return gulp.src([rootDir + '/' + paths.staticFiles.npmPackage, rootDir + '/' + paths.staticFiles.bowerPackage]) - .pipe(git.commit(generateBumpMessage())); - }); - - /** Checks out the git dist branch */ - gulp.task('checkout-dist', ['commit-master'], function(cb) { - git.checkout('dist', function(err) { - if (err) { return cb(err); } - cb(); - }); - }); - - /** Copies the dist files to their rightful location */ - gulp.task('copy-dist-bits', ['checkout-dist'], function() { - return gulp.src(paths.release.glob) - .pipe(gulp.dest(paths.dist.root)); - }); - - /** Removes the temporary dist files */ - gulp.task('clean-temp-bits', ['copy-dist-bits'], function(cb) { - del([paths.release.root], cb); - }); - - /** Writes the bower and npm package files with new version number */ - gulp.task('write-version-updates', ['clean-temp-bits'], function() { - return writeUpdatedVersionNumbers(); - }); - - /** Commits the bower/npm package files and the dist folder */ - gulp.task('commit-dist', ['write-version-updates'], function() { - return gulp.src([paths.staticFiles.npmPackage, paths.staticFiles.bowerPackage, paths.dist.gitGlob]) - .pipe(git.commit(generateBumpMessage())); - }); - - /** Creates a git tag with the new version number */ - gulp.task('write-dist-tag', ['commit-dist'], function(cb) { - return git.tag('v' + newVersion, generateBumpMessage(), function(err) { - if (err) { return cb(err); } - cb(); - }); - }); - - /** Checks out back to master branch */ - gulp.task('checkout-master', ['write-dist-tag'], function(cb) { - return git.checkout('master', function(err) { - if (err) { return cb(err); } - cb(); - }); - }); - - /** The main task for bumping versions and publishing to dist branch */ - gulp.task('release', ['checkout-master'], function() { - console.log('Version bumped, please run `git push --tags` and `npm/bower publish` to make updates available.'); - });; - - /** Builds the minified version of your app */ - gulp.task('build-minify', ['minify', 'copy-static-files-minified']); -}; diff --git a/tasks/test.js b/tasks/test.js deleted file mode 100644 index 5b00a70..0000000 --- a/tasks/test.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -module.exports = function(options) { - var _ = require('lodash'); - - var karma = options.karma; - var gulp = options.gulp; - var paths = options.paths; - var rootDir = options.rootDir; - - var karmaOptions = options.karmaOptions; - - gulp.task('test-preprocess', function() { - return gulp.src(paths.test.glob) - .pipe(gulp.dest(paths.temp.test)); - }); - - gulp.task('test-build', ['test-preprocess', 'tsc-amd', 'copy-static-js-files', 'copy-onejs-js-files']); - - gulp.task('test', ['test-build', 'build'], function (done) { - karma.start(_.merge({ - configFile: rootDir + '/karma.conf.js', - singleRun: true - }, karmaOptions), done); - }); -} From 0bdd8aad3520ff09d10b2ae2322f4366e02ee32f Mon Sep 17 00:00:00 2001 From: Bob Nisco Date: Wed, 26 Nov 2014 10:34:45 -0800 Subject: [PATCH 20/20] Bump version to 1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73d895c..087bc87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-onejs-compiler", - "version": "1.1.60", + "version": "1.2.0", "description": "Compiles OneJS html templates and generates a variety of output.", "license": "MIT", "repository": "http://github.com/onejstoolkit/gulp-onejs-compiler",