-
Notifications
You must be signed in to change notification settings - Fork 6
/
publish.ts
68 lines (63 loc) · 2 KB
/
publish.ts
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
import { Octokit } from "@octokit/core";
import dotenv from "dotenv";
import fsAsync from "fs/promises";
import { exec as execCallback } from "child_process";
import axios from "axios";
function exec(command: string) {
return new Promise<void>((resolve) => {
execCallback(command, () => {
resolve();
});
});
}
dotenv.config();
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
(async () => {
const deviconVersion = (
await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {
owner: "devicons",
repo: "devicon",
})
).data.tag_name.replace("v", "");
const currentVersion = (
await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {
owner: "devicons",
repo: "react-devicons",
})
).data.tag_name.replace("v", "");
await fsAsync.writeFile(
".npmrc",
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`
);
if (!deviconVersion.includes(currentVersion)) {
console.log(
`New version available (${currentVersion} -> ${deviconVersion})`
);
console.log(" - Building");
await exec("pnpm build");
console.log(" - Publishing");
await exec(
`pnpm publish dist --non-interactive --new-version ${deviconVersion}`
);
console.log(" - Creating github release");
const release_id = (
await octokit.request("POST /repos/{owner}/{repo}/releases", {
owner: "devicons",
repo: "react-devicons",
tag_name: `v${deviconVersion}`,
})
).data.id;
await exec("zip react-devicons.zip dist -r");
await axios({
url: `https://uploads.github.com/repos/devicons/react-devicons/releases/${release_id}/assets?name=react-devicons.zip`,
data: Buffer.from(await fsAsync.readFile("./react-devicons.zip")),
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
"Content-Type": "application/zip",
},
});
console.log("All done!");
} else {
console.log(`Version up to date (${deviconVersion})`);
}
})();