From 97797a3170000965379db632da4fe2df24cc6511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Mon, 12 Aug 2019 11:08:48 -0700 Subject: [PATCH] chore: clean up repository root, shrinkwrap CLIs Move all files that don't need to be at the repository root under the dedicated sub-directory for those. This means all `.sh` files were moved under `scripts`. Some of those were also renamed, and the common uses have been aliased using `package.json` scripts (`npm run bootstrap`, `npm run build`, `npm run package`, ...). Additionally, ran `npm shrinkwrap` on the major CLIs (`jsii`, `jsii-diff`, `jsii-pacmak`) as a way to improve overall reliability. --- .gitignore | 1 - .travis.yml | 2 +- CONTRIBUTING.md | 19 +++++----- buildspec.yaml | 8 ++--- package-lock.json | 1 + package.json | 36 +++++++++++-------- ...{package-lock.json => npm-shrinkwrap.json} | 0 ...{package-lock.json => npm-shrinkwrap.json} | 0 ...{package-lock.json => npm-shrinkwrap.json} | 0 install.sh => scripts/bootstrap.sh | 2 +- build.sh => scripts/build.sh | 11 ++---- bump.sh => scripts/bump.sh | 0 .../fetch-dotnet-snk.sh | 0 ...ocal-deps.js => install-local-packages.js} | 25 ++++++++++--- link-all.sh => scripts/link-all.sh | 0 pack.sh => scripts/package.sh | 0 16 files changed, 63 insertions(+), 42 deletions(-) rename packages/jsii-diff/{package-lock.json => npm-shrinkwrap.json} (100%) rename packages/jsii-pacmak/{package-lock.json => npm-shrinkwrap.json} (100%) rename packages/jsii/{package-lock.json => npm-shrinkwrap.json} (100%) rename install.sh => scripts/bootstrap.sh (95%) rename build.sh => scripts/build.sh (65%) rename bump.sh => scripts/bump.sh (100%) rename fetch-dotnet-snk.sh => scripts/fetch-dotnet-snk.sh (100%) rename scripts/{install-local-deps.js => install-local-packages.js} (81%) rename link-all.sh => scripts/link-all.sh (100%) rename pack.sh => scripts/package.sh (100%) diff --git a/.gitignore b/.gitignore index 205aaaa545..2a7f2eda56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules/ -.BUILD_COMPLETED lerna-debug.log tsconfig.tsbuildinfo .DS_Store diff --git a/.travis.yml b/.travis.yml index b66f16bcf6..650039b285 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ script: # Building the Docker image - docker build --pull --build-arg BUILD_TIMESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ') --build-arg COMMIT_ID="${TRAVIS_COMMIT}" -t "jsii/superchain:nightly" ./superchain # Building jsii itself within the Docker image - - docker run --rm -it --net=host -v ${PWD}:${PWD} -w ${PWD} jsii/superchain:nightly ./build.sh + - docker run --rm -it --net=host -v ${PWD}:${PWD} -w ${PWD} jsii/superchain:nightly npm run build # Make sure the build did not change the source tree - git update-index --refresh - git diff-index --exit-code --stat HEAD diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f67206009e..b1a069cc0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ $ cd jsii # go to the root of the jsii repo $ docker run --rm --net=host -it -v $PWD:$PWD -w $PWD ${IMAGE} ``` -You can then run `./build.sh` as described below. +You can then run `npm run build` as described below. ## Getting Started ### Bootstrapping @@ -59,7 +59,7 @@ The project is managed as a [monorepo] using [lerna]. [lerna]: https://github.com/lerna/lerna 1. Check out this repository. -2. Run `./build.sh` to install lerna, bootstrap the repository and perform an +2. Run `npm run build` to install lerna, bootstrap the repository and perform an initial build and test cycle. ### Development Workflow @@ -78,20 +78,23 @@ Each one of these scripts can be executed either from the root of the repo using ### Bump -To bump the version of this repository, use the [`./bump.sh`](./bump.sh) script. +To bump the version of this repository, use the [`npm run bump`] script. + +[`npm run bump`]: ./scripts/bump.sh ### Packaging and Bundling -This repository emits artifacts in multiple languages. The -[`pack.sh`](./pack.sh) and [`bundle.sh`](./bundle.sh) scripts are used to -prepare the repository for publishing. +This repository emits artifacts in multiple languages. The [`npm run package`] +script is used to prepare the repository for publishing. + +[`npm run package`]: ./scripts/package.sh Each module that needs to be published implements an npm script called `package` which emits publishable artifacts to `dist/` (e.g. `dist/dotnet` for NuGet, `dist/js` for npm, `dist/java` for Maven Central). All those "dist" directories are merged into a single .zip file that is later on used in our -CI/CD publishing tasks. Each `lang` directory is published to the respective -repository. +CI/CD publishing tasks. Each `` directory is published to the respective +package repository. ## Implementing Language Bindings diff --git a/buildspec.yaml b/buildspec.yaml index b23384f617..e4f1b0093c 100644 --- a/buildspec.yaml +++ b/buildspec.yaml @@ -3,16 +3,16 @@ version: 0.2 phases: install: commands: - - /bin/bash ./install.sh + - npm run bootstrap pre_build: commands: - - /bin/bash ./fetch-dotnet-snk.sh + - npm run fetch-dotnet-snk build: commands: - - /bin/bash ./build.sh + - npm run build post_build: commands: - - "[ -f .BUILD_COMPLETED ] && /bin/bash ./pack.sh" + - '[ ${CODEBUILD_BUILD_SUCCEEDING} = 1 ] && npm run package' artifacts: files: - "**/*" diff --git a/package-lock.json b/package-lock.json index 3e3686e9df..607e183a28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,4 +1,5 @@ { + "name": "jsii-all", "requires": true, "lockfileVersion": 1, "dependencies": { diff --git a/package.json b/package.json index fe7719e35c..686c357350 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,24 @@ { - "private": true, - "license": "Apache-2.0", - "devDependencies": { - "@types/node": "^8.10.51", - "lerna": "^3.16.4", - "nodeunit": "^0.11.3", - "nyc": "^14.1.1", - "tslint": "^5.18.0", - "typescript": "^3.5.3" - }, - "repository": { - "type": "git", - "url": "https://github.com/aws/jsii.git" - } + "private": true, + "license": "Apache-2.0", + "scripts": { + "bootstrap": "bash scripts/bootstrap.sh", + "build": "bash scripts/build.sh", + "bump": "bash scripts/bump.sh", + "fetch-dotnet-snk": "bash scripts/fetch-dotnet-snk.sh", + "install-local-packages": "node scripts/install-local-packages.js", + "package": "bash scripts/package.sh" + }, + "devDependencies": { + "@types/node": "^8.10.51", + "lerna": "^3.16.4", + "nodeunit": "^0.11.3", + "nyc": "^14.1.1", + "tslint": "^5.18.0", + "typescript": "^3.5.3" + }, + "repository": { + "type": "git", + "url": "https://github.com/aws/jsii.git" + } } diff --git a/packages/jsii-diff/package-lock.json b/packages/jsii-diff/npm-shrinkwrap.json similarity index 100% rename from packages/jsii-diff/package-lock.json rename to packages/jsii-diff/npm-shrinkwrap.json diff --git a/packages/jsii-pacmak/package-lock.json b/packages/jsii-pacmak/npm-shrinkwrap.json similarity index 100% rename from packages/jsii-pacmak/package-lock.json rename to packages/jsii-pacmak/npm-shrinkwrap.json diff --git a/packages/jsii/package-lock.json b/packages/jsii/npm-shrinkwrap.json similarity index 100% rename from packages/jsii/package-lock.json rename to packages/jsii/npm-shrinkwrap.json diff --git a/install.sh b/scripts/bootstrap.sh similarity index 95% rename from install.sh rename to scripts/bootstrap.sh index aa88ba62a4..06a633d588 100755 --- a/install.sh +++ b/scripts/bootstrap.sh @@ -22,4 +22,4 @@ lerna bootstrap --reject-cycles --ci echo "=============================================================================================" echo "installing local links..." -node scripts/install-local-deps.js +npm run install-local-packages diff --git a/build.sh b/scripts/build.sh similarity index 65% rename from build.sh rename to scripts/build.sh index c0b6cfb828..f685d9fa2d 100755 --- a/build.sh +++ b/scripts/build.sh @@ -1,14 +1,11 @@ #!/bin/bash set -euo pipefail -if [ ! -d node_modules ]; then - /bin/bash ./install.sh +if [ ! -d ./node_modules ]; then + npm run bootstrap fi -BUILD_INDICATOR=".BUILD_COMPLETED" -rm -rf $BUILD_INDICATOR - -export PATH=node_modules/.bin:$PATH +export PATH=./node_modules/.bin:$PATH echo "=============================================================================================" echo "building..." @@ -17,5 +14,3 @@ lerna run build --stream --sort echo "=============================================================================================" echo "testing..." lerna run test --stream - -touch $BUILD_INDICATOR diff --git a/bump.sh b/scripts/bump.sh similarity index 100% rename from bump.sh rename to scripts/bump.sh diff --git a/fetch-dotnet-snk.sh b/scripts/fetch-dotnet-snk.sh similarity index 100% rename from fetch-dotnet-snk.sh rename to scripts/fetch-dotnet-snk.sh diff --git a/scripts/install-local-deps.js b/scripts/install-local-packages.js similarity index 81% rename from scripts/install-local-deps.js rename to scripts/install-local-packages.js index 2e7058572e..48d5aa137e 100644 --- a/scripts/install-local-deps.js +++ b/scripts/install-local-packages.js @@ -2,8 +2,8 @@ * Installs repo-local dependencies manually, as lerna ignores those... */ const { exec, execSync } = require('child_process'); -const { removeSync, mkdirpSync, pathExistsSync, symlinkSync, writeJsonSync } = require('fs-extra'); -const { dirname, join, relative, resolve } = require('path'); +const { removeSync, mkdirpSync, pathExistsSync, readFileSync, symlinkSync, writeJsonSync } = require('fs-extra'); +const { basename, dirname, join, resolve } = require('path'); exec('lerna ls --json --all', { shell: true }, (error, stdout) => { if (error) { @@ -25,7 +25,9 @@ exec('lerna ls --json --all', { shell: true }, (error, stdout) => { function installDeps(location, ...depLists) { const nodeModules = join(location, 'node_modules'); - const lockFile = join(location, 'package-lock.json'); + + const shrinkWrap = join(location, 'npm-shrinkwrap.json'); + const lockFile = pathExistsSync(shrinkWrap) ? shrinkWrap : join(location, 'package-lock.json'); const locks = pathExistsSync(lockFile) && require(lockFile); @@ -48,11 +50,11 @@ function installDeps(location, ...depLists) { }); } if (process.env.VERBOSE) { - console.log(`Fixing up package-lock.json in ${location}`); + console.log(`Fixing up ${basename(lockFile)} in ${location}`); } if (locks) { sortKeys(locks.dependencies); - writeJsonSync(lockFile, locks, { spaces: '\t' }); + writeJsonSync(lockFile, locks, { spaces: findIndent(lockFile) }); } else { // This is dog slow, hence we're playing funky games elsewhere... but we're not in the business of bootstrapping // a lock-file from scratch, so if there was none, let npm do it's thing instead of trying to replicate. @@ -61,6 +63,19 @@ function installDeps(location, ...depLists) { } +function findIndent(path) { + if (pathExistsSync(path)) { + const lines = readFileSync(path, { encoding: 'utf-8' }).split('\n'); + for (const line of lines) { + const match = line.match(/^(\s+)/) + if (match) { + return match[1]; + } + } + } + return 2; +} + /** * Installs a symlink to a local package, and symlinks any "bin" items into the node_modules/.bin directory * @param {string} nodeModules the root of the "installing" node_modules directory diff --git a/link-all.sh b/scripts/link-all.sh similarity index 100% rename from link-all.sh rename to scripts/link-all.sh diff --git a/pack.sh b/scripts/package.sh similarity index 100% rename from pack.sh rename to scripts/package.sh