Skip to content

Commit 4f33ecb

Browse files
authored
Insource code from vite-plugin (#4)
* add tsconfig * insource code from vite-plugin-mkcert * add required deps and clean up update readme * use resolvePath * 1.2.0-0
1 parent a8e9d6e commit 4f33ecb

File tree

10 files changed

+607
-934
lines changed

10 files changed

+607
-934
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# mkcert-cli
1414

15-
Simple CLI wrapper for [`vite-plugin-mkcert`](https://github.com/liuweiGL/vite-plugin-mkcert) to use outside of a `vite` context.
15+
Node cli wrapper for [`mkcert`][mkcert] based entirely on the fantastic work done in [`vite-plugin-mkcert`][vite-plugin-mkcert].
1616

1717
## Quick start
1818

@@ -65,5 +65,9 @@ To pass multiple values, just pass several named args.
6565

6666
## Thanks
6767

68-
- [vite-plugin-mkcert](https://github.com/liuweiGL/vite-plugin-mkcert)
69-
- [mkcert](https://github.com/FiloSottile/mkcert)
68+
- [vite-plugin-mkcert][vite-plugin-mkcert]
69+
- [mkcert][mkcert]
70+
71+
72+
[vite-plugin-mkcert]:https://github.com/liuweiGL/vite-plugin-mkcert
73+
[mkcert]:https://github.com/FiloSottile/mkcert

mkcert-cli.js renamed to cli.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
#!/usr/bin/env node
2-
//@ts-check
3-
import { homedir } from "os";
4-
import { join } from "path";
52
import { existsSync } from "fs";
63
import { mkdir, writeFile } from "fs/promises";
74
import minimist from "minimist";
85
import pc from "picocolors";
9-
import mkcert from "vite-plugin-mkcert";
6+
import { DATA_DIR, resolvePath } from "./src/utils.js";
7+
import { createCertificate } from "./src/index.js";
108

119
/**
1210
* Init, read variables and create folders
1311
*/
14-
const defaultOutDir = join(homedir(), ".mkcert-cli", "certs");
12+
const defaultOutDir = resolvePath("certs", DATA_DIR);
1513
const argv = minimist(process.argv.slice(2));
1614
const cwd = process.cwd();
1715

1816
const force = argv.f ?? false;
1917
const verbose = argv.v ?? false;
20-
const outDir = argv.outDir ? join(cwd, argv.outDir) : defaultOutDir;
18+
const outDir = argv.outDir ? resolvePath(argv.outDir, cwd) : defaultOutDir;
2119
const hosts = argv.host ? (Array.isArray(argv.host) ? argv.host : [argv.host]) : [];
2220
const certFile = argv.cert ?? "dev.cert";
2321
const keyFile = argv.key ?? "dev.key";
24-
const certFilePath = join(outDir, certFile);
25-
const keyFilePath = join(outDir, keyFile);
22+
const certFilePath = resolvePath(certFile, outDir);
23+
const keyFilePath = resolvePath(keyFile, outDir);
2624

2725
console.log(`
2826
Running ${pc.green(`${pc.bold("mkcert-cli")}`)}...
@@ -54,20 +52,10 @@ if (!writeFiles) {
5452
}
5553

5654
try {
57-
/** @type { any } */
58-
const { config: installMkCert } = mkcert({
59-
force,
60-
hosts: hosts.length ? hosts : undefined,
61-
// autoUpgrade: boolean
62-
// source?: SourceType;
63-
// mkcertPath?: string;
64-
});
65-
const {
66-
server: { https: { key, cert } },
67-
} = await installMkCert({});
55+
const { cert, key } = await createCertificate({ force, autoUpgrade: false, keyFilePath, certFilePath });
6856
await writeFile(keyFilePath, key, { encoding: "utf-8" });
6957
await writeFile(certFilePath, cert, { encoding: "utf-8" });
70-
} catch (writeErr) {
58+
} catch (/** @type {any}*/ writeErr) {
7159
console.error(writeErr.toString());
7260
process.exit(1);
7361
}

0 commit comments

Comments
 (0)