diff --git a/gulpfile.js b/gulpfile.js index 897982a0143..998cd427f1d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,9 +6,20 @@ const path = require('path'); +const tsconfigPath = path.join(__dirname, 'tools/gulp/tsconfig.json'); +const tsconfig = require(tsconfigPath); + // Register TS compilation. require('ts-node').register({ - project: path.join(__dirname, 'tools/gulp/tsconfig.json') + project: tsconfigPath +}); + +// The gulp tsconfig file maps specific imports to relative paths. In combination with ts-node +// this doesn't work because the JavaScript output will still refer to the imports instead of +// to the relative path. Tsconfig-paths can be used to support path mapping inside of Node. +require("tsconfig-paths").register({ + baseUrl: path.dirname(tsconfigPath), + paths: tsconfig.compilerOptions.paths }); require('./tools/gulp/gulpfile'); diff --git a/tools/gulp/gulpfile.ts b/tools/gulp/gulpfile.ts index b153b43292d..bd158374ca9 100644 --- a/tools/gulp/gulpfile.ts +++ b/tools/gulp/gulpfile.ts @@ -1,4 +1,4 @@ -import {createPackageBuildTasks} from './packaging/build-tasks-gulp'; +import {createPackageBuildTasks} from 'material2-build-tools'; // Create gulp tasks to build the different packages in the project. createPackageBuildTasks('cdk'); diff --git a/tools/gulp/tasks/aot.ts b/tools/gulp/tasks/aot.ts index ba294573a59..9c7d35ba5ba 100644 --- a/tools/gulp/tasks/aot.ts +++ b/tools/gulp/tasks/aot.ts @@ -1,8 +1,8 @@ import {task} from 'gulp'; import {copySync} from 'fs-extra'; -import {sequenceTask, execNodeTask} from '../util/task_helpers'; +import {execNodeTask} from '../util/task_helpers'; import {join} from 'path'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; const {outputDir} = buildConfig; diff --git a/tools/gulp/tasks/clean.ts b/tools/gulp/tasks/clean.ts index e69b2bcca1e..842f5cc8e1b 100644 --- a/tools/gulp/tasks/clean.ts +++ b/tools/gulp/tasks/clean.ts @@ -1,6 +1,6 @@ import {task} from 'gulp'; import {cleanTask} from '../util/task_helpers'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; /** Deletes the dist/ directory. */ diff --git a/tools/gulp/tasks/coverage.ts b/tools/gulp/tasks/coverage.ts index c2da6e6af8c..06a3b8c87f5 100644 --- a/tools/gulp/tasks/coverage.ts +++ b/tools/gulp/tasks/coverage.ts @@ -4,7 +4,7 @@ import {existsSync} from 'fs-extra'; import {spawnSync} from 'child_process'; import {isTravisMasterBuild} from '../util/travis-ci'; import {openFirebaseDashboardApp} from '../util/firebase'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; /** Path to the file that includes all coverage information form Karma. */ const coverageResultFile = join(buildConfig.outputDir, 'coverage/coverage-summary.json'); diff --git a/tools/gulp/tasks/development.ts b/tools/gulp/tasks/development.ts index 5aef01b9e7a..1812ea35db5 100644 --- a/tools/gulp/tasks/development.ts +++ b/tools/gulp/tasks/development.ts @@ -1,11 +1,9 @@ import {task, watch} from 'gulp'; -import { - sassBuildTask, tsBuildTask, copyTask, buildAppTask, sequenceTask, triggerLivereload, - serverTask -} from '../util/task_helpers'; +import {tsBuildTask, copyTask, buildAppTask, serverTask} from '../util/task_helpers'; import {join} from 'path'; -import {copyFiles} from '../util/copy-files'; -import {buildConfig} from '../packaging/build-config'; +import { + buildConfig, copyFiles, buildScssTask, triggerLivereload, sequenceTask +} from 'material2-build-tools'; // These imports don't have any typings provided. const firebaseTools = require('firebase-tools'); @@ -44,7 +42,7 @@ task(':watch:devapp', () => { const tsconfigPath = join(appDir, 'tsconfig-build.json'); task(':build:devapp:ts', tsBuildTask(tsconfigPath)); -task(':build:devapp:scss', sassBuildTask(outDir, appDir)); +task(':build:devapp:scss', buildScssTask(outDir, appDir)); task(':build:devapp:assets', copyTask(appDir, outDir)); task('build:devapp', buildAppTask('devapp')); diff --git a/tools/gulp/tasks/docs.ts b/tools/gulp/tasks/docs.ts index ed38895c56e..1ae20de8d9a 100644 --- a/tools/gulp/tasks/docs.ts +++ b/tools/gulp/tasks/docs.ts @@ -1,7 +1,7 @@ import {task, src, dest} from 'gulp'; import {Dgeni} from 'dgeni'; import * as path from 'path'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; // There are no type definitions available for these imports. const markdown = require('gulp-markdown'); diff --git a/tools/gulp/tasks/e2e.ts b/tools/gulp/tasks/e2e.ts index b23bd04135f..236f6ee2208 100644 --- a/tools/gulp/tasks/e2e.ts +++ b/tools/gulp/tasks/e2e.ts @@ -1,8 +1,8 @@ import {task, watch} from 'gulp'; import {join} from 'path'; -import {ngcBuildTask, copyTask, execNodeTask, sequenceTask, serverTask} from '../util/task_helpers'; +import {ngcBuildTask, copyTask, execNodeTask, serverTask} from '../util/task_helpers'; import {copySync} from 'fs-extra'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; // There are no type definitions available for these imports. const gulpConnect = require('gulp-connect'); diff --git a/tools/gulp/tasks/lint.ts b/tools/gulp/tasks/lint.ts index 86e968eee5b..ed3d2e864b7 100644 --- a/tools/gulp/tasks/lint.ts +++ b/tools/gulp/tasks/lint.ts @@ -1,7 +1,7 @@ import {task} from 'gulp'; import {execNodeTask} from '../util/task_helpers'; import {join} from 'path'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; /** Glob that matches all SCSS or CSS files that should be linted. */ const stylesGlob = '+(tools|src)/**/*.+(css|scss)'; diff --git a/tools/gulp/tasks/material-release.ts b/tools/gulp/tasks/material-release.ts index 9762bb529c7..712de95deef 100644 --- a/tools/gulp/tasks/material-release.ts +++ b/tools/gulp/tasks/material-release.ts @@ -2,9 +2,7 @@ import {task, src, dest} from 'gulp'; import {join} from 'path'; import {writeFileSync, mkdirpSync} from 'fs-extra'; import {Bundler} from 'scss-bundle'; -import {sequenceTask} from '../util/task_helpers'; -import {composeRelease} from '../packaging/build-release'; -import {buildConfig} from '../packaging/build-config'; +import {composeRelease, buildConfig, sequenceTask} from 'material2-build-tools'; // There are no type definitions available for these imports. const gulpRename = require('gulp-rename'); diff --git a/tools/gulp/tasks/payload.ts b/tools/gulp/tasks/payload.ts index 01ab2f82dd4..2fd17e939bb 100644 --- a/tools/gulp/tasks/payload.ts +++ b/tools/gulp/tasks/payload.ts @@ -2,7 +2,7 @@ import {task} from 'gulp'; import {join} from 'path'; import {statSync} from 'fs'; import {isTravisBuild, isTravisMasterBuild} from '../util/travis-ci'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; import {openFirebaseDashboardApp, openFirebaseDashboardAppAsGuest} from '../util/firebase'; import {spawnSync} from 'child_process'; import * as firebaseAdmin from 'firebase-admin'; diff --git a/tools/gulp/tasks/publish.ts b/tools/gulp/tasks/publish.ts index 2d076962cb3..c07cf437ce5 100644 --- a/tools/gulp/tasks/publish.ts +++ b/tools/gulp/tasks/publish.ts @@ -2,8 +2,8 @@ import {spawn} from 'child_process'; import {existsSync, statSync} from 'fs-extra'; import {join} from 'path'; import {task} from 'gulp'; -import {execTask, sequenceTask} from '../util/task_helpers'; -import {buildConfig} from '../packaging/build-config'; +import {execTask} from '../util/task_helpers'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; import {yellow, green, red, grey} from 'chalk'; import * as minimist from 'minimist'; diff --git a/tools/gulp/tasks/unit-test.ts b/tools/gulp/tasks/unit-test.ts index 1222debeef3..642a03b37fc 100644 --- a/tools/gulp/tasks/unit-test.ts +++ b/tools/gulp/tasks/unit-test.ts @@ -1,7 +1,6 @@ import {join} from 'path'; import {task, watch} from 'gulp'; -import {sequenceTask} from '../util/task_helpers'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; // There are no type definitions available for these imports. const runSequence = require('run-sequence'); diff --git a/tools/gulp/tasks/universal.ts b/tools/gulp/tasks/universal.ts index ab466abed03..bb01f2e82d0 100644 --- a/tools/gulp/tasks/universal.ts +++ b/tools/gulp/tasks/universal.ts @@ -1,8 +1,8 @@ import {task} from 'gulp'; -import {ngcBuildTask, tsBuildTask, copyTask, sequenceTask, execTask} from '../util/task_helpers'; +import {ngcBuildTask, tsBuildTask, copyTask, execTask} from '../util/task_helpers'; import {join} from 'path'; import {copySync} from 'fs-extra'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; const {outputDir, packagesDir} = buildConfig; diff --git a/tools/gulp/tasks/validate-release.ts b/tools/gulp/tasks/validate-release.ts index 81249c2850f..95bf37a11f6 100644 --- a/tools/gulp/tasks/validate-release.ts +++ b/tools/gulp/tasks/validate-release.ts @@ -2,10 +2,9 @@ import {task} from 'gulp'; import {readFileSync, existsSync} from 'fs'; import {join} from 'path'; import {green, red} from 'chalk'; -import {sequenceTask} from '../util/task_helpers'; import {releasePackages} from './publish'; import {sync as glob} from 'glob'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig, sequenceTask} from 'material2-build-tools'; /** Path to the directory where all releases are created. */ const releasesDir = join(buildConfig.outputDir, 'releases'); diff --git a/tools/gulp/tsconfig.json b/tools/gulp/tsconfig.json index d1d21079a03..c47c244937d 100644 --- a/tools/gulp/tsconfig.json +++ b/tools/gulp/tsconfig.json @@ -1,5 +1,3 @@ -// TypeScript config file that will be used to compile the gulp tasks. The normal gulpfile will -// use TS-Node to compile the gulp tasks at runtime. { "compilerOptions": { "experimentalDecorators": true, @@ -13,7 +11,11 @@ "target": "es5", "types": [ "node" - ] + ], + "baseUrl": ".", + "paths": { + "material2-build-tools": ["../package-tools/index"] + } }, "files": [ "gulpfile.ts" diff --git a/tools/gulp/util/task_helpers.ts b/tools/gulp/util/task_helpers.ts index b1837eed909..958171f44be 100644 --- a/tools/gulp/util/task_helpers.ts +++ b/tools/gulp/util/task_helpers.ts @@ -2,16 +2,12 @@ import * as child_process from 'child_process'; import * as fs from 'fs'; import * as gulp from 'gulp'; import * as path from 'path'; -import {yellow} from 'chalk'; -import {buildConfig} from '../packaging/build-config'; +import {buildConfig} from 'material2-build-tools'; /* Those imports lack typings. */ const gulpClean = require('gulp-clean'); const gulpRunSequence = require('run-sequence'); -const gulpSass = require('gulp-sass'); const gulpConnect = require('gulp-connect'); -const gulpIf = require('gulp-if'); -const gulpCleanCss = require('gulp-clean-css'); // There are no type definitions available for these imports. const resolveBin = require('resolve-bin'); @@ -44,17 +40,6 @@ export function ngcBuildTask(tsConfigPath: string) { return execNodeTask('@angular/compiler-cli', 'ngc', ['-p', tsConfigPath]); } -/** Create a SASS Build Task. */ -export function sassBuildTask(dest: string, root: string, minify = false) { - return () => { - return gulp.src(_globify(root, '**/*.scss')) - .pipe(gulpSass().on('error', gulpSass.logError)) - .pipe(gulpIf(minify, gulpCleanCss())) - .pipe(gulp.dest(dest)); - }; -} - - /** Options that can be passed to execTask or execNodeTask. */ export interface ExecTaskOptions { // Whether STDOUT and STDERR messages should be printed. @@ -177,20 +162,3 @@ export function serverTask(packagePath: string, livereload = true) { }); }; } - -/** Triggers a reload when livereload is enabled and a gulp-connect server is running. */ -export function triggerLivereload() { - console.log(yellow('Server: Changes were detected and a livereload was triggered.')); - return gulp.src('dist').pipe(gulpConnect.reload()); -} - - -/** Create a task that's a sequence of other tasks. */ -export function sequenceTask(...args: any[]) { - return (done: any) => { - gulpRunSequence( - ...args, - done - ); - }; -} diff --git a/tools/gulp/packaging/build-bundles.ts b/tools/package-tools/build-bundles.ts similarity index 100% rename from tools/gulp/packaging/build-bundles.ts rename to tools/package-tools/build-bundles.ts diff --git a/tools/gulp/packaging/build-config.ts b/tools/package-tools/build-config.ts similarity index 100% rename from tools/gulp/packaging/build-config.ts rename to tools/package-tools/build-config.ts diff --git a/tools/gulp/packaging/build-release.ts b/tools/package-tools/build-release.ts similarity index 97% rename from tools/gulp/packaging/build-release.ts rename to tools/package-tools/build-release.ts index 0b02a9be6aa..4b355a88527 100644 --- a/tools/gulp/packaging/build-release.ts +++ b/tools/package-tools/build-release.ts @@ -1,5 +1,5 @@ import {join} from 'path'; -import {copyFiles} from '../util/copy-files'; +import {copyFiles} from './copy-files'; import {addPureAnnotationsToFile} from './pure-annotations'; import {updatePackageVersion} from './package-versions'; import {inlinePackageMetadataFiles} from './metadata-inlining'; diff --git a/tools/gulp/util/copy-files.ts b/tools/package-tools/copy-files.ts similarity index 100% rename from tools/gulp/util/copy-files.ts rename to tools/package-tools/copy-files.ts diff --git a/tools/gulp/packaging/find-build-config.ts b/tools/package-tools/find-build-config.ts similarity index 100% rename from tools/gulp/packaging/find-build-config.ts rename to tools/package-tools/find-build-config.ts diff --git a/tools/package-tools/gulp/build-scss-task.ts b/tools/package-tools/gulp/build-scss-task.ts new file mode 100644 index 00000000000..ddd040dab0c --- /dev/null +++ b/tools/package-tools/gulp/build-scss-task.ts @@ -0,0 +1,17 @@ +import {src, dest} from 'gulp'; +import {join} from 'path'; + +// These imports lack of type definitions. +const gulpSass = require('gulp-sass'); +const gulpIf = require('gulp-if'); +const gulpCleanCss = require('gulp-clean-css'); + +/** Create a gulp task that builds SCSS files. */ +export function buildScssTask(outputDir: string, sourceDir: string, minifyOutput = false) { + return () => { + return src(join(sourceDir, '**/*.scss')) + .pipe(gulpSass().on('error', gulpSass.logError)) + .pipe(gulpIf(minifyOutput, gulpCleanCss())) + .pipe(dest(outputDir)); + }; +} diff --git a/tools/gulp/packaging/build-tasks-gulp.ts b/tools/package-tools/gulp/build-tasks-gulp.ts similarity index 88% rename from tools/gulp/packaging/build-tasks-gulp.ts rename to tools/package-tools/gulp/build-tasks-gulp.ts index c677d5bf815..57681321afd 100644 --- a/tools/gulp/packaging/build-tasks-gulp.ts +++ b/tools/package-tools/gulp/build-tasks-gulp.ts @@ -1,11 +1,13 @@ import {task, watch, src, dest} from 'gulp'; import {join} from 'path'; import {main as tsc} from '@angular/tsc-wrapped'; -import {buildConfig} from './build-config'; -import {sequenceTask, sassBuildTask, copyTask, triggerLivereload} from '../util/task_helpers'; -import {composeRelease} from './build-release'; -import {buildPackageBundles} from './build-bundles'; -import {inlineResourcesForDirectory} from './inline-resources'; +import {buildConfig} from '../build-config'; +import {composeRelease} from '../build-release'; +import {buildPackageBundles} from '../build-bundles'; +import {inlineResourcesForDirectory} from '../inline-resources'; +import {buildScssTask} from './build-scss-task'; +import {sequenceTask} from './sequence-task'; +import {triggerLivereload} from './trigger-livereload'; // There are no type definitions available for these imports. const htmlmin = require('gulp-htmlmin'); @@ -87,8 +89,10 @@ export function createPackageBuildTasks(packageName: string, requiredPackages: s `${packageName}:assets:scss`, `${packageName}:assets:copy-styles`, `${packageName}:assets:html` ]); - task(`${packageName}:assets:scss`, sassBuildTask(packageOut, packageRoot, true)); - task(`${packageName}:assets:copy-styles`, copyTask(stylesGlob, packageOut)); + task(`${packageName}:assets:scss`, buildScssTask(packageOut, packageRoot, true)); + task(`${packageName}:assets:copy-styles`, () => { + return src(stylesGlob).pipe(dest(packageOut)); + }); task(`${packageName}:assets:html`, () => { return src(htmlGlob).pipe(htmlmin(htmlMinifierOptions)).pipe(dest(packageOut)); }); diff --git a/tools/package-tools/gulp/sequence-task.ts b/tools/package-tools/gulp/sequence-task.ts new file mode 100644 index 00000000000..7bff529fa53 --- /dev/null +++ b/tools/package-tools/gulp/sequence-task.ts @@ -0,0 +1,12 @@ +// This import does not have any type definitions. +const gulpRunSequence = require('run-sequence'); + +/** Create a task that's a sequence of other tasks. */ +export function sequenceTask(...args: any[]) { + return (done: any) => { + gulpRunSequence( + ...args, + done + ); + }; +} diff --git a/tools/package-tools/gulp/trigger-livereload.ts b/tools/package-tools/gulp/trigger-livereload.ts new file mode 100644 index 00000000000..c1b3193943c --- /dev/null +++ b/tools/package-tools/gulp/trigger-livereload.ts @@ -0,0 +1,11 @@ +import {yellow} from 'chalk'; +import {src} from 'gulp'; + +// This import does not have any type definitions. +const gulpConnect = require('gulp-connect'); + +/** Triggers a reload when livereload is enabled and a gulp-connect server is running. */ +export function triggerLivereload() { + console.log(yellow('Server: Changes were detected and a livereload was triggered.')); + return src('dist').pipe(gulpConnect.reload()); +} diff --git a/tools/package-tools/index.ts b/tools/package-tools/index.ts new file mode 100644 index 00000000000..60b77fdcb2b --- /dev/null +++ b/tools/package-tools/index.ts @@ -0,0 +1,11 @@ +// Expose general package utilities. +export * from './build-config'; +export * from './build-bundles'; +export * from './build-release'; +export * from './copy-files'; + +// Expose gulp utilities. +export * from './gulp/build-tasks-gulp'; +export * from './gulp/build-scss-task'; +export * from './gulp/sequence-task'; +export * from './gulp/trigger-livereload'; diff --git a/tools/gulp/packaging/inline-resources.ts b/tools/package-tools/inline-resources.ts similarity index 100% rename from tools/gulp/packaging/inline-resources.ts rename to tools/package-tools/inline-resources.ts diff --git a/tools/gulp/packaging/metadata-inlining.ts b/tools/package-tools/metadata-inlining.ts similarity index 100% rename from tools/gulp/packaging/metadata-inlining.ts rename to tools/package-tools/metadata-inlining.ts diff --git a/tools/gulp/packaging/metadata-reexport.ts b/tools/package-tools/metadata-reexport.ts similarity index 100% rename from tools/gulp/packaging/metadata-reexport.ts rename to tools/package-tools/metadata-reexport.ts diff --git a/tools/gulp/packaging/minify-sources.ts b/tools/package-tools/minify-sources.ts similarity index 100% rename from tools/gulp/packaging/minify-sources.ts rename to tools/package-tools/minify-sources.ts diff --git a/tools/gulp/packaging/package-versions.ts b/tools/package-tools/package-versions.ts similarity index 100% rename from tools/gulp/packaging/package-versions.ts rename to tools/package-tools/package-versions.ts diff --git a/tools/gulp/packaging/pure-annotations.ts b/tools/package-tools/pure-annotations.ts similarity index 100% rename from tools/gulp/packaging/pure-annotations.ts rename to tools/package-tools/pure-annotations.ts diff --git a/tools/gulp/packaging/rollup-helpers.ts b/tools/package-tools/rollup-helpers.ts similarity index 100% rename from tools/gulp/packaging/rollup-helpers.ts rename to tools/package-tools/rollup-helpers.ts diff --git a/tools/gulp/packaging/sourcemap-remap.ts b/tools/package-tools/sourcemap-remap.ts similarity index 100% rename from tools/gulp/packaging/sourcemap-remap.ts rename to tools/package-tools/sourcemap-remap.ts diff --git a/tools/gulp/packaging/typescript-transpile.ts b/tools/package-tools/typescript-transpile.ts similarity index 100% rename from tools/gulp/packaging/typescript-transpile.ts rename to tools/package-tools/typescript-transpile.ts diff --git a/tools/gulp/packaging/typings-reexport.ts b/tools/package-tools/typings-reexport.ts similarity index 100% rename from tools/gulp/packaging/typings-reexport.ts rename to tools/package-tools/typings-reexport.ts