-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #610
- Loading branch information
Manuel Mujica
committed
Feb 20, 2017
1 parent
0b98e16
commit afa271e
Showing
5 changed files
with
122 additions
and
2 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 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,57 @@ | ||
var _ = require("lodash"); | ||
var winston = require("winston"); | ||
var stealTools = require("../../index"); | ||
var clone = require("lodash/cloneDeep"); | ||
var options = clone(require("./options")); | ||
var makeStealConfig = require("./make_steal_config"); | ||
|
||
var pathsToOmit = [ | ||
"bundles-path", | ||
"bundle-steal", | ||
"watch" | ||
]; | ||
|
||
var bundleOptions = _.assign( | ||
{}, | ||
_.omit(options, pathsToOmit), | ||
{ | ||
dest: { | ||
alias: "d", | ||
type: "string", | ||
default: "", | ||
describe: "Defaults to root folder, a directory to save the bundles" | ||
}, | ||
filter: { | ||
alias: "f", | ||
type: "string", | ||
default: "node_modules/**/*", | ||
describe: "Glob patter to match modules to be included in the bundle" | ||
} | ||
} | ||
); | ||
|
||
module.exports = { | ||
command: "bundle", | ||
|
||
describe: "Creates a custom bundle", | ||
|
||
builder: bundleOptions, | ||
|
||
handler: function(argv) { | ||
var options = argv; | ||
var config = makeStealConfig(argv); | ||
|
||
return stealTools.bundle(config, options) | ||
.then(function() { | ||
winston.info("\nBundle created successfully".green); | ||
}) | ||
.catch(function(e) { | ||
e = typeof e === "string" ? new Error(e) : e; | ||
|
||
winston.error(e.message.red); | ||
winston.error("\nBuild failed".red); | ||
|
||
process.exit(1); | ||
}); | ||
} | ||
}; |
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 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,60 @@ | ||
var assert = require("assert"); | ||
var mockery = require("mockery"); | ||
|
||
describe("cmd bundle module", function() { | ||
var cmdBundle; | ||
var bundleArgs; | ||
var cmdBundlePath = "../../lib/cli/cmd_bundle"; | ||
|
||
beforeEach(function() { | ||
bundleArgs = {}; | ||
|
||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
}); | ||
|
||
mockery.registerAllowable(cmdBundlePath); | ||
|
||
mockery.registerMock("../../index", { | ||
bundle: function(system, options) { | ||
bundleArgs.system = system; | ||
bundleArgs.options = options; | ||
return Promise.resolve(); | ||
} | ||
}); | ||
|
||
cmdBundle = require(cmdBundlePath); | ||
}); | ||
|
||
afterEach(function() { | ||
mockery.disable(); | ||
mockery.deregisterAll(); | ||
}); | ||
|
||
it("exposes the right command", function() { | ||
assert.equal(cmdBundle.command, "bundle"); | ||
}); | ||
|
||
it("command options have sensible defaults", function() { | ||
var options = cmdBundle.builder; | ||
|
||
assert.equal(options.dest.default, ""); | ||
assert.equal(options.config.default, "package.json!npm"); | ||
assert.equal(options.filter.default, "node_modules/**/*"); | ||
}); | ||
|
||
it("handler calls steal.bundle", function() { | ||
cmdBundle.handler({ | ||
minify: true, | ||
config: "/stealconfig.js" | ||
}); | ||
|
||
assert.deepEqual(bundleArgs.system, { | ||
config: "/stealconfig.js" | ||
}); | ||
|
||
assert(bundleArgs.options.minify); | ||
}); | ||
}); |
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