-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
19.1.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 🔐 makecert | ||
|
||
`makecert` is a small utility to generate self-signed certificates for local development. | ||
|
||
## Prerequisites | ||
|
||
This package requires `mkcert` to be installed on your system. Please follow the [installation instructions](https://github.com/FiloSottile/mkcert#installation) for your platform. | ||
|
||
## Installation | ||
|
||
```shell | ||
# With Yarn | ||
yarn add makecert | ||
|
||
# or with npm | ||
npm i makecert | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import makeCert from 'makecert'; | ||
|
||
const { key, cert } = await makeCert(); | ||
``` | ||
|
||
## ✨Roadmap | ||
|
||
- [ ] Make it a class, so we offer more ways to retrieve the cert | ||
- [ ] Add a check to see if `mkcert` is installed and if not, install it | ||
- [ ] Make sure that `mkcert` was initialized: `mkcert -install` | ||
- [ ] Add a check to see if the certificate is already created and ask the user if they want to overwrite it | ||
- [ ] Add more options for customizations (e.g. hosts, expiration time etc.) | ||
- [ ] Add a way to revoke the certificate | ||
- [ ] Add a way to check if the certificate is valid | ||
- [ ] Allow creating multiple certificates | ||
- [ ] Add tests | ||
- [ ] Add CI/CD | ||
- [ ] Add ESLint and Prettier | ||
|
||
_There is no place like 127.0.0.1 🏠_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference types="node" /> | ||
/** | ||
* Create a certificate using `mkcert` and return it | ||
*/ | ||
declare const makeCert: () => Promise<{ | ||
key: Buffer; | ||
cert: Buffer; | ||
}>; | ||
export default makeCert; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function getInfo(): { | ||
name: any; | ||
version: any; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "makecert", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"author": "David Gamote", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Gamote/makecert.git" | ||
}, | ||
"keywords": ["makecert", "certificate", "ssl", "https", "tls", "local", "development", "mkcert"], | ||
"scripts": { | ||
"build": "rm -rf dist && tsc", | ||
"start": "node dist/index.js" | ||
}, | ||
"dependencies": { | ||
"typescript": "^4.9.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.11.9" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import util from 'util'; | ||
import {exec, ExecSyncOptionsWithBufferEncoding} from 'child_process'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import getInfo from "./info"; | ||
|
||
const { name } = getInfo(); | ||
|
||
const execAsync = util.promisify(exec); | ||
|
||
const config = { | ||
tempDir: `node_modules/.${name}`, | ||
privateKeyName: 'private_key.pem', | ||
certName: 'cert.pem', | ||
hosts: ['localhost', '0.0.0.0', '::1'], | ||
execOptions: { | ||
stdio: 'pipe', | ||
} as ExecSyncOptionsWithBufferEncoding, | ||
}; | ||
|
||
/** | ||
* Create a certificate using `mkcert` and return it | ||
*/ | ||
const makeCert = async () => { | ||
try { | ||
// Create the temp directory | ||
await execAsync(`mkdir -p ${config.tempDir}`, config.execOptions); | ||
|
||
// Create the certificate | ||
await execAsync( | ||
`mkcert -key-file ${config.tempDir}/${config.privateKeyName} -cert-file ${config.tempDir}/${config.certName} ${config.hosts.join(' ')}`, | ||
config.execOptions, | ||
); | ||
} catch (e) { | ||
throw new Error( | ||
// @ts-ignore | ||
`"${name}" failed with the following error:\n${e?.stderr?.toString()}`, | ||
); | ||
} | ||
|
||
// Read the private key | ||
const privateKey = await fs.readFileSync( | ||
path.resolve(process.cwd(), config.tempDir, config.privateKeyName), | ||
); | ||
|
||
// Read the certificate | ||
const cert = await fs.readFileSync( | ||
path.resolve(process.cwd(), config.tempDir, config.certName), | ||
); | ||
|
||
// TODO: should we delete the files after we're done? (maybe not, because we might need them again) | ||
|
||
return { key: privateKey, cert }; | ||
}; | ||
|
||
export default makeCert; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Cannot be `import` as it's not under TS root dir | ||
// This way it will be excluded from the `dist` folder | ||
// More info [here](https://stackoverflow.com/a/57934516/10878244) | ||
const { name, version } = require('../package.json'); | ||
|
||
export default function getInfo() { | ||
return { name, version }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2017", | ||
"declaration": true, | ||
"strictNullChecks": false, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"outDir": "./dist", | ||
"baseUrl": "./", | ||
"resolveJsonModule": true, | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": ["node_modules", "dist"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/node@^18.11.9": | ||
version "18.11.9" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4" | ||
integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg== | ||
|
||
typescript@^4.9.3: | ||
version "4.9.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db" | ||
integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA== |