Skip to content

Commit

Permalink
fix(js): adjust minimal publish script to display better error for ve…
Browse files Browse the repository at this point in the history
…rsion validation
  • Loading branch information
nartc committed Apr 12, 2022
1 parent 2193c1f commit cbfe573
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/js/src/utils/minimal-publish-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ const [, , name, version, tag = 'next'] = process.argv;
// A simple SemVer validation to validate the version
const validVersion = /^\\d+\\.\\d+\\.\\d(-\\w+\\.\\d+)?/;
if (!version || !validVersion.test(version)) {
console.error(chalk.red(\`Invalid version\`));
process.exit(1);
console.error(chalk.bold.red(\`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag, got \${version}\`));
process.exit(1);
}
// Updating the version in "package.json" before publishing
const json = JSON.parse(readFileSync(\`package.json\`).toString());
json.version = version;
writeFileSync(\`package.json\`, JSON.stringify(json, null, 2));
try {
const json = JSON.parse(readFileSync(\`package.json\`).toString());
json.version = version;
writeFileSync(\`package.json\`, JSON.stringify(json, null, 2));
} catch (e) {
console.error(chalk.bold.red(\`Error reading package.json file from library build output.\`))
}
// Execute "npm publish" to publish
execSync(\`npm publish --access public\`);
`;

export function addMinimalPublishScript(tree: Tree) {
const publishScriptPath = 'tools/scripts/publish.mjs';

if (!tree.exists(publishScriptPath)) {
tree.write(publishScriptPath, publishScriptContent);
}
Expand Down

0 comments on commit cbfe573

Please sign in to comment.