Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Commit 0d91a34

Browse files
committed
fix: fix postinstall script
1 parent f18545d commit 0d91a34

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.*
22
index.ts
3-
tsconfig.json
3+
tsconfig.json
4+
*.dev.js
5+
src/
6+
tsconfig.eslint.json

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"build": "tsc",
1212
"build:check": "tsc --noEmit --incremental false",
1313
"npm:publish": "npm publish --access public",
14-
"download": "node script/download",
15-
"postinstall": "(is-ci && npm run download) || (npm run build && npm run download && husky install)"
14+
"postinstall:prod": "node script/download",
15+
"postinstall": "npm run build && node script/download && husky install",
16+
"prepublishOnly": "node script/prepublishOnly.dev",
17+
"postpublish": "node script/postpublish.dev"
1618
},
1719
"repository": {
1820
"type": "git",
@@ -48,8 +50,8 @@
4850
"distube": "^3.3.2",
4951
"eslint": "^8.8.0",
5052
"eslint-config-distube": "^1.6.3",
53+
"fromentries": "^1.3.2",
5154
"husky": "^7.0.4",
52-
"is-ci": "^3.0.1",
5355
"nano-staged": "^0.5.0",
5456
"prettier": "^2.5.1",
5557
"typescript": "^4.5.5"

script/postpublish.dev.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const fromEntries = require("fromentries");
4+
5+
function fn(name) {
6+
if (name === "postinstall:dev") return "postinstall";
7+
else if (name === "postinstall") return "postinstall:prod";
8+
return name;
9+
}
10+
11+
const file = path.join(process.cwd(), "package.json");
12+
let data = fs.readFileSync(file, "utf-8");
13+
const pkg = JSON.parse(data);
14+
pkg.scripts = fromEntries(Object.entries(pkg.scripts).map(([key, value]) => [fn(key), value]));
15+
const regex = /^[ ]+|\t+/m;
16+
const res = regex.exec(data);
17+
const indent = res ? res[0] : null;
18+
data = JSON.stringify(pkg, null, indent);
19+
fs.writeFileSync(file, `${data}\n`);

script/prepublishOnly.dev.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const fromEntries = require("fromentries");
4+
5+
function fn(name) {
6+
if (name === "postinstall:prod") return "postinstall";
7+
else if (name === "postinstall") return "postinstall:dev";
8+
return name;
9+
}
10+
11+
const file = path.join(process.cwd(), "package.json");
12+
let data = fs.readFileSync(file, "utf-8");
13+
const pkg = JSON.parse(data);
14+
pkg.scripts = fromEntries(Object.entries(pkg.scripts).map(([key, value]) => [fn(key), value]));
15+
const regex = /^[ ]+|\t+/m;
16+
const res = regex.exec(data);
17+
const indent = res ? res[0] : null;
18+
data = JSON.stringify(pkg, null, indent);
19+
fs.writeFileSync(file, `${data}\n`);

0 commit comments

Comments
 (0)