Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Tasks refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarlepp committed Jan 8, 2016
1 parent 44ec7e9 commit 1ba8e05
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 78 deletions.
17 changes: 9 additions & 8 deletions tools/tasks/build.assets.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {join} from 'path';
import {APP_SRC, APP_DEST} from '../config';

export = function buildImagesDev(gulp, plugins) {
return function () {
return function() {
return gulp.src([
join(APP_SRC, '**/*.gif'),
join(APP_SRC, '**/*.jpg'),
join(APP_SRC, '**/*.png'),
join(APP_SRC, '**/*.svg'),
join(APP_SRC, '**/*.css'),
join(APP_SRC, '**/*.html')
]).pipe(gulp.dest(APP_DEST));
join(APP_SRC, '**/*.gif'),
join(APP_SRC, '**/*.jpg'),
join(APP_SRC, '**/*.png'),
join(APP_SRC, '**/*.svg'),
join(APP_SRC, '**/*.css'),
join(APP_SRC, '**/*.html')
])
.pipe(gulp.dest(APP_DEST));
};
}
13 changes: 7 additions & 6 deletions tools/tasks/build.assets.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {join} from 'path';
import {APP_SRC, APP_DEST} from '../config';

export = function buildImagesDev(gulp, plugins) {
return function () {
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));
join(APP_SRC, '**/*.gif'),
join(APP_SRC, '**/*.jpg'),
join(APP_SRC, '**/*.png'),
join(APP_SRC, '**/*.svg')
])
.pipe(gulp.dest(APP_DEST));
};
}
6 changes: 4 additions & 2 deletions tools/tasks/build.bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BUNDLE_OPTS = {
};

export = function bundles(gulp, plugins) {
return function (done) {
return function(done) {
let builder = new Builder(SYSTEM_CONFIG_BUILDER);

parallel([
Expand All @@ -20,7 +20,9 @@ export = function bundles(gulp, plugins) {
function bundleApp(done) {
builder.bundle(
'bootstrap - angular2/*',
join(BUNDLES_DEST, 'app.js'), BUNDLE_OPTS).then(done);
join(BUNDLES_DEST, 'app.js'),
BUNDLE_OPTS
).then(done);
}
};
};
6 changes: 5 additions & 1 deletion tools/tasks/build.deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as merge from 'merge-stream';
import {DEPENDENCIES} from '../config';

export = function buildDepsProd(gulp, plugins) {
return function () {
return function() {
let stream = merge();

DEPENDENCIES.forEach(dep => {
Expand All @@ -11,9 +11,13 @@ export = function buildDepsProd(gulp, plugins) {

return stream;

// Private

function addStream(dep) {
let stream = gulp.src(dep.src);

stream.pipe(gulp.dest(dep.dest));

return stream;
}
};
Expand Down
37 changes: 19 additions & 18 deletions tools/tasks/build.docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ 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')
];
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
}));
};
.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
})
);
};
}
10 changes: 4 additions & 6 deletions tools/tasks/build.html_css.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ 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 function() {
return merge(minifyHtml(), minifyCss());

// Private

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(plugins.cssnano())
.pipe(gulp.dest(TMP_DIR));
}
};
Expand Down
4 changes: 3 additions & 1 deletion tools/tasks/build.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {APP_SRC, APP_DEST, DEPENDENCIES, ENV} from '../config';
import {transformPath, templateLocals} from '../utils';

export = function buildIndexDev(gulp, plugins) {
return function () {
return function() {
return gulp.src(join(APP_SRC, 'index.html'))
// NOTE: There might be a way to pipe in loop.
.pipe(inject('shims'))
Expand All @@ -13,6 +13,7 @@ export = function buildIndexDev(gulp, plugins) {
.pipe(gulp.dest(APP_DEST));
};

// Private

function inject(name?: string) {
return plugins.inject(gulp.src(getInjectablesDependenciesRef(name), { read: false }), {
Expand All @@ -29,6 +30,7 @@ export = function buildIndexDev(gulp, plugins) {

function mapPath(dep) {
let prodPath = join(dep.dest, dep.src.split(sep).pop());

return ('prod' === ENV ? prodPath : dep.src );
}
};
9 changes: 5 additions & 4 deletions tools/tasks/build.js.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {templateLocals, tsProjectFn} from '../utils';

export = function buildJSDev(gulp, plugins) {
let tsProject = tsProjectFn(plugins);
return function () {

return function() {
let src = [
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*_spec.ts')
];
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*_spec.ts')
];

let result = gulp.src(src)
.pipe(plugins.plumber())
Expand Down
8 changes: 4 additions & 4 deletions tools/tasks/build.js.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {APP_SRC, TMP_DIR} from '../config';
import {templateLocals, tsProjectFn} from '../utils';

export = function buildJSDev(gulp, plugins) {
return function () {
return function() {
let tsProject = tsProjectFn(plugins);
let src = [
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*_spec.ts')
];
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*_spec.ts')
];

let result = gulp.src(src)
.pipe(plugins.plumber())
Expand Down
6 changes: 3 additions & 3 deletions tools/tasks/build.sass.dev.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {join} from 'path';
import {APP_SRC} from '../config';
import {APP_SRC, APP_DEST} from '../config';

export = function buildSassDev(gulp, plugins, option) {
return function () {
return function() {
return gulp.src(join(APP_SRC, '**', '*.scss'))
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(gulp.dest(APP_SRC));
.pipe(gulp.dest(APP_DEST));
};
}
10 changes: 10 additions & 0 deletions tools/tasks/build.sass.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {join} from 'path';
import {APP_SRC, APP_DEST} from '../config';

export = function buildSassProd(gulp, plugins, option) {
return function() {
return gulp.src(join(APP_SRC, '**', '*.scss'))
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(gulp.dest(APP_DEST));
};
}
8 changes: 4 additions & 4 deletions tools/tasks/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {APP_SRC, TEST_DEST} from '../config';
import {tsProjectFn} from '../utils';

export = function buildTest(gulp, plugins) {
return function () {
return function() {
let tsProject = tsProjectFn(plugins);
let src = [
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, 'bootstrap.ts')
];
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, 'bootstrap.ts')
];

let result = gulp.src(src)
.pipe(plugins.plumber())
Expand Down
6 changes: 3 additions & 3 deletions tools/tasks/check.versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ function reportError(message: string) {
}

module.exports = function check(gulp, plugins) {
return function () {
return function() {
let exec = require('child_process').exec;
let semver = require('semver');

exec('npm --version',
function (error, stdout, stderr) {
function(error, stdout, stderr) {
if (error !== null) {
reportError('npm preinstall error: ' + error + stderr);
}
Expand All @@ -22,7 +22,7 @@ module.exports = function check(gulp, plugins) {
});

exec('node --version',
function (error, stdout, stderr) {
function(error, stdout, stderr) {
if (error !== null) {
reportError('npm preinstall error: ' + error + stderr);
}
Expand Down
8 changes: 3 additions & 5 deletions tools/tasks/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import * as del from 'del';
import {APP_DEST, TEST_DEST, TMP_DIR} from '../config';

export = function clean(gulp, plugins, option) {
return function (done) {

return function(done) {
switch(option) {
case 'all' : cleanAll(done); break;
case 'dist' : cleanDist(done); break;
Expand All @@ -28,21 +27,20 @@ function cleanAll(done) {
function cleanDist(done) {
del(APP_DEST).then((paths) => {
util.log('Deleted', chalk.yellow(paths && paths.join(', ') || '-'));

done();
});
}

function cleanTest(done) {
del(TEST_DEST).then((paths) => {
util.log('Deleted', chalk.yellow(paths && paths.join(', ') || '-'));

done();
});
}

function cleanTmp(done) {
del(TMP_DIR).then((paths) => {
util.log('Deleted', chalk.yellow(paths && paths.join(', ') || '-'));

done();
});
}
2 changes: 1 addition & 1 deletion tools/tasks/karma.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as karma from 'karma';
import {join} from 'path';

export = function karmaStart() {
return function (done) {
return function(done) {
new (<any>karma).Server({
configFile: join(process.cwd(), 'karma.conf.js'),
singleRun: true
Expand Down
2 changes: 1 addition & 1 deletion tools/tasks/serve.docs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {serveDocs} from '../utils';

export = function serverStart(gulp, plugins) {
return function () {
return function() {
serveDocs();
};
};
2 changes: 1 addition & 1 deletion tools/tasks/server.start.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {serveSPA} from '../utils';

export = function serverStart(gulp, plugins) {
return function () {
return function() {
serveSPA();
};
};
10 changes: 5 additions & 5 deletions tools/tasks/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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')
];
join(APP_SRC, '**/*.ts'),
join(TOOLS_DIR, '**/*.ts'),
'!' + join(APP_SRC, '**/*.d.ts'),
'!' + join(TOOLS_DIR, '**/*.d.ts')
];

return gulp.src(src)
.pipe(plugins.tslint())
Expand Down
2 changes: 1 addition & 1 deletion tools/tasks/watch.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {join} from 'path';
import {APP_SRC} from '../config';

export = function watchDev(gulp, plugins) {
return function () {
return function() {
plugins.watch(join(APP_SRC, '**/*'), () => gulp.start('build.dev'));
};
};
6 changes: 3 additions & 3 deletions tools/tasks/watch.serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ 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))
return function() {
plugins.watch(join(APP_SRC, '**'), event =>
runSequence('build.dev', () => notifyLiveReload(event))
);
};
};
2 changes: 1 addition & 1 deletion tools/tasks/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {join} from 'path';
import {APP_SRC} from '../config';

export = function watchTest(gulp, plugins) {
return function () {
return function() {
plugins.watch(join(APP_SRC, '**/*.ts'), () => gulp.start('build.test'));
};
};

0 comments on commit 1ba8e05

Please sign in to comment.