Skip to content

Commit

Permalink
feat: use local .env file instead of pulling from railway
Browse files Browse the repository at this point in the history
  • Loading branch information
Eejit43 committed Nov 4, 2024
1 parent 1179523 commit 5b4333a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store

.env

node_modules/

/*.js
Expand Down
14 changes: 10 additions & 4 deletions development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { compileTypescript } from './compile.js';
readline.emitKeypressEvents(process.stdin);

const config = {
command: {
name: 'railway',
args: 'run node --no-warnings --enable-source-maps dist/app.js'.split(' '),
},
command: { name: 'pnpm', args: ['run', 'start'] },
watch: ['ts', 'hbs', 'css'],
ignored: ['node_modules', 'dist', '.git', 'development.ts'],
};
Expand All @@ -28,8 +25,11 @@ let running: ChildProcess;
*/
async function spawnProcess() {
rmSync('dist', { recursive: true, force: true });

await compileTypescript();

consola.success('Successfully compiled TypeScript and CSS!');

running = spawn(config.command.name, config.command.args, { stdio: 'inherit', shell: true });
}

Expand All @@ -48,8 +48,11 @@ function logMessage(...message: string[]) {
*/
async function restartProcess() {
logMessage('Restarting...');

await kill(running.pid!);

spawnProcess();

await new Promise((resolve) => setTimeout(resolve, 500));
}

Expand All @@ -58,7 +61,9 @@ async function restartProcess() {
*/
function stopProcess() {
logMessage('Killing process...');

execSync('pnpm run remove-compiled');

process.exit(0); // eslint-disable-line unicorn/no-process-exit
}

Expand All @@ -67,6 +72,7 @@ function stopProcess() {
*/
function openWebsite() {
logMessage('Opening website...');

exec(`open http://localhost:${process.env.PORT ?? 3000}`);
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"type": "module",
"scripts": {
"build": "pnpm run remove-compiled && npx esbuild compile.ts --outfile=compile.js --target=node20 --platform=node && node compile.js",
"dev": "pnpm run build && node development.js --enable-source-maps",
"force-deploy": "railway up",
"dev": "pnpm run build && node --env-file=.env development.js --enable-source-maps",
"remove-compiled": "rm -rf dist && find . -maxdepth 1 -type f \\( -name '*.js' -o -name '*.js.map' \\) ! -name 'eslint.config.js' -delete",
"start": "node --no-warnings --enable-source-maps --max-old-space-size=100 dist/app.js"
},
Expand Down

0 comments on commit 5b4333a

Please sign in to comment.