forked from sinonjs/sinon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
executable file
·79 lines (71 loc) · 2.05 KB
/
build.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
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
"use strict";
/* eslint-disable @sinonjs/no-prototype-methods/no-prototype-methods */
var fs = require("fs");
var browserify = require("browserify");
var pkg = require("./package.json");
var sinon = require("./lib/sinon");
// YYYY-MM-DD
var date = new Date().toISOString().split("T")[0];
// Keep the preamble on one line to retain source maps
var preamble = "/* Sinon.JS " + pkg.version + ", " + date + ", @license BSD-3 */";
try {
fs.mkdirSync("pkg");
} catch (ignore) {
// We seem to have it already
}
function makeBundle(entryPoint, config, done) {
browserify(entryPoint, config).bundle(function(err, buffer) {
if (err) {
throw err;
}
done(buffer.toString());
});
}
makeBundle(
"./lib/sinon.js",
{
// Add inline source maps to the default bundle
debug: true,
// Create a UMD wrapper and install the "sinon" global:
standalone: "sinon",
// Do not detect and insert globals:
detectGlobals: false
},
function(bundle) {
var script = preamble + bundle;
fs.writeFileSync("pkg/sinon.js", script);
}
);
makeBundle(
"./lib/sinon.js",
{
// Create a UMD wrapper and install the "sinon" global:
standalone: "sinon",
// Do not detect and insert globals:
detectGlobals: false
},
function(bundle) {
var script = preamble + bundle;
fs.writeFileSync("pkg/sinon-no-sourcemaps.js", script);
}
);
makeBundle(
"./lib/sinon-esm.js",
{
// Do not detect and insert globals:
detectGlobals: false
},
function(bundle) {
var intro = "let sinon;";
var outro =
"\nexport default sinon;\n" +
Object.keys(sinon)
.map(function(key) {
return "const _" + key + " = sinon." + key + ";\nexport { _" + key + " as " + key + " };";
})
.join("\n");
var script = preamble + intro + bundle + outro;
fs.writeFileSync("pkg/sinon-esm.js", script);
}
);