diff --git a/README.md b/README.md index f2036617a573d..647c3e7a9a5ec 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,10 @@ Set-ExecutionPolicy Unrestricted ### Install the command-line toolkit and docs -Install (or update) `aws-cdk` and `aws-cdk-docs` globally +Install (or update) `aws-cdk` globally ```shell -y-npm install --global aws-cdk aws-cdk-docs # sudo might be needed +y-npm install --global aws-cdk # sudo might be needed ``` > `y-npm` is an npm wrapper which allows installing npm modules from a local repository located at `~/.cdk/y/npm`. `y-npm` will fall back to the public npm repository if a module cannot be found locally. diff --git a/bundle-beta.sh b/bundle-beta.sh index 391a1d2f37703..99ca8c4ae9929 100755 --- a/bundle-beta.sh +++ b/bundle-beta.sh @@ -26,7 +26,8 @@ echo "Staging: ${staging}" # │ └ maven # ├─ y # │ └─ npm -# └─ node_modules +# ├─ node_modules +# └─ .version # Creating a `y-npm` registry echo "Preparing local NPM registry" @@ -50,13 +51,14 @@ mkdir -p repo/maven rsync -av ${root}/packages/aws-cdk-java/maven-repo/ repo/maven/ rsync -av ${root}/node_modules/jsii-java-runtime/maven-repo/ repo/maven/ -# Symlink the docs website to docs -echo "Symlinking docs" -ln -s node_modules/aws-cdk-docs/dist/docs docs +# Copy the docs website to docs +echo "Copying docs" +cp -r ${root}/packages/aws-cdk-docs/dist/docs docs # Create an archive under ./dist echo "Creating ZIP bundle" version="$(cat ${root}/lerna.json | grep version | cut -d '"' -f4)" +echo ${version} > .version dist=${root}/dist output=${dist}/aws-cdk-${version}.zip rm -fr ${dist} diff --git a/packages/aws-cdk-docs/package.json b/packages/aws-cdk-docs/package.json index f13cd632f1de7..300a5b38d0ff2 100644 --- a/packages/aws-cdk-docs/package.json +++ b/packages/aws-cdk-docs/package.json @@ -1,6 +1,7 @@ { "name": "aws-cdk-docs", "version": "0.7.4-beta", + "private": true, "description": "AWS CDK Documentation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/aws-cdk/lib/commands/docs.ts b/packages/aws-cdk/lib/commands/docs.ts index aafef6025f581..e6fdb8f282ee9 100644 --- a/packages/aws-cdk/lib/commands/docs.ts +++ b/packages/aws-cdk/lib/commands/docs.ts @@ -2,7 +2,7 @@ import childProcess = require('child_process'); import colors = require('colors/safe'); import process = require('process'); import yargs = require('yargs'); -import { debug, error, warning } from '../../lib/logging'; +import { debug, print, warning } from '../../lib/logging'; export const command = 'docs'; export const describe = 'Opens the documentation in a browser'; @@ -20,22 +20,18 @@ export interface Arguments extends yargs.Arguments { browser: string } -export async function handler(argv: Arguments): Promise { - let documentationIndexPath: string; - try { - // tslint:disable-next-line:no-var-require Taking an un-declared dep on aws-cdk-docs, to avoid a dependency circle - const docs = require('aws-cdk-docs'); - documentationIndexPath = docs.documentationIndexPath; - } catch (err) { - error('Unable to open CDK documentation - the aws-cdk-docs package appears to be missing. Please run `npm install -g aws-cdk-docs`'); - return -1; - } - - const browserCommand = argv.browser.replace(/%u/g, documentationIndexPath); +export function handler(argv: Arguments): Promise { + const docVersion = require('../../package.json').version; + const url = `https://awslabs.github.io/aws-cdk/versions/${docVersion}/`; + print(colors.green(url)); + const browserCommand = argv.browser.replace(/%u/g, url); debug(`Opening documentation ${colors.green(browserCommand)}`); - return await new Promise((resolve, reject) => { + return new Promise((resolve, _reject) => { childProcess.exec(browserCommand, (err, stdout, stderr) => { - if (err) { return reject(err); } + if (err) { + debug(`An error occurred when trying to open a browser: ${err.stack || err.message}`); + return resolve(0); + } if (stdout) { debug(stdout); } if (stderr) { warning(stderr); } resolve(0); diff --git a/packages/aws-cdk/lib/commands/doctor.ts b/packages/aws-cdk/lib/commands/doctor.ts index 6b9c68b4d2146..4ca07ebf8fb7e 100644 --- a/packages/aws-cdk/lib/commands/doctor.ts +++ b/packages/aws-cdk/lib/commands/doctor.ts @@ -19,8 +19,7 @@ export async function handler(): Promise { const verifications: Array<() => boolean | Promise> = [ displayVersionInformation, - displayAwsEnvironmentVariables, - checkDocumentationIsAvailable + displayAwsEnvironmentVariables ]; // ### Verifications ### @@ -42,14 +41,3 @@ function displayAwsEnvironmentVariables() { } return true; } - -function checkDocumentationIsAvailable() { - try { - const version = require('aws-cdk-docs/package.json').version; - print(`✅ AWS CDK Documentation: ${version}`); - return true; - } catch (e) { - print(`❌ AWS CDK Documentation: install using ${colors.green('y-npm install --global aws-cdk-docs')}`); - return false; - } -} diff --git a/packages/aws-cdk/test/test.cdk-docs.ts b/packages/aws-cdk/test/test.cdk-docs.ts index 08abbd7fb171e..193795c601b09 100644 --- a/packages/aws-cdk/test/test.cdk-docs.ts +++ b/packages/aws-cdk/test/test.cdk-docs.ts @@ -9,6 +9,7 @@ module.exports = testCase({ mockery.registerMock('../../lib/logging', { debug() { return; }, error() { return; }, + print() { return; }, warning() { return; } }); mockery.enable({ useCleanCache: true, warnOnReplace: true, warnOnUnregistered: false }); @@ -20,7 +21,6 @@ module.exports = testCase({ cb(); }, async 'exits with 0 when everything is OK'(test: Test) { - mockery.registerMock('aws-cdk-docs', { documentationIndexPath: 'index.html' }); try { const result = await require('../lib/commands/docs').handler(argv); test.equal(result, 0, 'exit status was 0'); @@ -30,10 +30,15 @@ module.exports = testCase({ test.done(); } }, - async 'exits with non-0 when documentation is missing'(test: Test) { + async 'exits with 0 when opening the browser fails'(test: Test) { + mockery.registerMock('child_process', { + exec(_: string, cb: (err: Error, stdout?: string, stderr?: string) => void) { + cb(new Error('TEST')); + } + }); try { const result = await require('../lib/commands/docs').handler(argv); - test.notEqual(result, 0, 'exit status was non-0'); + test.equal(result, 0, 'exit status was 0'); } catch (e) { test.doesNotThrow(() => { throw e; }); } finally { diff --git a/packages/aws-cdk/test/test.cdk-doctor.ts b/packages/aws-cdk/test/test.cdk-doctor.ts index 5399243e35c70..062044186bc16 100644 --- a/packages/aws-cdk/test/test.cdk-doctor.ts +++ b/packages/aws-cdk/test/test.cdk-doctor.ts @@ -16,8 +16,6 @@ module.exports = testCase({ cb(); }, async 'exits with 0 when everything is OK'(test: Test) { - mockery.registerMock('aws-cdk-docs/package.json', { version: 'x.y.z' }); - try { const result = await require('../lib/commands/doctor').handler(); test.equal(result, 0, 'exit status was 0'); @@ -26,16 +24,6 @@ module.exports = testCase({ } finally { test.done(); } - }, - async 'exits with non-0 when documentation is missing'(test: Test) { - try { - const result = await require('../lib/commands/doctor').handler(); - test.notEqual(result, 0, 'exit status was non-0'); - } catch (e) { - test.doesNotThrow(() => e); - } finally { - test.done(); - } } } }); diff --git a/publish.sh b/publish.sh new file mode 100755 index 0000000000000..f0ca30df446c8 --- /dev/null +++ b/publish.sh @@ -0,0 +1,95 @@ +#!/bin/bash +set -euo pipefail + +### +# Usage: ./publish.sh +# +# Publishes the content of a release bundle ZIP file to the standard package +# repositories for the various supported languages: +# * Javascript & TypeScript: NPM +# * Documentation: GitHub Pages +# * (More to come later) +### + +if [ $# -ne 1 ]; then + echo "Missing release zip file argument" + echo "Usage: ./publish.sh " + exit 1 +fi + +RELEASE_BUNDLE=$1 +if [ ! -f ${RELEASE_BUNDLE} ]; then + echo "${RELEASE_BUNDLE} is not a file!" + exit 127 +fi + +############### +# PREPARATION # +############### + +declare -a CLEANUP=() +function cleanup() { + for ((i = 0; i < ${#CLEANUP[@]}; i++ )) + do + eval "${CLEANUP[$i]}" + done + echo '🍻 Done!' +} +trap cleanup 'EXIT' + + +WORK_DIR=$(mktemp -d) +CLEANUP+=("echo '🚮 Cleaning up working directory'" "rm -fr ${WORK_DIR}") +echo "💼 Working directory: ${WORK_DIR}" + +echo "🗜 Unzipping release bundle (be patient - this may take a while)" +unzip -q ${RELEASE_BUNDLE} -d ${WORK_DIR} + +PKG_VERSION=$(cat ${WORK_DIR}/.version) + +####### +# NPM # +####### + +echo "📦 Publishing to NPM" +REGISTRY='https://registry.npmjs.org/' +OLD_REGISTRY=$(npm config get registry) +if [ ${OLD_REGISTRY} != ${REGISTRY} ]; then + echo "👉 Switching to NPM registry ${REGISTRY}" + npm config set registry ${REGISTRY} + CLEANUP+=("echo '👈 Resetting NPM registry to ${OLD_REGISTRY}'" "npm config set registry ${OLD_REGISTRY}") +fi + +TOKENS=$(npm token list 2>&1 || echo '') +if echo ${TOKENS} | grep 'EAUTHUNKNOWN' > /dev/null; then + echo "🔑 Can't list tokens - apparently missing authentication info" + npm login +fi + +for TGZ in $(find ${WORK_DIR}/y/npm -iname '*.tgz'); do + npm publish $TGZ --access=public +done + +################ +# GitHub Pages # +################ + +echo "📖 Publishing to GitHub Pages" + +GIT_REPO=$(mktemp -d) +CLEANUP+=("echo '🚮 Cleaning up GitHub Pages working copy'" "rm -fr ${GIT_REPO}") + +git clone -b gh-pages --depth=1 ssh://github.com/awslabs/aws-cdk ${GIT_REPO} +mkdir -p ${GIT_REPO}/versions + +rsync -ar --delete --exclude=/.git --exclude=/versions ${WORK_DIR}/docs/ ${GIT_REPO}/ +rsync -ar --delete ${WORK_DIR}/docs/ ${GIT_REPO}/versions/${PKG_VERSION}/ + +( + cd ${GIT_REPO} + git add . + git commit -m "Release ${PKG_VERSION}" + git push +) + +echo "✅ All OK!"