diff options
Diffstat (limited to 'tools/tasks/build.index.ts')
-rw-r--r-- | tools/tasks/build.index.ts | 34 |
1 files changed, 34 insertions, 0 deletions
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 ); + } +}; |