1 | import * as path from "path";
|
2 | import * as glob from "glob";
|
3 | import * as fs from "fs-extra";
|
4 | import * as iconv from "iconv-lite";
|
5 | import {spawn} from "child_process";
|
6 |
|
7 | export async function keygenAsync(argv: { alias: string; password: string }): Promise<void> {
|
8 | const keytoolPaths = glob.sync(path.resolve("c:", "Program Files", "Java", "jdk*", "bin", "keytool.exe"));
|
9 | const keytoolPath = keytoolPaths.last();
|
10 |
|
11 | if (fs.existsSync(path.resolve(process.cwd(), ".sign", argv.alias, "release-signing.jks"))) {
|
12 | throw new Error("키쌍이 이미 존재합니다.");
|
13 | }
|
14 |
|
15 | fs.mkdirsSync(path.resolve(process.cwd(), ".sign", argv.alias));
|
16 |
|
17 | const cmd = spawn(
|
18 | "\"" + keytoolPath + "\"",
|
19 | [
|
20 | "-genkey", "-noprompt",
|
21 | "-alias", argv.alias,
|
22 | "-dname", "CN=",
|
23 | "-keyalg", "RSA",
|
24 | "-keysize", "2048",
|
25 | "-validity", "10000",
|
26 | "-keystore", "release-signing.jks",
|
27 | "-storepass", argv.password,
|
28 | "-keypass", argv.password
|
29 | ],
|
30 | {
|
31 | shell: true,
|
32 | cwd: path.resolve(process.cwd(), ".sign", argv.alias)
|
33 | }
|
34 | );
|
35 |
|
36 | await new Promise<void>((resolve, reject) => {
|
37 | let errorMessage = "";
|
38 | cmd.stdout.on("data", (data: Buffer) => {
|
39 | errorMessage += iconv.decode(data, "euc-kr");
|
40 | });
|
41 | cmd.stderr.on("data", (data: Buffer) => {
|
42 | const str = iconv.decode(data, "euc-kr");
|
43 | if (!str.includes("PKCS12") && !str.includes("Warning")) {
|
44 | console.log(str);
|
45 | }
|
46 | });
|
47 | cmd.on("exit", code => {
|
48 | if (code !== 0) {
|
49 | reject(new Error(errorMessage));
|
50 | }
|
51 | resolve();
|
52 | });
|
53 | });
|
54 |
|
55 | fs.writeFileSync(
|
56 | path.resolve(process.cwd(), ".sign", argv.alias, "release-signing.properties"),
|
57 | "key.store=release-signing.jks" + "\n" +
|
58 | "key.store.password=" + argv.password + "\n" +
|
59 | "key.alias=" + argv.alias + "\n" +
|
60 | "key.alias.password=" + argv.password
|
61 | );
|
62 | } |
\ | No newline at end of file |