forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepublish.js
63 lines (52 loc) · 2.03 KB
/
prepublish.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
// Reconfigures the repository before publishing
const fs = require("fs");
const path = require("path");
const pkg = require("../package.json");
const devFiles = require("./postpublish-files.json");
if (!pkg.releaseFiles) {
console.log("Package has already been updated");
return;
}
console.log("Backing up development files ...");
devFiles.forEach(originalName => {
const backupName = originalName + ".backup";
console.log("- " + originalName + " -> " + backupName);
fs.copyFileSync(
path.join(__dirname, "..", originalName),
path.join(__dirname, "..", backupName)
);
});
console.log("Updating package.json ...");
// Stuff we don't need in release
Object.keys(pkg.devDependencies).forEach(dep => delete pkg.dependencies[dep]);
delete pkg.devDependencies;
delete pkg.scripts;
// Stuff we want in release
pkg.files = pkg.releaseFiles;
delete pkg.releaseFiles;
// Copy contributors from NOTICE to .contributors
const notice = fs.readFileSync(path.join(__dirname, "..", "NOTICE"), "utf8");
const noticeRange = ["dcode.io>", "Portions of this software"];
const posStart = notice.indexOf(noticeRange[0]);
const posEnd = notice.indexOf(noticeRange[1], posStart);
if (posStart < 0 || posEnd < 0) throw Error("unexpected NOTICE format");
pkg.contributors = [];
for (let entry of notice.substring(posStart + noticeRange[0].length, posEnd).trim().matchAll(/^\* ([^<\n]+(?: <([^>\n]+)>))/mg)) {
pkg.contributors.push(entry[1]);
}
if (!pkg.contributors.length) throw Error("missing contributors");
fs.writeFileSync(path.join(__dirname, "..", "package.json"), [
JSON.stringify(pkg, null, 2), '\n'
].join(""));
console.log("Copying index.release.js -> index.js ...");
fs.copyFileSync(
path.join(__dirname, "..", "index.release.js"),
path.join(__dirname, "..", "index.js")
);
console.log("Copying index.release.d.ts -> index.d.ts ...");
fs.copyFileSync(
path.join(__dirname, "..", "index.release.d.ts"),
path.join(__dirname, "..", "index.d.ts")
);
// We are going to use these immediately, so, to be sure:
setTimeout(() => console.log("OK"), 2000);