Skip to content

Commit

Permalink
Don't use defaults for WORKER_ENV and RUN
Browse files Browse the repository at this point in the history
  • Loading branch information
ramesaliyev committed Jul 29, 2024
1 parent 3f0ba8a commit df468ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"type": "module",
"scripts": {
"// Githooks": "",
"gh:pre-commit": "node tools/pre-deploy",
"gh:pre-commit": "WORKER_ENV=local RUN=0-0-0 node tools/pre-deploy",
"set:githooks": "node tools/githooks/_set",

"// Deployment": "",
"manual-deploy": "node tools/pre-deploy && wrangler deploy -c packages/worker/wrangler.toml --env $WORKER_ENV",
"manual-deploy": "RUN=0-0-0 node tools/pre-deploy && wrangler deploy -c packages/worker/wrangler.toml --env $WORKER_ENV",
"manual-deploy:prod": "WORKER_ENV=prod npm run manual-deploy",

"// Testing": "",
Expand Down
22 changes: 16 additions & 6 deletions tools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ export function loadPackageJson() {
}

// Export env vars with defaults.
export function getEnv() {
return {
WORKER_ENV: process.env.WORKER_ENV || 'prod',
RUN: process.env.RUN || '0-0-0',
};
}
export const getEnv = (() => {
const vars = ['WORKER_ENV', 'RUN'];

const env = Object.fromEntries(
vars.map(name => {
const value = process.env[name];
if (value === undefined) {
console.error(`${name} is not set.`);
process.exit(1);
}
return [name, value];
})
);

return () => Object.assign({}, env);
})();

// Chalk helpers.
export function logYellow(message) {
Expand Down

0 comments on commit df468ce

Please sign in to comment.