forked from baconjs/bacon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assemble-specs.js
67 lines (53 loc) · 1.77 KB
/
assemble-specs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env babel-node
"use strict";
var _ = require("lodash");
var fs = require("fs");
var path = require("path");
var shell = require('shelljs');
var Deps = require('./build-deps')
// Manifest to build
var defaultOutput = path.join(__dirname, "spec", "BaconSpec.coffee");
// Boilerplate: *header* and *footer*
var header = fs.readFileSync(path.join(__dirname, "spec", "boilerplate", "SpecHeader.coffee"), "utf-8");
var helper = fs.readFileSync(path.join(__dirname, "spec", "boilerplate", "SpecHelper.coffee"), "utf-8");
function resolvePieceNames() {
var argPieceNames = process.argv.slice(2)
if (argPieceNames.length) return argPieceNames
return fs.readdirSync("spec/specs")
.map(function(name) { return name.substring(0, name.length - 7)})
}
function readPiece(pieceName) {
return fs.readFileSync(path.join(__dirname, "spec", "specs", pieceName + ".coffee"), "utf-8");
}
function buildArgs(pieceNames) {
if (pieceNames.length > 3) return ""
var pieceNames = Deps.resolvePieces(pieceNames, "spec/specs", { recursive: false })
.map(function(piece) { return piece.name })
return pieceNames.join(" ")
}
var main = function(options){
var pieceNames = (options.pieceNames || resolvePieceNames())
var pieces = pieceNames.map(readPiece)
var output = [
header,
helper,
pieces.join("\n"),
].join("\n");
console.log("Building lib with args: " + buildArgs(pieceNames))
var result = shell.exec("./build " + buildArgs(pieceNames))
if (result.code != 0)
process.exit(result.code)
if (options.output) {
try {fs.mkdirSync("dist")} catch (e) {}
fs.writeFileSync(options.output, output);
} else {
console.log(output);
}
}
if (require.main === module) {
main({
verbose: true,
output: defaultOutput,
});
}
exports.main = main;