Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ Forks of this project demonstrate how to extend and integrate with other librari
│   │   ├── banner-256.txt
│   │   ├── banner.txt
│   │   ├── project.config.ts <- configuration of the specific project
│   │   ├── project.tasks.json <- override composite gulp tasks
│   │   ├── seed.config.ts <- generic configuration of the seed project
│   │   ├── seed.config.interfaces.ts
│   │   ── seed.config.ts <- generic configuration of the seed project
│   │   ── seed.tasks.json <- default composite gulp tasks
│   │   └── seed.tslint.json <- generic tslint configuration of the seed project
│   ├── config.ts <- exported configuration (merge both seed.config and project.config, project.config overrides seed.config)
│   ├── debug.ts
Expand Down
139 changes: 2 additions & 137 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,149 +3,14 @@ import * as util from 'gulp-util';
import * as runSequence from 'run-sequence';

import Config from './tools/config';
import { loadTasks } from './tools/utils';
import { loadTasks, loadCompositeTasks } from './tools/utils';


loadTasks(Config.SEED_TASKS_DIR);
loadTasks(Config.PROJECT_TASKS_DIR);

loadCompositeTasks(Config.SEED_COMPOSITE_TASKS, Config.PROJECT_COMPOSITE_TASKS);

// --------------
// Build dev.
gulp.task('build.dev', (done: any) =>
runSequence('clean.once',
// 'tslint',
'build.assets.dev',
'build.html_css',
'build.js.dev',
'build.index.dev',
done));

// --------------
// Build dev watch.
gulp.task('build.dev.watch', (done: any) =>
runSequence('build.dev',
'watch.dev',
done));

// --------------
// Build e2e.
gulp.task('build.e2e', (done: any) =>
runSequence('clean.e2e',
'tslint',
'build.js.e2e',
done));

// --------------
// Build prod.
gulp.task('build.prod', (done: any) =>
runSequence('check.tools',
'clean.prod',
'tslint',
'build.assets.prod',
'build.html_css',
'copy.prod',
'build.js.prod',
'build.bundles',
'build.bundles.app',
'minify.bundles',
'build.index.prod',
done));

// --------------
// Build prod.
gulp.task('build.prod.exp', (done: any) =>
runSequence('check.tools',
'clean.prod',
'tslint',
'build.assets.prod',
'build.html_css',
'copy.prod',
'compile.ahead.prod',
'build.js.prod.exp',
'build.bundles',
'build.bundles.app.exp',
'minify.bundles',
'build.index.prod',
done));

// --------------
// Build test.
gulp.task('build.test', (done: any) =>
runSequence('clean.once',
// 'tslint',
'build.assets.dev',
'build.html_css',
'build.js.dev',
'build.js.test',
'build.index.dev',
done));

// --------------
// Build test watch.
gulp.task('test.watch', (done: any) =>
runSequence('build.test',
'watch.test',
'karma.watch',
done));


// --------------
// Docs
// gulp.task('docs', (done: any) =>
// runSequence('build.docs',
// 'serve.docs',
// done));

// --------------
// Serve dev
gulp.task('serve.dev', (done: any) =>
runSequence('build.dev',
'server.start',
'watch.dev',
done));

// --------------
// Serve e2e
gulp.task('serve.e2e', (done: any) =>
runSequence(
'tslint',
'build.dev',
'build.js.e2e',
'server.start',
'watch.dev',
'watch.e2e',
done));


// --------------
// Serve prod
gulp.task('serve.prod', (done: any) =>
runSequence('build.prod',
'server.prod',
done));


// --------------
// Serve prod exp
gulp.task('serve.prod.exp', (done: any) =>
runSequence('build.prod.exp',
'server.prod',
done));

// --------------
// Test.
gulp.task('test', (done: any) =>
runSequence('build.test',
'karma.run',
done));

// --------------
// Clean directories after i18n
// TODO: find a better way to do it
gulp.task('clean.i18n', (done: any) =>
runSequence('clear.files',
done));

// --------------
// Clean dev/coverage that will only run once
Expand Down
8 changes: 8 additions & 0 deletions tools/config/project.tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"test": [
"tslint",
"build.test",
"karma.run"
]
}

12 changes: 12 additions & 0 deletions tools/config/seed.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ export class SeedConfig {
*/
SEED_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'seed');

/**
* Seed tasks which are composition of other tasks.
*/
SEED_COMPOSITE_TASKS = join(process.cwd(), this.TOOLS_DIR, 'config', 'seed.tasks.json');

/**
* Project tasks which are composition of other tasks
* and aim to override the tasks defined in
* SEED_COMPOSITE_TASKS.
*/
PROJECT_COMPOSITE_TASKS = join(process.cwd(), this.TOOLS_DIR, 'config', 'project.tasks.json');

/**
* The destination folder for the generated documentation.
* @type {string}
Expand Down
94 changes: 94 additions & 0 deletions tools/config/seed.tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"build.dev": [
"clean.once",
"build.assets.dev",
"build.html_css",
"build.js.dev",
"build.index.dev"
],

"build.dev.watch": [
"build.dev",
"watch.dev"
],

"build.e2e": [
"clean.e2e",
"tslint",
"build.js.e2e"
],

"build.prod": [
"check.tools",
"clean.prod",
"tslint",
"build.assets.prod",
"build.html_css",
"copy.prod",
"build.js.prod",
"build.bundles",
"build.bundles.app",
"minify.bundles",
"build.index.prod"
],

"build.prod.exp": [
"check.tools",
"clean.prod",
"tslint",
"build.assets.prod",
"build.html_css",
"copy.prod",
"compile.ahead.prod",
"build.js.prod.exp",
"build.bundles",
"build.bundles.app.exp",
"minify.bundles",
"build.index.prod"
],

"build.test": [
"build.assets.dev",
"build.html_css",
"build.js.dev",
"build.js.test",
"build.index.dev"
],

"test.watch": [
"build.test",
"watch.test",
"karma.watch"
],

"serve.dev": [
"build.dev",
"server.start",
"watch.dev"
],

"serve.e2e": [
"tslint",
"build.dev",
"build.js.e2e",
"server.start",
"watch.dev",
"watch.e2e"
],

"serve.prod": [
"build.prod",
"server.prod"
],

"serve.prod.exp": [
"build.prod.exp",
"server.prod"
],

"test": [
"build.test",
"karma.run"
]
}

86 changes: 85 additions & 1 deletion tools/utils/seed/tasks_tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync, lstatSync, readdirSync } from 'fs';
import { existsSync, lstatSync, readFileSync, readdirSync } from 'fs';
import * as runSequence from 'run-sequence';
import * as gulp from 'gulp';
import * as util from 'gulp-util';
import * as isstream from 'isstream';
Expand All @@ -17,6 +18,89 @@ export function loadTasks(path: string): void {
readDir(path, taskname => registerTask(taskname, path));
}

function validateTasks(tasks: any) {
return Object.keys(tasks)
.map((taskName: string) => {
if (!tasks[taskName] ||
!Array.isArray(tasks[taskName]) ||
tasks[taskName].some((t: any) => typeof t !== 'string')) {
return taskName;
}
return null;
}).filter((taskName: string) => !!taskName);
}

function registerTasks(tasks: any) {
Object.keys(tasks)
.forEach((t: string) => {
gulp.task(t, (done: any) => runSequence.apply(null, [...tasks[t], done]));
});
}

function getInvalidTaskErrorMessage(invalid: string[], file: string) {
let error = `Invalid configuration in "${file}. `;
if (invalid.length === 1) {
error += 'Task';
} else {
error += 'Tasks';
}
error += ` ${invalid.map((t: any) => `"${t}"`).join(', ')} do not have proper format.`;
return error;
}

/**
* Defines complex, composite tasks. The composite tasks
* are simply a composition of another tasks.
* Each composite tasks has the following format:
*
* "composite_task": ["task1", "task2"]
*
* This means that the format should be flat, with no nesting.
*
* The existing composite tasks are defined in
* "tools/config/seed.tasks.json" and can be overriden by
* editing the composite tasks project configuration.
*
* By default it is located in: "tools/config/project.tasks.json".
*
* Override existing tasks by simply providing a task
* name and a list of tasks that this task hould execute.
*
* For instance:
* ```
* {
* "test": [
* "build.test",
* "mocha.run"
* ]
* }
* ```
*
* Note that the tasks do not support nested objects.
*/
export function loadCompositeTasks(seedTasksFile: string, projectTasksFile: string): void {
let seedTasks: any;
let projectTasks: any;
try {
seedTasks = JSON.parse(readFileSync(seedTasksFile).toString());
projectTasks = JSON.parse(readFileSync(projectTasksFile).toString());
} catch (e) {
util.log('Cannot load the task configuration files: ' + e.toString());
return;
}
[[seedTasks, seedTasksFile], [projectTasks, projectTasksFile]]
.forEach(([tasks, file]: [string, string]) => {
const invalid = validateTasks(tasks);
if (invalid.length) {
const errorMessage = getInvalidTaskErrorMessage(invalid, file);
util.log(util.colors.red(errorMessage));
process.exit(1);
}
});
const mergedTasks = Object.assign({}, seedTasks, projectTasks);
registerTasks(mergedTasks);
}

function normalizeTask(task: any, taskName: string) {
if (task instanceof Task) {
return task;
Expand Down
Loading