aboutsummaryrefslogtreecommitdiff
path: root/tools/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'tools/tasks')
-rw-r--r--tools/tasks/build.bundles.ts26
-rw-r--r--tools/tasks/build.deps.ts20
-rw-r--r--tools/tasks/build.docs.ts27
-rw-r--r--tools/tasks/build.fonts.dev.ts15
-rw-r--r--tools/tasks/build.html_css.prod.ts24
-rw-r--r--tools/tasks/build.img.dev.ts14
-rw-r--r--tools/tasks/build.index.ts34
-rw-r--r--tools/tasks/build.js.dev.ts25
-rw-r--r--tools/tasks/build.js.prod.ts22
-rw-r--r--tools/tasks/build.sass.dev.ts22
-rw-r--r--tools/tasks/build.test.ts21
-rw-r--r--tools/tasks/check.versions.ts35
-rw-r--r--tools/tasks/clean.ts34
-rw-r--r--tools/tasks/karma.start.ts11
-rw-r--r--tools/tasks/npm.ts5
-rw-r--r--tools/tasks/serve.docs.ts7
-rw-r--r--tools/tasks/server.start.ts7
-rw-r--r--tools/tasks/tsd.ts7
-rw-r--r--tools/tasks/tslint.ts21
-rw-r--r--tools/tasks/watch.dev.ts8
-rw-r--r--tools/tasks/watch.serve.ts12
-rw-r--r--tools/tasks/watch.test.ts8
22 files changed, 405 insertions, 0 deletions
diff --git a/tools/tasks/build.bundles.ts b/tools/tasks/build.bundles.ts
new file mode 100644
index 0000000..52eb381
--- /dev/null
+++ b/tools/tasks/build.bundles.ts
@@ -0,0 +1,26 @@
+import {parallel} from 'async';
+import {join} from 'path';
+import * as Builder from 'systemjs-builder';
+import {BUNDLES_DEST, SYSTEM_CONFIG_BUILDER} from '../config';
+
+const BUNDLE_OPTS = {
+ minify: true,
+ sourceMaps: true,
+ format: 'cjs'
+};
+
+export = function bundles(gulp, plugins) {
+ return function (done) {
+ let builder = new Builder(SYSTEM_CONFIG_BUILDER);
+
+ parallel([
+ bundleApp
+ ], () => done());
+
+ function bundleApp(done) {
+ builder.bundle(
+ 'bootstrap - angular2/*',
+ join(BUNDLES_DEST, 'app.js'), BUNDLE_OPTS).then(done);
+ }
+ };
+};
diff --git a/tools/tasks/build.deps.ts b/tools/tasks/build.deps.ts
new file mode 100644
index 0000000..071f4cd
--- /dev/null
+++ b/tools/tasks/build.deps.ts
@@ -0,0 +1,20 @@
+import * as merge from 'merge-stream';
+import {DEPENDENCIES} from '../config';
+
+export = function buildDepsProd(gulp, plugins) {
+ return function () {
+ let stream = merge();
+
+ DEPENDENCIES.forEach(dep => {
+ stream.add(addStream(dep));
+ });
+
+ return stream;
+
+ function addStream(dep) {
+ let stream = gulp.src(dep.src);
+ stream.pipe(gulp.dest(dep.dest));
+ return stream;
+ }
+ };
+};
diff --git a/tools/tasks/build.docs.ts b/tools/tasks/build.docs.ts
new file mode 100644
index 0000000..a464c67
--- /dev/null
+++ b/tools/tasks/build.docs.ts
@@ -0,0 +1,27 @@
+import {join} from 'path';
+import {APP_SRC, APP_TITLE, DOCS_DEST} from '../config';
+
+export = function buildDocs(gulp, plugins, option) {
+ return function() {
+
+ let src = [
+ join(APP_SRC, '**/*.ts'),
+ '!' + join(APP_SRC, '**/*_spec.ts')
+ ];
+
+ return gulp.src(src)
+ .pipe(plugins.typedoc({
+ // TypeScript options (see typescript docs)
+ module: 'commonjs',
+ target: 'es5',
+ includeDeclarations: true,
+ // Output options (see typedoc docs)
+ out: DOCS_DEST,
+ json: join(DOCS_DEST , 'data/docs.json' ),
+ name: APP_TITLE,
+ ignoreCompilerErrors: false,
+ experimentalDecorators: true,
+ version: true
+ }));
+ };
+}
diff --git a/tools/tasks/build.fonts.dev.ts b/tools/tasks/build.fonts.dev.ts
new file mode 100644
index 0000000..6aa0b92
--- /dev/null
+++ b/tools/tasks/build.fonts.dev.ts
@@ -0,0 +1,15 @@
+import {join} from 'path';
+import {APP_SRC, APP_DEST} from '../config';
+
+export = function buildFontsDev(gulp, plugins) {
+ return function () {
+ return gulp.src([
+ join(APP_SRC, '**/*.eot'),
+ join(APP_SRC, '**/*.ttf'),
+ join(APP_SRC, '**/*.woff'),
+ join(APP_SRC, '**/*.woff2'),
+ join(APP_SRC, '**/*.otf')
+ ])
+ .pipe(gulp.dest(APP_DEST));
+ };
+}
diff --git a/tools/tasks/build.html_css.prod.ts b/tools/tasks/build.html_css.prod.ts
new file mode 100644
index 0000000..93d0aa9
--- /dev/null
+++ b/tools/tasks/build.html_css.prod.ts
@@ -0,0 +1,24 @@
+import * as merge from 'merge-stream';
+import {join} from 'path';
+import {APP_SRC, TMP_DIR} from '../config';
+
+// const HTML_MINIFIER_OPTS = { empty: true };
+
+export = function buildJSDev(gulp, plugins) {
+ return function () {
+
+ return merge(minifyHtml(), minifyCss());
+
+ function minifyHtml() {
+ return gulp.src(join(APP_SRC, '**/*.html'))
+ // .pipe(plugins.minifyHtml(HTML_MINIFIER_OPTS))
+ .pipe(gulp.dest(TMP_DIR));
+ }
+
+ function minifyCss() {
+ return gulp.src(join(APP_SRC, '**/*.css'))
+ .pipe(plugins.minifyCss())
+ .pipe(gulp.dest(TMP_DIR));
+ }
+ };
+};
diff --git a/tools/tasks/build.img.dev.ts b/tools/tasks/build.img.dev.ts
new file mode 100644
index 0000000..28a7897
--- /dev/null
+++ b/tools/tasks/build.img.dev.ts
@@ -0,0 +1,14 @@
+import {join} from 'path';
+import {APP_SRC, APP_DEST} from '../config';
+
+export = function buildImagesDev(gulp, plugins) {
+ return function () {
+ return gulp.src([
+ join(APP_SRC, '**/*.gif'),
+ join(APP_SRC, '**/*.jpg'),
+ join(APP_SRC, '**/*.png'),
+ join(APP_SRC, '**/*.svg')
+ ])
+ .pipe(gulp.dest(APP_DEST));
+ };
+}
diff --git a/tools/tasks/build.index.ts b/tools/tasks/build.index.ts
new file mode 100644
index 0000000..bbf98ee
--- /dev/null
+++ b/tools/tasks/build.index.ts
@@ -0,0 +1,34 @@
+import {join, sep} from 'path';
+import {APP_SRC, APP_DEST, DEPENDENCIES, ENV} from '../config';
+import {transformPath, templateLocals} from '../utils';
+
+export = function buildIndexDev(gulp, plugins) {
+ return function () {
+ return gulp.src(join(APP_SRC, 'index.html'))
+ // NOTE: There might be a way to pipe in loop.
+ .pipe(inject('shims'))
+ .pipe(inject('libs'))
+ .pipe(inject())
+ .pipe(plugins.template(templateLocals()))
+ .pipe(gulp.dest(APP_DEST));
+ };
+
+
+ function inject(name?: string) {
+ return plugins.inject(gulp.src(getInjectablesDependenciesRef(name), { read: false }), {
+ name,
+ transform: transformPath(plugins, 'dev')
+ });
+ }
+
+ function getInjectablesDependenciesRef(name?: string) {
+ return DEPENDENCIES
+ .filter(dep => dep['inject'] && dep['inject'] === (name || true))
+ .map(mapPath);
+ }
+
+ function mapPath(dep) {
+ let prodPath = join(dep.dest, dep.src.split(sep).pop());
+ return ('prod' === ENV ? prodPath : dep.src );
+ }
+};
diff --git a/tools/tasks/build.js.dev.ts b/tools/tasks/build.js.dev.ts
new file mode 100644
index 0000000..dfe9539
--- /dev/null
+++ b/tools/tasks/build.js.dev.ts
@@ -0,0 +1,25 @@
+import {join} from 'path';
+import {APP_SRC, APP_DEST} from '../config';
+import {templateLocals, tsProjectFn} from '../utils';
+
+export = function buildJSDev(gulp, plugins) {
+ let tsProject = tsProjectFn(plugins);
+ return function () {
+ let src = [
+ join(APP_SRC, '**/*.ts'),
+ '!' + join(APP_SRC, '**/*_spec.ts')
+ ];
+
+ let result = gulp.src(src)
+ .pipe(plugins.plumber())
+ // Won't be required for non-production build after the change
+ .pipe(plugins.inlineNg2Template({ base: APP_SRC }))
+ .pipe(plugins.sourcemaps.init())
+ .pipe(plugins.typescript(tsProject));
+
+ return result.js
+ .pipe(plugins.sourcemaps.write())
+ .pipe(plugins.template(templateLocals()))
+ .pipe(gulp.dest(APP_DEST));
+ };
+};
diff --git a/tools/tasks/build.js.prod.ts b/tools/tasks/build.js.prod.ts
new file mode 100644
index 0000000..54ed21a
--- /dev/null
+++ b/tools/tasks/build.js.prod.ts
@@ -0,0 +1,22 @@
+import {join} from 'path';
+import {APP_SRC, TMP_DIR} from '../config';
+import {templateLocals, tsProjectFn} from '../utils';
+
+export = function buildJSDev(gulp, plugins) {
+ return function () {
+ let tsProject = tsProjectFn(plugins);
+ let src = [
+ join(APP_SRC, '**/*.ts'),
+ '!' + join(APP_SRC, '**/*_spec.ts')
+ ];
+
+ let result = gulp.src(src)
+ .pipe(plugins.plumber())
+ .pipe(plugins.inlineNg2Template({ base: TMP_DIR }))
+ .pipe(plugins.typescript(tsProject));
+
+ return result.js
+ .pipe(plugins.template(templateLocals()))
+ .pipe(gulp.dest(TMP_DIR));
+ };
+};
diff --git a/tools/tasks/build.sass.dev.ts b/tools/tasks/build.sass.dev.ts
new file mode 100644
index 0000000..a2127be
--- /dev/null
+++ b/tools/tasks/build.sass.dev.ts
@@ -0,0 +1,22 @@
+import {join} from 'path';
+import {APP_SRC} from '../config';
+
+export = function buildSassDev(gulp, plugins, option) {
+ return function() {
+ return gulp.src(join(APP_SRC, '**', '*.scss'))
+ .pipe(plugins.plumber({
+ // this allows gulp not to crash on sass compilation errors
+ errorHandler: function(error) {
+ console.log(error.message);
+ this.emit('end');
+ }
+ }))
+ .pipe(plugins.compass({
+ // config_file: './config.rb',
+ style: 'compressed',
+ css: 'app/assets/css',
+ sass: join(APP_SRC, 'assets/sass'),
+ }))
+ .pipe(gulp.dest(join(APP_SRC, 'assets')));
+ };
+}
diff --git a/tools/tasks/build.test.ts b/tools/tasks/build.test.ts
new file mode 100644
index 0000000..3e089cd
--- /dev/null
+++ b/tools/tasks/build.test.ts
@@ -0,0 +1,21 @@
+import {join} from 'path';
+import {APP_SRC, TEST_DEST} from '../config';
+import {tsProjectFn} from '../utils';
+
+export = function buildTest(gulp, plugins) {
+ return function () {
+ let tsProject = tsProjectFn(plugins);
+ let src = [
+ join(APP_SRC, '**/*.ts'),
+ '!' + join(APP_SRC, 'bootstrap.ts')
+ ];
+
+ let result = gulp.src(src)
+ .pipe(plugins.plumber())
+ .pipe(plugins.inlineNg2Template({ base: APP_SRC }))
+ .pipe(plugins.typescript(tsProject));
+
+ return result.js
+ .pipe(gulp.dest(TEST_DEST));
+ };
+};
diff --git a/tools/tasks/check.versions.ts b/tools/tasks/check.versions.ts
new file mode 100644
index 0000000..211d5ed
--- /dev/null
+++ b/tools/tasks/check.versions.ts
@@ -0,0 +1,35 @@
+import {VERSION_NPM, VERSION_NODE} from '../config';
+
+function reportError(message: string) {
+ console.error(require('chalk').white.bgRed.bold(message));
+ process.exit(1);
+}
+
+module.exports = function check(gulp, plugins) {
+ return function () {
+ let exec = require('child_process').exec;
+ let semver = require('semver');
+
+ exec('npm --version',
+ function (error, stdout, stderr) {
+ if (error !== null) {
+ reportError('npm preinstall error: ' + error + stderr);
+ }
+
+ if (!semver.gte(stdout, VERSION_NPM)) {
+ reportError('NPM is not in required version! Required is ' + VERSION_NPM + ' and you\'re using ' + stdout);
+ }
+ });
+
+ exec('node --version',
+ function (error, stdout, stderr) {
+ if (error !== null) {
+ reportError('npm preinstall error: ' + error + stderr);
+ }
+
+ if (!semver.gte(stdout, VERSION_NODE)) {
+ reportError('NODE is not in required version! Required is ' + VERSION_NODE + ' and you\'re using ' + stdout);
+ }
+ });
+ };
+};
diff --git a/tools/tasks/clean.ts b/tools/tasks/clean.ts
new file mode 100644
index 0000000..9f0ebf2
--- /dev/null
+++ b/tools/tasks/clean.ts
@@ -0,0 +1,34 @@
+import * as async from 'async';
+import * as del from 'del';
+import {APP_DEST, TEST_DEST, TMP_DIR} from '../config';
+
+export = function clean(gulp, plugins, option) {
+ return function (done) {
+
+ switch(option) {
+ case 'all' : cleanAll(done); break;
+ case 'dist' : cleanDist(done); break;
+ case 'test' : cleanTest(done); break;
+ case 'tmp' : cleanTmp(done); break;
+ default: done();
+ }
+
+ };
+};
+
+function cleanAll(done) {
+ async.parallel([
+ cleanDist,
+ cleanTest,
+ cleanTmp
+ ], done);
+}
+function cleanDist(done) {
+ del(APP_DEST, done);
+}
+function cleanTest(done) {
+ del(TEST_DEST, done);
+}
+function cleanTmp(done) {
+ del(TMP_DIR, done);
+}
diff --git a/tools/tasks/karma.start.ts b/tools/tasks/karma.start.ts
new file mode 100644
index 0000000..313aacd
--- /dev/null
+++ b/tools/tasks/karma.start.ts
@@ -0,0 +1,11 @@
+import * as karma from 'karma';
+import {join} from 'path';
+
+export = function karmaStart() {
+ return function (done) {
+ new (<any>karma).Server({
+ configFile: join(process.cwd(), 'karma.conf.js'),
+ singleRun: true
+ }).start(done);
+ };
+};
diff --git a/tools/tasks/npm.ts b/tools/tasks/npm.ts
new file mode 100644
index 0000000..2ab5e76
--- /dev/null
+++ b/tools/tasks/npm.ts
@@ -0,0 +1,5 @@
+export = function npm(gulp, plugins) {
+ return plugins.shell.task([
+ 'npm prune'
+ ]);
+};
diff --git a/tools/tasks/serve.docs.ts b/tools/tasks/serve.docs.ts
new file mode 100644
index 0000000..2aa5f05
--- /dev/null
+++ b/tools/tasks/serve.docs.ts
@@ -0,0 +1,7 @@
+import {serveDocs} from '../utils';
+
+export = function serverStart(gulp, plugins) {
+ return function () {
+ serveDocs();
+ };
+};
diff --git a/tools/tasks/server.start.ts b/tools/tasks/server.start.ts
new file mode 100644
index 0000000..e733e92
--- /dev/null
+++ b/tools/tasks/server.start.ts
@@ -0,0 +1,7 @@
+import {serveSPA} from '../utils';
+
+export = function serverStart(gulp, plugins) {
+ return function () {
+ serveSPA();
+ };
+};
diff --git a/tools/tasks/tsd.ts b/tools/tasks/tsd.ts
new file mode 100644
index 0000000..bf38ad0
--- /dev/null
+++ b/tools/tasks/tsd.ts
@@ -0,0 +1,7 @@
+export = function tsd(gulp, plugins) {
+ return plugins.shell.task([
+ 'tsd reinstall --clean',
+ 'tsd link',
+ 'tsd rebundle'
+ ]);
+};
diff --git a/tools/tasks/tslint.ts b/tools/tasks/tslint.ts
new file mode 100644
index 0000000..ccea264
--- /dev/null
+++ b/tools/tasks/tslint.ts
@@ -0,0 +1,21 @@
+import {join} from 'path';
+import {APP_SRC, TOOLS_DIR} from '../config';
+
+export = function tslint(gulp, plugins) {
+ return function () {
+ let src = [
+ join(APP_SRC, '**/*.ts'),
+ '!' + join(APP_SRC, '**/*.d.ts'),
+ join(TOOLS_DIR, '**/*.ts'),
+ '!' + join(TOOLS_DIR, '**/*.d.ts')
+ ];
+
+ return gulp.src(src)
+ .pipe(plugins.tslint())
+ .pipe(plugins.tslint.report(plugins.tslintStylish, {
+ emitError: false,
+ sort: true,
+ bell: true
+ }));
+ };
+};
diff --git a/tools/tasks/watch.dev.ts b/tools/tasks/watch.dev.ts
new file mode 100644
index 0000000..bfa37a3
--- /dev/null
+++ b/tools/tasks/watch.dev.ts
@@ -0,0 +1,8 @@
+import {join} from 'path';
+import {APP_SRC} from '../config';
+
+export = function watchDev(gulp, plugins) {
+ return function () {
+ plugins.watch(join(APP_SRC, '**/*'), () => gulp.start('build.dev'));
+ };
+};
diff --git a/tools/tasks/watch.serve.ts b/tools/tasks/watch.serve.ts
new file mode 100644
index 0000000..2bb18f1
--- /dev/null
+++ b/tools/tasks/watch.serve.ts
@@ -0,0 +1,12 @@
+import * as runSequence from 'run-sequence';
+import {join} from 'path';
+import {APP_SRC} from '../config';
+import {notifyLiveReload} from '../utils';
+
+export = function watchServe(gulp, plugins) {
+ return function () {
+ plugins.watch(join(APP_SRC, '**'), e =>
+ runSequence('build.dev', () => notifyLiveReload(e))
+ );
+ };
+};
diff --git a/tools/tasks/watch.test.ts b/tools/tasks/watch.test.ts
new file mode 100644
index 0000000..2a8b55b
--- /dev/null
+++ b/tools/tasks/watch.test.ts
@@ -0,0 +1,8 @@
+import {join} from 'path';
+import {APP_SRC} from '../config';
+
+export = function watchTest(gulp, plugins) {
+ return function () {
+ plugins.watch(join(APP_SRC, '**/*.ts'), () => gulp.start('build.test'));
+ };
+};