aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/remove_tags.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
commit9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a (patch)
treef72aae5170b6f1f6d3d70ebf6c03ed171680ff50 /packages/monorepo-scripts/src/remove_tags.ts
parent9744b1906a111aa0c65c8fafb4db66aef32a5a23 (diff)
parent6aed4fb1ae27dabed027c855f2cbdc0bfb4f3b6b (diff)
downloaddexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.gz
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.bz2
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.lz
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.xz
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.zst
dexon-sol-tools-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.zip
Merge branch 'development' into v2-prototype
Diffstat (limited to 'packages/monorepo-scripts/src/remove_tags.ts')
-rw-r--r--packages/monorepo-scripts/src/remove_tags.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/remove_tags.ts b/packages/monorepo-scripts/src/remove_tags.ts
new file mode 100644
index 000000000..6d09729c7
--- /dev/null
+++ b/packages/monorepo-scripts/src/remove_tags.ts
@@ -0,0 +1,58 @@
+#!/usr/bin/env node
+
+import lernaGetPackages = require('lerna-get-packages');
+import * as _ from 'lodash';
+import * as path from 'path';
+import { exec as execAsync } from 'promisify-child-process';
+import semverSort = require('semver-sort');
+
+import { constants } from './constants';
+import { Changelog } from './types';
+import { utils } from './utils';
+
+(async () => {
+ const shouldIncludePrivate = true;
+ const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate);
+
+ for (const lernaPackage of updatedPublicLernaPackages) {
+ const packageName = lernaPackage.package.name;
+ const currentVersion = lernaPackage.package.version;
+ const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json');
+ // Private packages don't have changelogs, and their versions are always incremented
+ // by a patch version.
+ const changelogJSONIfExists = utils.getChangelogJSONIfExists(changelogJSONPath);
+
+ let latestChangelogVersion: string;
+ if (!_.isUndefined(changelogJSONIfExists)) {
+ let changelogs: Changelog[];
+ try {
+ changelogs = JSON.parse(changelogJSONIfExists);
+ } catch (err) {
+ throw new Error(
+ `${lernaPackage.package.name}'s CHANGELOG.json contains invalid JSON. Please fix and try again.`,
+ );
+ }
+ latestChangelogVersion = changelogs[0].version;
+ } else {
+ latestChangelogVersion = utils.getNextPatchVersion(currentVersion);
+ }
+
+ const sortedVersions = semverSort.desc([latestChangelogVersion, currentVersion]);
+ if (sortedVersions[0] === latestChangelogVersion && latestChangelogVersion !== currentVersion) {
+ const tagName = `${packageName}@${latestChangelogVersion}`;
+ try {
+ await execAsync(`git tag -d ${tagName}`, { cwd: constants.monorepoRootPath });
+ utils.log(`removed tag: ${tagName}`);
+ } catch (err) {
+ if (_.includes(err.message, 'not found')) {
+ utils.log(`Could not find tag: ${tagName}`);
+ } else {
+ throw err;
+ }
+ }
+ }
+ }
+})().catch(err => {
+ utils.log(err);
+ process.exit(1);
+});