Skip to content

Commit

Permalink
Introducing y-npm (aka: Why NPM?)
Browse files Browse the repository at this point in the history
A drop-in replacement for the `npm` command that uses a local repository
as a source for packages, and falls back to the standard `npm` registry
for packages that are not locally available.

This can be used to make private packages available to consumers without
the need to set up a full blown repository and managing user
authentication and authorization; and also to overlay customized
versions of third party packages in a simple way.

The `y-npm` command has an additional sub-command `y-npm my-packages`
that will output the name and version of all packages that are locally
available.

This commit also changes `cdk-beta-npm` to be a simple wrapper around
`y-npm` that sets the correct environment variables to configure the
location of the local repository to `~/.cdk/repo/npm` or
`$CDK_HOME/repo/npm` if `$CDK_HOME` is set. Also, the release `.zip`
file no longer includes a full installation of the `cdk`, instead only
makes `cdk-beta-npm` available, so people can use `cdk-beta-npm` instead
of `npm` and work as they normally would besides that.
  • Loading branch information
RomainMuller committed Jun 21, 2018
1 parent b101d1c commit 05f6167
Show file tree
Hide file tree
Showing 42 changed files with 2,913 additions and 2,607 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Make sure the ~/.cdk/bin is in your `PATH`
export PATH=$PATH:$HOME/.cdk/bin
```

Install (or update) the CDK toolkit globally:

```shell
cdk-beta-npm install -g aws-cdk
```

To check which CDK version you have installed:

```shell
Expand Down
44 changes: 31 additions & 13 deletions bundle-beta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ set -euo pipefail
root=$PWD

staging="$(mktemp -d)"
cleanup() {
# Clean-up after yourself
echo "Cleaning up staging directory: ${staging}"
cd ${root}
rm -rf ${staging}
}
trap cleanup EXIT
cd ${staging}

echo "Staging: ${staging}"
Expand All @@ -21,28 +28,39 @@ echo "Staging: ${staging}"
# + node_modules
#

# Create a local npm repository
# Creating a `y-npm` registry
echo "Preparing local NPM registry"
mkdir -p repo/npm
${root}/tools/pkgtools/bin/publish-to-verdaccio \
repo/npm \
${root}/pack \
${root}/.local-npm
export Y_NPM_REPOSITORY="${staging}/repo/npm"
Y_NPM="${root}/tools/y-npm/bin/y-npm"
for tarball in $(find ${root}/.local-npm -iname '*.tgz') $(find ${root}/pack -iname '*.tgz'); do
${Y_NPM} publish ${tarball}
done

echo "Installing y-npm" # using my-npm!
${Y_NPM} install --global-style --no-save y-npm

# Symlink 'bin' to the root
echo "Installing cdk-beta-npm"
mkdir -p bin
cat > bin/cdk-beta-npm <<-'HERE'
#!/usr/bin/env node
const path = require('path');
const os = require('os');
const cdkHome = process.env.CDK_HOME ? process.env.CDK_HOME : path.join(os.homedir(), '.cdk');
process.env.Y_NPM_REPOSITORY = path.join(cdkHome, 'repo', 'npm');
require('../node_modules/.bin/y-npm');
HERE
chmod +x bin/cdk-beta-npm

# Create a local maven repository
echo "Preparing local MVN registry"
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/

# Bootstrap a production-ready node_modules closure with all npm modules (jsii and CDK)
echo "Bootstrapping a production-ready npm closure"
npm install --global-style --production --no-save $(find repo/npm -iname '*.tgz')

# Symlink 'bin' to the root
echo "Symlinking bin"
ln -s node_modules/.bin bin

# Symlink the docs website to docs
echo "Symlinking docs"
ln -s node_modules/aws-cdk-docs/dist/docs docs
Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/acm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions packages/@aws-cdk/applet-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/assert/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/cloudformation-diff/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/@aws-cdk/cloudfront/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/@aws-cdk/cloudtrail/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/@aws-cdk/codebuild/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/@aws-cdk/codecommit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 05f6167

Please sign in to comment.