Skip to content

Commit b23c947

Browse files
committedJun 17, 2018
Run the build as an npm project
1. Give the build project a package.json with all of its deps 2. Install the dependencies in the build folder 3. Run the build Closes #282
1 parent 70cdcee commit b23c947

24 files changed

+837
-924
lines changed
 

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- 4
43
- 6
54
- 8
65
script: npm test

‎lib/configured/configured_test.js

+289-339
Large diffs are not rendered by default.

‎lib/configured/get_project.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ module.exports = function(project){
8787
console.log("downloading",project.source);
8888
ghdownload(project.source, finalDest)
8989
.on('zip', function(zipUrl) { //only emitted if Github API limit is reached and the zip file is downloaded
90-
console.log("Using zip dowload. This might take a few miniutes.");
90+
console.log("Using zip dowload. This might take a few minutes.");
9191
})
9292
.on('error',function(err){
9393
console.log("ERROR", err);

‎lib/configured/test/custom_tags/templates/layout.mustache

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
{{#if devBuild}}
4646
<script type='text/javascript'
4747
data-main="static"
48-
data-config="./static/config.js"
4948
src="./static/steal/steal.js"></script>
5049
{{else}}
5150
<script>

‎lib/generate/test/generate_test.js

+63-80
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,68 @@
1-
var generate = require("../generate"),
2-
assert = require("assert");
3-
rmdir = require('rimraf'),
4-
Browser = require("zombie"),
5-
connect = require("connect"),
6-
path = require("path"),
7-
slash = require("../../slash");
8-
9-
// Helpers
10-
var find = function(browser, property, callback, done){
11-
var start = new Date();
12-
var check = function(){
13-
if(browser.window && browser.window[property]) {
14-
callback(browser.window[property]);
15-
} else if(new Date() - start < 2000){
16-
setTimeout(check, 20);
17-
} else {
18-
done("failed to find "+property);
19-
}
20-
};
21-
check();
22-
};
1+
var generate = require("../generate");
2+
var assert = require("assert");
3+
var path = require("path");
4+
var slash = require("../../slash");
5+
var Q = require("q");
236

24-
var open = function(url, callback, done){
25-
var server = connect().use(connect.static(path.join(__dirname))).listen(8081);
26-
var browser = new Browser();
27-
browser.visit("http://localhost:8081/"+url)
28-
.then(function(){
29-
callback(browser, function(){
30-
server.close();
31-
done();
7+
// test helpers
8+
var find = require("../../../test/find");
9+
var open = require("../../../test/open");
10+
11+
var rmdir = Q.denodeify(require("rimraf"));
12+
13+
describe("documentjs/lib/generate/generate", function() {
14+
this.timeout(5 * 1000 * 60);
15+
16+
after(function() {
17+
return rmdir(path.join(__dirname, "out"));
18+
});
19+
20+
it("works", function() {
21+
return rmdir(path.join(__dirname, "out"))
22+
.then(function() {
23+
return generate({
24+
glob: slash(path.join(__dirname, "example")) + "/*.js",
25+
dest: path.join(__dirname, "out"),
26+
parent: "mylib",
27+
forceBuild: true,
28+
minifyBuild: false
29+
});
30+
})
31+
.then(function() {
32+
return open(__dirname, "out/Foo.html");
3233
})
33-
}).catch(function(e){
34-
server.close();
35-
done(e)
36-
});
37-
};
38-
39-
describe("documentjs/lib/generate/generate",function(){
40-
41-
it("works",function(done){
42-
this.timeout(10000);
43-
rmdir(__dirname+"/out",function(error){
44-
45-
generate({
46-
glob: slash( path.join(__dirname,"example") )+"/*.js",
47-
dest: path.join(__dirname,"out"),
48-
parent: "mylib",
49-
forceBuild: true,
50-
minifyBuild: false
51-
}).then(function(){
52-
open("out/Foo.html",function(browser, close){
53-
var code = browser.window.document.getElementsByTagName("code")[0];
54-
assert.ok( /prettyprinted/.test(code.className), "code blocks added" )
55-
close();
56-
},done);
57-
58-
}, done);
59-
60-
});
61-
34+
.then(function(browser) {
35+
var code = browser.window.document.getElementsByTagName(
36+
"code"
37+
)[0];
38+
39+
assert.ok(
40+
/prettyprinted/.test(code.className),
41+
"code blocks added"
42+
);
43+
});
6244
});
63-
64-
it("@outline works", function(done){
65-
this.timeout(30000);
66-
generate({
67-
glob: __dirname+"/example/*.js",
68-
dest: __dirname+"/out",
69-
parent: "mylib",
70-
forceBuild: true,
71-
minifyBuild: false
72-
}).then(function(){
73-
open("out/index.html",function(browser, close){
74-
var code = browser.window.document.getElementsByClassName("contents")[0];
75-
var lis = code.getElementsByTagName("li")
76-
assert.equal( lis.length, 5, "outline added "+lis.length );
77-
close();
78-
},done);
79-
80-
}, done);
45+
46+
it("@outline works", function() {
47+
return Promise.resolve()
48+
.then(function() {
49+
return generate({
50+
glob: path.join(__dirname, "example", "*.js"),
51+
dest: path.join(__dirname, "out"),
52+
parent: "mylib",
53+
forceBuild: true,
54+
minifyBuild: false
55+
});
56+
})
57+
.then(function() {
58+
return open(__dirname, "out/index.html");
59+
})
60+
.then(function(browser) {
61+
var code = browser.window.document.getElementsByClassName(
62+
"contents"
63+
)[0];
64+
var lis = code.getElementsByTagName("li");
65+
assert.equal(lis.length, 5, "outline added " + lis.length);
66+
});
8167
});
82-
8368
});
84-
85-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function makePackageJson(options) {
2+
return {
3+
name: "docs",
4+
version: "1.0.0",
5+
main: "static.js",
6+
system: {
7+
npmAlgorithm: "flat",
8+
meta: {
9+
jquery: {
10+
exports: "jQuery"
11+
},
12+
prettify: { format: "global" }
13+
}
14+
},
15+
dependencies: {
16+
"can-control": "^3.0.10",
17+
"can-map": "^3.0.7",
18+
"can-stache": "^3.0.24",
19+
"can-util": "^3.6.1",
20+
jquery: "~1.11.0",
21+
steal: "0.16.X",
22+
"steal-stache": "^3.0.7",
23+
"steal-tools": "0.16.X"
24+
}
25+
};
26+
};
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var spawn = require("cross-spawn");
2+
3+
module.exports = function npmInstall(spawnArgs) {
4+
return new Promise(function(resolve, reject) {
5+
var proc = spawn(
6+
"npm",
7+
["install", "--no-bin-links", "--no-package-lock", "--no-audit"],
8+
spawnArgs
9+
);
10+
11+
proc.once("exit", function(code) {
12+
if (code === 0) {
13+
resolve();
14+
} else {
15+
reject(new Error(`exit code ${code}`));
16+
}
17+
});
18+
});
19+
};
+100-67
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,133 @@
1-
var fss = require('../../../fs_extras.js'),
2-
Q = require('q'),
3-
path = require('path'),
4-
md5 = require('md5'),
5-
promiseLock = require("../../../promise_lock");
6-
7-
var queue = promiseLock(),
8-
buildHash = require("./build_hash");
1+
var fss = require("../../../fs_extras");
2+
var Q = require("q");
3+
var path = require("path");
4+
var buildHash = require("./build_hash");
5+
var promiseLock = require("../../../promise_lock");
6+
var fs = require("fs-extra");
7+
var makePackageJson = require("./make_package_json");
8+
var npmInstall = require("./npm_install");
9+
10+
var copy = Q.denodeify(fs.copy);
11+
var writeFile = Q.denodeify(fs.writeFile);
12+
var queue = promiseLock();
913

1014
/**
1115
* @function documentjs.generators.html.build.staticDist
1216
* @parent documentjs.generators.html.build.methods
13-
*
17+
*
1418
* Builds a static distributable which will eventually be copied
1519
* to the `static` folder of the generated output.
16-
*
20+
*
1721
* @signature `.build.staticDist(options)`
18-
*
22+
*
1923
* Builds the static distributable with the following steps:
20-
*
21-
* 1. Copies everything from _documentjs/site/default/static_ to
22-
* _documentjs/site/static/build_.
23-
* 2. Copies the path in `options.dest` to _documentjs/site/static/build_.
24-
* 3. `require`s the module at _documentjs/site/static/build/build.js_.
25-
* 4. Calls that "build" module function with the options and returns the result.
26-
*
27-
* The "build" module is expected to build a minified distributable
24+
*
25+
* 1. Copies everything from _documentjs/site/default/static_ to _documentjs/site/static/build_.
26+
* 2. Overwrites site/static/build with content in `options.static`.
27+
* 3. Writes a `package.json` file to _documentjs/site/static/build_.
28+
* 4. Runs `npm install` in _documentjs/site/static/build_ to get the dependencies for the build.
29+
* 5. Calls that "build" function at _documentjs/site/static/build/build.js_ with
30+
* the options and returns the result.
31+
*
32+
* The "build" module is expected to build a minified distributable
2833
* and copy the necessary contents to _documentjs/site/static/dist_ and
2934
* return a promise that resolves when complete.
30-
*
35+
*
3136
* @param {{}} options
32-
*
33-
* @option {Boolean} [forceBuild=false] If set to `true`, rebuilds the
37+
*
38+
* @option {Boolean} [forceBuild=false] If set to `true`, rebuilds the
3439
* static bundle even if it has already been built.
35-
*
40+
*
3641
* @option {String} dest The final destination ouput of the static
3742
* distributable.
38-
*
43+
*
3944
* @option {String} static The location of static content used to overwrite or
4045
* add to the default static content.
41-
*
42-
* @option {Boolean} [minifyBuild=true] If set to `false` the build will not
46+
*
47+
* @option {Boolean} [minifyBuild=true] If set to `false` the build will not
4348
* be minified. This behavior should be implemented by the "build" module.
44-
*
49+
*
4550
* @return {Promise} A promise that resolves if the static dist was successfully created.
46-
*
51+
*
4752
*/
48-
module.exports = function(options){
53+
module.exports = function(options) {
4954
// only run one build at a time.
50-
return queue(function(){
51-
var builtAlready;
52-
55+
return queue(function staticDistQueue() {
5356
var hash = buildHash(options);
54-
55-
var distFolder = path.join("site","static","dist", hash),
56-
buildFolder = path.join("site","static","build", hash);
57+
var distFolder = path.join("site", "static", "dist", hash);
58+
var buildFolder = path.join("site", "static", "build", hash);
5759

5860
var mkdirPromise = Q.all([
5961
fss.mkdirs(distFolder),
6062
fss.mkdirs(buildFolder)
6163
]);
62-
63-
return mkdirPromise.then(function(){
64-
return fss.exists(path.join(distFolder,"bundles","static.css"))
65-
.then(function(exists){
64+
65+
var buildPromise = mkdirPromise
66+
.then(function() {
67+
return fss.exists(
68+
path.join(distFolder, "bundles", "static.css")
69+
);
70+
})
71+
.then(function(exists) {
6672
// If we have already built, don't build again
67-
if(exists && !options.forceBuild) {
68-
builtAlready = true;
69-
if(options.debug) {
70-
console.log("BUILD: Using cache",distFolder);
73+
if (exists && !options.forceBuild) {
74+
if (options.debug) {
75+
console.log("BUILD: Using cache", distFolder);
7176
}
72-
73-
return;
77+
} else {
78+
return buildSiteStaticAssets();
7479
}
75-
76-
return fss.copy(path.join("site","default","static"), buildFolder)
77-
.then(function(){
78-
if(options["static"]){
80+
});
81+
82+
function buildSiteStaticAssets() {
83+
var docjsRoot = path.join(__dirname, "..", "..", "..", "..");
84+
85+
return Promise.resolve()
86+
.then(function copyFromSiteDefaultToBuildFolder() {
87+
return fss.copy(
88+
path.join("site", "default", "static"),
89+
buildFolder
90+
);
91+
})
92+
.then(function overrideWithOptionsStatic() {
93+
if (options["static"]) {
7994
return fss.copyFrom(options["static"], buildFolder);
80-
}
95+
}
96+
})
97+
.then(function writeBuildPackageJson() {
98+
var pkg = makePackageJson(options);
99+
return writeFile(
100+
path.join(docjsRoot, buildFolder, "package.json"),
101+
JSON.stringify(pkg, null, 2)
102+
);
103+
})
104+
.then(function installDependencies() {
105+
if (options.debug) {
106+
console.log("BUILD: Installing node_modules");
107+
}
108+
return npmInstall({
109+
stdio: options.debug ? "inherit" : "pipe",
110+
cwd: path.join(docjsRoot, buildFolder)
111+
});
112+
})
113+
.then(function runBuildScript() {
114+
if (options.debug) {
115+
console.log("BUILD: Running build script");
116+
}
117+
118+
var build = require(path.join(
119+
docjsRoot,
120+
buildFolder,
121+
"build.js"
122+
));
123+
124+
return build(options, {
125+
dist: distFolder,
126+
build: buildFolder
127+
});
81128
});
82-
});
83-
}).then(function(){
84-
if(builtAlready){
85-
return;
86-
}
87-
if(options.debug) {
88-
console.log("BUILD: Getting build module");
89-
}
90-
91-
var build = require("../../../../site/static/build/"+hash+"/build.js");
92-
return build(options,{
93-
dist: distFolder,
94-
build: buildFolder
95-
});
96-
});
129+
}
130+
131+
return buildPromise;
97132
});
98-
99-
100133
};

‎lib/generators/html/generate.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var build = require("./build/build"),
32
write = require("./write/write"),
43
Q = require("q"),
@@ -9,55 +8,56 @@ var build = require("./build/build"),
98
/**
109
* @function documentjs.generators.html.generate
1110
* @parent documentjs.generators.html.methods
12-
*
11+
*
1312
* Generates an HTML site for a [documentjs.process.docMap docMap]
1413
* given configuration options.
15-
*
14+
*
1615
* @signature `.generate(docMapPromise, options)`
17-
*
18-
* @param {Promise<documentjs.process.docMap>} docMapPromise A promise that
16+
*
17+
* @param {Promise<documentjs.process.docMap>} docMapPromise A promise that
1918
* contains a `docMap` created by [documentjs.process.files].
2019
* @param {Object} options Configuration options.
21-
*
20+
*
2221
* @return {Promise} A promise that resolves when the site has been built.
2322
*/
24-
module.exports = function(docMapPromise, options){
25-
// 1. Copies everything from site/default/static to site/static/build
26-
// 2. Overwrites site/static/build with content in `options.static`
27-
// 3. Runs site/static/build/build.js
28-
// A. Builds itself and copies everything to site/static/dist
29-
var staticPromise = build.staticDist(options).then(function(){
23+
module.exports = function(docMapPromise, options) {
24+
var staticPromise = build.staticDist(options).then(function() {
3025
// copies statics to documentation location.
3126
return write.staticDist(options);
3227
});
33-
34-
var buildTemplatesPromise = build.templates(options).then(function(){
28+
29+
var buildTemplatesPromise = build.templates(options).then(function() {
3530
return Handlebars.create();
3631
});
37-
buildTemplatesPromise["catch"](function(){
32+
buildTemplatesPromise["catch"](function() {
3833
console.log("problem building templates");
3934
});
40-
35+
4136
var currentDocObject;
42-
var getCurrent = function(){
37+
var getCurrent = function() {
4338
return currentDocObject;
4439
};
45-
var setCurrent = function(current){
40+
var setCurrent = function(current) {
4641
currentDocObject = current;
4742
};
48-
var helpersReadyPromise = docMapPromise.then(function(docMap){
49-
return build.helpers(buildTemplatesPromise, docMap, options, getCurrent);
43+
var helpersReadyPromise = docMapPromise.then(function(docMap) {
44+
return build.helpers(
45+
buildTemplatesPromise,
46+
docMap,
47+
options,
48+
getCurrent
49+
);
5050
});
51-
51+
5252
var docsPromise = Q.all([
53-
docMapPromise,
54-
build.renderer(buildTemplatesPromise, options),
55-
helpersReadyPromise,
56-
mkdirs(options.dest)
57-
]).then(function(results){
53+
docMapPromise,
54+
build.renderer(buildTemplatesPromise, options),
55+
helpersReadyPromise,
56+
mkdirs(options.dest)
57+
]).then(function(results) {
5858
var docMap = results[0],
5959
renderer = results[1];
6060
return write.docMap(docMap, renderer, options, setCurrent);
6161
});
6262
return Q.all([staticPromise, docsPromise]);
63-
};
63+
};

‎lib/generators/html/html_test.js

+91-83
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,99 @@
1-
require("./build/build_test");
1+
var html = require("./html");
2+
var assert = require("assert");
3+
var Q = require("q");
4+
var path = require("path");
5+
var fs = require("fs-extra");
6+
var cleanDocMap = require("../../process/clean_doc_map");
27

8+
var readFile = Q.denodeify(fs.readFile);
9+
var pathExists = Q.denodeify(fs.pathExists);
10+
var rmdir = Q.denodeify(require("rimraf"));
311

12+
const timeout = 5 * 1000 * 60;
413

5-
var html = require("./html"),
6-
assert = require('assert'),
7-
Q = require('q'),
8-
path = require('path'),
9-
fs = require('fs'),
10-
rmdir = require('rimraf'),
11-
cleanDocMap = require("../../process/clean_doc_map");
12-
13-
describe("documentjs/lib/generators/html",function(){
14-
it("can push out dev mode static", function(done){
15-
16-
this.timeout(60000);
17-
rmdir(path.join(__dirname,"test","tmp"), function(e){
18-
if(e) {
19-
return done(e);
20-
}
21-
var options = {
22-
dest: path.join(__dirname, "test","tmp"),
23-
devBuild: true,
24-
minify: false,
25-
parent: "index",
26-
forceBuild: true
27-
};
28-
29-
30-
var docMap = Q.Promise(function(resolve){
31-
resolve(cleanDocMap({
32-
index: {name: "index", type: "page", body: "Hello <strong>World</strong>"}
33-
}, options));
34-
});
35-
html.generate(docMap,options).then(function(){
36-
if(!fs.existsSync(path.join(__dirname,"test","tmp","static","can-control","can-control.js"))) {
37-
done(new Error("canjs does not exist"));
38-
} else if(fs.existsSync(path.join(__dirname,"test","tmp","static","bundles","static.js"))) {
39-
done(new Error("static build exists"));
40-
} else {
41-
done();
42-
}
43-
},done);
44-
}, done);
14+
describe("documentjs/lib/generators/html", function() {
15+
this.timeout(timeout);
16+
var tmpPath = path.join(__dirname, "test", "tmp");
17+
18+
beforeEach(function() {
19+
return rmdir(tmpPath);
4520
});
4621

47-
it("body is rendered as a mustache template prior to markdown", function(done){
48-
this.timeout(40000);
49-
rmdir(path.join(__dirname,"test","tmp"), function(e){
50-
if(e) {
51-
return done(e);
52-
}
53-
var options = {
54-
dest: path.join(__dirname, "test","tmp"),
55-
parent: "index"
56-
};
57-
58-
59-
var docMap = Q.Promise(function(resolve){
60-
resolve(cleanDocMap({
61-
index: {
62-
name: "index",
63-
type: "page",
64-
body: "Hello `{{thing.params.0.name}}`"
65-
},
66-
thing: {
67-
name: "thing",
68-
params: [
69-
{name: "first"}
70-
]
71-
}
72-
}, options));
22+
afterEach(function() {
23+
return rmdir(tmpPath);
24+
});
25+
26+
it("can push out dev mode static", function() {
27+
return Promise.resolve()
28+
.then(function runHtmlGenerator() {
29+
var options = {
30+
dest: tmpPath,
31+
devBuild: true,
32+
minify: false,
33+
parent: "index",
34+
forceBuild: true,
35+
debug: false
36+
};
37+
var docMap = Promise.resolve(
38+
cleanDocMap(
39+
{
40+
index: {
41+
name: "index",
42+
type: "page",
43+
body: "Hello <strong>World</strong>"
44+
}
45+
},
46+
options
47+
)
48+
);
49+
return html.generate(docMap, options);
50+
})
51+
.then(function assertDevelopmentFiles() {
52+
return Promise.all([
53+
pathExists(path.join(tmpPath, "node_modules")),
54+
pathExists(path.join(tmpPath, "package.json")),
55+
pathExists(path.join(tmpPath, "fonts")),
56+
pathExists(path.join(tmpPath, "img")),
57+
pathExists(path.join(tmpPath, "styles")),
58+
pathExists(path.join(tmpPath, "index.html"))
59+
]);
7360
});
74-
75-
html.generate(docMap,options).then(function(){
76-
fs.readFile(
77-
path.join(__dirname,"test","tmp","index.html"),
78-
function(err, data){
79-
if(err) {
80-
done(err);
81-
}
82-
assert.ok( /<code>first<\/code>/.test(""+data), "got first" );
83-
done();
84-
});
61+
});
8562

86-
},done);
87-
});
63+
it("body is rendered as a mustache template prior to markdown", function() {
64+
return Promise.resolve()
65+
.then(function runHtmlGenerator() {
66+
var options = {
67+
dest: tmpPath,
68+
parent: "index",
69+
debug: false
70+
};
71+
var docMap = Promise.resolve(
72+
cleanDocMap(
73+
{
74+
index: {
75+
name: "index",
76+
type: "page",
77+
body: "Hello `{{thing.params.0.name}}`"
78+
},
79+
thing: {
80+
name: "thing",
81+
params: [{ name: "first" }]
82+
}
83+
},
84+
options
85+
)
86+
);
87+
return html.generate(docMap, options);
88+
})
89+
.then(function readIndexHtml() {
90+
return fs.readFile(path.join(tmpPath, "index.html"));
91+
})
92+
.then(function verifyGeneratedContent(data) {
93+
assert.ok(
94+
/<code>first<\/code>/.test(data.toString()),
95+
"got first"
96+
);
97+
});
8898
});
89-
90-
91-
});
99+
});
+23-18
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
var fss = require('../../../fs_extras.js'),
2-
Q = require('q'),
1+
var fss = require("../../../fs_extras.js"),
2+
Q = require("q"),
33
path = require("path"),
44
buildHash = require("../build/build_hash"),
5-
fs = require('fs-extra'),
5+
fs = require("fs-extra"),
66
mkdirs = Q.denodeify(fs.mkdirs);
77

88
/**
99
* @function documentjs.generators.html.write.staticDist
1010
* @parent documentjs.generators.html.write.methods
11-
*
11+
*
1212
* Copies the [documentjs.generators.html.build.staticDist built distributable]
1313
* to a _static_ folder in `options.dest`.
14-
*
14+
*
1515
* @signature `.write.staticDist(options)`
16-
*
16+
*
1717
* @param {Object} options Configuration options.
18-
*
19-
* @option {String} dest The static distributable will be written to
18+
*
19+
* @option {String} dest The static distributable will be written to
2020
* `options.dest + "static"`.
21-
*
21+
*
2222
* @return {Promise} A promise that resolves when successfully copied over.
2323
*/
24-
module.exports = function(options){
25-
var dest = path.join(options.dest,"static");
26-
var distFolder = path.join('site','static','dist', buildHash(options));
27-
return mkdirs(dest).then(function(){
28-
if(options.debug) {
29-
console.log("BUILD: Copying production files to "+path.relative(process.cwd(),dest));
24+
module.exports = function(options) {
25+
var source = path.join("site", "static", "dist", buildHash(options));
26+
var dest = options.devBuild
27+
? options.dest
28+
: path.join(options.dest, "static");
29+
30+
return mkdirs(dest).then(function() {
31+
if (options.debug) {
32+
var env = options.devBuild ? "development" : "production";
33+
var where = path.relative(process.cwd(), dest);
34+
console.log(`BUILD: Copying ${env} files to ${where}`);
3035
}
31-
32-
return fss.copyTo(distFolder,dest);
36+
37+
return fss.copyTo(source, dest);
3338
});
34-
};
39+
};

‎package.json

+12-14
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,46 @@
1414
"documentjs": "./bin/documentjs"
1515
},
1616
"scripts": {
17-
"test": "mocha test.js --reporter spec",
17+
"test": "mocha test/test.js --reporter spec",
1818
"publish": "git push origin && git push origin --tags",
1919
"release:prerelease": "npm version prerelease && npm publish",
2020
"release:patch": "npm version patch && npm publish",
2121
"release:minor": "npm version minor && npm publish",
2222
"release:major": "npm version major && npm publish"
2323
},
2424
"devDependencies": {
25+
"can-control": "^3.0.10",
26+
"can-map": "^3.0.7",
27+
"can-stache": "^3.0.24",
28+
"can-util": "^3.6.1",
2529
"connect": "^2.14.4",
26-
"mocha": ">= 1.18.0",
30+
"jquery": "~1.11.0",
31+
"mocha": "^5.2.0",
2732
"qunit-mocha-ui": "*",
2833
"rimraf": "2.1",
34+
"steal": "0.16.X",
35+
"steal-stache": "^3.0.7",
36+
"steal-tools": "0.16.X",
2937
"zombie": "^4.2.1"
3038
},
3139
"dependencies": {
3240
"async": "~0.2.7",
33-
"can-control": "^3.0.10",
34-
"can-map": "^3.0.7",
35-
"can-stache": "^3.0.24",
36-
"can-util": "^3.6.1",
3741
"chokidar": "^1.0.0-rc5",
42+
"cross-spawn": "^6.0.5",
3843
"cross-spawn-async": "^2.1.9",
3944
"documentjs-github-download": "^0.3.0",
4045
"esprima": "~2.5.0",
41-
"fs-extra": "^0.24.0",
46+
"fs-extra": "^6.0.1",
4247
"glob": "~6.0.3",
4348
"handlebars": "1.0.10",
44-
"jquery": "~1.11.0",
4549
"less": "^1.7.0",
4650
"lodash": "~2.4.1",
4751
"md5": "^2.0.0",
4852
"minimatch": "~1.0.0",
4953
"q": "~1.0.1",
5054
"resolve": "^1.4.0",
51-
"steal": "0.16.X",
52-
"steal-stache": "^3.0.7",
53-
"steal-tools": "0.16.X",
5455
"yargs": "^1.3.1"
5556
},
56-
"system": {
57-
"npmAlgorithm": "flat"
58-
},
5957
"homepage": "http://documentjs.com",
6058
"repository": {
6159
"type": "git",

‎site/default/static/build.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<html>
22
<body>
3-
<script src="../../../node_modules/steal/steal.js"
4-
data-config="./config.js"></script>
3+
<script src="../../../node_modules/steal/steal.js"></script>
54
</body>
65

76
</html>

‎site/default/static/build.js

+66-98
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,75 @@
1-
var assign = require("can-util/js/assign/assign");
2-
var fs = require('fs');
3-
var map = require('./map');
4-
var resolve = require('resolve');
5-
var stealTools = require("steal-tools"),
6-
fsx = require('../../../../lib/fs_extras'),
7-
Q = require('q'),
8-
path = require("path");
1+
var fsExtras = require("../../../../lib/fs_extras");
2+
var Q = require("q");
3+
var path = require("path");
4+
var stealTools = require("steal-tools");
95

10-
11-
module.exports = function(options, folders){
12-
13-
var copyDir = function(name){
14-
return fsx.mkdirs( path.join(folders.dist,name) ).then(function(){
15-
return fsx.exists(path.join(folders.build,name)).then(function(exists){
16-
if(exists) {
17-
return fsx.copy( path.join(folders.build,name), path.join(folders.dist,name) );
18-
}
19-
});
6+
module.exports = function(options, folders) {
7+
var copyDir = function(name) {
8+
return fsExtras.mkdirs(path.join(folders.dist, name)).then(function() {
9+
return fsExtras
10+
.exists(path.join(folders.build, name))
11+
.then(function(exists) {
12+
if (exists) {
13+
return fsExtras.copy(
14+
path.join(folders.build, name),
15+
path.join(folders.dist, name)
16+
);
17+
}
18+
});
2019
});
2120
};
22-
if(options.devBuild) {
23-
var promise = Q.all([
24-
fsx.copy(path.join(folders.build), path.join(folders.dist) ),
25-
fsx.copy(path.join("node_modules"), path.join(folders.dist) ),
26-
]);
27-
// copy everything and steal.js
28-
return promise;
21+
if (options.devBuild) {
22+
// copy everything to site/static/dist
23+
return fsExtras.copy(path.join(folders.build), path.join(folders.dist));
2924
} else {
30-
// manually configure Can/Steal packages for Steal build
31-
var paths = {
32-
'jquery': path.relative(__dirname, require.resolve('jquery'))
33-
};
34-
35-
// generate the remaining paths
36-
var mapCopy = {};
37-
for (var packageName in map) {
38-
if (map.hasOwnProperty(packageName)) {
39-
// map[packageName] can either be just a string (e.g. jquery) or
40-
// an object, so we want the path for the module, not an object
41-
var resolvePath = (typeof map[packageName] === 'object') ? map[packageName][packageName] : map[packageName];
42-
if (!resolvePath) {
43-
// Fall back to Node’s resolution for npm 3+
44-
// …or the “resolve” package’s resolution implementation
45-
resolvePath = require.resolve(packageName) || resolve.sync(packageName, {basedir: process.cwd()});
25+
return stealTools
26+
.build(
27+
{
28+
main: "static",
29+
config: path.join(__dirname, "package.json!npm"),
30+
bundlesPath: path.join(__dirname, "bundles")
31+
},
32+
{
33+
minify: options.minifyBuild === false ? false : true,
34+
quiet: options.debug ? false : true,
35+
debug: options.debug ? true : false
4636
}
47-
48-
// Get the path relative to the build folder
49-
var moduleRelativePath = path.relative(__dirname, resolvePath);
50-
51-
// Update the paths object with the AMD configuration
52-
paths[packageName + '/*'] = path.dirname(moduleRelativePath) + '/*.js';
53-
paths[packageName] = moduleRelativePath;
54-
55-
// Make a copy of the object without the key
56-
// that was used to locate the module
57-
if (map[packageName][packageName]) {
58-
mapCopy[packageName] = assign({}, map[packageName]);
59-
delete mapCopy[packageName][packageName];
60-
} else {
61-
mapCopy[packageName] = map[packageName];
37+
)
38+
.then(function() {
39+
if (options.debug) {
40+
console.log("BUILD: Copying build to dist.");
6241
}
63-
}
64-
}
6542

66-
// conditional map
67-
// write it out for the client to consume
68-
var mapJSON = JSON.stringify(mapCopy);
69-
fs.writeFileSync(path.join(__dirname, 'map.json'), mapJSON);
70-
71-
// makes sure can is not added to the global so we can build nicely.
72-
global.GLOBALCAN = false;
73-
return stealTools.build({
74-
main: "static",
75-
config: __dirname + "/config.js",
76-
bundlesPath: __dirname+"/bundles",
77-
paths: paths,
78-
map: mapCopy,
79-
ext: {
80-
'stache': 'steal-stache'
81-
}
82-
},{
83-
minify: options.minifyBuild === false ? false : true,
84-
quiet: options.debug ? false : true,
85-
debug: options.debug ? true : false
86-
}).then(function(){
87-
if(options.debug) {
88-
console.log("BUILD: Copying build to dist.");
89-
}
90-
91-
// copy everything to DIST
92-
return Q.all([
93-
fsx.mkdirs( path.join(folders.dist,"bundles") ).then(function(){
94-
return fsx.copy(path.join(folders.build,"bundles"), path.join(folders.dist,"bundles") );
95-
}),
96-
fsx.copyFrom(path.join( require.resolve("steal"), "..", "steal.production.js"), path.join(folders.dist,"steal.production.js") ),
97-
fsx.copy( path.join(folders.build,"html5shiv.js"), path.join(folders.dist,"html5shiv.js")),
98-
99-
copyDir("fonts"),
100-
101-
copyDir("img"),
102-
copyDir("templates")
103-
]);
104-
105-
});
43+
// copy everything to DIST
44+
return Q.all([
45+
fsExtras
46+
.mkdirs(path.join(folders.dist, "bundles"))
47+
.then(function() {
48+
return fsExtras.copy(
49+
path.join(folders.build, "bundles"),
50+
path.join(folders.dist, "bundles")
51+
);
52+
}),
53+
fsExtras.copyFrom(
54+
path.join(
55+
require.resolve("steal"),
56+
"..",
57+
"steal.production.js"
58+
),
59+
path.join(folders.dist, "steal.production.js")
60+
),
61+
fsExtras.copy(
62+
path.join(folders.build, "package.json"),
63+
path.join(folders.dist, "package.json")
64+
),
65+
fsExtras.copy(
66+
path.join(folders.build, "html5shiv.js"),
67+
path.join(folders.dist, "html5shiv.js")
68+
),
69+
copyDir("fonts"),
70+
copyDir("img"),
71+
copyDir("templates")
72+
]);
73+
});
10674
}
10775
};

‎site/default/static/config.js

-32
This file was deleted.

‎site/default/static/map.js

-96
This file was deleted.

‎site/default/templates/layout.mustache

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
<meta name="description" content="">
2323
<meta name="author" content="">
2424
{{^devBuild}}
25-
<link rel="stylesheet" type="text/css" href="./static/bundles/static.css">
25+
<link rel="stylesheet" type="text/css" href="./static/bundles/static.css">
2626
{{/devBuild}}
2727
<!--[if lt IE 9]>
28-
<script type="text/javascript" src="static/html5shiv.js"></script>
29-
<!--<![endif]-->
28+
<script type="text/javascript" src="static/html5shiv.js"></script>
29+
<!--<![endif]-->
3030
</head>
3131

3232
<body class="docs">
@@ -71,24 +71,24 @@
7171
</script>
7272

7373
{{#if devBuild}}
74-
<script type='text/javascript'
74+
<script type="text/javascript"
7575
data-main="static"
76-
data-config="./static/config.js"
77-
src="./static/steal/steal.js"></script>
76+
src="./node_modules/steal/steal.js">
77+
</script>
7878
{{else}}
7979
<script>
80-
steal = {
81-
instantiated: {
82-
"bundles/static.css!$css" : null
83-
}
84-
}
80+
steal = {
81+
instantiated: {
82+
"bundles/static.css!$css" : null
83+
}
84+
};
8585
</script>
86-
<script type='text/javascript'
86+
<script type="text/javascript"
8787
data-main="static"
88-
data-config="./config.js"
89-
src="./static/steal.production.js"
90-
bundles-path="static/bundles"></script>
88+
data-config="package.json!npm"
89+
data-bundles-path="./static/bundles"
90+
src="./static/steal.production.js">
91+
</script>
9192
{{/if}}
9293
</body>
93-
9494
</html>

‎test.js

-49
This file was deleted.

‎test/find.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Find [property] in browser's window object
3+
* @param {Object} browser Zombie browser instance
4+
* @param {String} property The property name to be looked for in window
5+
* @return {Promise<property>}
6+
*/
7+
module.exports = function find(browser, property) {
8+
return new Promise(function(resolve, reject) {
9+
var start = new Date();
10+
var check = function() {
11+
if (browser.window && browser.window[property]) {
12+
resolve(browser.window[property]);
13+
} else if (new Date() - start < 2000) {
14+
setTimeout(check, 20);
15+
} else {
16+
reject(new Error("failed to find " + property));
17+
}
18+
};
19+
check();
20+
});
21+
};

‎test/main_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var assert = require("assert");
2+
var docjs = require("../main.js");
3+
4+
describe("documentjs/main", function() {
5+
it("exports configured", function() {
6+
assert.deepEqual(
7+
docjs.configured,
8+
require("../lib/configured/configured"),
9+
"configured is exported"
10+
);
11+
});
12+
it("exports find", function() {
13+
assert.deepEqual(
14+
docjs.find,
15+
require("../lib/find/find"),
16+
"find is exported"
17+
);
18+
});
19+
it("exports generators", function() {
20+
assert.ok(
21+
typeof docjs.generators !== "undefined",
22+
"generators is exported"
23+
);
24+
});
25+
it("exports process", function() {
26+
assert.deepEqual(
27+
docjs.process,
28+
require("../lib/process/process"),
29+
"process is exported"
30+
);
31+
});
32+
it("exports tag", function() {
33+
assert.deepEqual(
34+
docjs.tag,
35+
require("../lib/tags/tags"),
36+
"tag is exported"
37+
);
38+
});
39+
});

‎test/open.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Q = require("q");
2+
var connect = require("connect");
3+
var Browser = require("zombie");
4+
5+
module.exports = function open(dir, url) {
6+
var server = connect()
7+
.use(connect.static(dir))
8+
.listen(8081);
9+
var browser = new Browser();
10+
return Q.resolve(browser.visit("http://localhost:8081/" + url))
11+
.then(function() {
12+
return browser;
13+
})
14+
.finally(function() {
15+
server.close();
16+
});
17+
};

‎test/test.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require("./main_test");
2+
3+
require("../lib/find/find_test");
4+
require("../lib/tags/tags_tests");
5+
require("../lib/process/process_test");
6+
require("../lib/configured/npm/npm_test");
7+
require("../lib/configured/configured_test");
8+
require("../lib/generators/html/build/build_test");
9+
require("../lib/generators/html/html_test");
10+
require("../lib/generate/test/generate_test");

‎test/wait_for.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function waitFor(browser, checker) {
2+
return new Promise(function(resolve, reject) {
3+
var start = new Date();
4+
var check = function() {
5+
if (checker(browser.window)) {
6+
resolve(browser.window);
7+
} else if (new Date() - start < 2000) {
8+
setTimeout(check, 20);
9+
} else {
10+
reject(new Error("checker was never true"));
11+
}
12+
};
13+
check();
14+
});
15+
};

0 commit comments

Comments
 (0)
Please sign in to comment.