basisjs-tools-build
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -0,1 +1,9 @@ | ||
## 1.7.0 (July 15, 2016) | ||
- Don't pack JavaScript with implicit `jsPackCmd`, but using `uglify.js` instead or explicit `jsPackCmd` if specified | ||
- Fixed warning count on build in non-verbose mode | ||
- Added warning count output for each build handler summary | ||
- Implemented option `--l10n-package` to store l10n cultures outside of bundle (except selected one) and load them asynchronously on demand (@fateevv) | ||
- Bump `basisjs-tools-ast` to [1.4.0](https://github.com/basisjs/basisjs-tools-ast/releases/tag/v1.4.0) | ||
## 1.6.0 (June 24, 2016) | ||
@@ -2,0 +10,0 @@ |
@@ -105,2 +105,6 @@ var path = require('path'); | ||
.option('-l, --l10n-pack', 'Build l10n index, pack dictionaries and replace token names for shorter one if possible (temporary do nothing)') | ||
.option('--l10n-package [storageKey]', 'Split dictionaries by cultures and move them to external package files', function(key){ | ||
return key || 'l10n'; | ||
}) | ||
.option('--l10n-default-culture <name>', 'Culture by default (have effect only when --l10n-package is used, default: en-US)', 'en-US') | ||
@@ -107,0 +111,0 @@ // tmpl |
@@ -209,2 +209,3 @@ var fs = require('fs'); | ||
var taskCount = 0; | ||
var warningCount = 0; | ||
var timing = []; | ||
@@ -235,5 +236,7 @@ var time; | ||
{ | ||
var newWarnings = flow.warns.length - warningCount; | ||
var timeDiff = process.hrtime(time.time); | ||
time.time = parseInt(timeDiff[0] * 1e3 + timeDiff[1] / 1e6, 10); | ||
timing.push(time); | ||
warningCount = flow.warns.length; | ||
@@ -263,2 +266,3 @@ if (!options.silent && !options.verbose && !stdoutHandlerSilent && handlers.length) | ||
chalk.green('DONE') + | ||
(newWarnings > 0 ? ' ' + chalk.bgRed('(' + newWarnings + (newWarnings > 1 ? ' warnings)' : ' warning)')) : '') + | ||
(time.time > 10 ? chalk.gray(' (' + time.time + 'ms)') : '') + | ||
@@ -265,0 +269,0 @@ '\n' |
var exec = require('child_process').exec; | ||
function repeat(str, count){ | ||
return new Array(count + 1).join(str); | ||
} | ||
(module.exports = function(flow, startFn, doneFn){ | ||
var queue = flow.files.queue; | ||
var fconsole = flow.console; | ||
var processor; | ||
startFn(); | ||
var command = flow.options.jsPackCmd || 'google-closure-compiler --charset UTF-8'; | ||
tryCmd(flow, function(processor){ | ||
flow.js.compressProcessor = processor.name; | ||
// process files | ||
fconsole.start(); | ||
for (var i = 0, file; file = queue[i]; i++) | ||
if (file.type == 'script' && file.outputContent && (file.htmlNode || file.outputFilename)) | ||
processor.process(file, flow, processor.name, startFn, doneFn); | ||
doneFn(); | ||
}); | ||
}).handlerName = '[js] Compress'; | ||
module.exports.extraInfo = function(flow){ | ||
return flow.js.compressProcessor; | ||
}; | ||
module.exports.skip = function(flow){ | ||
if (!flow.options.jsPack) | ||
return 'Use --js-pack or --pack to allow javascript file compess.'; | ||
}; | ||
// | ||
// choose processor | ||
// | ||
function tryCmd(flow, callback){ | ||
var command = flow.options.jsPackCmd; | ||
var processor = { | ||
name: 'uglify-js', | ||
process: uglifyProcess | ||
}; | ||
if (!command) | ||
{ | ||
process.nextTick(function(){ | ||
callback(processor); | ||
}); | ||
return; | ||
} | ||
// check command is works | ||
@@ -14,4 +57,2 @@ exec( | ||
function(error){ | ||
var processFile = cmdProcess; | ||
// if command doesn't work | ||
@@ -24,36 +65,14 @@ if (error) | ||
flow.warn({ message: '[WARN] `google-closure-compiler` is not available, downgrade to uglify.js' }); | ||
processFile = uglifyProcess; | ||
processor = 'uglify-js'; | ||
} | ||
else | ||
{ | ||
if (flow.options.jsPackCmd) | ||
processor = flow.options.jsPackCmd; | ||
else | ||
processor = 'google-closure-compiler'; | ||
processor = { | ||
name: flow.options.jsPackCmd || 'google-closure-compiler', | ||
process: cmdProcess | ||
}; | ||
} | ||
flow.js.compressProcessor = processor; | ||
// process files | ||
fconsole.start(); | ||
for (var i = 0, file; file = queue[i]; i++) | ||
if (file.type == 'script' && file.outputContent && (file.htmlNode || file.outputFilename)) | ||
processFile(file, flow, command, startFn, doneFn); | ||
doneFn(); | ||
callback(processor); | ||
} | ||
); | ||
}).handlerName = '[js] Compress'; | ||
module.exports.extraInfo = function(flow){ | ||
return flow.js.compressProcessor; | ||
}; | ||
module.exports.skip = function(flow){ | ||
if (!flow.options.jsPack) | ||
return 'Use --js-pack or --pack to allow javascript file compess.'; | ||
}; | ||
function repeat(str, count){ | ||
return new Array(count + 1).join(str); | ||
} | ||
@@ -60,0 +79,0 @@ |
@@ -1,25 +0,237 @@ | ||
(module.exports = function(){ | ||
// solution for basis.js prior 1.0 | ||
var js_at = require('basisjs-tools-ast').js; | ||
// var fconsole = flow.console; | ||
(module.exports = function(flow){ | ||
var fconsole = flow.console; | ||
// var cultureDictionaries = flow.l10n.cultureDictionaries; | ||
// var packages = []; | ||
var storagePrefix = flow.options.l10nPackage; | ||
var defaultCulture = flow.options.l10nDefaultCulture; | ||
// // make culture packs | ||
// fconsole.start('Make packages'); | ||
// for (var culture in cultureDictionaries) | ||
// { | ||
// fconsole.log(culture + ' add to resource map - OK'); | ||
var cultures = flow.l10n.cultures; | ||
var dictionaries = flow.l10n.dictionaries; | ||
// packages.push(flow.files.add({ | ||
// jsRef: 'l10n/' + culture + '.json', | ||
// type: 'json', | ||
// isResource: true, | ||
// jsResourceContent: cultureDictionaries[culture] | ||
// })); | ||
// } | ||
// | ||
// process dictionaries | ||
// | ||
// flow.l10n.packages = packages; | ||
fconsole.start('Split cultures by packages'); | ||
var packageContent = {}; | ||
var cultureList = []; | ||
var baseCulture; | ||
for (var culture in cultures) | ||
{ | ||
if (!baseCulture) | ||
baseCulture = culture; | ||
cultureList.push(cultures[culture].join('/')); | ||
packageContent[culture] = []; | ||
cultures[culture].push(baseCulture); | ||
} | ||
for (var path in dictionaries) | ||
{ | ||
var dictionary = dictionaries[path]; | ||
var basisjsDictionary = dictionary.basisjsDictionary; | ||
var dictOffset = parseInt(dictionary.file.jsRef, 36); | ||
for (var culture in cultures) | ||
packageContent[culture][dictOffset] = { | ||
_meta: { | ||
type: {} | ||
} | ||
}; | ||
for (var tokenName in dictionary.tokens) | ||
for (var culture in cultures) | ||
for (var i = 0, fallbackCulture; fallbackCulture = cultures[culture][i]; i++) | ||
{ | ||
var descriptor = basisjsDictionary.getCultureDescriptor(fallbackCulture, tokenName); | ||
if (descriptor) | ||
{ | ||
var dictContent = packageContent[culture][dictOffset]; | ||
var isLeafToken = typeof descriptor.value == 'string'; | ||
var isSubtoken = descriptor.name.indexOf('.') != -1; | ||
if (isLeafToken) | ||
{ | ||
if (isSubtoken) | ||
{ | ||
var namePath = descriptor.name.split('.'); | ||
dictContent[namePath[0]][namePath[1]] = descriptor.value; | ||
} | ||
else | ||
{ | ||
dictContent[descriptor.name] = descriptor.value; | ||
} | ||
} | ||
else | ||
{ | ||
dictContent[descriptor.name] = {}; | ||
} | ||
if (!isSubtoken && descriptor.types[descriptor.name] != 'default') | ||
dictContent._meta.type[descriptor.name] = descriptor.types[descriptor.name]; | ||
break; | ||
} | ||
} | ||
for (var culture in cultures) | ||
{ | ||
var dictContent = packageContent[culture][dictOffset]; | ||
if (!Object.keys(dictContent._meta.type).length) | ||
delete dictContent._meta; | ||
} | ||
dictionary.file.jsResourceContent = ''; | ||
} | ||
fconsole.endl(); | ||
// | ||
// generate package files | ||
// | ||
fconsole.start('Create generic files'); | ||
var packages = {}; | ||
for (var culture in packageContent) | ||
if (culture == defaultCulture) | ||
{ | ||
packages[culture] = { | ||
content: packageContent[culture] | ||
}; | ||
} | ||
else | ||
{ | ||
var file = flow.files.add({ | ||
type: 'culture', | ||
generated: true, | ||
isResource: true, | ||
outputFilename: 'res/' + culture + '.culture', | ||
outputContent: JSON.stringify(packageContent[culture]) | ||
}); | ||
packages[culture] = { | ||
cacheKey: storagePrefix + ':' + culture, | ||
filename: './res/' + culture + '.culture?' + file.digest, | ||
digest: file.digest | ||
}; | ||
fconsole.log(packages[culture].filename); | ||
} | ||
fconsole.endl(); | ||
// | ||
// inject package load script into module code | ||
// | ||
var injection = { | ||
body: function(cultureList, defaultCulture, packages){ | ||
/* eslint-env browser */ | ||
/* global basis, setCulture, setCultureList, dictionaryByUrl, currentCulture, onCultureChange, Dictionary, internalResolveDictionary */ | ||
setCultureList(cultureList); | ||
setCulture(defaultCulture); | ||
var packageCache = {}; | ||
packageCache[defaultCulture] = packages[defaultCulture].content; | ||
basis.resource.extensions['.l10n'] = function(content, url){ | ||
var packageContent = getPackageContent(currentCulture); | ||
if (packageContent) | ||
{ | ||
var dictOffset = parseInt(url.match(/.+\/(.+)\.l10n$/)[1], 36); | ||
var dictContent = {}; | ||
dictContent[currentCulture] = packageContent[dictOffset]; | ||
return internalResolveDictionary(url, true).update(dictContent); | ||
} | ||
}; | ||
Dictionary.extend(function(super_, proto_){ | ||
return { | ||
syncValues: function(){ | ||
if (getPackageContent(currentCulture)) | ||
proto_.syncValues.call(this); | ||
} | ||
}; | ||
}); | ||
onCultureChange(function(culture){ | ||
var packageContent = getPackageContent(culture); | ||
if (packageContent) | ||
applyPackage(packageContent); | ||
else | ||
loadPackage(culture); | ||
}, null, true); | ||
function getPackageContent(culture){ | ||
var packageContent = packageCache[culture]; | ||
if (!packageContent) | ||
{ | ||
var cacheData; | ||
try { | ||
cacheData = basis.json.parse(localStorage.getItem(packages[culture].cacheKey)); | ||
} catch(e) {}; | ||
if (cacheData && cacheData[1] == packages[culture].digest) | ||
packageContent = packageCache[culture] = cacheData[0]; | ||
else | ||
try { | ||
localStorage.removeItem(packages[culture].cacheKey); | ||
} catch(e) {}; | ||
} | ||
return packageContent; | ||
} | ||
function applyPackage(packageContent){ | ||
for (var i = 0, cultureData; cultureData = packageContent[i]; i++) | ||
{ | ||
var url = basis.path.resolve(i.toString(36) + '.l10n'); | ||
if (dictionaryByUrl[url]) | ||
{ | ||
var dictContent = {}; | ||
dictContent[currentCulture] = cultureData; | ||
dictionaryByUrl[url].update(dictContent); | ||
} | ||
} | ||
} | ||
function loadPackage(culture){ | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function(){ | ||
if (this.readyState == 4 && ((this.status >= 200 && this.status < 300) || this.status == 304)) | ||
{ | ||
var packageContent; | ||
try { | ||
packageContent = basis.json.parse(this.responseText); | ||
} catch(e) {}; | ||
if (packageContent) | ||
{ | ||
packageCache[culture] = packageContent; | ||
try { | ||
localStorage.setItem(packages[culture].cacheKey, JSON.stringify([packageContent, packages[culture].digest])); | ||
} catch(e) {}; | ||
applyPackage(packageContent); | ||
} | ||
} | ||
}; | ||
xhr.open('GET', packages[culture].filename, true); | ||
xhr.send(); | ||
} | ||
}, | ||
args: [cultureList, defaultCulture, packages].map(JSON.stringify).join(',') | ||
}; | ||
js_at.append(flow.l10n.module.ast, js_at.parse('(' + injection.body + ')(' + injection.args + ')')); | ||
}).handlerName = '[l10n] Make packages'; | ||
@@ -31,4 +243,7 @@ | ||
if (flow.l10n.version != 1) | ||
return 'Step is not supported for new version of basis.l10n'; | ||
if (!flow.options.l10nPackage) | ||
return 'Use option --l10n-package to split cultures by packages.'; | ||
if (typeof (flow.js.basis.l10n.getDictionaries()[0] || {}).getDescriptor != 'function') | ||
return 'l10n packages supported only in basis.js 1.7+'; | ||
}; |
@@ -11,8 +11,8 @@ var chalk = require('chalk'); | ||
fconsole.enabled = true; | ||
fconsole.log(); | ||
} | ||
if (false && !flow.warns.length) | ||
if (!flow.warns.length) | ||
{ | ||
fconsole.log(chalk.green('No warning')); | ||
if (flow.options.warnings) | ||
fconsole.log(chalk.green('\nNo warning')); | ||
return; | ||
@@ -22,6 +22,8 @@ } | ||
{ | ||
if (!flow.options.verbose) | ||
fconsole.log('Warnings: ' + chalk.bgRed(flow.warns.length)); | ||
fconsole.log('\nWarnings: ' + chalk.bgRed(flow.warns.length)); | ||
} | ||
if (!flow.options.warnings) | ||
return; | ||
flow.warns.forEach(function(item){ | ||
@@ -46,4 +48,1 @@ var filename = item.file || '[no file]'; | ||
module.exports.silent = true; | ||
module.exports.skip = function(flow){ | ||
return !flow.options.warnings; | ||
}; |
@@ -10,3 +10,3 @@ var path = require('path'); | ||
var textFileExt = ['.css', '.js', '.json', '.tmpl', '.txt', '.svg', '.html']; | ||
var textType = ['script', 'style', 'template', 'json', 'l10n', 'xml', 'svg', 'text']; | ||
var textType = ['script', 'style', 'template', 'json', 'l10n', 'culture', 'xml', 'svg', 'text']; | ||
@@ -13,0 +13,0 @@ var typeByExt = { |
@@ -231,3 +231,3 @@ var html = require('../html'); | ||
var removals = file.removals.map(function(fragment){ | ||
return fragment.token; | ||
return fragment.node || fragment.token; // new delaration uses `node` but previously `token` was using | ||
}); | ||
@@ -234,0 +234,0 @@ processTemplateAst(file, removals, idMapRemovals, classMapRemovals); |
@@ -135,3 +135,3 @@ var path = require('path'); | ||
list[i] = clist[0]; | ||
flow.l10n.cultures[clist[0]] = {}; | ||
flow.l10n.cultures[clist[0]] = clist; | ||
} | ||
@@ -138,0 +138,0 @@ |
@@ -12,3 +12,3 @@ var Dictionary = require('./Dictionary.js'); | ||
cultures: { 'en-US': {} }, | ||
cultures: { 'en-US': ['en-US'] }, | ||
dictionaries: {}, | ||
@@ -15,0 +15,0 @@ |
@@ -22,2 +22,3 @@ var Token = require('./Token.js'); | ||
file.jsResourceContent = dict._data; | ||
this.basisjsDictionary = dict; | ||
@@ -24,0 +25,0 @@ for (var culture in dict.cultureValues) |
{ | ||
"name": "basisjs-tools-build", | ||
"title": "Basis.js build tools", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"homepage": "https://github.com/basisjs/basisjs-tools", | ||
@@ -35,12 +35,12 @@ "description": "Build tools for basis.js framework", | ||
"dependencies": { | ||
"basisjs-tools-ast": "1.3.0", | ||
"basisjs-tools-config": "1.1.0", | ||
"chalk": "1.1.1", | ||
"clap": "1.1.0", | ||
"es6-promise-polyfill": "1.2.0", | ||
"fixed-width-string": "1.0.0", | ||
"mime": "1.3.4", | ||
"minimatch": "^3.0.0", | ||
"basisjs-tools-ast": "~1.4.0", | ||
"basisjs-tools-config": "~1.1.0", | ||
"chalk": "~1.1.1", | ||
"clap": "~1.1.0", | ||
"es6-promise-polyfill": "^1.2.0", | ||
"fixed-width-string": "^1.0.0", | ||
"mime": "~1.3.4", | ||
"minimatch": "^3.0.2", | ||
"resolve": "^1.1.7", | ||
"seedrandom": "2.4.2", | ||
"seedrandom": "~2.4.2", | ||
"uglify-js": "1.3.5" | ||
@@ -47,0 +47,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
289443
8899
+ Addedbasisjs-tools-ast@1.4.2(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclap@1.1.3(transitive)
+ Addedfixed-width-string@1.1.0(transitive)
+ Addedmime@1.3.6(transitive)
+ Addedseedrandom@2.4.4(transitive)
- Removedbasisjs-tools-ast@1.3.0(transitive)
- Removedchalk@1.1.1(transitive)
- Removedclap@1.1.0(transitive)
- Removedfixed-width-string@1.0.0(transitive)
- Removedmime@1.3.4(transitive)
- Removedseedrandom@2.4.2(transitive)
Updatedbasisjs-tools-ast@~1.4.0
Updatedbasisjs-tools-config@~1.1.0
Updatedchalk@~1.1.1
Updatedclap@~1.1.0
Updatedes6-promise-polyfill@^1.2.0
Updatedfixed-width-string@^1.0.0
Updatedmime@~1.3.4
Updatedminimatch@^3.0.2
Updatedseedrandom@~2.4.2