diff --git a/gulpfile.js b/gulpfile.js index f849d98ae4..a2cfef0b61 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,8 +13,6 @@ const gulp = require('gulp'); const gulpif = require('gulp-if'); -const audit = require('gulp-audit'); -const rename = require('gulp-rename'); const runseq = require('run-sequence'); const del = require('del'); const eslint = require('gulp-eslint'); @@ -22,7 +20,6 @@ const fs = require('fs'); const path = require('path'); const mergeStream = require('merge-stream'); const babel = require('gulp-babel'); -const htmlmin = require('gulp-htmlmin'); const size = require('gulp-size'); const lazypipe = require('lazypipe'); const closure = require('google-closure-compiler').gulp(); @@ -30,22 +27,12 @@ const minimalDocument = require('./util/minimalDocument.js') const DIST_DIR = 'dist'; const BUNDLED_DIR = path.join(DIST_DIR, 'bundled'); -const UNBUNDLED_DIR = path.join(DIST_DIR, 'unbundled'); const COMPILED_DIR = path.join(DIST_DIR, 'compiled'); -const DEFAULT_BUILD_DIR = BUNDLED_DIR; const POLYMER_LEGACY = 'polymer.html'; const POLYMER_ELEMENT = 'polymer-element.html'; -const DEFAULT_BUILD_TARGET = POLYMER_LEGACY; -const ENTRY_POINTS = [POLYMER_LEGACY, POLYMER_ELEMENT]; const polymer = require('polymer-build'); const PolymerProject = polymer.PolymerProject; -const project = new PolymerProject({ entrypoint: DEFAULT_BUILD_TARGET }); -const fork = polymer.forkStream; - -gulp.task('clean', function() { - return del(DIST_DIR); -}); const {Transform} = require('stream'); @@ -86,9 +73,29 @@ class Log extends Transform { } } +class Uniq extends Transform { + constructor() { + super({ objectMode: true }); + this.map = {}; + } + _transform(file, enc, cb) { + this.map[file.path] = file; + cb(); + } + _flush(done) { + for (let filePath in this.map) { + let file = this.map[filePath]; + this.push(file); + } + done(); + } +} + let CLOSURE_LINT_ONLY = false; let EXPECTED_WARNING_COUNT = 498; +gulp.task('clean', () => del(DIST_DIR)); + gulp.task('closure', ['clean'], () => { let entry, splitRx, joinRx; @@ -109,7 +116,11 @@ gulp.task('closure', ['clean'], () => { full(); const project = new PolymerProject({ - shell: `./${entry}` + shell: `./${entry}`, + fragments: [ + 'bower_components/shadycss/apply-shim.html', + 'bower_components/shadycss/custom-style-interface.html' + ] }); function closureLintLogger(log) { @@ -165,42 +176,11 @@ gulp.task('closure', ['clean'], () => { // process dependencies const dependencies = project.dependencies(); - class Uniq extends Transform { - constructor() { - super({ objectMode: true }); - this.map = {}; - } - _transform(file, enc, cb) { - this.map[file.path] = file; - cb(); - } - _flush(done) { - for (let filePath in this.map) { - let file = this.map[filePath]; - this.push(file); - } - done(); - } - } - - class NoDeps extends Transform { - constructor() { - super({objectMode: true}); - } - _transform(file, enc, cb) { - if (file.path.match(/shadycss/)) { - file.contents = new Buffer(''); - } - cb(null, file); - } - } - // merge the source and dependencies streams to we can analyze the project const mergedFiles = mergeStream(sources, dependencies); const splitter = new polymer.HtmlSplitter(); return mergedFiles - .pipe(new NoDeps()) .pipe(project.bundler()) .pipe(new Uniq()) .pipe(splitter.split()) @@ -216,106 +196,44 @@ gulp.task('lint-closure', (done) => { runseq('closure', done); }) -gulp.task('build', ['clean'], () => { - // process source files in the project - const sources = project.sources(); - - // process dependencies - const dependencies = project.dependencies(); - - // merge the source and dependencies streams to we can analyze the project - const mergedFiles = mergeStream(sources, dependencies); - - const bundlePipe = lazypipe() - .pipe(() => project.splitHtml()) - .pipe(() => gulpif(/\.js$/, babel({presets: ['babili']}))) - .pipe(() => project.rejoinHtml()) - .pipe(htmlmin, {removeComments: true}) - .pipe(minimalDocument) - .pipe(size, {title: 'bundled size', gzip: true, showTotal: false, showFiles: true}) - - return mergeStream( - fork(mergedFiles) - .pipe(project.bundler) - .pipe(gulpif(/polymer\.html/, bundlePipe())) - // write to the bundled folder - .pipe(gulp.dest(BUNDLED_DIR)), - - fork(mergedFiles) - .pipe(project.splitHtml()) - // add compilers or optimizers here! - .pipe(gulpif(/\.js$/, babel({presets: ['babili']}))) - .pipe(project.rejoinHtml()) - .pipe(htmlmin({removeComments: true})) - // write to the unbundled folder - .pipe(gulp.dest(UNBUNDLED_DIR)) - ); -}); - -// copy bower.json into dist folder -gulp.task('copy-bower-json', function() { - return gulp.src('bower.json').pipe(gulp.dest(DEFAULT_BUILD_DIR)); -}); - -// Build -gulp.task('build-steps', function(cb) { - runseq('restore-src', 'build', 'print-size', cb); -}); +gulp.task('estimate-size', ['clean'], () => { -// Bundled build -gulp.task('build-bundled', function(cb) { - runseq('build-steps', 'save-src', 'link-bundled', cb); -}); - -// Unbundled build -gulp.task('build-unbundled', function(cb) { - runseq('build-steps', 'save-src', 'link-unbundled', cb); -}); + const babelPresets = { + presets: [['babili', {regexpConstructors: false}]] + }; -// Default Task -gulp.task('default', ['build-bundled']); + const project = new PolymerProject({ + shell: POLYMER_LEGACY, + fragments: [ + 'bower_components/shadycss/apply-shim.html', + 'bower_components/shadycss/custom-style-interface.html' + ] + }); -// switch src and build for testing -gulp.task('save-src', function() { - return gulp.src(ENTRY_POINTS) - .pipe(rename(function(p) { - p.extname += '.src'; - })) - .pipe(gulp.dest('.')); -}); + // process source files in the project + const sources = project.sources(); -gulp.task('restore-src', function(cb) { - const files = ENTRY_POINTS.map(f => `${f}.src`); - gulp.src(files) - .pipe(rename(function(p) { - p.extname = ''; - })) - .pipe(gulp.dest('.')) - .on('end', () => Promise.all(files.map(f => del(f))).then(() => cb())); -}); + // process dependencies + const dependencies = project.dependencies(); -gulp.task('link-bundled', function(cb) { - ENTRY_POINTS.forEach(f => { - fs.writeFileSync(f, ``); - }); - cb(); -}); + // merge the source and dependencies streams to we can analyze the project + const mergedFiles = mergeStream(sources, dependencies); -gulp.task('link-unbundled', function(cb) { - ENTRY_POINTS.forEach(f => { - fs.writeFileSync(f, ``); - }); - cb(); -}); + const bundledSplitter = new polymer.HtmlSplitter(); -gulp.task('audit', function() { - return gulp.src(ENTRY_POINTS.map(f => path.join(DEFAULT_BUILD_DIR, f))) - .pipe(audit('build.log', { repos: ['.'] })) - .pipe(gulp.dest(DEFAULT_BUILD_DIR)); -}); + const bundlePipe = lazypipe() + .pipe(() => bundledSplitter.split()) + .pipe(() => gulpif(/\.js$/, babel(babelPresets))) + .pipe(() => bundledSplitter.rejoin()) + .pipe(minimalDocument) -gulp.task('release', function(cb) { - runseq('default', ['copy-bower-json', 'audit'], cb); + return mergedFiles + .pipe(project.bundler()) + .pipe(gulpif(/polymer\.html$/, bundlePipe())) + .pipe(new Uniq()) + .pipe(gulpif(/polymer\.html$/, size({ title: 'bundled size', gzip: true, showTotal: false, showFiles: true }))) + // write to the bundled folder + .pipe(gulp.dest(BUNDLED_DIR)) }); gulp.task('lint', function() { diff --git a/package.json b/package.json index 344a32a07d..d9e3423390 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,9 @@ "eslint-plugin-html": "^2.0.1", "google-closure-compiler": "^20170409.0.0", "gulp": "^3.9.1", - "gulp-audit": "^1.0.0", "gulp-babel": "^6.1.2", "gulp-eslint": "^3.0.1", - "gulp-htmlmin": "^3.0.0", "gulp-if": "^2.0.1", - "gulp-rename": "^1.2.2", "gulp-size": "^2.1.0", "gulp-vulcanize": "^6.0.1", "lazypipe": "^1.0.1",