From 9c856de49ce0871b2093df90ab46410e91381424 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 30 Mar 2018 14:45:39 +0200 Subject: Move monorepo root constant to constants file --- packages/monorepo-scripts/src/constants.ts | 5 +++++ packages/monorepo-scripts/src/publish.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 packages/monorepo-scripts/src/constants.ts (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts new file mode 100644 index 000000000..74387a159 --- /dev/null +++ b/packages/monorepo-scripts/src/constants.ts @@ -0,0 +1,5 @@ +import * as path from 'path'; + +export const constants = { + monorepoRootPath: path.join(__dirname, '../../..'), +}; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 4265ee9e2..3de382c50 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -9,11 +9,11 @@ import { exec as execAsync, spawn } from 'promisify-child-process'; import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); +import { constants } from './constants'; import { Changelog, Changes, SemVerIndex, UpdatedPackage } from './types'; import { utils } from './utils'; const IS_DRY_RUN = true; -const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..'); const TODAYS_TIMESTAMP = moment().unix(); const LERNA_EXECUTABLE = './node_modules/lerna/bin/lerna.js'; const semverNameToIndex: { [semver: string]: number } = { @@ -26,7 +26,7 @@ const semverNameToIndex: { [semver: string]: number } = { const updatedPublicPackages = await getPublicLernaUpdatedPackagesAsync(); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - const allLernaPackages = lernaGetPackages(MONOREPO_ROOT_PATH); + const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); const relevantLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); @@ -87,9 +87,9 @@ const semverNameToIndex: { [semver: string]: number } = { }); if (!IS_DRY_RUN) { - await execAsync(`git add . --all`, { cwd: MONOREPO_ROOT_PATH }); - await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: MONOREPO_ROOT_PATH }); - await execAsync(`git push`, { cwd: MONOREPO_ROOT_PATH }); + await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); + await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); + await execAsync(`git push`, { cwd: constants.monorepoRootPath }); utils.log(`Pushed CHANGELOG updates to Github`); } @@ -102,7 +102,7 @@ const semverNameToIndex: { [semver: string]: number } = { async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }) { // HACK: Lerna publish does not provide a way to specify multiple package versions as // flags so instead we need to interact with their interactive prompt interface. - const child = spawn('lerna', ['publish'], { cwd: MONOREPO_ROOT_PATH }); + const child = spawn('lerna', ['publish'], { cwd: constants.monorepoRootPath }); child.stdout.on('data', (data: Buffer) => { const output = data.toString('utf8'); const isVersionPrompt = _.includes(output, 'Select a new version'); @@ -124,7 +124,7 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin } async function getPublicLernaUpdatedPackagesAsync(): Promise { - const result = await execAsync(`${LERNA_EXECUTABLE} updated --json`, { cwd: MONOREPO_ROOT_PATH }); + const result = await execAsync(`${LERNA_EXECUTABLE} updated --json`, { cwd: constants.monorepoRootPath }); const updatedPackages = JSON.parse(result.stdout); const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); return updatedPublicPackages; -- cgit v1.2.3