feat: Only generate manifest if update is specified #8

Merged
msrose merged 4 commits from only-generate-manifest-with-option into master 2020-03-08 17:12:50 +00:00
2 changed files with 11 additions and 2 deletions
Showing only changes of commit 411c4daa59 - Show all commits

View file

@ -31,7 +31,7 @@ While you can install `packwatch` as a global package, it's better to include it
## Usage ## Usage
`packwatch` tracks your packages' size via its `.packwatch.json` manifest. To get started, call `packwatch` at the root of your project: a fresh manifest will be generated for you using your current package's size as the initial upper limit for package size. `packwatch` tracks your packages' size via its `.packwatch.json` manifest. To get started, call `packwatch --update-manifest` at the root of your project: a fresh manifest will be generated for you using your current package's size as the initial upper limit for package size.
Once a manifest file exists, calling `packwatch` again will compare its data to the current state of your package. Every time `packwatch` compares your code to the manifest, it will update the last reported package size statistics it contains, but not the limit you have set. Once a manifest file exists, calling `packwatch` again will compare its data to the current state of your package. Every time `packwatch` compares your code to the manifest, it will update the last reported package size statistics it contains, but not the limit you have set.

View file

@ -16,7 +16,9 @@ if (!existsSync('package.json')) {
process.exit(1) process.exit(1)
} }
const isUpdatingManifest = process.argv.includes('--update-manifest') const UPDATE_MANIFEST_OPTION = '--update-manifest'
const isUpdatingManifest = process.argv.includes(UPDATE_MANIFEST_OPTION)
const currentStats = getCurrentPackageStats() const currentStats = getCurrentPackageStats()
@ -26,6 +28,13 @@ const currentStats = getCurrentPackageStats()
*/ */
if (!existsSync(MANIFEST_FILENAME)) { if (!existsSync(MANIFEST_FILENAME)) {
if (!isUpdatingManifest) {
console.log(
`🔥🔥📦🔥🔥 No manifest file exists! Run packwatch with ${UPDATE_MANIFEST_OPTION} to generate a manifest file`,
)
process.exit(1)
}
createOrUpdateManifest({ current: currentStats }) createOrUpdateManifest({ current: currentStats })
console.log( console.log(
mcataford commented 2020-03-08 17:12:19 +00:00 (Migrated from github.com)
Review

An argument could be made that there's never a valid use case in which you'd want CI to run --update-manifest and pass either (since having --update-manifest in CI would always pass the check). That being said, I feel that this can be addressed further up and check if a CI env variable is set to error out early if --update-manifest is passed in.

LGTM.

An argument could be made that there's never a valid use case in which you'd want CI to run `--update-manifest` and pass either (since having `--update-manifest` in CI would always pass the check). That being said, I feel that this can be addressed further up and check if a CI env variable is set to error out early if `--update-manifest` is passed in. LGTM.
`📝 No Manifest to compare against! Current package stats written to ${MANIFEST_FILENAME}!`, `📝 No Manifest to compare against! Current package stats written to ${MANIFEST_FILENAME}!`,