-
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.
Basics of the development bundle working
- Loading branch information
Manuel Mujica
committed
Feb 15, 2017
1 parent
ca6ad21
commit a225f52
Showing
9 changed files
with
300 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var minify = require("../stream/minify"); | ||
var devBundle = require("../stream/dev_bundle"); | ||
var transpile = require("../stream/transpile"); | ||
var concat = require("../bundle/concat_stream"); | ||
var stealWriteStream = require("../stream/steal"); | ||
var filterDevBundleGraph = require("../stream/filter_dev_bundle_graph"); | ||
|
||
var assignDefaultOptions = require("../assign_default_options"); | ||
var createWriteStream = require("../bundle/write_bundles").createWriteStream; | ||
var createBundleGraphStream = require("../graph/make_graph_with_bundles").createBundleGraphStream; | ||
|
||
module.exports = function(config, options) { | ||
// Use the build-development environment. | ||
if (!options) options = {}; | ||
|
||
// Minification is on by default | ||
options.minify = options.minify == null ? true : options.minify; | ||
|
||
try { | ||
options = assignDefaultOptions(config, options); | ||
} catch(err) { | ||
return Promise.reject(err); | ||
} | ||
|
||
options.dest = ""; | ||
options.defaultBundlesPathName = ""; | ||
|
||
var graphStream = createBundleGraphStream(config, options); | ||
var filteredGraphStream = graphStream.pipe(filterDevBundleGraph()); | ||
var transpileStream = filteredGraphStream.pipe(transpile()); | ||
var minifyStream = transpileStream.pipe(minify()); | ||
var buildStream = minifyStream.pipe(devBundle()); | ||
var concatStream = buildStream.pipe(concat()); | ||
|
||
// Return a Promise that will resolve after bundles have been written | ||
return new Promise(function(resolve, reject) { | ||
// Pipe the build result into a write stream. | ||
var writeStream = buildStream | ||
.pipe(createWriteStream()) | ||
.pipe(stealWriteStream()); | ||
|
||
writeStream.on("data", function(data){ | ||
this.end(); | ||
resolve(data); | ||
}); | ||
|
||
var streams = [ | ||
graphStream, | ||
filteredGraphStream, | ||
transpileStream, | ||
minifyStream, | ||
buildStream, | ||
concatStream | ||
]; | ||
|
||
streams.forEach(function(stream) { | ||
stream.on("error", reject); | ||
}); | ||
}); | ||
}; |
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,67 @@ | ||
var _ = require("lodash"); | ||
var through = require("through2"); | ||
var hasES6 = require("../graph/has_es6"); | ||
var unbundle = require("../graph/unbundle"); | ||
var makeBundle = require("../bundle/make_bundle"); | ||
var splitByBuildType = require("../bundle/split_by_build_type"); | ||
var addTraceurRuntime = require("../bundle/add_traceur_runtime"); | ||
var makeBundlesConfig = require("../bundle/make_bundles_config"); | ||
|
||
module.exports = function() { | ||
return through.obj(function(data, enc, done) { | ||
try { | ||
var result = bundle(data); | ||
done(null, result); | ||
} catch(err) { | ||
done(err); | ||
} | ||
}); | ||
}; | ||
|
||
function bundle(data) { | ||
var graph = data.graph; | ||
var configGraph = data.configGraph; | ||
var configuration = data.configuration; | ||
|
||
unbundle(graph); | ||
|
||
var mainBundle = makeBundle(graph); | ||
var splitMainBundles = nameBundles(splitByBuildType(mainBundle)); | ||
|
||
splitMainBundles.forEach(function(mainJSBundle) { | ||
var unshift = [].unshift; | ||
|
||
unshift.apply(mainJSBundle.nodes, configGraph); | ||
|
||
// Make config JS code so System knows where to look for bundles. | ||
var configNode = makeBundlesConfig( | ||
splitMainBundles, | ||
configuration, | ||
mainJSBundle, | ||
{ excludedBundles: [] } | ||
); | ||
|
||
mainJSBundle.nodes.unshift(configNode); | ||
|
||
// Traceur code requires a runtime. | ||
if (hasES6(graph)) { | ||
addTraceurRuntime(mainJSBundle); | ||
} | ||
}); | ||
|
||
return _.assign( | ||
{}, | ||
data, | ||
{ bundles: splitMainBundles } | ||
); | ||
} | ||
|
||
function nameBundles(bundles) { | ||
return bundles.map(function(bundle) { | ||
return _.assign( | ||
{}, | ||
bundle, | ||
{ name: "dev-bundle" } | ||
); | ||
}); | ||
} |
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,50 @@ | ||
var _ = require("lodash"); | ||
var winston = require("winston"); | ||
var through = require("through2"); | ||
var npmUtils = require("steal/ext/npm-utils"); | ||
|
||
var isNpm = npmUtils.moduleName.isNpm; | ||
|
||
module.exports = function() { | ||
return through.obj(function(data, enc, done) { | ||
try { | ||
done(null, filterGraph(data)); | ||
} catch(err) { | ||
done(err); | ||
} | ||
}); | ||
}; | ||
|
||
function filterGraph(data) { | ||
var visited = {}; | ||
var filtered = {}; | ||
var graph = data.graph; | ||
|
||
function visit(name) { | ||
if (!visited[name]) { | ||
|
||
visited[name] = true; | ||
var node = graph[name]; | ||
|
||
if (!node) { | ||
if (name && name[0] !== "@") { | ||
winston.warn("Can't find dependency", name, "in graph."); | ||
} | ||
return; | ||
} | ||
|
||
node.dependencies.forEach(visit); | ||
filtered[name] = node; | ||
} | ||
} | ||
|
||
_.keys(graph).forEach(function(name) { | ||
if (isNpm(name)) visit(name); | ||
}); | ||
|
||
return _.assign( | ||
{}, | ||
_.omit(data, "graph"), | ||
{ graph: filtered } | ||
); | ||
} |
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,58 @@ | ||
var path = require("path"); | ||
var fs = require("fs-extra"); | ||
var assert = require("assert"); | ||
var denodeify = require("pdenodeify"); | ||
var testHelpers = require("./helpers"); | ||
var devBundleBuild = require("../lib/build/bundle"); | ||
|
||
var open = testHelpers.popen; | ||
var rmdir = denodeify(require("rimraf")); | ||
|
||
describe("dev bundle build", function() { | ||
|
||
// what should I assert here? | ||
it.skip("app without npm dependencies?", function() { | ||
return rmdir(path.join(__dirname, "bundle", "dist")) | ||
.then(function() { | ||
return devBundleBuild({ | ||
config: path.join(__dirname, "bundle", "stealconfig.js"), | ||
main: "bundle" | ||
}); | ||
}); | ||
}); | ||
|
||
// what should I assert here? | ||
it("should work", function() { | ||
this.timeout(5000); | ||
|
||
var config = { | ||
config: path.join(__dirname, "npm", "package.json!npm"), | ||
main: "src/main" | ||
}; | ||
|
||
var options = { | ||
minify: false | ||
}; | ||
|
||
var devBundlePath = path.join(__dirname, "npm", "dev-bundle.js"); | ||
|
||
return devBundleBuild(config, options) | ||
.then(function() { | ||
var exists = fs.existsSync(devBundlePath); | ||
assert(exists, "dev bundle should be created"); | ||
}) | ||
.then(function() { | ||
return open(path.join(__dirname, "npm"), "dev-bundle-main.html"); | ||
}) | ||
.then(function({ browser, close }) { | ||
var h1s = browser.window.document.getElementsByTagName('h1'); | ||
assert.equal(h1s.length, 1, "Wrote H!."); | ||
close(); | ||
}) | ||
.then(function() { | ||
return rmdir(devBundlePath); | ||
}); | ||
}); | ||
|
||
}); | ||
|
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,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<script> | ||
window.QUnit = window.parent.QUnit; | ||
window.removeMyself = window.parent.removeMyself; | ||
|
||
window.steal = { | ||
map: { | ||
"@dev": "dev-bundle" | ||
} | ||
}; | ||
</script> | ||
|
||
<script type="text/javascript" src="node_modules/steal/steal.js"></script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
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