From 8e9079a66c3f9954277ff2c1a70848d0d6591db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Thu, 10 Oct 2024 17:48:55 +0800 Subject: [PATCH] chore: update --- scripts/generate.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index 5030a21..da0310a 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -1,6 +1,7 @@ #!/usr/bin/env node const fs = require('fs-extra'); const path = require('path'); +const semverValidRange = require('semver/ranges/valid'); /** * 用 CLI 方式添加新的包或者 scope @@ -21,8 +22,12 @@ const path = require('path'); */ const HELP = ` Usage: - npm run add --package={package name}:{version range} - npm run add --scope=@{scope name} + npm run add -- --package={package name}:{version range} + npm run add -- --scope=@{scope name} + +Debug mode: + Set DEBUG=true environment variable to use draft output and enable debug logging. + eg: DEBUG=true npm run add -- "--package=urllib:*" `; const DEBUG = !!process.env.DEBUG @@ -45,6 +50,8 @@ function addPkg(input) { // exits if (PKG.allowPackages[name]) { throw new Error(`Package ${name} already exists`); + } else if (!semverValidRange(version)) { + throw new Error(`Invalid version range: ${version}`); } DEBUG && console.log(`Add package: ${name}@${version}`);