Skip to content

Commit

Permalink
add script DEV_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
darian committed Nov 5, 2024
1 parent ee6f208 commit c7f177b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 23 additions & 0 deletions docker/dev/setDevMode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const envFilePath = join(__dirname, '.env');
const mode = process.argv[2] || 'hot-reload';

function updateDevEnvVariable() {
let envContent = readFileSync(envFilePath, 'utf8');

if (envContent.includes('DEV_MODE=')) {
envContent = envContent.replace(/DEV_MODE=.*/g, `DEV_MODE=${mode}`);
} else {
envContent += `\nDEV_MODE=${mode}`;
}

writeFileSync(envFilePath, envContent.trim() + '\n');
}

updateDevEnvVariable();
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"lint:fix": "eslint --max-warnings=0 --fix .",
"compose": "docker compose -f ./docker/dev/docker-compose.yml",
"compose:prod": "docker compose -f ./docker/prod/docker-compose.yml",
"localenv:start": "DEV_MODE=hot-reload pnpm compose up -d --build",
"localenv:start:debug": "DEV_MODE=debug pnpm compose up -d --build",
"localenv:start:lite": "DEV_MODE=lite pnpm compose up -d --build",
"localenv:start": "node docker/dev/setDevMode.mjs hot-reload && pnpm compose up -d --build",
"localenv:start:debug": "node docker/dev/setDevMode.mjs debug && pnpm compose up -d --build",
"localenv:start:lite": "node docker/dev/setDevMode.mjs lite && pnpm compose up -d --build",
"localenv:stop": "pnpm compose down",
"preinstall": "npx only-allow pnpm",
"prettier:write": "prettier --config '.prettierrc.js' --write .",
Expand Down

0 comments on commit c7f177b

Please sign in to comment.