Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Mar 6, 2024
1 parent 1045bb1 commit c0a8bad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
12 changes: 6 additions & 6 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os'
import { cli as command, log } from '@stacksjs/cli'
import { fs } from '@stacksjs/storage'
import { readFileSync, writeFileSync } from '@stacksjs/storage'
import { startProxy } from '../src/start'
import { config } from '../src/config'
import { version } from '../package.json'
Expand Down Expand Up @@ -66,7 +66,7 @@ cli
if (config && typeof config === 'object') {
const entriesToAdd = Object.entries(config).map(([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`)
try {
let currentHostsContent = fs.readFileSync(hostsFilePath, 'utf8')
let currentHostsContent = readFileSync(hostsFilePath, 'utf8')
let updated = false

for (const entry of entriesToAdd) {
Expand All @@ -83,19 +83,19 @@ cli
}

if (updated) {
fs.writeFileSync(hostsFilePath, currentHostsContent, 'utf8')
writeFileSync(hostsFilePath, currentHostsContent, 'utf8')

log.success('Hosts file updated with latest proxy domains.')
}
else {
log.info('No new entries were added to the hosts file.')
}
}
catch (error) {
if (error.code === 'EACCES')
catch (error: unknown) {
if ((error as NodeJS.ErrnoException).code === 'EACCES')
console.error('Permission denied. Please run this command with administrative privileges.')
else
console.error(`An error occurred: ${error.message}`)
console.error(`An error occurred: ${(error as NodeJS.ErrnoException).message}`)
}
}
else {
Expand Down
6 changes: 6 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { $ } from 'bun'
import dts from 'bun-plugin-dts-auto'

console.log('Building...')

await Bun.build({
entrypoints: ['./src/index.ts', './bin/cli.ts'],
outdir: './dist',
Expand All @@ -20,3 +22,7 @@ await $`cp ./dist/bin/cli.js ./dist/cli.js`
await $`rm -rf ./dist/bin`
await $`cp ./bin/cli.d.ts ./dist/cli.d.ts` // while bun-plugin-dts-auto doesn't support bin files well
await $`rm ./bin/cli.d.ts`
await $`cp ./bin/reverse-proxy ./dist/reverse-proxy`
await $`rm ./bin/reverse-proxy`

console.log('Build done!')
Binary file modified bun.lockb
Binary file not shown.
9 changes: 0 additions & 9 deletions compile.ts

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
],
"scripts": {
"build": "bun build.ts && bun compile.ts",
"compile": "bun build ./bin/cli.ts --compile --minify --sourcemap --outfile dist/reverse-proxy",
"lint": "eslint .",
"lint:fix": "bunx eslint . --fix",
"fresh": "bunx rimraf node_modules/ bun.lock && bun i",
Expand All @@ -58,13 +59,13 @@
"docs:preview": "vitepress preview docs"
},
"dependencies": {
"@stacksjs/cli": "^0.59.1",
"@stacksjs/path": "^0.59.1",
"@stacksjs/storage": "^0.59.1",
"@stacksjs/cli": "^0.59.4",
"@stacksjs/path": "^0.59.4",
"@stacksjs/storage": "^0.59.4",
"c12": "^1.9.0"
},
"devDependencies": {
"@stacksjs/development": "^0.59.1",
"@stacksjs/development": "^0.59.4",
"@types/bun": "^1.0.8",
"@types/node": "^20.11.24",
"bun-plugin-dts-auto": "^0.10.0",
Expand Down

0 comments on commit c0a8bad

Please sign in to comment.