forked from sinonjs/sinon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cjs
executable file
·82 lines (74 loc) · 2.09 KB
/
build.cjs
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
80
81
82
#!/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
}
/**
* @param entryPoint
* @param config
* @param done
*/
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); // WebWorker can only load js files
}
);
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.cjs", 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);
}
);