Skip to content

Commit

Permalink
feat: added build path option to CLI (#37)
Browse files Browse the repository at this point in the history
* feat: added build path option to CLI

created option --build-path / -d to change the artifacts path name created by react

* doc: update readme with --build-path option
  • Loading branch information
gmonte authored Aug 2, 2021
1 parent e02a5bb commit 4987166
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

### Options

-s, --skip-compile Skip compilation
-h, --help Output usage information
-e, --env [path] (./.env) Path to environment variables file
-m, --mode [mode] Output mode
-s, --skip-compile Skip compilation
-h, --help Output usage information
-e, --env [path] (./.env) Path to environment variables file
-m, --mode [mode] Output mode
-d, --build-path [path] (./build) Path to react build output

#### Output modes

Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ const Dotenv = require("dotenv-webpack");
const program = require("commander");
const path = require("path");

const BUILD_SW_FILE_PATH = "build/service-worker.js";
const BUNDLE_FILE_NAME = "bundle.js";
let BUILD_SW_FILE_PATH;

/**
* Command line options
*/
program
.arguments("<file>")
.option("-s, --skip-compile", "skip compilation")
.option(
"-d, --build-path [path]",
"path of build artifacts [./build]",
"./build"
)
.option(
"-e, --env [path]",
"path to environment variables files [./.env]",
Expand All @@ -26,6 +31,8 @@ program
/^(dev|build|replace)$/i
)
.action(function(file) {
BUILD_SW_FILE_PATH = `${ program.buildPath }/service-worker.js`

if (program.mode === "dev") {
process.env.BABEL_ENV = "development";
process.env.NODE_ENV = "development";
Expand Down Expand Up @@ -147,7 +154,7 @@ function append(code, file) {
return writeFile(code, `public/${filename}`);
} else if (program.mode === "build") {
const filename = path.basename(file);
return writeFile(code, `build/${filename}`);
return writeFile(code, `${program.buildPath}/${filename}`);
} else if (program.mode === "replace") {
const filename = path.basename(file);
return writeFile(code, BUILD_SW_FILE_PATH);
Expand Down

2 comments on commit 4987166

@pedromarta
Copy link

@pedromarta pedromarta commented on 4987166 May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmonte Any chance this change is going to get published any time soon? 👀

@gmonte
Copy link
Contributor Author

@gmonte gmonte commented on 4987166 May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pedromarta I do not have access to publish this package. I only sent the PR to maintainers. Anyway temporarily you can install this package on your project from git instead of npm.

@tszarzynski this PR was accepted 10 months ago, but not published to npm. Could you publish this update on npm?

Please sign in to comment.