From 411c4daa594e1ffbbeca5969683d327a96115b27 Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Wed, 4 Mar 2020 23:44:18 -0500 Subject: [PATCH] Only generate manifest if update is specified BREAKING CHANGE: packwatch will now exit with a non-zero code if run without an existing manifest file and without the --update-manifest flag. Now run packwatch --update-manifest to generate a manifest for the first time. --- README.md | 2 +- src/index.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ec5de2..078eed8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ While you can install `packwatch` as a global package, it's better to include it ## 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. diff --git a/src/index.js b/src/index.js index d3f3f23..cf69e65 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,9 @@ if (!existsSync('package.json')) { 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() @@ -26,6 +28,13 @@ const currentStats = getCurrentPackageStats() */ 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 }) console.log( `📝 No Manifest to compare against! Current package stats written to ${MANIFEST_FILENAME}!`,