forked from ajv-validator/ajv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the "bundle" script with a cross platform Node script called…
… "bundle.js" (modeled after the original). Added "del-cli" as a dev dependency, as a cross platform replacement of "rm". Changed the quotes in the "if-node-version" call to doubles, to prevent dummy file being created on Windows.
- Loading branch information
Showing
3 changed files
with
65 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
var pkg = process.argv[2]; | ||
var standalone = process.argv[3]; | ||
var compress = process.argv[4]; | ||
|
||
var fs = require('fs'); | ||
var packageDir = __dirname + '/..'; | ||
if ('.' !== pkg) { | ||
packageDir += '/node_modules/' + pkg; | ||
} | ||
var json = JSON.parse(fs.readFileSync(packageDir + '/package.json', 'utf8')); | ||
|
||
var distDir = __dirname + '/../dist'; | ||
if (!fs.existsSync(distDir)) { | ||
fs.mkdirSync(distDir); | ||
} | ||
|
||
var browserify = require('browserify'); | ||
var bo = {}; | ||
if (standalone) { | ||
bo.standalone = standalone; | ||
} | ||
var b = browserify(bo); | ||
b.require(packageDir + '/' + json.main, {expose: json.name}); | ||
var outputPath = distDir + '/' + json.name + '.bundle.js'; | ||
b.bundle().pipe(fs.createWriteStream(outputPath)).on('close', function () { | ||
var UglifyJS = require("uglify-js"); | ||
var uglifyOpts = { | ||
warnings: true, | ||
compress: {}, | ||
output: { | ||
preamble: '/* ' + json.name + ' ' + json.version + ': ' + json.description + ' */' | ||
} | ||
}; | ||
if (compress) { | ||
var compressOpts = compress.split(','); | ||
for (var i = 0, l = compressOpts.length; i<l; ++i) { | ||
var pair = compressOpts[i].split('='); | ||
uglifyOpts.compress[pair[0]] = pair.length < 1 || 'false' !== pair[1]; | ||
} | ||
} | ||
if (standalone) { | ||
uglifyOpts.outSourceMap = json.name + '.min.js.map'; | ||
uglifyOpts.mangle = {except: [standalone]}; | ||
} | ||
|
||
var result = UglifyJS.minify(distDir + '/' + json.name + '.bundle.js', uglifyOpts); | ||
fs.writeFileSync(distDir + '/' + json.name + '.min.js', result.code); | ||
if (result.map) { | ||
fs.writeFileSync(distDir + '/' + json.name + '.min.js.map', result.map); | ||
} | ||
if (!standalone) { | ||
fs.unlinkSync(distDir + '/' + json.name + '.bundle.js'); | ||
} | ||
}); |