Skip to content

Commit

Permalink
fix: run build in production settings except if --dev is set
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Feb 21, 2021
1 parent b79e697 commit 392c145
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
27 changes: 25 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node
const args = require('args');
const path = require('path');

args.options([
{
Expand All @@ -13,12 +12,33 @@ args.options([
description: 'defines if build output logs should be sent to the console',
defaultValue: undefined,
},
{
name: 'prod',
description:
'defines if process.env should be set to production before the build starts',
defaultValue: true,
},
{
name: 'dev',
description:
'defines if process.env should be set to development before the build starts, defaults to false',
defaultValue: false,
},
]);

const run = () => {
const flags = args.parse(process.argv);

const getEntryPath = require('@teclone/node-utils').getEntryPath;

const prevEnv = process.env.NODE_ENV;

if (flags.dev) {
process.env.NODE_ENV = 'development';
} else {
process.env.NODE_ENV = 'production';
}

const loadFile = require(`${flags.dir}/modules/utils`).loadFile;
const Bundler = require(`${flags.dir}/modules/Bundler`).Bundler;

Expand All @@ -28,7 +48,10 @@ const run = () => {
const bunder = new Bundler(options, {
generateOutputLogs: flags.silent !== true,
});
return bunder.process();

return bunder.process().then(() => {
process.env.NODE_ENV = prevEnv;
});
};

run().then(() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@teclone/node-utils": "1.0.5",
"@types/node": "^14.14.31",
"args": "5.0.1",
"chalk": "4.0.0",
"glob-to-regexp": "0.4.1",
Expand Down
1 change: 1 addition & 0 deletions src/modules/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class Bundler {
* runs the process
*/
async process() {
console.log(process.env.NODE_ENV);
const config = this.config;
const startAt = path.resolve(this.entryPath, config.srcDir);

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/node@*":
"@types/node@*", "@types/node@^14.14.31":
version "14.14.31"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==
Expand Down

0 comments on commit 392c145

Please sign in to comment.