From 96964328ca5c90f6e6163040af9db52d7201fe3f Mon Sep 17 00:00:00 2001 From: Matthew Pirocchi Date: Tue, 10 Jul 2018 17:03:50 -0700 Subject: [PATCH] Fix setup on Windows and update README for Windows. --- README.md | 18 ++++++++++++++++++ bundle-beta.sh | 3 +++ .../app/typescript/package.template.json | 2 +- .../app/typescript/scripts/prepare.js | 8 ++++++++ packages/aws-cdk/lib/init.ts | 7 +++++-- tools/y-npm/bin/.y-npm.cmd | 7 +++++++ tools/y-npm/lib/run-npm-command.ts | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 packages/aws-cdk/lib/init-templates/app/typescript/scripts/prepare.js create mode 100644 tools/y-npm/bin/.y-npm.cmd diff --git a/README.md b/README.md index 4225aa8818965..86c93a3ff04d5 100644 --- a/README.md +++ b/README.md @@ -39,19 +39,37 @@ aws s3 cp ~/aws-cdk.zip Once you've downloaded the bits, install them into `~/.cdk`: +#### Linux/MacOS (Shell) + ```shell rm -fr ~/.cdk mkdir ~/.cdk unzip -d ~/.cdk ``` +#### Windows (PowerShell) +```powershell +Remove-Item -Force -Recurse ~/.cdk +New-Item -Type Directory ~/.cdk +Expand-Archive -Path -DestinationPath ~/.cdk +``` + Make sure the `~/.cdk/bin` is in your `PATH` +#### Linux/MacOS (Shell) + ```shell # at the end of your ~/.bashrc or ~/.zshrc file export PATH=$PATH:$HOME/.cdk/bin ``` +#### Windows (PowerShell) + +```powershell +$profilePath = Join-Path ([Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)) "Profile.ps1" +Add-Content -Path $profilePath -Value '$env:Path = "$env:Path;$env:UserProfile\.cdk\bin"' +``` + Install (or update) `aws-cdk` and `aws-cdk-docs` globally ```shell diff --git a/bundle-beta.sh b/bundle-beta.sh index 1e94dc86ff3da..82d04733e9b8b 100755 --- a/bundle-beta.sh +++ b/bundle-beta.sh @@ -39,6 +39,9 @@ done echo "Installing y-npm" # using y-npm, we're so META! ${Y_NPM} install --global-style --no-save y-npm +# Because y-npm is installed on the build server, we need to bootstrap +# it on windows by manually creating the shim batch file. +cp ${root}/tools/y-npm/bin/.y-npm.cmd node_modules/.bin/y-npm.cmd ln -s node_modules/.bin bin # Create a local maven repository diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json b/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json index a5003cd4c5226..a07b274108394 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json +++ b/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json @@ -7,7 +7,7 @@ "%name%": "bin/%name%.js" }, "scripts": { - "prepare": "tsc && chmod a+x bin/%name%.js", + "prepare": "node scripts/prepare.js", "watch": "tsc -w", "cdk": "cdk" }, diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/scripts/prepare.js b/packages/aws-cdk/lib/init-templates/app/typescript/scripts/prepare.js new file mode 100644 index 0000000000000..a093b375fd0b6 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/typescript/scripts/prepare.js @@ -0,0 +1,8 @@ +const child_process = require('child_process') +const os = require('os') + +child_process.spawn('tsc') + +if (os.platform() !== 'win32') { + child_process.spawn('chmod', [ 'a+x', 'bin/%name%.js' ]) +} diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index b7ba863a02882..8c87b1ab05d05 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -201,7 +201,10 @@ async function postInstall(language: string) { } async function postInstallTypescript() { - const yNpm = path.join(CDK_HOME, 'bin', 'y-npm'); + + const yNpm = os.platform() === 'win32' ? + path.join(CDK_HOME, 'node_modules', '.bin', 'y-npm.cmd') : + path.join(CDK_HOME, 'bin', 'y-npm'); const command = await fs.pathExists(yNpm) ? yNpm : 'npm'; print(`Executing ${colors.green(`${command} install`)}...`); try { @@ -245,7 +248,7 @@ function isRoot(dir: string) { * @returns STDOUT (if successful). */ async function execute(cmd: string, ...args: string[]) { - const child = spawn(cmd, args, { stdio: [ 'ignore', 'pipe', 'inherit' ] }); + const child = spawn(cmd, args, { shell: true, stdio: [ 'ignore', 'pipe', 'inherit' ] }); let stdout = ''; child.stdout.on('data', chunk => stdout += chunk.toString()); return new Promise((ok, fail) => { diff --git a/tools/y-npm/bin/.y-npm.cmd b/tools/y-npm/bin/.y-npm.cmd new file mode 100644 index 0000000000000..324122c1bebdb --- /dev/null +++ b/tools/y-npm/bin/.y-npm.cmd @@ -0,0 +1,7 @@ +@IF EXIST "%~dp0\node.exe" ( + "%~dp0\node.exe" "%~dp0\..\y-npm\bin\y-npm" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.JS;=;% + node "%~dp0\..\y-npm\bin\y-npm" %* +) diff --git a/tools/y-npm/lib/run-npm-command.ts b/tools/y-npm/lib/run-npm-command.ts index 522f237e5ad41..ffa46f78a52e3 100644 --- a/tools/y-npm/lib/run-npm-command.ts +++ b/tools/y-npm/lib/run-npm-command.ts @@ -80,7 +80,7 @@ export function runCommand(command: string, args: string[], additionalEnv?: Node env[key] = value; } } - const child = spawn(command, args, { detached: false, env, stdio: ['inherit', 'pipe', 'pipe'] }); + const child = spawn(command, args, { detached: false, env, shell: true, stdio: ['inherit', 'pipe', 'pipe'] }); debug(`Command PID: ${child.pid}`); const stdout = new Array(); const stderr = new Array();