generated from parzh/package-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
postinstall.js
37 lines (27 loc) · 928 Bytes
/
postinstall.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
"use strict";
const producerPackageName = require("./package.json").name; // expected to see "@iso4217/json"
const consumerPackageName = process.env.npm_package_name ?? ""; // expected to see arbitrary package name
const logPrefix = `${producerPackageName}:`;
/** @param {unknown[]} values @returns {void} */
function log(...values) {
console.log(logPrefix, "[meta]", ...values);
}
function postinstall() {
if (consumerPackageName === producerPackageName) {
const fs = require("fs");
if (!fs.existsSync("./build-grouped-by-data-files.js")) {
const { spawnSync } = require("child_process");
log("Compiling script file ...");
const { error } = spawnSync("npm", [ "run", "build" ], {
cwd: process.cwd(),
timeout: 20000,
stdio: "inherit",
});
if (error)
throw error;
log("Script file has been compiled");
}
}
require("./build-grouped-by-data-files").default();
}
postinstall();