diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-24 09:34:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-24 09:34:40 +0800 |
commit | 04c07d9006ad1a66044e6d32009d23d552a5b099 (patch) | |
tree | 223eb7dff2b0be899870c4c11698d044db8d31ac /packages/monorepo-scripts/src/publish.ts | |
parent | d08bfbf7054d0d98680daab3d1fdc0ac878dcc16 (diff) | |
parent | a3cc5c1dd7e88aea50859560f7d751435cb577bd (diff) | |
download | dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.gz dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.bz2 dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.lz dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.xz dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.zst dexon-sol-tools-04c07d9006ad1a66044e6d32009d23d552a5b099.zip |
Merge pull request #541 from 0xProject/improveMonorepoScripts
Improve Monorepo-scripts
Diffstat (limited to 'packages/monorepo-scripts/src/publish.ts')
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index a2d641ff9..0ca3ea7a1 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -38,8 +38,14 @@ const packageNameToWebsitePath: { [name: string]: string } = { }; (async () => { + const hasRequiredSetup = await checkPublishRequiredSetupAsync(); + if (!hasRequiredSetup) { + return; // abort + } + // Fetch public, updated Lerna packages - const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + const shouldIncludePrivate = false; + const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); await confirmDocPagesRenderAsync(updatedPublicLernaPackages); @@ -107,6 +113,54 @@ package.ts. Please add an entry for it and try again.`, } } +async function checkPublishRequiredSetupAsync(): Promise<boolean> { + // check to see if logged into npm before publishing + try { + // HACK: for some reason on some setups, the `npm whoami` will not recognize a logged-in user + // unless run with `sudo` (i.e Fabio's NVM setup) but is fine for others (Jacob's N setup). + await execAsync(`sudo npm whoami`); + } catch (err) { + utils.log('You must be logged into npm in the commandline to publish. Run `npm login` and try again.'); + return false; + } + + // Check to see if Git personal token setup + if (_.isUndefined(constants.githubPersonalAccessToken)) { + utils.log( + 'You must have a Github personal access token set to an envVar named `GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS`. Add it then try again.', + ); + return false; + } + + // Check NPM version is 5.X + const result = await execAsync(`npm --version`); + const version = result.stdout; + const versionSegments = version.split('.'); + const majorVersion = _.parseInt(versionSegments[0]); + if (majorVersion < 5) { + utils.log('You npm version must be v5.x or higher. Upgrade your npm and try again.'); + return false; + } + + // Check that `aws` commandline tool is installed + try { + await execAsync(`aws help`); + } catch (err) { + utils.log('You must have `awscli` commandline tool installed. Install it and try again.'); + return false; + } + + // Check that `aws` credentials are setup + try { + await execAsync(`aws sts get-caller-identity`); + } catch (err) { + utils.log('You must setup your AWS credentials by running `aws configure`. Do this and try again.'); + return false; + } + + return true; +} + async function pushChangelogsToGithubAsync() { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); @@ -114,23 +168,12 @@ async function pushChangelogsToGithubAsync() { utils.log(`Pushed CHANGELOG updates to Github`); } -async function getUpdatedPublicLernaPackagesAsync(): Promise<LernaPackage[]> { - const updatedPublicPackages = await getPublicLernaUpdatedPackagesAsync(); - const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); - const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { - return _.includes(updatedPackageNames, pkg.package.name); - }); - return updatedPublicLernaPackages; -} - async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise<PackageToVersionChange> { const packageToVersionChange: PackageToVersionChange = {}; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); - const changelogJSON = getChangelogJSONOrCreateIfMissing(lernaPackage.package.name, changelogJSONPath); + const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath); let changelogs: Changelog[]; try { changelogs = JSON.parse(changelogJSON); @@ -225,13 +268,6 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin }); } -async function getPublicLernaUpdatedPackagesAsync(): Promise<UpdatedPackage[]> { - 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; -} - function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string) { if (proposedNextVersion === currentVersion) { return utils.getNextPatchVersion(currentVersion); @@ -243,19 +279,6 @@ function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion return proposedNextVersion; } -function getChangelogJSONOrCreateIfMissing(packageName: string, changelogPath: string): string { - let changelogJSON: string; - try { - changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); - return changelogJSON; - } catch (err) { - // If none exists, create new, empty one. - const emptyChangelogJSON = JSON.stringify([], null, 4); - fs.writeFileSync(changelogPath, emptyChangelogJSON); - return emptyChangelogJSON; - } -} - function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelog[]): boolean { if (_.isEmpty(changelogs)) { return true; |