@samitouri / QOS-React / commits / 9c60cbe3d1

[compiler] Clean up publish script (#31278)

Few small tweaks to make it easier to run adhoc publishes --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31278). * #31283 * __->__ #31278

lauren committed Oct 17, 2024 at 18:02 UTC 9c60cbe3d1b95d531ddcd64e0a6730db640c934e
2 files changed +34 -28
.github/workflows/compiler_prereleases.yml
+1 -1
@@ -49,4 +49,4 @@ jobs:
49 - name: Publish packages to npm
50 run: |
51 cp ./scripts/release/ci-npmrc ~/.npmrc
52 - scripts/release/publish.js --frfr --ci --tags ${{ inputs.dist_tag }}
52 + scripts/release/publish.js --frfr --ci --versionName=0.0.0 --tag ${{ inputs.dist_tag }}
compiler/scripts/release/publish.js
+33 -27
@@ -59,12 +59,19 @@ async function main() {
59 type: 'boolean',
60 default: false,
61 })
62 - .option('tags', {
63 - description: 'Tags to publish to npm',
64 - type: 'string',
62 + .option('tag', {
63 + description: 'Tag to publish to npm',
64 + type: 'choices',
65 + choices: ['experimental', 'beta'],
66 default: 'experimental',
67 })
68 + .option('version-name', {
69 + description: 'Version name',
70 + type: 'string',
71 + default: '0.0.0',
72 + })
73 .help('help')
74 + .strict()
75 .parseSync();
76
77 if (argv.debug === false) {
@@ -82,7 +89,7 @@ async function main() {
89 pkgNames = [argv.packages];
90 }
91 const spinner = ora(
85 - `Preparing to publish ${
92 + `Preparing to publish ${argv.versionName}@${argv.tag} ${
93 argv.forReal === true ? '(for real)' : '(dry run)'
94 } [debug=${argv.debug}]`
95 ).info();
@@ -118,14 +125,15 @@ async function main() {
125 }
126 );
127 const dateString = await getDateStringForCommit(commit);
121 - const otp = argv.ci === false ? await promptForOTP() : null;
128 + const otp =
129 + argv.ci === false && argv.debug === false ? await promptForOTP() : null;
130 const {hash} = await hashElement(path.resolve(__dirname, '../..'), {
131 encoding: 'hex',
132 folders: {exclude: ['node_modules']},
133 files: {exclude: ['.DS_Store']},
134 });
135 const truncatedHash = hash.slice(0, 7);
128 - const newVersion = `0.0.0-experimental-${truncatedHash}-${dateString}`;
136 + const newVersion = `${argv.versionName}-${argv.tag}-${truncatedHash}-${dateString}`;
137
138 for (const pkgName of pkgNames) {
139 const pkgDir = path.resolve(__dirname, `../../packages/${pkgName}`);
@@ -179,29 +187,27 @@ async function main() {
187 spinner.succeed(`Successfully published ${pkgName} to npm`);
188
189 spinner.start('Pushing tags to npm');
182 - if (typeof argv.tags === 'string') {
183 - for (const tag of argv.tags.split(',')) {
184 - try {
185 - let opts = ['dist-tag', 'add', `${pkgName}@${newVersion}`, tag];
186 - if (otp != null) {
187 - opts.push(`--otp=${otp}`);
188 - }
189 - if (argv.debug === true) {
190 - spinner.info(`dry-run: npm ${opts.join(' ')}`);
191 - } else {
192 - await spawnHelper('npm', opts, {
193 - cwd: pkgDir,
194 - stdio: 'inherit',
195 - });
196 - }
197 - } catch (e) {
198 - spinner.fail(e.toString());
199 - throw e;
190 + if (typeof argv.tag === 'string') {
191 + try {
192 + let opts = ['dist-tag', 'add', `${pkgName}@${newVersion}`, argv.tag];
193 + if (otp != null) {
194 + opts.push(`--otp=${otp}`);
195 }
201 - spinner.succeed(
202 - `Successfully pushed dist-tag ${tag} for ${pkgName} to npm`
203 - );
196 + if (argv.debug === true) {
197 + spinner.info(`dry-run: npm ${opts.join(' ')}`);
198 + } else {
199 + await spawnHelper('npm', opts, {
200 + cwd: pkgDir,
201 + stdio: 'inherit',
202 + });
203 + }
204 + } catch (e) {
205 + spinner.fail(e.toString());
206 + throw e;
207 }
208 + spinner.succeed(
209 + `Successfully pushed dist-tag ${argv.tag} for ${pkgName} to npm`
210 + );
211 }
212 }
213