publish.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import { cliArguments, workingDirectory } from '../utils.mjs';
  4. const [level, tag = 'latest'] = cliArguments();
  5. if (!level) {
  6. throw new Error('A version level — e.g. "path" — must be provided.');
  7. }
  8. // Go to the client directory and install the dependencies.
  9. cd(path.join(workingDirectory, 'clients', 'js'));
  10. await $`pnpm install`;
  11. // Update the version.
  12. const versionArgs = [
  13. '--no-git-tag-version',
  14. ...(level.startsWith('pre') ? [`--preid ${tag}`] : []),
  15. ];
  16. let { stdout } = await $`pnpm version ${level} ${versionArgs}`;
  17. const newVersion = stdout.slice(1).trim();
  18. // Expose the new version to CI if needed.
  19. if (process.env.CI) {
  20. await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
  21. }
  22. // Publish the package.
  23. // This will also build the package before publishing (see prepublishOnly script).
  24. await $`pnpm publish --no-git-checks --tag ${tag}`;
  25. // Commit the new version.
  26. await $`git commit -am "Publish JS client v${newVersion}"`;
  27. // Tag the new version.
  28. await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`;