graphql-engine/frontend/tools/scripts/publish.mjs
Nicolas Beaussart 1c942fe69e frontend: upgrade to storybook 7
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9006
Co-authored-by: Nicolas Inchauspe <710410+nicoinch@users.noreply.github.com>
Co-authored-by: Brandon Simmons <210815+jberryman@users.noreply.github.com>
Co-authored-by: Daniele Cammareri <5709409+dancamma@users.noreply.github.com>
Co-authored-by: Daniel Harvey <4729125+danieljharvey@users.noreply.github.com>
Co-authored-by: Rishichandra Wawhal <27274869+wawhal@users.noreply.github.com>
Co-authored-by: Samir Talwar <47582+SamirTalwar@users.noreply.github.com>
Co-authored-by: Anon Ray <616387+ecthiender@users.noreply.github.com>
Co-authored-by: Tom Harding <6302310+i-am-tom@users.noreply.github.com>
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
Co-authored-by: John Kiragu <11444316+kigsmtua@users.noreply.github.com>
Co-authored-by: Matthew Goodwin <49927862+m4ttheweric@users.noreply.github.com>
Co-authored-by: Divi <32202683+imperfect-fourth@users.noreply.github.com>
Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com>
Co-authored-by: Aaysha <109507451+aayshasura@users.noreply.github.com>
Co-authored-by: Vijay Prasanna <11921040+vijayprasanna13@users.noreply.github.com>
Co-authored-by: Erik Magnusson <32518962+ejkkan@users.noreply.github.com>
GitOrigin-RevId: fe4953db62326fb3a8de118f8bba2add9bb9c2c2
2023-05-09 17:41:28 +00:00

76 lines
2.3 KiB
JavaScript

/**
* This is a minimal script to publish your package to "npm".
* This is meant to be used as-is or customize as you see fit.
*
* This script is executed on "dist/path/to/library" as "cwd" by default.
*
* You might need to authenticate with NPM before running this script.
*/
import devkit from '@nrwl/devkit';
import { execSync } from 'child_process';
import { readFileSync, appendFileSync, writeFileSync } from 'fs';
import chalk from 'chalk';
function invariant(condition, message) {
if (!condition) {
console.error(chalk.bold.red(message));
process.exit(1);
}
}
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
const [, , name, version, tagInput] = process.argv;
const tag = tagInput ?? 'next';
// A simple SemVer validation to validate the version
const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/;
invariant(
version && validVersion.test(version),
`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.`
);
const graph = devkit.readCachedProjectGraph();
const project = graph.nodes[name];
invariant(
project,
`Could not find project "${name}" in the workspace. Is the project.json configured correctly?`
);
const outputPath = project.data?.targets?.build?.options?.outputPath;
invariant(
outputPath,
`Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?`
);
process.chdir(outputPath);
// Updating the version in "package.json" before publishing
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.`)
);
}
try {
appendFileSync('.npmrc', '//registry.npmjs.org/:_authToken=${NPM_TOKEN}');
} catch (e) {
console.error(chalk.bold.red(`Error writing to npmrc.`));
}
if (process.env.BUILDKITE) {
execSync(`npm publish --access public --tag ${tag}`, {
env: { ...process.env, CI: 'true' },
});
} else {
console.log('DRY RUN, since we are not in CI.');
console.log(`npm publish --access public --tag ${tag}`);
console.log(`With version ${version}`);
}