From 5d1997a89f21ca9762bb51fd0a967d1cdacbed92 Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Wed, 8 Feb 2017 12:58:13 -0800 Subject: [PATCH] Major gulp refactor: blueprint.defineTaskGroup() (#617) * blueprint.defineTaskGroup gulp helper function defines a task group based on a block query with some cool options. gulp task itself is defined in callback so it can be configured precisely as needed. this removes the need to specify deps in config. function accepts options object to support more complex usage and multiple args. * copy-files => copy + remove `copy: false` * compile tasks use simpler `taskGroup` sass-compile => sass sass-lint => stylelint typescript-compile => tsc typescript-lint => tslint webpack-compile-docs => webpack-docs webpack-compile-w-docs => webpack-docs-watch -w- => :only for incremental build tasks so: sass-compile-table => sass-table:only dependencies are much easier to trace now because they're all listed in task definition. * remove now unused blueprint.task() --- Gulpfile.js | 3 - gulp/aliases.js | 8 +-- gulp/copy.js | 33 +++++---- gulp/dist.js | 58 +++++++++------- gulp/hygiene.js | 4 +- gulp/icons.js | 43 ++++++------ gulp/index.js | 39 +++++++---- gulp/isotest.js | 14 ++-- gulp/karma.js | 12 ++-- gulp/sass.js | 44 +++++++----- gulp/typescript.js | 49 ++++++++------ gulp/util/task.js | 67 ------------------- gulp/watch.js | 8 +-- gulp/webpack.js | 5 +- packages/landing/scripts/dedupe-svg-ids.js | 3 +- packages/landing/src/logo.ts | 4 +- packages/landing/src/svgs.ts | 2 +- .../table/config/webpack.config.preview.js | 38 +++++------ 18 files changed, 205 insertions(+), 229 deletions(-) delete mode 100644 gulp/util/task.js diff --git a/Gulpfile.js b/Gulpfile.js index f94c4a18a5c..a7114a15761 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -56,7 +56,6 @@ const projects = [ id: "core", cwd: "packages/core/", dependencies: [], - copy: false, isotest: true, karma: true, sass: "compile", @@ -65,7 +64,6 @@ const projects = [ id: "datetime", cwd: "packages/datetime/", dependencies: ["core"], - copy: false, isotest: true, karma: true, sass: "compile", @@ -111,7 +109,6 @@ const projects = [ id: "table", cwd: "packages/table/", dependencies: ["core"], - copy: false, isotest: true, karma: true, sass: "compile", diff --git a/gulp/aliases.js b/gulp/aliases.js index 88dbf592c10..b457e9b1f35 100644 --- a/gulp/aliases.js +++ b/gulp/aliases.js @@ -9,20 +9,20 @@ module.exports = (blueprint, gulp) => { // lint all the things! // this will fail the CI build but will not block starting the server. // your editor is expected to handle this in realtime during development. - gulp.task("check", ["tslint", "sass-lint", "typescript-lint", "typescript-lint-docs"]); + gulp.task("check", ["tslint", "tslint-gulp", "stylelint"]); // compile all the project source codes EXCEPT for docs webpack // (so we can run it in watch mode during development) - gulp.task("compile", ["sass-compile", "typescript-compile", "copy-files"]); + gulp.task("compile", ["sass", "tsc", "copy"]); // generate docs data files gulp.task("docs", ["docs-interfaces", "docs-kss", "docs-versions", "docs-releases"]); // perform a full build of the code and then finish - gulp.task("build", (done) => rs("clean", "compile", "bundle", "webpack-compile-docs", done)); + gulp.task("build", (done) => rs("clean", "compile", "bundle", "webpack-docs", done)); // run test tasks in series to keep outputs separate - gulp.task("test", (done) => rs("test-dist", "karma", "isotest-mocha-w", done)); + gulp.task("test", (done) => rs("test-dist", "karma", "isotest", done)); // compile code and start watching for development gulp.task("default", (done) => rs("clean", "compile", "docs", "watch", done)); diff --git a/gulp/copy.js b/gulp/copy.js index cc9cce9f38c..419deae29a3 100644 --- a/gulp/copy.js +++ b/gulp/copy.js @@ -7,23 +7,20 @@ module.exports = (blueprint, gulp, plugins) => { var mergeStream = require("merge-stream"); var path = require("path"); - blueprint.task("copy", "files", [], (project) => { - // allow for no-op on project dependencies - if (project.copy === false) { - return; - } - - // copy options is a map of file globs to array of dest directories. - // given: "copy": { "path/to/file.txt": {to: ["foo/bar"], base: "path"} } - // the file at currProject/path/to/file.txt is copied to currProject/build/foo/bar/to/file.txt - return mergeStream(Object.keys(project.copy).map((key) => { - var dests = project.copy[key].to; - var base = project.copy[key].base || ""; - var stream = gulp.src(path.join(project.cwd, key), { base: path.join(project.cwd, base) }); - dests.forEach((dest) => { - stream = stream.pipe(gulp.dest(blueprint.destPath(project, dest))); - }); - return stream; - })).pipe(plugins.count(`${project.id}: <%= files %> copied`)); + blueprint.defineTaskGroup({ block: "copy" }, (project, taskName) => { + gulp.task(taskName, () => { + // copy options is a map of file globs to array of dest directories. + // given: "copy": { "path/to/file.txt": {to: ["foo/bar"], base: "path"} } + // the file at currProject/path/to/file.txt is copied to currProject/build/foo/bar/to/file.txt + return mergeStream(Object.keys(project.copy).map((key) => { + var dests = project.copy[key].to; + var base = project.copy[key].base || ""; + var stream = gulp.src(path.join(project.cwd, key), { base: path.join(project.cwd, base) }); + dests.forEach((dest) => { + stream = stream.pipe(gulp.dest(blueprint.destPath(project, dest))); + }); + return stream; + })).pipe(plugins.count(`${project.id}: <%= files %> copied`)); + }); }); }; diff --git a/gulp/dist.js b/gulp/dist.js index 2264ac492ae..72bca57aceb 100644 --- a/gulp/dist.js +++ b/gulp/dist.js @@ -10,39 +10,47 @@ module.exports = (blueprint, gulp) => { const webpack = require("webpack"); const webpackConfig = require("./util/webpack-config"); - blueprint.projectsWithBlock("typescript").forEach((project) => { - gulp.task(`bundle-${project.id}`, (done) => { + blueprint.defineTaskGroup({ + block: "typescript", + name: "bundle", + }, (project, taskName) => { + gulp.task(taskName, (done) => { webpack( webpackConfig.generateWebpackBundleConfig(project), webpackConfig.webpackDone(done) ); }); }); - gulp.task("bundle", blueprint.taskMapper("typescript", "bundle")); // asserts that all main fields in package.json reference existing files - function testDist(project) { - const pkgJson = require(path.resolve(project.cwd, "package.json")); - const promises = ["main", "style", "typings"] - .filter((field) => pkgJson[field] !== undefined) - .map((field) => { - const filePath = path.resolve(project.cwd, pkgJson[field]); - return new Promise((resolve, reject) => { - // non-existent file will callback with err; we don't care about actual contents - fs.readFile(filePath, (err) => { - if (err) { - reject(`${pkgJson.name}: "${field}" not found (${pkgJson[field]})`); - } else { - resolve(); - } - }); - }); + const PACKAGE_MAIN_FIELDS = ["main", "style", "typings"]; + blueprint.defineTaskGroup({ + block: "all", + name: "test-dist", + }, (project, taskName) => { + gulp.task(taskName, () => { + const pkgJson = require(path.resolve(project.cwd, "package.json")); + const promises = PACKAGE_MAIN_FIELDS + .filter((field) => pkgJson[field] !== undefined) + .map((field) => assertFileExists( + path.resolve(project.cwd, pkgJson[field]), + `${pkgJson.name}: "${field}" not found (${pkgJson[field]})` + )); + // using promises here so errors will be produced for each failing package, not just the first + return Promise.all(promises); + }); + }); + + function assertFileExists(filePath, errorMessage) { + return new Promise((resolve, reject) => { + // non-existent file will callback with err; we don't care about actual contents + fs.readFile(filePath, (err) => { + if (err) { + reject(errorMessage); + } else { + resolve(); + } }); - return Promise.all(promises); + }); } - - blueprint.projects.forEach((project) => { - gulp.task(`test-dist-${project.id}`, () => testDist(project)); - }); - gulp.task("test-dist", blueprint.taskMapper("id", "test", "dist")); }; diff --git a/gulp/hygiene.js b/gulp/hygiene.js index a098b607e81..7beef17b015 100644 --- a/gulp/hygiene.js +++ b/gulp/hygiene.js @@ -17,8 +17,8 @@ module.exports = (blueprint, gulp, plugins) => { return del(cleanDirs, { force: true }); }); - gulp.task("tslint", () => ( - gulp.src(["*.js", "gulp/**/*.js", "packages/*/*.js"]) + gulp.task("tslint-gulp", () => ( + gulp.src(["*.js", "gulp/**/*.js"]) .pipe(plugins.tslint({ formatter: "verbose" })) .pipe(plugins.tslint.report()) .pipe(plugins.count("## javascript files linted")) diff --git a/gulp/icons.js b/gulp/icons.js index c0a31a70cb2..d33930c2fa6 100644 --- a/gulp/icons.js +++ b/gulp/icons.js @@ -9,30 +9,10 @@ module.exports = (blueprint, gulp, plugins) => { const text = require("./util/text"); const mergeStream = require("merge-stream"); - // accepts map of filename to array of lines, writes lines to file, writes to src/generated - function writeFiles(files) { - const streams = map(files, (contents, filename) => text.fileStream(filename, contents.join("\n") + "\n")); - const outputDir = path.join(blueprint.findProject("core").cwd, "src", "generated"); - return mergeStream(...streams).pipe(gulp.dest(outputDir)); - } + const ICONS = require(path.resolve(blueprint.findProject("core").cwd, "resources", "icons", "icons.json")); // generate sass and typescript files containing icon variables, driven by docs/src/icons.json gulp.task("icons", () => { - const ICONS = require(path.resolve(blueprint.findProject("core").cwd, "resources", "icons", "icons.json")); - - function toEnumName(icon) { - return icon.className.replace("pt-icon-", "").replace(/-/g, "_").toUpperCase(); - } - function buildTSObject(objectName, valueGetter) { - return [ - // the TS files are published to NPM so they need a header, but the Sass files are compiled away - text.COPYRIGHT_HEADER, - "// tslint:disable:object-literal-sort-keys", - `export const ${objectName} = {`, - ...ICONS.map((prop) => ` ${toEnumName(prop)}: "${valueGetter(prop)}",`), - "};", - ]; - } return writeFiles({ // great big map for iteration @@ -53,4 +33,25 @@ module.exports = (blueprint, gulp, plugins) => { "iconStrings.ts": buildTSObject("IconContents", (icon) => icon.content.replace("\\", "\\u")), }); }); + + // accepts map of filename to array of lines, writes lines to file, writes to src/generated + function writeFiles(files) { + const streams = map(files, (contents, filename) => text.fileStream(filename, contents.join("\n") + "\n")); + const outputDir = path.join(blueprint.findProject("core").cwd, "src", "generated"); + return mergeStream(...streams).pipe(gulp.dest(outputDir)); + } + + function toEnumName(icon) { + return icon.className.replace("pt-icon-", "").replace(/-/g, "_").toUpperCase(); + } + function buildTSObject(objectName, valueGetter) { + return [ + // the TS files are published to NPM so they need a header, but the Sass files are compiled away + text.COPYRIGHT_HEADER, + "// tslint:disable:object-literal-sort-keys", + `export const ${objectName} = {`, + ...ICONS.map((prop) => ` ${toEnumName(prop)}: "${valueGetter(prop)}",`), + "};", + ]; + } }; diff --git a/gulp/index.js b/gulp/index.js index 0a03581725a..faada3e7801 100644 --- a/gulp/index.js +++ b/gulp/index.js @@ -3,7 +3,9 @@ */ "use strict"; +const rs = require("run-sequence"); const path = require("path"); +const util = require("util"); const plugins = require("gulp-load-plugins")(); /** @@ -43,22 +45,35 @@ module.exports = (gulp, config) => { }, /** - * Returns an array of task names of the format [prefix]-[...prefixes]-[project] - * for every project with the given block. - * @param block {string} name of project config block - * @param prefix {string} first prefix, defaults to block name - * @param prefixes {string[]} additional prefixes before project name - * @returns {string[]} + * Define a group of tasks for projects with the given config block. + * The special block `"all"` will operate on all projects. + * The `block` is used as the task name, unless `name` is explicitly defined. + * The `taskFn` is called for each matched project with `(project, taskName, depTaskNames)`. + * The task name is of the format `[name]-[project.id]`. + * Finally, a "group task" is defined with the base name that runs all the project tasks. + * This group task can be configured to run in parallel or in sequence. + * @param {{block: string, name?: string, parallel?: boolean}} options + * @param {Function} taskFn called for each project containing block with `(project, taskName, depTaskNames)` */ - taskMapper(block, prefix = block, ...prefixes) { - return blueprint - .projectsWithBlock(block) - .map(({ id }) => [prefix, ...prefixes, id].join("-")); + defineTaskGroup(options, taskFn) { + const { block, name = block, parallel = true } = options; + + const projects = (block === "all") ? blueprint.projects : blueprint.projectsWithBlock(block); + + const taskNames = projects.map((project) => { + const { dependencies = [], id } = project; + // string name is combined with block; array name ignores/overrides block + const taskName = [name, id].join("-"); + const depNames = dependencies.map((dep) => [name, dep].join("-")); + taskFn(project, taskName, depNames); + return taskName; + }); + + // can run tasks in series when it's preferable to keep output separate + gulp.task(name, parallel ? taskNames : (done) => rs(...taskNames, done)); }, }, config); - blueprint.task = require("./util/task.js")(blueprint, gulp); - [ "aliases", "copy", diff --git a/gulp/isotest.js b/gulp/isotest.js index 85f73bd2b50..3db690f49f5 100644 --- a/gulp/isotest.js +++ b/gulp/isotest.js @@ -4,10 +4,14 @@ "use strict"; module.exports = (blueprint, gulp, plugins) => { - const path = require("path"); - - blueprint.task("isotest", "mocha", ["typescript-compile-*"], (project) => { - return gulp.src(path.join(project.cwd, "test", "isotest.js")) - .pipe(plugins.mocha()); + blueprint.defineTaskGroup({ + block: "isotest", + parallel: false, + }, (project, taskName) => { + // be sure to run `gulp tsc` beforehand + gulp.task(taskName, () => { + return gulp.src(project.cwd + "test/isotest.js") + .pipe(plugins.mocha()); + }); }); }; diff --git a/gulp/karma.js b/gulp/karma.js index df2593da5bb..e30e29d763e 100644 --- a/gulp/karma.js +++ b/gulp/karma.js @@ -4,12 +4,14 @@ "use strict"; module.exports = (blueprint, gulp, plugins) => { - const rs = require("run-sequence").use(gulp); const karma = require("karma"); const createConfig = require("./util/karma-config"); - blueprint.projectsWithBlock("karma").forEach((project) => { - gulp.task(`karma-${project.id}`, (done) => { + blueprint.defineTaskGroup({ + block: "karma", + parallel: false, + }, (project, taskName) => { + gulp.task(taskName, (done) => { const server = new karma.Server(createConfig(project), done); return server.start(); }); @@ -32,8 +34,4 @@ module.exports = (blueprint, gulp, plugins) => { return server.start(); }); }); - - // running in sequence so output is human-friendly - // (in parallel, all suites get interspersed and it's a mess) - gulp.task("karma", (done) => rs(...blueprint.taskMapper("karma"), done)); }; diff --git a/gulp/sass.js b/gulp/sass.js index c04f645b065..c62883f10ae 100644 --- a/gulp/sass.js +++ b/gulp/sass.js @@ -33,19 +33,31 @@ module.exports = (blueprint, gulp, plugins) => { ], }; - blueprint.task("sass", "lint", [], (project, isDevMode) => ( - gulp.src(config.srcGlob(project)) - .pipe(plugins.stylelint({ - failAfterError: !isDevMode, - reporters: [ - { formatter: "string", console: true }, - ], - syntax: "scss", - })) - .pipe(plugins.count(`${project.id}: ## stylesheets linted`)) - )); + blueprint.defineTaskGroup({ + block: "sass", + name: "stylelint", + }, (project, taskName) => { + gulp.task(taskName, () => ( + gulp.src(config.srcGlob(project)) + .pipe(plugins.stylelint({ + failAfterError: true, + reporters: [ + { formatter: "string", console: true }, + ], + syntax: "scss", + })) + .pipe(plugins.count(`${project.id}: ## stylesheets linted`)) + )); + }); + + blueprint.defineTaskGroup({ + block: "sass", + }, (project, taskName, depTaskNames) => { + gulp.task(taskName, ["icons", "sass-variables", ...depTaskNames], () => sassCompile(project, false)); + gulp.task(`${taskName}:only`, () => sassCompile(project, true)); + }); - blueprint.task("sass", "compile", ["icons", "sass-variables"], (project, isDevMode) => { + function sassCompile(project, isDevMode) { const sassCompiler = plugins.sass({ importer: packageImporter({ cwd: project.cwd }), }); @@ -85,9 +97,13 @@ module.exports = (blueprint, gulp, plugins) => { // see https://github.com/floridoo/vinyl-sourcemaps-apply/issues/11#issuecomment-231220574 .pipe(plugins.sourcemaps.write(".", { sourceRoot: null })) .pipe(gulp.dest(blueprint.destPath(project))) + .pipe(plugins.count({ + logFiles: `write ${plugins.util.colors.yellow("<%= file.relative %>")}`, + message: false, + })) // only bundled packages will reload the dev site .pipe(project.sass === "bundle" ? plugins.connect.reload() : plugins.util.noop()); - }); + } // concatenate all sass variables files together into one single exported list of variables gulp.task("sass-variables", ["icons"], () => { @@ -115,6 +131,4 @@ module.exports = (blueprint, gulp, plugins) => { .pipe(plugins.insert.append(".unit-test { width: @pt-grid-size * 2; }")) .pipe(plugins.less()); }); - - gulp.task("sass", ["sass-lint", "sass-compile"]); }; diff --git a/gulp/typescript.js b/gulp/typescript.js index 392025511ec..86a95d2d689 100644 --- a/gulp/typescript.js +++ b/gulp/typescript.js @@ -7,33 +7,40 @@ module.exports = (blueprint, gulp, plugins) => { const mergeStream = require("merge-stream"); const path = require("path"); - function createTypescriptProject(tsConfigPath) { - return plugins.typescript.createProject(tsConfigPath, { + blueprint.defineTaskGroup({ + block: "all", + name: "tslint", + }, (project, taskName) => { + gulp.task(taskName, () => ( + gulp.src([ + path.join(project.cwd, "!(dist|node_modules|typings)", "**", "*.{js,jsx,ts,tsx}"), + // exclude nested dist directories (ex: table/preview/dist) + "!" + path.join(project.cwd, "*", "dist", "**", "*.{js,jsx,ts,tsx}"), + ]) + .pipe(plugins.tslint({ formatter: "verbose" })) + .pipe(plugins.tslint.report({ emitError: true })) + .pipe(plugins.count(`${project.id}: ## files tslinted`)) + )); + }); + + blueprint.defineTaskGroup({ + block: "typescript", + name: "tsc", + }, (project, taskName, depTaskNames) => { + // create a TypeScript project for each project to improve re-compile speed. + // this must be done outside of a task function so it can be reused across runs. + const tsconfigPath = path.join(project.cwd, "tsconfig.json"); + project.typescriptProject = plugins.typescript.createProject(tsconfigPath, { // ensure that only @types from this project are used (instead of from local symlinked blueprint) typeRoots: ["node_modules/@types"], }); - } - // create a TypeScript project for each project to improve re-compile speed. - // this must be done outside of a task function so it can be reused across runs. - blueprint.projectsWithBlock("typescript").forEach((project) => { - const tsconfig = path.join(project.cwd, "tsconfig.json"); - project.typescriptProject = createTypescriptProject(tsconfig); + gulp.task(taskName, ["icons", ...depTaskNames], () => typescriptCompile(project, false)); + gulp.task(`${taskName}:only`, () => typescriptCompile(project, true)); }); - const lintTask = (project, isDevMode) => ( - gulp.src(path.join(project.cwd, "!(dist|node_modules|typings)", "**", "*.ts{,x}")) - .pipe(plugins.tslint({ formatter: "verbose" })) - .pipe(plugins.tslint.report({ emitError: !isDevMode })) - .pipe(plugins.count(`${project.id}: ## typescript files linted`)) - ); - // Lint all source files using TSLint - blueprint.task("typescript", "lint", [], lintTask); - gulp.task("typescript-lint-docs", () => lintTask(blueprint.findProject("docs"), false)); - gulp.task("typescript-lint-w-docs", () => lintTask(blueprint.findProject("docs"), true)); - // Compile a TypeScript project using gulp-typescript to individual .js files - blueprint.task("typescript", "compile", ["icons"], (project, isDevMode) => { + function typescriptCompile(project, isDevMode) { const tsProject = project.typescriptProject; const tsResult = tsProject.src() @@ -52,5 +59,5 @@ module.exports = (blueprint, gulp, plugins) => { tsResult.js.pipe(plugins.sourcemaps.write(".", { sourceRoot: null })), tsResult.dts, ]).pipe(gulp.dest(blueprint.destPath(project))); - }); + } }; diff --git a/gulp/util/task.js b/gulp/util/task.js deleted file mode 100644 index 998308eacc9..00000000000 --- a/gulp/util/task.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016 Palantir Technologies, Inc. All rights reserved. - */ -"use strict"; - -const util = require("util"); - -// expand each of the project IDs to begin with all the prefixes. -function expandDeps(project, prefixes, extras) { - if (util.isFunction(extras)) { extras = extras(project); } - if (extras == null) { extras = []; } - return (project.dependencies || []) - .map((dep) => prefixes.concat(dep).join("-")) - .concat(extras.map((dep) => dep.replace("*", project.id))); -} - -/** - * This function defines a group of tasks for each project that defines the given block. Tasks are - * generated with the following name scheme: - * - [block]-[taskname]-[project.id] normal build task for each project, - * - [block]-[taskname] parent task to run each of the project tasks, - * - [block]-[taskname]-w-[project.id] watch task for each project, - * - [block]-[taskname]-w parent task to run each of the project watch tasks, - * - * The watch task is run when the relevant files are changed during development. It should not - * fail on errors and can use debug options such as sourcemaps. - * - * Any given dependencies will be run before each of the project tasks. Also, any project - * dependencies will be mapped to the task prefix and run before each project task. (For instance, - * if project X depends on project Y then task sass-compile-X will depend on task sass-compile-Y.) - * - * @param block {string} block name of task - * @param taskname {string} name of task - * @param dependencies {string[]} dependencies for generated task and watch task - * @param callback {(project, isDevMode) => stream} task callback - */ -module.exports = (blueprint, gulp) => { - return (block, taskname, dependencies, callback) => { - if (!Array.isArray(dependencies) && !util.isFunction(dependencies)) { - throw new Error(`${block}-${taskname} expected dependencies array or function.`); - } - if (!util.isFunction(callback)) { - throw new Error(`${block}-${taskname} expected callback function.`); - } - - const projects = blueprint.projectsWithBlock(block); - - // create build tasks with all dependencies - const taskNames = projects.map((project) => { - const taskName = [block, taskname, project.id].join("-"); - const deps = expandDeps(project, [block, taskname], dependencies); - gulp.task(taskName, deps, () => callback(project, false)); - return taskName; - }); - - // create watch tasks with no dependencies - const watchTaskNames = projects.map((project) => { - const watchName = [block, taskname, "w", project.id].join("-"); - gulp.task(watchName, [], () => callback(project, true)); - return watchName; - }); - - // create parents tasks to run individual project tasks - gulp.task([block, taskname].join("-"), taskNames); - gulp.task([block, taskname, "w"].join("-"), watchTaskNames); - }; -}; diff --git a/gulp/watch.js b/gulp/watch.js index 0e7e44a4dfa..ce8cfd5be4f 100644 --- a/gulp/watch.js +++ b/gulp/watch.js @@ -23,7 +23,7 @@ module.exports = (blueprint, gulp, plugins) => { gulp.task("watch-files", ["connect"], () => { blueprint.projectsWithBlock("sass").forEach((project) => { - const tasks = [`sass-compile-w-${project.id}`]; + const tasks = [`sass-${project.id}:only`]; if (project.id !== "docs") { tasks.push("sass-variables", "docs-kss"); } @@ -31,15 +31,15 @@ module.exports = (blueprint, gulp, plugins) => { }); blueprint.projectsWithBlock("typescript").forEach((project) => { - gulp.watch(createSrcGlob(project, "*.ts{,x}"), [`typescript-compile-w-${project.id}`]); + gulp.watch(createSrcGlob(project, "*.ts{,x}"), [`tsc-${project.id}:only`]); }); const docsCwd = blueprint.findProject("docs").cwd; gulp.watch(`${docsCwd}/src/styleguide.md`, ["docs-kss"]); // recompile docs CSS when non-docs dist/*.css files change - gulp.watch("packages/!(docs)/dist/*.css", ["sass-compile-w-docs"]); + gulp.watch("packages/!(docs)/dist/*.css", ["sass-docs:only"]); }); - gulp.task("watch", ["watch-files", "webpack-compile-w-docs"]); + gulp.task("watch", ["watch-files", "webpack-docs-watch"]); }; diff --git a/gulp/webpack.js b/gulp/webpack.js index c13d637baef..df4672448cb 100644 --- a/gulp/webpack.js +++ b/gulp/webpack.js @@ -8,14 +8,13 @@ module.exports = (blueprint, gulp) => { const webpackConfig = require("./util/webpack-config"); const docsProject = blueprint.findProject("docs"); - const configuration = webpackConfig.generateWebpackTypescriptConfig(docsProject); - gulp.task("webpack-compile-docs", ["docs"], (callback) => { + gulp.task("webpack-docs", ["docs"], (callback) => { webpack(configuration, webpackConfig.webpackDone(callback)); }); - gulp.task("webpack-compile-w-docs", (callback) => { // eslint-disable-line no-unused-vars + gulp.task("webpack-docs-watch", (callback) => { // rely on editor for compiler errors during development--this results in _massive_ speed increase configuration.ts.transpileOnly = true; // never invoke callback so it runs forever! diff --git a/packages/landing/scripts/dedupe-svg-ids.js b/packages/landing/scripts/dedupe-svg-ids.js index f219108f470..fbb49a904b4 100644 --- a/packages/landing/scripts/dedupe-svg-ids.js +++ b/packages/landing/scripts/dedupe-svg-ids.js @@ -1,7 +1,7 @@ var fs = require("fs"); var path = require("path"); -function rewriteIds(contents, id){ +function rewriteIds(contents, id) { return contents .replace(/\bhref="#/g, `href="#${id}-`) .replace(/url\(#/g, `url(#${id}-`) @@ -11,6 +11,7 @@ function rewriteIds(contents, id){ var svgs = require("../src/svgs.json"); svgs.forEach(function(svg) { var filePath = path.join(__dirname, "..", "src/resources/inline", svg + ".svg"); + // tslint:disable-next-line:no-console console.log("Rewriting IDs:", filePath); fs.writeFileSync(filePath, rewriteIds(fs.readFileSync(filePath, "UTF8"), svg)); }); diff --git a/packages/landing/src/logo.ts b/packages/landing/src/logo.ts index 0c9133893ab..912488f5297 100644 --- a/packages/landing/src/logo.ts +++ b/packages/landing/src/logo.ts @@ -5,6 +5,8 @@ * and https://github.com/palantir/blueprint/blob/master/PATENTS */ +// tslint:disable + const LOGO_Y_OFFSET = 250; const SHADOW_DEPTH = 0.3; const EXPLOSION_DELAY = 150; @@ -568,7 +570,7 @@ export class Accumulator implements ITickable { } } -class Timeline implements ITickable { +export class Timeline implements ITickable { private queue = [] as IKeyFrame[]; public constructor() { diff --git a/packages/landing/src/svgs.ts b/packages/landing/src/svgs.ts index 646b8b299c7..478f47e42c0 100644 --- a/packages/landing/src/svgs.ts +++ b/packages/landing/src/svgs.ts @@ -30,7 +30,7 @@ const injectSVG = (elem: HTMLElement, id: string) => { }; export const init = (elem: HTMLElement) => { - for (const id in HERO_SVGS) { + for (const id of Object.keys(HERO_SVGS)) { injectSVG(elem, id); } }; diff --git a/packages/table/config/webpack.config.preview.js b/packages/table/config/webpack.config.preview.js index 35beffa495c..2f91d19fd84 100644 --- a/packages/table/config/webpack.config.preview.js +++ b/packages/table/config/webpack.config.preview.js @@ -16,40 +16,40 @@ module.exports = { perf: resolve("preview/perf.tsx") }, - resolve: { - extensions: ["", ".js", ".ts", ".tsx"], - alias: { - react: resolve("/node_modules/react"), - }, - }, - - ts: { - compilerOptions: { declaration: false }, - }, - module: { loaders: [ { + loader: "ts-loader", test: /\.tsx?$/, - loader: "ts-loader" }, { - test: /\.css$/, loader: ExtractTextPlugin.extract("style", "css"), + test: /\.css$/, }, { - test: /\.(eot|ttf|woff|woff2)$/, // We need to resolve to an absolute path so that this loader // can be applied to CSS in other projects (i.e. packages/core) - loader: require.resolve("file-loader") + "?name=fonts/[name].[ext]" + loader: require.resolve("file-loader") + "?name=fonts/[name].[ext]", + test: /\.(eot|ttf|woff|woff2)$/, }, ], }, + output: { + filename: "[name].bundle.js", + path: resolve("preview/dist/") + }, + plugins: [ new ExtractTextPlugin("[name].css"), ], - output: { - filename: "[name].bundle.js", - path: resolve("preview/dist/") - } + resolve: { + alias: { + react: resolve("/node_modules/react"), + }, + extensions: ["", ".js", ".ts", ".tsx"], + }, + + ts: { + compilerOptions: { declaration: false }, + }, };