Skip to content

Commit a789a0f

Browse files
committed
feat: implement dev/setup script; add it to npm scripts with command setup
1 parent dd76de9 commit a789a0f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

dev/setup.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import crypto from "node:crypto";
2+
import fs from "node:fs/promises";
3+
import registerGitHubApp from "./lib/register-github-app/index.js";
4+
5+
// register app and retrieve credentials
6+
const appCredentials = await registerGitHubApp({
7+
// name of your app
8+
name: "jargons.dev-app-for-",
9+
url: "https://github.com/babblebey/jargons.dev/CONTRIBUTING.md",
10+
default_permissions: {
11+
issues: "write",
12+
}
13+
});
14+
15+
// convert private key to pkcs8 format (recommended for better cross plattform support)
16+
const privateKeyPKCS8 = String(
17+
crypto.createPrivateKey(appCredentials.pem).export({
18+
type: "pkcs8",
19+
format: "pem",
20+
}),
21+
);
22+
const singleLinePrivateKey = privateKeyPKCS8.trim().replace(/\n/g, "\\n");
23+
24+
// write credentials into `.env` file
25+
const envFileTemp = await fs.readFile(".env.example", "utf-8");
26+
const newEnvFileContent = envFileTemp
27+
.replace(/^GITHUB_APP_ID=.*$/m, `GITHUB_APP_ID=${appCredentials.id}`)
28+
.replace(/^GITHUB_APP_PRIVATE_KEY=.*$/m, `GITHUB_APP_PRIVATE_KEY="${singleLinePrivateKey}"`)
29+
await fs.writeFile(".env", newEnvFileContent);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": "astro dev",
99
"build": "astro build",
1010
"preview": "astro preview",
11-
"astro": "astro"
11+
"astro": "astro",
12+
"setup": "node dev/setup.js"
1213
},
1314
"keywords": [],
1415
"author": "",

0 commit comments

Comments
 (0)