Yuki Takei 4 лет назад
Родитель
Сommit
26c7c33491

+ 4 - 0
bin/bump-versions/README.md

@@ -0,0 +1,4 @@
+bump-versions.js
+==============
+
+Custom cli for bumping package versions based on [algolia/shipjs@0.23.3](https://github.com/algolia/shipjs/tree/v0.23.3/packages/shipjs)

+ 16 - 0
bin/bump-versions/cli.js

@@ -0,0 +1,16 @@
+import { print, parseArgs } from 'shipjs/src/util';
+import bumpVersions from './flow/bump-versions';
+
+export async function cli(argv) {
+  const { fn, arg: argSpec } = bumpVersions;
+  try {
+    const opts = parseArgs(argSpec, argv);
+    await fn(opts);
+  } catch (error) {
+    if (error.code === 'ARG_UNKNOWN_OPTION') {
+      print(error);
+    } else {
+      throw error;
+    }
+  }
+}

+ 71 - 0
bin/bump-versions/flow/bump-versions.js

@@ -0,0 +1,71 @@
+import semver from 'semver';
+import { loadConfig, getCurrentVersion, getReleaseType } from 'shipjs-lib';
+
+import printDryRunBanner from 'shipjs/src/step/printDryRunBanner';
+import confirmNextVersion from 'shipjs/src/step/prepare/confirmNextVersion';
+import updateVersion from 'shipjs/src/step/prepare/updateVersion';
+import updateVersionMonorepo from 'shipjs/src/step/prepare/updateVersionMonorepo';
+import installDependencies from 'shipjs/src/step/prepare/installDependencies';
+
+import printHelp from '../step/printHelp';
+
+async function bumpVersions({
+  help = false,
+  dir = '.',
+  dryRun = false,
+  increment = 'patch',
+  preid = 'RC',
+}) {
+  if (help) {
+    printHelp();
+    return;
+  }
+  if (dryRun) {
+    printDryRunBanner();
+  }
+
+  const config = await loadConfig(dir, 'bump-versions.config');
+  
+  // get current version
+  const { monorepo } = config;
+  const currentVersion =
+    monorepo && monorepo.mainVersionFile
+      ? getCurrentVersion(dir, monorepo.mainVersionFile)
+      : getCurrentVersion(dir);
+  
+  // determine next version
+  let nextVersion = semver.inc(currentVersion, increment, preid); // set preid if type is 'prerelease'
+  nextVersion = await confirmNextVersion({
+    yes: true,
+    currentVersion,
+    nextVersion,
+    dryRun,
+  });
+  const releaseType = getReleaseType(nextVersion);
+
+  // update
+  const updateVersionFn = monorepo
+    ? updateVersionMonorepo
+    : updateVersion;
+  await updateVersionFn({ config, nextVersion, releaseType, dir, dryRun });
+  installDependencies({ config, dir, dryRun });
+}
+
+const arg = {
+  '--dir': String,
+  '--help': Boolean,
+  '--dry-run': Boolean,
+  '--increment': String,
+  '--preid': String,
+
+  // Aliases
+  '-d': '--dir',
+  '-h': '--help',
+  '-D': '--dry-run',
+  '-i': '--increment',
+};
+
+export default {
+  arg,
+  fn: bumpVersions,
+};

+ 12 - 0
bin/bump-versions/index.js

@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+
+require = require('esm')(module);
+(async function() {
+  try {
+    process.env.SHIPJS = true;
+    await require('./cli').cli(process.argv);
+  } catch (e) {
+    console.error(e);
+    process.exit(1);
+  }
+})();

+ 55 - 0
bin/bump-versions/step/printHelp.js

@@ -0,0 +1,55 @@
+import runStep from 'shipjs/src/step/runStep';
+import { print } from 'shipjs/src/util';
+import { bold, underline } from 'shipjs/src/color';
+
+export default () =>
+  runStep({}, () => {
+    const indent = (line) => `\t${line}`;
+
+    const help = `--help`;
+    const dir = `--dir ${underline('PATH')}`;
+    const increment = `--increment ${underline('LEVEL')}`;
+    const preId = `--preid ${underline('IDENTIFIER')}`;
+    const dryRun = `--dry-run`;
+    const all = [help, dir, increment, preId, dryRun]
+      .map((x) => `[${x}]`)
+      .join(' ');
+
+    const messages = [
+      bold('NAME'),
+      indent('bump-versions - Bump versions of packages.'),
+      '',
+      bold('USAGE'),
+      indent(`node ./bin/github-actions/bump-versions ${all}`),
+      '',
+      bold('OPTIONS'),
+      indent(`-h, ${help}`),
+      indent('  Print this help'),
+      '',
+      indent(`-d, ${dir}`),
+      indent(
+        `  Specify the ${underline(
+          'PATH'
+        )} of the repository (default: the current directory).`
+      ),
+      '',
+      indent(`-i, ${increment}`),
+      indent(
+        `  Specify the ${underline(
+          'LEVEL'
+        )} for semver.inc() to increment a version (default: 'patch').`
+      ),
+      '',
+      indent(`${preId}`),
+      indent(
+        `  Specify the ${underline(
+          'IDENTIFIER'
+        )} for semver.inc() with 'prerelease' type (default: 'RC').`
+      ),
+      '',
+      indent(`-D, ${dryRun}`),
+      indent('  Displays the steps without actually doing them.'),
+      '',
+    ];
+    print(messages.join('\n'));
+  });

+ 7 - 1
bump-versions.config.js

@@ -1,6 +1,12 @@
 module.exports = {
   monorepo: {
     mainVersionFile: 'package.json',
-    packagesToBump: ['packages/app', 'packages/common'],
+    packagesToBump: [
+      'packages/app',
+      'packages/core',
+      'packages/slack',
+      'packages/ui',
+      'packages/plugin-*',
+    ],
   },
 };