Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #263 from Nargonath/master
Browse files Browse the repository at this point in the history
Deploy 3.4.0
  • Loading branch information
Nargonath authored Nov 1, 2020
2 parents 7165a49 + 6ef6fbb commit 9014d4a
Show file tree
Hide file tree
Showing 7 changed files with 1,435 additions and 1,192 deletions.
4 changes: 4 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ update_configs:
default_labels:
- 'dependency'
target_branch: 'master'
commit_message:
prefix: 'fix'
prefix_development: 'build'
include_scope: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ typings/
# dotenv environment variables file
.env

# ignore NPM package-lock because we use yarn
package-lock.json
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ By default the script will generate everything into `build/` at your project roo

If those defaults do not work for you, the script accepts some arguments:

- `--after-initial-build-hook`: accepts a string of shell code that will be run only once after the initial build in the same process as the `cra-build-watch`.
- `--after-rebuild-hook`: accepts a string of shell code that will be run every time webpack rebuilds your project after a filesystem change. It runs in the same process as `cra-build-watch`.
- `-b|--build-path`: expects either an absolute or relative path. If a relative path is given it will be prefixed by your project root path.
- default: `yourProjectRoot/build`.
- `--chunk-filename`: Set the naming you want to use for non-entry chunk files. Accepts webpack placeholders such as `[id]`, `[name]`, `[hash]`. Directories can be supplied.
Expand All @@ -99,4 +101,4 @@ If those defaults do not work for you, the script accepts some arguments:

# Contributions

All contributions are welcomed. Please base your PR on the `develop` branch rather than `master`.
All contributions are welcomed.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@
"react-scripts": ">= 1.0.x"
},
"devDependencies": {
"@commitlint/cli": "8.3.5",
"@commitlint/cli": "11.0.0",
"@commitlint/config-conventional": "8.3.4",
"@dixeed/eslint-config": "2.0.0",
"cz-conventional-changelog": "3.1.0",
"eslint": "6.8.0",
"husky": "4.2.1",
"jest": "^25.1.0",
"lint-staged": "10.0.7",
"prettier": "1.19.1"
"husky": "4.3.0",
"jest": "^26.6.1",
"lint-staged": "10.5.1",
"prettier": "2.1.2"
},
"dependencies": {
"cross-spawn": "7.0.1",
"fs-extra": "^8.1.0",
"cross-spawn": "7.0.3",
"fs-extra": "^9.0.1",
"html-webpack-plugin": "^4.5.0",
"import-cwd": "3.0.0",
"meow": "6.0.0",
"meow": "8.0.0",
"ora": "4.0.3",
"semver": "^7.1.1"
}
Expand Down
32 changes: 28 additions & 4 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fs = require('fs-extra');
const path = require('path');
const ora = require('ora');
const assert = require('assert');
const exec = require('child_process').exec;

const {
flags: {
Expand All @@ -18,6 +19,8 @@ const {
disableChunks,
outputFilename,
chunkFilename,
afterInitialBuildHook,
afterRebuildHook,
},
} = require('../utils/cliHandler');
const { getReactScriptsVersion, isEjected } = require('../utils');
Expand Down Expand Up @@ -91,12 +94,11 @@ if (disableChunks) {

// update media path destination
if (major >= 4) {
const oneOfIndex = 1
const oneOfIndex = 1;
config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`;
config.module.rules[oneOfIndex].oneOf[1].options.name = `media/[name].[hash:8].[ext]`;
config.module.rules[oneOfIndex].oneOf[8].options.name = `media/[name].[hash:8].[ext]`;
}
else if (major >= 2) {
} else if (major >= 2) {
// 2.0.0 => 2
// 2.0.1 => 3
// 2.0.2 => 3
Expand Down Expand Up @@ -150,6 +152,9 @@ fs.emptyDir(paths.appBuild)
}

spinner.succeed();

runHook('after rebuild hook', spinner, afterRebuildHook);

inProgress = false;

if (verbose) {
Expand All @@ -167,7 +172,8 @@ fs.emptyDir(paths.appBuild)
});
});
})
.then(() => copyPublicFolder());
.then(() => copyPublicFolder())
.then(() => runHook('after initial build hook', spinner, afterInitialBuildHook));

function copyPublicFolder() {
return fs.copy(paths.appPublic, resolvedBuildPath, {
Expand All @@ -176,6 +182,24 @@ function copyPublicFolder() {
});
}

function runHook(label, spinner, hook) {
if (!hook || typeof hook !== 'string') {
return;
}

spinner.start(label);

exec(hook, (error, stdout, stderr) => {
if (error) {
spinner.fail(`${label}: exec error: ${error}`);
} else if (stderr) {
spinner.warn(`${label}: ${stderr}`);
} else {
spinner.succeed(`${label}: ${stdout}`);
}
});
}

function handleBuildPath(userBuildPath) {
if (path.isAbsolute(userBuildPath)) {
return userBuildPath;
Expand Down
10 changes: 10 additions & 0 deletions utils/cliHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module.exports = meow(
-p, --public-path Public URL.
--after-rebuild-hook Run a command after each build/rebuild (e.g. 'node ./afterbuild.js')
--after-initial-build-hook Run a command after each the initial build only (e.g. 'node ./afterbuild.js')
--react-scripts-version Version of the react-scripts package used in your project i.e 2.0.3. If not given it will be implied from your package.json and if it cannot be implied the major version 2 will be the default.
-v, --verbose
Expand Down Expand Up @@ -54,6 +58,12 @@ module.exports = meow(
type: 'boolean',
alias: 'v',
},
'after-initial-build-hook': {
type: 'string',
},
'after-rebuild-hook': {
type: 'string',
}
},
}
);
Loading

0 comments on commit 9014d4a

Please sign in to comment.