Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed May 13, 2024
1 parent 9bf44e9 commit d667b1b
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 68 deletions.
4 changes: 1 addition & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"@ow3"
]
"extends": ["@ow3"]
}
8 changes: 2 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@
"yaml",
"toml"
],
"cSpell.ignorePaths": [
"node_modules"
],
"cSpell.dictionaries": [
"custom-dictionary"
],
"cSpell.ignorePaths": ["node_modules"],
"cSpell.dictionaries": ["custom-dictionary"],
"cSpell.diagnosticLevel": "Hint",
"cSpell.customDictionaries": {
"bun-plugin-env": {
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os'
import { CAC } from 'cac'
import { log } from '@stacksjs/logging'
import { CAC } from 'cac'
import { version } from '../package.json'
import { addCertToSystemTrustStore, generateCert } from '../src'

Expand Down
4 changes: 1 addition & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
},
"overrides": [
{
"include": [
".vscode/**"
],
"include": [".vscode/**"],
"json": {
"parser": {
"allowComments": true,
Expand Down
22 changes: 17 additions & 5 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config = {
},
prompt: {
messages: {
type: 'Select the type of change that you\'re committing:',
type: "Select the type of change that you're committing:",
scope: 'Select the SCOPE of this change (optional):',
customScope: 'Select the SCOPE of this change:',
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
Expand All @@ -22,12 +22,24 @@ const config = {
{ value: 'fix', name: 'fix: 🐛 A bug fix', emoji: ':bug:' },
{ value: 'docs', name: 'docs: 📝 Documentation only changes', emoji: ':memo:' },
{ value: 'style', name: 'style: 💄 Changes that do not affect the meaning of the code', emoji: ':lipstick:' },
{ value: 'refactor', name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature', emoji: ':recycle:' },
{
value: 'refactor',
name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature',
emoji: ':recycle:',
},
{ value: 'perf', name: 'perf: ⚡️ A code change that improves performance', emoji: ':zap:' },
{ value: 'test', name: 'test: ✅ Adding missing tests or adjusting existing tests', emoji: ':white_check_mark:' },
{ value: 'build', name: 'build: 📦️ Changes that affect the build system or external dependencies', emoji: ':package:' },
{
value: 'test',
name: 'test: ✅ Adding missing tests or adjusting existing tests',
emoji: ':white_check_mark:',
},
{
value: 'build',
name: 'build: 📦️ Changes that affect the build system or external dependencies',
emoji: ':package:',
},
{ value: 'ci', name: 'ci: 🎡 Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' },
{ value: 'chore', name: 'chore: 🔨 Other changes that don\'t modify src or test files', emoji: ':hammer:' },
{ value: 'chore', name: "chore: 🔨 Other changes that don't modify src or test files", emoji: ':hammer:' },
{ value: 'revert', name: 'revert: ⏪️ Reverts a previous commit', emoji: ':rewind:' },
],
useEmoji: false,
Expand Down
4 changes: 1 addition & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export default defineConfig({
},
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
],
socialLinks: [{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }],
},
})
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@
"bin": {
"tlsx": "./dist/cli.js"
},
"files": [
"dist",
"scripts",
"src"
],
"files": ["dist", "scripts", "src"],
"scripts": {
"build": "bun scripts/build.ts && bun run compile",
"compile": "bun build ./bin/cli.ts --compile --external rollup --minify --sourcemap --outfile dist/tlsx",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { log } from '@stacksjs/logging'
import { $ } from 'bun'
import dts from 'bun-plugin-dts-auto'
import { log } from '@stacksjs/logging'

log.info('Building...')

Expand Down
3 changes: 1 addition & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export async function resolveConfig(options?: GenerateCertOptions) {
cwd: resolve(import.meta.dir, '..'),
})

if (!config)
config = def
if (!config) config = def

return config
}
Expand Down
64 changes: 32 additions & 32 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ export async function generateCert(options?: GenerateCertOptions) {
cert.validity.notBefore = new Date()
cert.validity.notAfter = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * (opts.validityDays ?? 1))

const attrs = [{
name: 'countryName',
value: opts.countryName ?? 'US',
}, {
shortName: 'ST',
value: opts.stateName ?? 'California',
}, {
name: 'organizationName',
value: opts.organizationName ?? 'tlsx stacks.localhost', // simply for a recognizable name
}]
const attrs = [
{
name: 'countryName',
value: opts.countryName ?? 'US',
},
{
shortName: 'ST',
value: opts.stateName ?? 'California',
},
{
name: 'organizationName',
value: opts.organizationName ?? 'tlsx stacks.localhost', // simply for a recognizable name
},
]

cert.setSubject(attrs)
cert.setIssuer(attrs)

// add alt names so that the browser won't complain
cert.setExtensions([{
name: 'subjectAltName',
altNames: [
...(opts.altNameURIs !== undefined
? opts.altNameURIs.map(uri => ({ type: 6, value: uri }))
: []
),

...(opts.altNameIPs !== undefined
? opts.altNameIPs.map(uri => ({ type: 7, ip: uri }))
: []
),
],
}])
cert.setExtensions([
{
name: 'subjectAltName',
altNames: [
...(opts.altNameURIs !== undefined ? opts.altNameURIs.map((uri) => ({ type: 6, value: uri })) : []),

...(opts.altNameIPs !== undefined ? opts.altNameIPs.map((uri) => ({ type: 7, ip: uri })) : []),
],
},
])

// self-sign certificate
cert.sign(keys.privateKey)
Expand All @@ -74,17 +74,18 @@ export async function addCertToSystemTrustStore(cert: string, options?: AddCertO
const certPath = storeCert(cert, options)
const platform = os.platform()

if (platform === 'darwin') // macOS
if (platform === 'darwin')
// macOS
await runCommand(`sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${certPath}`)
else if (platform === 'win32') // Windows
else if (platform === 'win32')
// Windows

await runCommand(`certutil -f -v -addstore -enterprise Root ${certPath}`)

else if (platform === 'linux') // Linux (This might vary based on the distro)
else if (platform === 'linux')
// Linux (This might vary based on the distro)
// for Ubuntu/Debian based systems
await runCommands([`sudo cp ${certPath} /usr/local/share/ca-certificates/`, `sudo update-ca-certificates`])
else
throw new Error(`Unsupported platform: ${platform}`)
else throw new Error(`Unsupported platform: ${platform}`)
return certPath
}

Expand All @@ -94,8 +95,7 @@ export function storeCert(cert: string, options?: AddCertOptions) {

// Ensure the directory exists before writing the file
const certDir = path.dirname(certPath)
if (!fs.existsSync(certDir))
fs.mkdirSync(certDir, { recursive: true })
if (!fs.existsSync(certDir)) fs.mkdirSync(certDir, { recursive: true })

fs.writeFileSync(certPath, cert)

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
[P in keyof T]?: DeepPartial<T[P]>
}

export interface TlsOptions {
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"compilerOptions": {
"target": "esnext",
"lib": [
"esnext"
],
"lib": ["esnext"],
"moduleDetection": "force",
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"types": [
"node"
],
"allowImportingTsExtensions": true,
"strict": true,
"strictNullChecks": true,
Expand Down

0 comments on commit d667b1b

Please sign in to comment.