mirror of
https://github.com/jlengrand/webcomponentsjs.git
synced 2026-03-10 08:51:22 +00:00
163 lines
4.5 KiB
JavaScript
163 lines
4.5 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
|
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
* Code distributed by Google as part of the polymer project is also
|
|
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
*/
|
|
|
|
// jshint node: true
|
|
|
|
'use strict';
|
|
|
|
var audit = require('gulp-audit');
|
|
var compilerPackage = require('google-closure-compiler');
|
|
var concat = require('gulp-concat');
|
|
var exec = require('child_process').exec;
|
|
var fs = require('fs');
|
|
var gulp = require('gulp');
|
|
var header = require('gulp-header');
|
|
var path = require('path');
|
|
var rename = require('gulp-rename');
|
|
var runseq = require('run-sequence');
|
|
var uglify = require('gulp-uglify');
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
var closureCompiler = compilerPackage.gulp();
|
|
|
|
// init tests with gulp
|
|
require('web-component-tester').gulp.init(gulp);
|
|
|
|
var isRelease = process.env.RELEASE !== undefined;
|
|
|
|
var banner = fs.readFileSync('banner.txt', 'utf8');
|
|
|
|
var pkg;
|
|
|
|
function defineBuildTask(name, manifest) {
|
|
(function() {
|
|
|
|
manifest = manifest || './src/' + name + '/build.json';
|
|
var output = name;
|
|
var list = readManifest(manifest);
|
|
gulp.task(name + '-debug', ['version'], function() {
|
|
return gulp.src(list)
|
|
.pipe(concat(output + '.js'))
|
|
.pipe(uglify({
|
|
mangle: false,
|
|
compress: false,
|
|
output: {
|
|
beautify: true,
|
|
indent_level: 2
|
|
}
|
|
}))
|
|
.pipe(header(banner, {pkg: pkg}))
|
|
.pipe(gulp.dest('dist/'))
|
|
;
|
|
});
|
|
|
|
gulp.task(name, ['version', name + '-debug'], function() {
|
|
return gulp.src(list)
|
|
.pipe(concat(output + '.min.js'))
|
|
.pipe(uglify())
|
|
.pipe(header(banner, {pkg: pkg}))
|
|
.pipe(gulp.dest('dist/'))
|
|
;
|
|
});
|
|
|
|
})();
|
|
}
|
|
|
|
function readJSON(filename) {
|
|
var blob = fs.readFileSync(filename, 'utf8');
|
|
return JSON.parse(blob);
|
|
}
|
|
|
|
gulp.task('audit', function() {
|
|
return gulp.src('dist/*.js')
|
|
.pipe(audit('build.log', {repos:['.']}))
|
|
.pipe(gulp.dest('dist/'));
|
|
});
|
|
|
|
gulp.task('version', function(cb) {
|
|
pkg = require('./package.json');
|
|
var cmd = ['git', 'rev-parse', '--short', 'HEAD'].join(' ');
|
|
if (!isRelease) {
|
|
exec(cmd, function(err, stdout, stderr) {
|
|
if (err) {
|
|
return cb(err);
|
|
}
|
|
if (stdout) {
|
|
stdout = stdout.trim();
|
|
}
|
|
pkg.version = pkg.version + '-' + stdout;
|
|
cb();
|
|
});
|
|
} else {
|
|
cb();
|
|
}
|
|
});
|
|
|
|
function readManifest(filename, modules) {
|
|
modules = modules || [];
|
|
var lines = readJSON(filename);
|
|
var dir = path.dirname(filename);
|
|
lines.forEach(function(line) {
|
|
var fullpath = path.join(dir, line);
|
|
if (line.slice(-5) == '.json') {
|
|
// recurse
|
|
modules = modules.concat(readManifest(fullpath, modules));
|
|
} else {
|
|
modules.push(fullpath);
|
|
}
|
|
});
|
|
var tmp = Object.create(null);
|
|
for (var i = 0; i < modules.length; i++) {
|
|
tmp[modules[i]] = 1;
|
|
}
|
|
modules = Object.keys(tmp);
|
|
return modules;
|
|
}
|
|
|
|
gulp.task('copy-bower', function() {
|
|
return gulp.src(['bower.json', 'package.json', 'README.md']).pipe(gulp.dest('dist/'));
|
|
});
|
|
|
|
defineBuildTask('webcomponents', './src/WebComponents/build.json');
|
|
defineBuildTask('webcomponents-lite', './src/WebComponents/build-lite.json');
|
|
defineBuildTask('CustomElements');
|
|
defineBuildTask('HTMLImports');
|
|
defineBuildTask('ShadowDOM');
|
|
defineBuildTask('MutationObserver');
|
|
|
|
gulp.task('CustomElementsV1', function () {
|
|
return gulp.src('./src/CustomElements/v1/CustomElements.js', {base: './'})
|
|
.pipe(sourcemaps.init())
|
|
.pipe(closureCompiler({
|
|
compilation_level: 'ADVANCED',
|
|
warning_level: 'VERBOSE',
|
|
language_in: 'ECMASCRIPT6_STRICT',
|
|
language_out: 'ECMASCRIPT5_STRICT',
|
|
externs: 'externs/html5.js',
|
|
js_output_file: 'CustomElementsV1.min.js',
|
|
new_type_inf: true,
|
|
rewrite_polyfills: false,
|
|
}))
|
|
.pipe(sourcemaps.write('/'))
|
|
.pipe(gulp.dest('./dist'));
|
|
});
|
|
|
|
gulp.task('build', ['webcomponents', 'webcomponents-lite', 'CustomElements',
|
|
'CustomElementsV1', 'HTMLImports', 'ShadowDOM', 'copy-bower',
|
|
'MutationObserver']);
|
|
|
|
gulp.task('release', function(cb) {
|
|
isRelease = true;
|
|
runseq('build', 'audit', cb);
|
|
});
|
|
|
|
gulp.task('default', function(cb) {
|
|
runseq('build', 'audit', cb);
|
|
});
|