i18n-element
Version:
I18N Base Element for lit-html and Polymer
927 lines (846 loc) • 31.4 kB
JavaScript
/*
@license https://github.com/t2ym/i18n-behavior/blob/master/LICENSE.md
Copyright (c) 2016, Tetsuya Mori <t2y3141592@gmail.com>. All rights reserved.
*/
const gulp = require('gulp');
const gulpif = require('gulp-if');
const size = require('gulp-size');
const debug = require('gulp-debug');
const gutil = require('gulp-util');
const sort = require('gulp-sort');
const fs = require('fs');
const path = require('path');
const del = require('del');
const merge = require('merge-stream');
const runSequence = require('run-sequence');
const through = require('through2');
const JSONstringify = require('json-stringify-safe');
//const babel = require('gulp-babel');
const crisper = require('gulp-crisper');
const minifyHtml = require('gulp-minify-html');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const vulcanize = require('gulp-vulcanize');
const replace = require('gulp-replace');
const i18nPreprocess = require('gulp-i18n-preprocess');
const i18nLeverage = require('gulp-i18n-leverage');
// Global object to store localizable attributes repository
var attributesRepository = {};
// Store Bundles for i18n-behavior
var bundles = {};
gulp.task('clean', function() {
return del([
'test/src-lite',
'test/preprocess',
'test/preprocess-lite',
'test/preprocess-raw',
'test/vulcanize',
'test/vulcanize-lite',
'test/minify',
'test/minify-lite'
]);
});
// Scan HTMLs and construct localizable attributes repository
gulp.task('scan', function () {
return gulp.src([ 'test/src/**/*.html', '!test/src/**/*-test.html' ]) // input custom element HTMLs
.pipe(i18nPreprocess({
constructAttributesRepository: true, // construct attributes repository
attributesRepository: attributesRepository, // output object
srcPath: 'test/src', // path to source root
attributesRepositoryPath: './bower_components/i18n-behavior/i18n-attr-repo.html', // path to i18n-attr-repo.html
dropHtml: true // drop HTMLs
}))
.pipe(gulp.dest('test/preprocess')); // no outputs; dummy output path
});
gulp.task('src-lite', function () {
return gulp.src([ 'test/src/**/*' ])
.pipe(gulpif('*-test.html',
replace('../webcomponentsjs/webcomponents.min.js',
'../webcomponentsjs/webcomponents-lite.min.js')))
.pipe(gulp.dest('test/src-lite'));
});
// Preprocess templates and externalize JSON
gulp.task('preprocess', function () {
console.log('attributesRepository = ' + JSON.stringify(attributesRepository, null, 2));
var elements = gulp.src([ 'test/src/**/*.html', '!test/src/**/*-test.html' ]) // input custom element HTMLs
.pipe(i18nPreprocess({
replacingText: true, // replace UI texts with {{annotations}}
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src', // path to source root
attributesRepository: attributesRepository // input attributes repository
}))
.pipe(gulp.dest('test/preprocess')); // output preprocessed HTMLs and default JSON files to dist
var html = gulp.src([ 'test/src/**/*-test.html' ]) // non-custom-element HTMLs
.pipe(i18nPreprocess({
replacingText: true, // replace UI texts with {{annotations}}
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src', // path to source root
force: true, // force processing even without direct i18n-behavior.html import
attributesRepository: attributesRepository // input attributes repository
}))
.pipe(gulp.dest('test/preprocess'));
var js = gulp.src([ 'test/src/**/*.js' ])
.pipe(gulp.dest('test/preprocess'));
return merge(elements, html, js)
.pipe(size({title: 'preprocess'}));
});
// Merge code changes into JSON
gulp.task('leverage', function () {
return gulp.src([ 'test/src/**/locales/*.json' ]) // input localized JSON files in source
.pipe(i18nLeverage({
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src', // path to source root
distPath: 'test/preprocess', // path to dist root to fetch next default JSON files
finalize: false, // leave meta
bundles: bundles // output bundles object
}))
//.pipe(debug())
.pipe(gulp.dest('test/preprocess')); // path to output next localized JSON files
});
// Save attributes respository in test/preprocess just for testing
gulp.task('attributes-repository', function (callback) {
var DEST_DIR = 'test' + path.sep + 'preprocess';
fs.writeFileSync(DEST_DIR + path.sep + 'attributes-repository.json',
JSONstringify(attributesRepository, null, 2));
callback();
});
gulp.task('preprocess-raw', function () {
return gulp.src([ 'test/preprocess/**/*' ])
//.pipe(debug())
.pipe(gulp.dest('test/preprocess-raw'));
});
gulp.task('preprocess-lite', function () {
return gulp.src([ 'test/preprocess/**/*' ])
.pipe(gulpif('*-test.html',
replace('../webcomponentsjs/webcomponents.min.js',
'../webcomponentsjs/webcomponents-lite.min.js')))
.pipe(gulp.dest('test/preprocess-lite'));
});
gulp.task('clone', function () {
return gulp.src([ '*.html', '*.js', 'test/preprocess/**/*' ], { base: '.' })
//.pipe(debug())
.pipe(gulp.dest('bower_components/i18n-behavior'));
});
gulp.task('vulcanize', function() {
return gulp.src(['bower_components/i18n-behavior/test/preprocess/*-test.html'])
.pipe(vulcanize({
excludes: [
'bower_components/webcomponentsjs/webcomponents.min.js',
'bower_components/webcomponentsjs/webcomponents-lite.min.js',
'bower_components/web-component-tester/browser.js'
],
stripComments: true,
inlineCss: true,
inlineScripts: true
}))
.pipe(gulp.dest('test/vulcanize'))
.pipe(size({title: 'vulcanize'}));
});
gulp.task('clean-clone', function() {
return del(['bower_components/i18n-behavior']);
});
gulp.task('clone-lite', function () {
return gulp.src([ '*.html', '*.js', 'test/preprocess-lite/**/*' ], { base: '.' })
//.pipe(debug())
.pipe(gulp.dest('bower_components/i18n-behavior'));
});
gulp.task('vulcanize-lite', function() {
return gulp.src(['bower_components/i18n-behavior/test/preprocess-lite/*-test.html'])
.pipe(vulcanize({
excludes: [
'bower_components/webcomponentsjs/webcomponents.min.js',
'bower_components/webcomponentsjs/webcomponents-lite.min.js',
'bower_components/web-component-tester/browser.js'
],
stripComments: true,
inlineCss: true,
inlineScripts: true
}))
.pipe(gulp.dest('test/vulcanize-lite'))
.pipe(size({title: 'vulcanize-lite'}));
});
gulp.task('clean-clone-lite', function() {
return del(['bower_components/i18n-behavior']);
});
gulp.task('bundles', function (callback) {
var DEST_DIR = 'test' + path.sep + 'vulcanize';
var DEST_DIR_LITE = 'test' + path.sep + 'vulcanize-lite';
var localesPath = DEST_DIR + path.sep + 'locales';
var localesPathLite = DEST_DIR_LITE + path.sep + 'locales';
try {
fs.mkdirSync(localesPath);
fs.mkdirSync(localesPathLite);
}
catch (e) {}
for (var lang in bundles) {
bundles[lang].bundle = true;
if (lang) {
fs.writeFileSync(localesPath + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 2));
fs.writeFileSync(localesPathLite + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 2));
}
else {
// This is not required for deployment
fs.writeFileSync(DEST_DIR + path.sep + 'bundle.json',
JSONstringify(bundles[lang], null, 2));
fs.writeFileSync(DEST_DIR_LITE + path.sep + 'bundle.json',
JSONstringify(bundles[lang], null, 2));
}
}
callback();
});
gulp.task('bundle-ru', function () {
return gulp.src(['test/vulcanize/**/locales/bundle.ru.json'])
.pipe(gulp.dest('test/preprocess'));
});
gulp.task('bundle-ru-lite', function () {
return gulp.src(['test/vulcanize-lite/**/locales/bundle.ru.json'])
.pipe(gulp.dest('test/preprocess-lite'));
});
gulp.task('empty-ja', function () {
return gulp.src(['test/src/**/locales/null-template-default-lang-element.ja.json'])
.pipe(gulp.dest('test/preprocess'));
});
gulp.task('empty-bundle-ja', function (done) {
del('test/vulcanize/locales/bundle.ja.json');
del('test/vulcanize-lite/locales/bundle.ja.json');
done();
});
gulp.task('empty-mini-bundle-ja', function (done) {
del('test/minify/locales/bundle.ja.json');
del('test/minify-lite/locales/bundle.ja.json');
done();
});
gulp.task('minify', function() {
return gulp.src(['test/vulcanize/**/*', '!test/vulcanize/bundle.json'])
.pipe(gulpif('*.html', crisper({
scriptInHead: false
})))
.pipe(gulpif('*.html', minifyHtml({
quotes: true,
empty: true,
spare: true
})))
.pipe(gulpif('*.js', uglify({
preserveComments: 'some'
})))
.pipe(gulp.dest('test/minify'))
.pipe(size({title: 'minify'}));
});
gulp.task('minify-lite', function() {
return gulp.src(['test/vulcanize-lite/**/*', '!test/vulcanize-lite/bundle.json'])
.pipe(gulpif('*.html', crisper({
scriptInHead: false
})))
.pipe(gulpif('*.html', minifyHtml({
quotes: true,
empty: true,
spare: true
})))
.pipe(gulpif('*.js', uglify({
preserveComments: 'some'
})))
.pipe(gulp.dest('test/minify-lite'))
.pipe(size({title: 'minify-lite'}));
});
gulp.task('mini-bundles', function (callback) {
var DEST_DIR = 'test' + path.sep + 'minify';
var DEST_DIR_LITE = 'test' + path.sep + 'minify-lite';
var localesPath = DEST_DIR + path.sep + 'locales';
var localesPathLite = DEST_DIR_LITE + path.sep + 'locales';
try {
fs.mkdirSync(localesPath);
fs.mkdirSync(localesPathLite);
}
catch (e) {}
for (var lang in bundles) {
bundles[lang].bundle = true;
if (lang) {
fs.writeFileSync(localesPath + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 0));
fs.writeFileSync(localesPathLite + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 0));
}
}
callback();
});
gulp.task('fake-server', function() {
var fakeContents = {};
var fakeServerFiles = [];
var fakeServerTemplate = 'window.fakeServerContents =\n%%%CONTENTS%%%;\n';
return gulp.src(['test/**/*.json', '!**/bundle.json', '!test/*-wct.conf.json', '!test/coverage*', '!test/bower*.json', '!**/*-polymer.json', '!**/*gulpfile.js'])
.pipe(sort())
.pipe(through.obj(function (file, enc, callback) {
fakeServerFiles.push(file);
callback();
}, function (callback) {
var base = fakeServerFiles[0].base;
var cwd = fakeServerFiles[0].cwd;
var file;
var match;
var suite;
while (fakeServerFiles.length > 0) {
file = fakeServerFiles.shift();
console.log(file.path);
match = file.path.substr(file.base.length).match(/^([^\/]*)(\/.*)$/);
fakeContents[match[1]] = fakeContents[match[1]] || {};
fakeContents[match[1]][match[2]] = String(file.contents);
}
for (suite in fakeContents) {
this.push(new gutil.File({
cwd: cwd,
base: base,
path: path.join(base, suite, 'fake-server.js'),
contents: new Buffer(fakeServerTemplate
.replace(/%%%CONTENTS%%%/g, JSONstringify(fakeContents[suite], null, 2)))
}));
}
callback();
}))
.pipe(debug({ title: 'fake-server' }))
.pipe(gulp.dest('test'))
.pipe(size({ title: 'fake-server' }));
});
gulp.task('clean2', function() {
return del([
'test/src2-min',
'test/preprocess2',
'test/preprocess2-min',
'test/preprocess2-raw',
'test/vulcanize2',
'test/vulcanize2-min',
'test/minify2',
'test/minify2-min'
]);
});
gulp.task('patchshadycss', () => {
return gulp.src([ 'bower_components/shadycss/shadycss.min.js' ])
.pipe(replace(/\n}\)[.]call\(this\)\n/, '\n}).call(this);\n', 'g'))
.pipe(debug())
.pipe(gulp.dest('bower_components/shadycss/'));
});
gulp.task('polyfillclone', () => {
return gulp.src([ 'test/webcomponents-lite.min.html' ])
.pipe(debug())
.pipe(gulp.dest('bower_components/webcomponentsjs/'));
});
gulp.task('webcomponents-min', () => {
return gulp.src([ 'bower_components/webcomponentsjs/webcomponents-lite.min.html' ], { base: 'bower_components/webcomponentsjs/' })
.pipe(vulcanize({
abspath: '',
excludes: [],
stripExcludes: false,
inlineScripts: true
}))
.pipe(crisper({
scriptInHead: false
}))
.pipe(gulpif('*.js', uglify()))
.pipe(debug())
.pipe(gulp.dest('test/webcomponentsjs/'));
});
gulp.task('patch-browserjs', () => {
return gulp.src([ 'bower_components/web-component-tester/**/*' ])
.pipe(gulpif('browser.js', replace(
"'test-fixture/test-fixture.html'",
"'test-fixture/test-fixture-es5.html'", 'g')))
.pipe(debug())
.pipe(gulp.dest('bower_components/web-component-tester-es5/'));
});
gulp.task('patch-web-component-tester', () => {
// Patch with PR https://github.com/Polymer/web-component-tester/pull/399/commits/67062d199a5bb8ad114652d5b2a9ed7a31e82b46
return gulp.src([ 'node_modules/web-component-tester/runner/webserver.js' ])
.pipe(gulpif('webserver.js', replace(
"yield wct.emitHook('prepare:webserver', app);",
"yield wct.emitHook('prepare:webserver', app, () => {});", 'g')))
.pipe(gulp.dest('node_modules/web-component-tester/runner/'));
});
// Scan HTMLs and construct localizable attributes repository
gulp.task('scan2', function () {
return gulp.src([ 'test/src2/**/*.html', '!test/src2/**/*-test.html' ]) // input custom element HTMLs
.pipe(i18nPreprocess({
constructAttributesRepository: true, // construct attributes repository
attributesRepository: attributesRepository, // output object
srcPath: 'test/src2', // path to source root
attributesRepositoryPath: './bower_components/i18n-behavior/i18n-attr-repo.html', // path to i18n-attr-repo.html
dropHtml: true, // drop HTMLs,
targetVersion: 2
}))
.pipe(gulp.dest('test/preprocess2')); // no outputs; dummy output path
});
gulp.task('src2-min', function () {
return gulp.src([ 'test/src2/**/*' ])
//.pipe(gulpif('*-test.html',
// replace('../../../webcomponentsjs/webcomponents-lite.js',
// '../webcomponentsjs/webcomponents-loader.js')))
.pipe(gulp.dest('test/src2-min'));
});
// Preprocess templates and externalize JSON
gulp.task('preprocess2', function () {
console.log('attributesRepository = ' + JSON.stringify(attributesRepository, null, 2));
var elements = gulp.src([ 'test/src2/**/*.html', '!test/src2/**/*-test.html' ]) // input custom element HTMLs
.pipe(i18nPreprocess({
replacingText: true, // replace UI texts with {{annotations}}
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src2', // path to source root
attributesRepository: attributesRepository, // input attributes repository
targetVersion: 2
}))
.pipe(gulp.dest('test/preprocess2')); // output preprocessed HTMLs and default JSON files to dist
var html = gulp.src([ 'test/src2/**/*-test.html' ]) // non-custom-element HTMLs
.pipe(i18nPreprocess({
replacingText: true, // replace UI texts with {{annotations}}
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src2', // path to source root
force: true, // force processing even without direct i18n-behavior.html import
attributesRepository: attributesRepository, // input attributes repository
targetVersion: 2
}))
.pipe(gulp.dest('test/preprocess2'));
var js = gulp.src([ 'test/src2/**/*.js' ])
.pipe(gulp.dest('test/preprocess2'));
return merge(elements, html, js)
.pipe(size({title: 'preprocess2'}));
});
// Merge code changes into JSON
gulp.task('leverage2', function () {
return gulp.src([ 'test/src2/**/locales/*.json' ]) // input localized JSON files in source
.pipe(i18nLeverage({
jsonSpace: 2, // JSON format with 2 spaces
srcPath: 'test/src2', // path to source root
distPath: 'test/preprocess2', // path to dist root to fetch next default JSON files
finalize: false, // leave meta
bundles: bundles // output bundles object
}))
//.pipe(debug())
.pipe(gulp.dest('test/preprocess2')); // path to output next localized JSON files
});
// Save attributes respository in test/preprocess just for testing
gulp.task('attributes-repository2', function (callback) {
var DEST_DIR = 'test' + path.sep + 'preprocess2';
fs.writeFileSync(DEST_DIR + path.sep + 'attributes-repository.json',
JSONstringify(attributesRepository, null, 2));
callback();
});
gulp.task('preprocess2-raw', function () {
return gulp.src([ 'test/preprocess2/**/*' ])
//.pipe(debug())
.pipe(gulp.dest('test/preprocess2-raw'));
});
gulp.task('preprocess2-min', function () {
return gulp.src([ 'test/preprocess2/**/*' ])
//.pipe(gulpif('*-test.html',
// replace('../../../webcomponentsjs/webcomponents-lite.js',
// '../webcomponentsjs/webcomponents-loader.js')))
.pipe(gulp.dest('test/preprocess2-min'));
});
gulp.task('clone2', function () {
return gulp.src([ '*.html', '*.js', 'test/preprocess2/**/*' ], { base: '.' })
//.pipe(debug())
.pipe(gulp.dest('bower_components/i18n-element'));
});
gulp.task('vulcanize2', function() {
return gulp.src([
'bower_components/i18n-element/test/preprocess2/*-test.html',
'bower_components/i18n-element/test/preprocess2/*-test-imports.html',
'bower_components/i18n-element/test/preprocess2/**/*.json'
])
.pipe(gulpif('*-test-imports.html', vulcanize({
excludes: [
'bower_components/webcomponentsjs/webcomponents-lite.js',
'bower_components/webcomponentsjs/webcomponents-loader.js',
'bower_components/web-component-tester/browser.js'
],
stripComments: true,
inlineCss: true,
inlineScripts: true
})))
.pipe(gulp.dest('test/vulcanize2'))
.pipe(size({title: 'vulcanize2'}));
});
gulp.task('clean-clone2', function() {
return del(['bower_components/i18n-element']);
});
gulp.task('clone2-min', function () {
return gulp.src([ '*.html', '*.js', 'test/preprocess2-min/**/*' ], { base: '.' })
//.pipe(debug())
.pipe(gulp.dest('bower_components/i18n-element'));
});
gulp.task('vulcanize2-min', function() {
return gulp.src([
'bower_components/i18n-element/test/preprocess2-min/*-test.html',
'bower_components/i18n-element/test/preprocess2-min/*-test-imports.html',
'bower_components/i18n-element/test/preprocess2-min/**/*.json'
])
.pipe(gulpif('*-test-imports.html', vulcanize({
excludes: [
'bower_components/webcomponentsjs/webcomponents-lite.js',
'bower_components/webcomponentsjs/webcomponents-loader.js',
'bower_components/web-component-tester/browser.js'
],
stripComments: true,
inlineCss: true,
inlineScripts: true
})))
.pipe(gulp.dest('test/vulcanize2-min'))
.pipe(size({title: 'vulcanize2-min'}));
});
gulp.task('clean-clone2-min', function() {
return del(['bower_components/i18n-element']);
});
gulp.task('bundles2', function (callback) {
var DEST_DIR = 'test' + path.sep + 'vulcanize2';
var DEST_DIR_LITE = 'test' + path.sep + 'vulcanize2-min';
var localesPath = DEST_DIR + path.sep + 'locales';
var localesPathLite = DEST_DIR_LITE + path.sep + 'locales';
try {
fs.mkdirSync(localesPath);
fs.mkdirSync(localesPathLite);
}
catch (e) {}
for (var lang in bundles) {
bundles[lang].bundle = true;
if (lang) {
fs.writeFileSync(localesPath + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 2));
fs.writeFileSync(localesPathLite + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 2));
}
else {
// This is not required for deployment
fs.writeFileSync(DEST_DIR + path.sep + 'bundle.json',
JSONstringify(bundles[lang], null, 2));
fs.writeFileSync(DEST_DIR_LITE + path.sep + 'bundle.json',
JSONstringify(bundles[lang], null, 2));
}
}
callback();
});
gulp.task('bundle-ru2', function () {
return gulp.src(['test/vulcanize2/**/locales/bundle.ru.json'])
.pipe(gulp.dest('test/preprocess2'));
});
gulp.task('bundle-ru2-min', function () {
return gulp.src(['test/vulcanize2-min/**/locales/bundle.ru.json'])
.pipe(gulp.dest('test/preprocess2-min'));
});
gulp.task('empty-ja2', function () {
return gulp.src(['test/src2/**/locales/null-template-default-lang-element.ja.json'])
.pipe(gulp.dest('test/preprocess2'));
});
gulp.task('empty-bundle-ja2', function (done) {
del('test/vulcanize2/locales/bundle.ja.json');
del('test/vulcanize2-min/locales/bundle.ja.json');
done();
});
gulp.task('empty-mini-bundle-ja2', function (done) {
del('test/minify2/locales/bundle.ja.json');
del('test/minify2-min/locales/bundle.ja.json');
done();
});
gulp.task('minify2', function() {
return gulp.src(['test/vulcanize2/**/*', '!test/vulcanize2/bundle.json'])
//.pipe(gulpif('*-test.html',
// replace('<!-- <script src="..\/..\/..\/custom-elements\/src\/native-shim.js"><\/script> -->',
// '<script src="..\/..\/..\/custom-elements\/src\/native-shim.js"><\/script>', 'g')))
.pipe(gulpif('*-test.html',
replace('"../../../web-component-tester/browser.js"',
'"../../../web-component-tester-es5/browser.js"', 'g')))
.pipe(gulpif('*.html', crisper({
scriptInHead: false
})))
.pipe(gulpif('*.js', babel({
"presets": [ /*'es2015'*/ ],
"plugins": [
'check-es2015-constants',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoped-functions',
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-computed-properties',
'transform-es2015-destructuring',
'transform-es2015-duplicate-keys',
'transform-es2015-for-of',
'transform-es2015-function-name',
'transform-es2015-literals',
//'transform-es2015-modules-commonjs',
'transform-es2015-object-super',
'transform-es2015-parameters',
'transform-es2015-shorthand-properties',
'transform-es2015-spread',
'transform-es2015-sticky-regex',
'transform-es2015-template-literals',
'transform-es2015-typeof-symbol',
'transform-es2015-unicode-regex',
'transform-regenerator'
]
})))
.pipe(gulpif('*.js', uglify({ mangle: false })))
.pipe(gulpif('*.html', minifyHtml({
quotes: true,
empty: true,
spare: true
})))
.pipe(gulp.dest('test/minify2'))
.pipe(size({title: 'minify2'}));
});
gulp.task('minify2-min', function() {
return gulp.src(['test/vulcanize2-min/**/*', '!test/vulcanize2-min/bundle.json'])
//.pipe(gulpif('*-test.html',
// replace('<!-- <script src="..\/..\/..\/custom-elements\/src\/native-shim.js"><\/script> -->',
// '<script src="..\/..\/..\/custom-elements\/src\/native-shim.js"><\/script>', 'g')))
.pipe(gulpif('*-test.html',
replace('"../../../web-component-tester/browser.js"',
'"../../../web-component-tester-es5/browser.js"', 'g')))
.pipe(gulpif('*.html', crisper({
scriptInHead: false
})))
.pipe(sourcemaps.init())
.pipe(gulpif('*.js', babel({
"presets": [ /*'es2015'*/ ],
"plugins": [
'check-es2015-constants',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoped-functions',
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-computed-properties',
'transform-es2015-destructuring',
'transform-es2015-duplicate-keys',
'transform-es2015-for-of',
'transform-es2015-function-name',
'transform-es2015-literals',
//'transform-es2015-modules-commonjs',
'transform-es2015-object-super',
'transform-es2015-parameters',
'transform-es2015-shorthand-properties',
'transform-es2015-spread',
'transform-es2015-sticky-regex',
'transform-es2015-template-literals',
'transform-es2015-typeof-symbol',
'transform-es2015-unicode-regex',
'transform-regenerator'
]
})))
.pipe(gulpif('*.js', uglify({ mangle: false })))
.pipe(gulpif('*.html', minifyHtml({
quotes: true,
empty: true,
spare: true
})))
.pipe(sourcemaps.write('sourcemaps'))
.pipe(gulp.dest('test/minify2-min'))
.pipe(size({title: 'minify2-min'}));
});
gulp.task('mini-bundles2', function (callback) {
var DEST_DIR = 'test' + path.sep + 'minify2';
var DEST_DIR_LITE = 'test' + path.sep + 'minify2-min';
var localesPath = DEST_DIR + path.sep + 'locales';
var localesPathLite = DEST_DIR_LITE + path.sep + 'locales';
try {
fs.mkdirSync(localesPath);
fs.mkdirSync(localesPathLite);
}
catch (e) {}
for (var lang in bundles) {
bundles[lang].bundle = true;
if (lang) {
fs.writeFileSync(localesPath + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 0));
fs.writeFileSync(localesPathLite + path.sep + 'bundle.' + lang + '.json',
JSONstringify(bundles[lang], null, 0));
}
}
callback();
});
gulp.task('pretest', ['clean'], function(cb) {
runSequence(
'scan',
'src-lite',
'preprocess',
'leverage',
'attributes-repository',
'preprocess-raw',
'empty-ja',
'preprocess-lite',
'clone',
'vulcanize',
'clean-clone',
'clone-lite',
'vulcanize-lite',
'clean-clone-lite',
'bundles',
'bundle-ru',
'bundle-ru-lite',
'empty-bundle-ja',
'minify',
'minify-lite',
'mini-bundles',
'empty-mini-bundle-ja',
'fake-server',
/*
'feedback',
*/
cb);
});
gulp.task('pretest2', ['clean2'], function(cb) {
runSequence(
//'patchshadycss',
//'polyfillclone',
//'webcomponents-min',
//'patch-browserjs',
//'patch-web-component-tester',
'scan2',
'src2-min',
'preprocess2',
'leverage2',
'attributes-repository2',
'preprocess2-raw',
'empty-ja2',
/*
'preprocess2-min',
'clone2',
'vulcanize2',
'clean-clone2',
'clone2-min',
'vulcanize2-min',
'clean-clone2-min',
'bundles2',
'bundle-ru2',
'bundle-ru2-min',
'empty-bundle-ja2',
'minify2',
'minify2-min',
'mini-bundles2',
'empty-mini-bundle-ja2',
*/
'fake-server',
/*
'feedback',
*/
cb);
});
//require('web-component-tester').gulp.init(gulp, [ 'pretest2' ]);
gulp.task('patch-wct-browser-legacy', () => {
return gulp.src([ 'test/browser.js' ], { base: 'test' })
.pipe(gulp.dest('node_modules/wct-browser-legacy'));
});
gulp.task('patch-browser-capabilities', () => {
return gulp.src([ 'test/browser-capabilities.js' ], { base: 'test' })
.pipe(gulp.dest('node_modules/browser-capabilities/lib'));
});
gulp.task('patch-web-component-tester-for-selenium-grid-ie11', () => {
return gulp.src([ 'node_modules/web-component-tester/runner/webserver.js '], { base: 'node_modules/web-component-tester/runner' })
.pipe(replace("const DEFAULT_HEADERS = {","const DEFAULT_HEADERS =/**/{\n 'X-UA-Compatible': 'IE=11',"))
.pipe(gulp.dest('node_modules/web-component-tester/runner/'));
});
gulp.task('patch-web-component-tester-for-http-caching', () => {
return gulp.src([ 'node_modules/web-component-tester/runner/webserver.js '], { base: 'node_modules/web-component-tester/runner' })
.pipe(replace("'Cache-Control': 'no-cache, no-store, must-revalidate',", "'Cache-Control': 'public, max-age=31536000',"))
.pipe(replace("'Pragma': 'no-cache',", "//'Pragma':/**/ 'no-cache',"))
.pipe(replace("'Expires': '0',", "//'Expires':/**/ '0',"))
.pipe(gulp.dest('node_modules/web-component-tester/runner/'));
});
const rollup = require('rollup');
const sizes = require('rollup-plugin-sizes');
const filesize = require('rollup-plugin-filesize');
const { terser } = require('rollup-plugin-terser');
const gzip = require('gulp-gzip');
gulp.task('size-webpack', function (cb) {
return gulp.src('dist/i18n.bundled-not-usable-as-it-is.js')
.pipe(debug())
.pipe(size())
.pipe(gzip())
.pipe(debug())
.pipe(size())
.pipe(gulp.dest('test/build/'));
});
gulp.task('size-polymer-build', function (cb) {
return gulp.src('test/build/i18n.js')
.pipe(debug())
.pipe(size())
.pipe(gzip())
.pipe(debug())
.pipe(size())
.pipe(gulp.dest('test/build/'));
});
gulp.task('size-polymer-build-core', function (cb) {
return gulp.src('test/core/i18n-core.js')
.pipe(debug())
.pipe(size())
.pipe(gzip())
.pipe(debug())
.pipe(size())
.pipe(gulp.dest('test/build/'));
});
gulp.task('size', function(cb) {
runSequence(
'size-webpack',
'size-polymer-build',
'size-polymer-build-core',
cb);
});
gulp.task('i18n-core.js', function() {
return gulp.src([ 'src/i18n.js' ])
.pipe(through.obj(function (file, enc, callback) {
const FOR_I18N_JS_BEGIN = '/* unnecessary part of i18n-core.js: BEGIN */';
const FOR_I18N_JS_END = '/* unnecessary part of i18n-core.js: END */';
const FOR_I18N_CORE_JS_BEGIN = '/* uncommented part of i18n-core.js: BEGIN';
const FOR_I18N_CORE_JS_END = 'uncommented part of i18n-core.js: END */';
let src = String(file.contents);
let lines = src.split(/\n/);
let i18n_js = [];
let i18n_core_js = [];
let for_i18n_js = false;
let for_i18n_core_js = false;
for (let line of lines) {
switch (line) {
case FOR_I18N_JS_BEGIN:
for_i18n_js = true;
break;
case FOR_I18N_JS_END:
for_i18n_js = false;
break;
case FOR_I18N_CORE_JS_BEGIN:
for_i18n_core_js = true;
break;
case FOR_I18N_CORE_JS_END:
for_i18n_core_js = false;
break;
default:
if (for_i18n_js) {
if (for_i18n_core_js) {
throw new Error('Incorrect format found in src/i18n.js at ' + line);
}
else {
i18n_js.push(line);
}
}
else {
if (for_i18n_core_js) {
i18n_core_js.push(line);
}
else {
i18n_js.push(line);
i18n_core_js.push(line);
}
}
break;
}
}
let i18nCoreFile = new gutil.File({
cwd: file.cwd,
base: file.cwd,
path: 'i18n-core.js',
contents: new Buffer(i18n_core_js.join('\n'))
});
this.push(i18nCoreFile);
file.base = file.cwd;
file.path = 'i18n.js';
file.contents = new Buffer(i18n_js.join('\n'));
callback(null, file);
}))
.pipe(gulp.dest('.'));
});