Skip to content

Commit

Permalink
Replaced the "bundle" script with a cross platform Node script called…
Browse files Browse the repository at this point in the history
… "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
boenrobot committed Mar 8, 2017
1 parent 86b5aeb commit ae3e5d4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 41 deletions.
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
],
"scripts": {
"jshint": "jshint lib/*.js lib/**/*.js --exclude lib/dotjs/**/*",
"eslint": "if-node-version '>=4' eslint lib/*.js lib/compile/*.js spec",
"eslint": "if-node-version \">=4\" eslint lib/*.js lib/compile/*.js spec",
"test-spec": "mocha spec/*.spec.js -R spec",
"test-fast": "AJV_FAST_TEST=true npm run test-spec",
"test-debug": "mocha spec/*.spec.js --debug-brk -R spec",
"test-cov": "nyc npm run test-spec",
"test-ts": "tsc --target ES5 --noImplicitAny lib/ajv.d.ts",
"bundle": "./scripts/bundle . Ajv pure_getters",
"bundle-regenerator": "./scripts/bundle regenerator",
"bundle-nodent": "./scripts/bundle nodent",
"bundle-all": "rm -rf dist && npm run bundle && npm run bundle-regenerator && npm run bundle-nodent",
"bundle-beautify": "./scripts/bundle js-beautify",
"build": "rm -f lib/dotjs/*.js && node scripts/compile-dots.js",
"bundle": "node ./scripts/bundle.js . Ajv pure_getters",
"bundle-regenerator": "node ./scripts/bundle.js regenerator",
"bundle-nodent": "node ./scripts/bundle.js nodent",
"bundle-all": "del-cli dist && npm run bundle && npm run bundle-regenerator && npm run bundle-nodent",
"bundle-beautify": "node ./scripts/bundle.js js-beautify",
"build": "del-cli lib/dotjs/*.js && node scripts/compile-dots.js",
"test-karma": "karma start --single-run --browsers PhantomJS",
"test-browser": "rm -rf .browser && npm run bundle-all && scripts/prepare-tests && npm run test-karma",
"test-browser": "del-cli .browser && npm run bundle-all && scripts/prepare-tests && npm run test-karma",
"test": "npm run jshint && npm run eslint && npm run test-ts && npm run build && npm run test-cov && npm run test-browser",
"prepublish": "npm run build && npm run bundle-all",
"watch": "watch 'npm run build' ./lib/dot"
Expand Down Expand Up @@ -73,6 +73,7 @@
"browserify": "^14.1.0",
"chai": "^3.5.0",
"coveralls": "^2.11.4",
"del-cli": "^0.2.1",
"dot": "^1.0.3",
"eslint": "^3.2.2",
"gh-pages-generator": "^0.2.0",
Expand Down
33 changes: 0 additions & 33 deletions scripts/bundle

This file was deleted.

56 changes: 56 additions & 0 deletions scripts/bundle.js
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');
}
});

0 comments on commit ae3e5d4

Please sign in to comment.