diff --git a/.nycrc b/.nycrc new file mode 100644 index 000000000000..3767eacced7d --- /dev/null +++ b/.nycrc @@ -0,0 +1,17 @@ +{ + "include": [ + "packages/example-codehub/src/**", + "packages/*/dist*/*" + ], + "exclude": [ + "packages/core/*/promisify.*" + ], + "extension": [ + ".js", + ".ts" + ], + "reporter": [ + "html" + ] + } + diff --git a/.prettierignore b/.prettierignore index 8232af516c3d..45fdb653e2a8 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ packages/*/dist packages/*/dist6 packages/*/api-docs +package.json +packages/*/package.json diff --git a/bin/compile-package.js b/bin/compile-package.js deleted file mode 100644 index 7da479270faf..000000000000 --- a/bin/compile-package.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright IBM Corp. 2013,2017. All Rights Reserved. -// Node module: loopback-next -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT - -/* -======== - -Usage: - node ../../bin/compile-package - -Where is either es2017 or es2015. - -Under the hood, we change the current directory to loopback-next root -and call tsc with project configuration from the original package's -tsconfig.build.json. This way tsc error messages contain a path -that's relative to loopback-next project root. - -TODO(bajtos) Detect whether "npm run build" was triggered by lerna -or manually. When triggered manually from the package directory, -then we should not change the directory. - -======== -*/ - -'use strict'; - -const path = require('path'); -const spawn = require('child_process').spawn; - -const rootDir = path.resolve(__dirname, '..'); -const packageDir = path.relative(rootDir, process.cwd()); - -const compilerOpts = process.argv.slice(2); -let target = compilerOpts.shift(); - -if (!target) { - const nodeMajorVersion = +process.versions.node.split('.')[0]; - target = nodeMajorVersion >= 7 ? 'es2017' : 'es2015'; -} - -let outDir; -switch (target) { - case 'es2017': - outDir = 'dist'; - break; - case 'es2015': - outDir = 'dist6'; - break; - default: - console.error('Unknown build target %s. Supported values: es2015, es2017'); - process.exit(1); -} - -process.chdir(rootDir); - -const args = [ - require.resolve('typescript/lib/tsc'), // see typescript/bin/tsc - '-p', - // It's important to keep this path relative to rootDir - path.join(packageDir, 'tsconfig.build.json'), - '--target', - target, - '--outDir', - path.join(packageDir, outDir), - ...compilerOpts, -]; - -console.log('loopback-next$ tsc', args.slice(1).join(' ')); - -spawn( - process.execPath, // Typically '/usr/local/bin/node' - args, - { - stdio: 'inherit', - } -).on('close', (number, signal) => (process.exitCode = number)); diff --git a/bin/generate-apidocs.js b/bin/generate-apidocs.js deleted file mode 100644 index 36f75d44d0a0..000000000000 --- a/bin/generate-apidocs.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; -var fs = require('fs'); -var path = require('path'); -var tsPath; -try { - tsPath = require.resolve('typedoc/node_modules/typescript/package.json'); -} catch (e) { - // Ignore the error -} -if (tsPath) { - tsPath = path.resolve(tsPath, '..'); - // Rename the nested typescript module for typedoc so that it uses the - // typescript version for our projects - try { - fs.renameSync(tsPath, tsPath + '.bak'); - } catch (e) { - // Ignore the error - } -} -const spawn = require('child_process').spawn; -// Call sdocs -spawn( - process.execPath, - [require.resolve('strong-docs/bin/cli'), '-o', 'api-docs'], - {stdio: 'inherit'} -).on('close', (number, signal) => (process.exitCode = number)); diff --git a/bin/select-dist.js b/bin/select-dist.js deleted file mode 100644 index bb7c94e38a59..000000000000 --- a/bin/select-dist.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright IBM Corp. 2013,2017. All Rights Reserved. -// Node module: loopback-next -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT - -/* -======== - -Usage: - node ../../bin/select-dist command [arguments...] - -The script will scan all arguments (including the command) and replace -the string DIST with either dist or dist6, depending on the current -Node.js version. - -Then the provided command is executed with the modified arguments. - -Example usage: - - node ../../bin/select-dist mocha DIST/test - -======== -*/ - -'use strict'; - -const path = require('path'); -const spawn = require('child_process').spawn; - -const nodeMajorVersion = +process.versions.node.split('.')[0]; -const dist = nodeMajorVersion >= 7 ? 'dist' : 'dist6'; - -const args = process.argv.slice(2).map(a => a.replace(/\bDIST\b/g, dist)); -const command = args.shift(); - -console.log(command, args.join(' ')); - -spawn( - command, - // wrap all arguments in double-quotes to prevent Unix shell from - // incorrectly resolving '**' as '*' - args.map(a => JSON.stringify(a)), - { - stdio: 'inherit', - // On Windows, npm creates `.cmd` files instead of symlinks in - // `node_modules/.bin` folder. These files cannot be executed directly, - // only via a shell. - shell: true, - } -).on('close', (number, signal) => (process.exitCode = number)); diff --git a/package.json b/package.json index 4a43f5eb4c3d..b8913bb2743b 100644 --- a/package.json +++ b/package.json @@ -22,50 +22,29 @@ "cz-conventional-changelog": "^2.0.0", "lerna": "^2.4.0", "mocha": "^4.0.0", - "nyc": "^11.2.1", - "prettier": "^1.7.3", "request": "^2.83.0", - "request-promise": "^4.2.2", - "strong-docs": "^1.6.0", - "tslint": "^5.7.0", - "typescript": "^2.5.3" + "request-promise": "^4.2.2" }, "scripts": { "bootstrap": "npm i && lerna bootstrap", - "coverage:ci": "nyc report --reporter=text-lcov | coveralls", + "coverage:ci": "node packages/build/bin/run-nyc report --reporter=text-lcov | coveralls", "precoverage": "npm test", "coverage": "open coverage/index.html", "lint": "npm run prettier:check && npm run tslint", "lint:fix": "npm run prettier:fix && npm run tslint:fix", - "tslint": "tslint -c tslint.full.json --project tsconfig.json", + "tslint": "node packages/build/bin/run-tslint --project tsconfig.json", "tslint:fix": "npm run tslint -- --fix", - "prettier:cli": "prettier \"**/*.ts\"", + "prettier:cli": "node packages/build/bin/run-prettier \"**/*.ts\"", "prettier:check": "npm run prettier:cli -- -l", "prettier:fix": "npm run prettier:cli -- --write", "clean": "lerna run --loglevel=silent clean", "build": "lerna run --loglevel=silent build", "build:current": "lerna run --loglevel=silent build:current", "pretest": "npm run build:current", - "test": "nyc npm run mocha", - "mocha": "node bin/select-dist mocha --exit --opts test/mocha.opts \"packages/*/DIST/test/**/*.js\"", + "test": "node packages/build/bin/run-nyc npm run mocha", + "mocha": "node packages/build/bin/select-dist mocha --exit --opts test/mocha.opts \"packages/*/DIST/test/**/*.js\"", "posttest": "npm run lint" }, - "nyc": { - "include": [ - "packages/example-codehub/src/**", - "packages/*/dist*/*" - ], - "exclude": [ - "packages/core/*/promisify.*" - ], - "extension": [ - ".js", - ".ts" - ], - "reporter": [ - "html" - ] - }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" diff --git a/packages/authentication/package.json b/packages/authentication/package.json index 98486440d615..7365af7d2ba5 100644 --- a/packages/authentication/package.json +++ b/packages/authentication/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-authentication*.tgz dist* package", - "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", + "integration": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", - "unit": "node bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", + "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-authentication*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -32,6 +32,7 @@ "passport-strategy": "^1.0.0" }, "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1", "@loopback/openapi-spec-builder": "^4.0.0-alpha.8", "@loopback/testlab": "^4.0.0-alpha.10", "passport-http": "^0.3.0" diff --git a/packages/authentication/tsconfig.build.json b/packages/authentication/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/authentication/tsconfig.build.json +++ b/packages/authentication/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/build/CODEOWNERS b/packages/build/CODEOWNERS deleted file mode 100644 index 162218c901ac..000000000000 --- a/packages/build/CODEOWNERS +++ /dev/null @@ -1,7 +0,0 @@ -# Lines starting with '#' are comments. -# Each line is a file pattern followed by one or more owners, -# the last matching pattern has the most precedence. - -# Core team members from IBM -* @bajtos @raymondfeng - diff --git a/packages/build/README.md b/packages/build/README.md index 69f6d6e2499b..682a84738dab 100644 --- a/packages/build/README.md +++ b/packages/build/README.md @@ -3,10 +3,13 @@ The module contains a set of common scripts and default configurations to build LoopBack 4 modules, including: -- lb-tsc: Use `tsc` to compile typescript files +- lb-tsc: Use [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to compile typescript files - lb-dist: Detect the correct distribution target: `dist` => ES2017, `dist6` => ES2015 -- lb-tslint: Run `tslint` with `/tslint.build.json` -- lb-prettier: Run `prettier` +- lb-tslint: Run [`tslint`](https://github.com/palantir/tslint) +- lb-prettier: Run [`prettier`](https://github.com/prettier/prettier) +- lb-nyc: Run [`nyc`](https://github.com/istanbuljs/nyc) + +These scripts first try to locate the CLI from target project dependencies and fall back to bundled ones in `@loopback/build`. # Usage @@ -40,7 +43,55 @@ To use `@loopback/build` for your package: }, ``` -3. Run builds +3. Override default configurations in your project + +- lb-tsc + - Create `tsconfig.build.json` in your project's root directory + ```json + { + "$schema": "http://json.schemastore.org/tsconfig", + "extends": "./node_modules/@loopback/build/config/tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, + "include": ["src", "test"] + } + ``` + - Set options for the script + ``` + lb-tsc -p tsconfig.json + ``` + +- lb-tslint + - Create `tslint.build.json` in your project's root directory + ```json + { + "$schema": "http://json.schemastore.org/tslint", + "extends": [ + "./node_modules/@loopback/build/config/tslint.common.json" + ], + // This configuration files enabled rules which require type checking + // and therefore cannot be run by Visual Studio Code TSLint extension + // See https://github.com/Microsoft/vscode-tslint/issues/70 + "rules": { + // These rules find errors related to TypeScript features. + + + // These rules catch common errors in JS programming or otherwise + // confusing constructs that are prone to producing bugs. + + "await-promise": true, + "no-floating-promises": true, + "no-void-expression": [true, "ignore-arrow-function-shorthand"] + } + } + ``` + - Set options for the script + `` + lb-tslint -c tslint.json -p tsconfig.json + ``` + +4. Run builds ``` npm run build diff --git a/packages/build/bin/compile-package.js b/packages/build/bin/compile-package.js index 3d9e9c167dfe..3b91832e5d26 100755 --- a/packages/build/bin/compile-package.js +++ b/packages/build/bin/compile-package.js @@ -17,7 +17,7 @@ Where is either es2017 or es2015. 'use strict'; -function run(argv) { +function run(argv, dryRun) { const utils = require('./utils'); const path = require('path'); const fs = require('fs'); @@ -25,50 +25,92 @@ function run(argv) { const packageDir = utils.getPackageDir(); const compilerOpts = argv.slice(2); - let target = compilerOpts.shift(); - if (!target) { - target = utils.getCompilationTarget(); + const isTargetSet = utils.isOptionSet(compilerOpts, '--target'); + const isOutDirSet = utils.isOptionSet(compilerOpts, '--outDir'); + const isProjectSet = utils.isOptionSet(compilerOpts, '-p', '--project'); + + var target; + + if (!isTargetSet) { + // Find the last non-option argument as the `target` + // For example `-p tsconfig.json es2017` or `es2017 -p tsconfig.json` + for (var i = compilerOpts.length - 1; i >= 0; i--) { + target = compilerOpts[i]; + // It's an option + if (target.indexOf('-') === 0) { + target = undefined; + continue; + } + // It's the value of an option + if (i >= 1 && compilerOpts[i - 1].indexOf('-') === 0) { + target = undefined; + continue; + } + // Remove the non-option + compilerOpts.splice(i, 1); + break; + } + + if (!target) { + target = utils.getCompilationTarget(); + } + } + + var outDir; + + if (!isOutDirSet) { + outDir = path.join(packageDir, utils.getDistribution(target)); } - let outDir = utils.getDistribution(); - - const tsConfigFile = path.join(utils.getPackageDir(), 'tsconfig.build.json'); - var baseConfigFile = path.join( - utils.getRootDir(), - 'config/tsconfig.common.json' - ); - baseConfigFile = path.relative(utils.getPackageDir(), baseConfigFile); - if (!fs.existsSync(tsConfigFile)) { - fs.writeFileSync( - tsConfigFile, - JSON.stringify( - { - extends: baseConfigFile, - include: ['src', 'test'], - exclude: [ - 'node_modules/**', - 'packages/*/node_modules/**', - '**/*.d.ts', - ], - }, - null, - ' ' - ) - ); + var tsConfigFile; + + if (!isProjectSet) { + var rootDir = utils.getRootDir(); + tsConfigFile = utils.getConfigFile('tsconfig.build.json', 'tsconfig.json'); + if (tsConfigFile === path.join(rootDir, 'config/tsconfig.build.json')) { + // No local tsconfig.build.json or tsconfig.json found + var baseConfigFile = path.join(rootDir, 'config/tsconfig.common.json'); + baseConfigFile = path.relative(packageDir, baseConfigFile); + // Create tsconfig.json under the package as it's required to parse + // include/exclude correctly + tsConfigFile = path.join(packageDir, 'tsconfig.json'); + fs.writeFileSync( + tsConfigFile, + JSON.stringify( + { + extends: baseConfigFile, + include: ['src', 'test'], + exclude: [ + 'node_modules/**', + 'packages/*/node_modules/**', + '**/*.d.ts', + ], + }, + null, + ' ' + ) + ); + } } - const args = [ - '-p', - tsConfigFile, - '--target', - target, - '--outDir', - path.join(packageDir, outDir), - ...compilerOpts, - ]; - - return utils.runCLI('typescript/lib/tsc', args); + const args = []; + + if (tsConfigFile) { + args.push('-p', tsConfigFile); + } + + if (outDir) { + args.push('--outDir', outDir); + } + + if (target) { + args.push('--target', target); + } + + args.push(...compilerOpts); + + return utils.runCLI('typescript/lib/tsc', args, dryRun); } module.exports = run; diff --git a/packages/build/bin/generate-apidocs.js b/packages/build/bin/generate-apidocs.js index e1a238587639..482ca6c335c6 100755 --- a/packages/build/bin/generate-apidocs.js +++ b/packages/build/bin/generate-apidocs.js @@ -5,7 +5,7 @@ // License text available at https://opensource.org/licenses/MIT 'use strict'; -function run(argv) { +function run(argv, dryRun) { const utils = require('./utils'); const fs = require('fs'); const path = require('path'); @@ -26,7 +26,7 @@ function run(argv) { } } - return utils.runCLI('strong-docs/bin/cli', ['-o', 'api-docs']); + return utils.runCLI('strong-docs/bin/cli', ['-o', 'api-docs'], dryRun); } module.exports = run; diff --git a/packages/build/bin/lint-commits.sh b/packages/build/bin/lint-commits.sh deleted file mode 100755 index 4bf14e2d1e1e..000000000000 --- a/packages/build/bin/lint-commits.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -set -e -set -u - -if [[ $TRAVIS_PULL_REQUEST_SLUG != "" && $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG ]]; then - # This is a Pull Request from a different slug, hence a forked repository - git remote add "$TRAVIS_PULL_REQUEST_SLUG" "https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git" - git fetch "$TRAVIS_PULL_REQUEST_SLUG" - - # Use the fetched remote pointing to the source clone for comparison - TO="$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_BRANCH" -else - # This is a Pull Request from the same remote, no clone repository - TO=$TRAVIS_COMMIT - - if [[ $TRAVIS_PULL_REQUEST_SHA != "" && $TRAVIS_PULL_REQUEST_SHA != $TRAVIS_COMMIT ]]; then - echo "TO => TRAVIS_PULL_REQUEST_SHA" - TO=$TRAVIS_PULL_REQUEST_SHA - fi -fi - -echo "TRAVIS_BRANCH => $TRAVIS_BRANCH" -echo "TRAVIS_COMMIT => $TRAVIS_COMMIT" -echo "TRAVIS_COMMIT_MSG => $TRAVIS_COMMIT_MESSAGE" -echo "TRAVIS_COMMIT_RANGE => $TRAVIS_COMMIT_RANGE" -echo "TRAVIS_EVENT_TYPE => $TRAVIS_EVENT_TYPE" -echo "TRAVIS_PULL_REQUEST => $TRAVIS_PULL_REQUEST" -echo "TRAVIS_PULL_REQUEST_BRANCH => $TRAVIS_PULL_REQUEST_BRANCH" -echo "TRAVIS_PULL_REQUEST_SHA => $TRAVIS_PULL_REQUEST_SHA" -echo "TRAVIS_PULL_REQUEST_SLUG => $TRAVIS_PULL_REQUEST_SLUG" -echo "TRAVIS_REPO_SLUG => $TRAVIS_REPO_SLUG" - -# Lint all commits in the PR -# - Covers fork pull requests (when TO=slug/branch) -# - Covers branch pull requests (when TO=branch) -./node_modules/.bin/commitlint --from="$TRAVIS_BRANCH" --to="$TO" - -# Always lint the triggering commit -# - Covers direct commits -COMMIT=$TRAVIS_COMMIT -if [[ $TRAVIS_PULL_REQUEST_SHA != "" && $TRAVIS_PULL_REQUEST_SHA != $TRAVIS_COMMIT ]]; then - COMMIT=$TRAVIS_PULL_REQUEST_SHA -fi - -./node_modules/.bin/commitlint --from="$COMMIT" diff --git a/packages/build/bin/run-clean.js b/packages/build/bin/run-clean.js new file mode 100755 index 000000000000..2587c7b445d7 --- /dev/null +++ b/packages/build/bin/run-clean.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: @loopback/build +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +/* +======== + +Usage: + node ./bin/run-clean file1 file2 ... + +The script will `rm -rf` all files/folders. + +Then the provided command is executed with the modified arguments. + +Example usage: + + node ./bin/run-clean dist dist6 + +======== +*/ + +'use strict'; + +function run(argv, dryRun) { + const fs = require('fs-extra'); + const path = require('path'); + const utils = require('./utils'); + var files = argv.slice(2); + var removed = []; + if (!files.length) { + files = [utils.getDistribution()]; + } + files.forEach(f => { + var file = path.relative(process.cwd(), f); + if (file.indexOf('..') !== -1) { + console.error('Skipping ' + f + ' as it is not inside the project'); + } else { + if (!dryRun) fs.removeSync(f); + removed.push(f); + } + }); + return 'rm -rf ' + removed.join(' '); +} + +module.exports = run; +if (require.main === module) run(process.argv); diff --git a/packages/build/bin/run-nyc.js b/packages/build/bin/run-nyc.js new file mode 100755 index 000000000000..e6e974c1924b --- /dev/null +++ b/packages/build/bin/run-nyc.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: @loopback/build +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +/* +======== + +Usage: + node ./bin/run-nyc + +======== +*/ + +'use strict'; + +function run(argv, dryRun) { + const utils = require('./utils'); + const path = require('path'); + + const nycOpts = argv.slice(2); + const args = [...nycOpts]; + + return utils.runCLI('nyc/bin/nyc', args, dryRun); +} + +module.exports = run; +if (require.main === module) run(process.argv); diff --git a/packages/build/bin/run-prettier.js b/packages/build/bin/run-prettier.js index fb951d47fb02..ca23d791e8e9 100755 --- a/packages/build/bin/run-prettier.js +++ b/packages/build/bin/run-prettier.js @@ -15,20 +15,26 @@ Usage: 'use strict'; -function run(argv) { +function run(argv, dryRun) { const utils = require('./utils'); const prettierOpts = argv.slice(2); - const configFile = utils.getConfigFile('.prettierrc'); - const args = [ - '--config', - // It's important to keep this path relative to rootDir - configFile, - ...prettierOpts, - ]; - - return utils.runCLI('prettier/bin/prettier', args); + const isConfigSet = utils.isOptionSet( + prettierOpts, + '--find-config-path', + '--no-config', + '--config' + ); + const configFile = isConfigSet ? null : utils.getConfigFile('.prettierrc'); + + const args = ['--config-precedence', 'prefer-file']; + if (configFile) { + args.push('--config', configFile); + } + args.push(...prettierOpts); + + return utils.runCLI('prettier/bin/prettier', args, dryRun); } module.exports = run; diff --git a/packages/build/bin/run-tslint.js b/packages/build/bin/run-tslint.js index 16729196b75f..ea36c915c084 100755 --- a/packages/build/bin/run-tslint.js +++ b/packages/build/bin/run-tslint.js @@ -15,15 +15,31 @@ Usage: 'use strict'; -function run(argv) { +function run(argv, dryRun) { const utils = require('./utils'); const tslintOpts = argv.slice(2); - const tsConfigFile = utils.getConfigFile('tsconfig.build.json'); - const args = ['-p', tsConfigFile, ...tslintOpts]; - - return utils.runCLI('tslint/bin/tslint', args); + const isConfigSet = utils.isOptionSet(tslintOpts, '-c', '--config'); + const isProjectSet = utils.isOptionSet(tslintOpts, '-p', '--project'); + + const tslintConfigFile = isConfigSet + ? null + : utils.getConfigFile('tslint.build.json', 'tslint.json'); + const tsConfigFile = isProjectSet + ? null + : utils.getConfigFile('tsconfig.build.json', 'tsconfig.json'); + + const args = []; + if (tsConfigFile) { + args.push('-p', tsConfigFile); + } + if (tslintConfigFile) { + args.push('-c', tslintConfigFile); + } + args.push(...tslintOpts); + + return utils.runCLI('tslint/bin/tslint', args, dryRun); } module.exports = run; diff --git a/packages/build/bin/select-dist.js b/packages/build/bin/select-dist.js index a5d435408c3f..edb31a9b2d11 100755 --- a/packages/build/bin/select-dist.js +++ b/packages/build/bin/select-dist.js @@ -25,19 +25,14 @@ Example usage: 'use strict'; -function run(argv) { +function run(argv, dryRun) { const utils = require('./utils'); const dist = utils.getDistribution(); - const args = argv - .slice(2) - .map(a => a.replace(/\bDIST\b/g, dist)) - // wrap all arguments in double-quotes to prevent Unix shell from - // incorrectly resolving '**' as '*' - .map(a => JSON.stringify(a)); + const args = argv.slice(2).map(a => a.replace(/\bDIST\b/g, dist)); const command = args.shift(); - return utils.runShell(command, args); + return utils.runShell(command, args, dryRun); } module.exports = run; diff --git a/packages/build/bin/utils.js b/packages/build/bin/utils.js index 5d3ed8463e41..961b5c54bdb4 100644 --- a/packages/build/bin/utils.js +++ b/packages/build/bin/utils.js @@ -5,9 +5,11 @@ 'use strict'; +const util = require('util'); const fs = require('fs'); const path = require('path'); -const spawn = require('child_process').spawn; +const spawn = require('cross-spawn'); +const debug = require('debug')('loopback:build'); /** * Get the Node.js compilation target - es2017 or es2015 @@ -19,7 +21,7 @@ function getCompilationTarget() { /** * Get the distribution name - * @param {*} target + * @param {*} target */ function getDistribution(target) { if (!target) { @@ -58,21 +60,29 @@ function getPackageDir() { /** * Get config file - * @param {*} name + * @param {string} name Preferred file + * @param {string} defaultName Default file */ -function getConfigFile(name) { +function getConfigFile(name, defaultName) { var dir = getPackageDir(); var configFile = path.join(dir, name); if (!fs.existsSync(configFile)) { - // Fall back to config/ - configFile = path.join(getRootDir(), 'config/' + name); + if (defaultName) { + configFile = path.join(dir, name); + if (!fs.existsSync(configFile)) { + configFile = path.join(getRootDir(), 'config/' + name); + } + } else { + // Fall back to config/ + configFile = path.join(getRootDir(), 'config/' + name); + } } return configFile; } /** * Resolve the path of the cli command - * @param {string} cli + * @param {string} cli */ function resolveCLI(cli) { const path = './node_modules/' + cli; @@ -87,19 +97,28 @@ function resolveCLI(cli) { * Run a command with the given arguments * @param {string} cli Path of the cli command * @param {string[]} args The arguments + * @param {boolean} dryRun Controls if the cli will be executed or not. If set + * to true, the command itself will be returned without running it */ -function runCLI(cli, args) { +function runCLI(cli, args, dryRun) { cli = resolveCLI(cli); args = [cli].concat(args); - console.log('%s', args.join(' ')); + debug('%s', args.join(' ')); + if (dryRun) { + return util.format('%s %s', process.execPath, args.join(' ')); + } var child = spawn( process.execPath, // Typically '/usr/local/bin/node' args, { stdio: 'inherit', + env: Object.create(process.env), } ); - child.on('close', (number, signal) => (process.exitCode = number)); + child.on('close', (code, signal) => { + debug('%s exits: %d', cli, code); + process.exitCode = code; + }); return child; } @@ -107,20 +126,39 @@ function runCLI(cli, args) { * Run the command in a shell * @param {string} command The command * @param {string[]} args The arguments + * @param {boolean} dryRun Controls if the cli will be executed or not. If set + * to true, the command itself will be returned without running it */ -function runShell(command, args) { - console.log('%s %s', command, args.join(' ')); +function runShell(command, args, dryRun) { + args = args.map(a => JSON.stringify(a)); + debug('%s %s', command, args.join(' ')); + if (dryRun) { + return util.format('%s %s', command, args.join(' ')); + } var child = spawn(command, args, { stdio: 'inherit', + env: Object.create(process.env), // On Windows, npm creates `.cmd` files instead of symlinks in // `node_modules/.bin` folder. These files cannot be executed directly, // only via a shell. shell: true, }); - child.on('close', (number, signal) => (process.exitCode = number)); + child.on('close', (code, signal) => { + debug('%s exits: %d', command, code); + process.exitCode = code; + }); return child; } +/** + * Check if one of the option names is set by the opts + * @param {string[]} opts + * @param {string[]} optionNames + */ +function isOptionSet(opts, ...optionNames) { + return opts.some(o => optionNames.indexOf(o) !== -1); +} + exports.getCompilationTarget = getCompilationTarget; exports.getDistribution = getDistribution; exports.getRootDir = getRootDir; @@ -129,3 +167,4 @@ exports.getConfigFile = getConfigFile; exports.resolveCLI = resolveCLI; exports.runCLI = runCLI; exports.runShell = runShell; +exports.isOptionSet = isOptionSet; diff --git a/packages/build/commitlint.config.js b/packages/build/commitlint.config.js deleted file mode 100644 index 04f80aea0cf2..000000000000 --- a/packages/build/commitlint.config.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright IBM Corp. 2013,2017. All Rights Reserved. -// Node module: loopback-next -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT - -module.exports = { - extends: ['@commitlint/config-angular', '@commitlint/config-lerna-scopes'], - rules: { - 'header-max-length': [2, 'always', 100], - 'footer-max-length': [2, 'always', 100], - 'body-tense': [1, 'always', ['present-imperative']], - 'footer-tense': [1, 'always', ['present-imperative']], - 'subject-tense': [2, 'always', ['present-imperative']], - lang: [0, 'always', 'eng'], - 'body-leading-blank': [2, 'always'], - 'footer-leading-blank': [0, 'always'], - }, -}; diff --git a/packages/build/config/.nycrc b/packages/build/config/.nycrc new file mode 100644 index 000000000000..c0db601acdbc --- /dev/null +++ b/packages/build/config/.nycrc @@ -0,0 +1,4 @@ +{ + "extension": [".js", ".ts"], + "reporter": ["html"] +} diff --git a/packages/build/config/nyc.common.json b/packages/build/config/nyc.common.json deleted file mode 100644 index 7a96f83a89ff..000000000000 --- a/packages/build/config/nyc.common.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "include": ["packages/example-codehub/src/**", "packages/*/dist*/*"], - "exclude": ["packages/core/*/promisify.*"], - "extension": [".js", ".ts"], - "reporter": ["html"] -} \ No newline at end of file diff --git a/packages/build/index.js b/packages/build/index.js new file mode 100644 index 000000000000..d1e891ac0d5e --- /dev/null +++ b/packages/build/index.js @@ -0,0 +1,12 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: @loopback/build +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +exports.tsc = require('./bin/compile-package'); +exports.prettier = require('./bin/run-prettier'); +exports.tslint = require('./bin/run-tslint'); +exports.nyc = require('./bin/run-nyc'); +exports.dist = require('./bin/select-dist'); diff --git a/packages/build/package.json b/packages/build/package.json index cd2c6c274fb4..20c0080812cd 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -12,13 +12,10 @@ "main": "index.js", "license": "MIT", "dependencies": { - "@commitlint/cli": "^4.2.0", - "@commitlint/config-angular": "^4.2.0", - "@commitlint/config-lerna-scopes": "^4.2.0", "@types/mocha": "^2.2.43", "@types/node": "^8.0.32", - "coveralls": "^3.0.0", - "cz-conventional-changelog": "^2.0.0", + "cross-spawn": "^5.1.0", + "debug": "^3.1.0", "mocha": "^4.0.0", "nyc": "^11.2.1", "prettier": "^1.7.3", @@ -30,28 +27,22 @@ "lb-tsc": "./bin/compile-package.js", "lb-tslint": "./bin/run-tslint.js", "lb-prettier": "./bin/run-prettier.js", + "lb-nyc": "./bin/run-nyc.js", "lb-dist": "./bin/select-dist.js", - "lb-apidocs": "./bin/generate-apidocs.js" + "lb-apidocs": "./bin/generate-apidocs.js", + "lb-clean": "./bin/run-clean.js" }, "scripts": { - "coverage:ci": "nyc report --reporter=text-lcov | coveralls", - "precoverage": "npm test", - "coverage": "open coverage/index.html", "lint": "npm run prettier:check", "lint:fix": "npm run prettier:fix", "prettier:cli": "node bin/run-prettier \"bin/**/*.js\"", "prettier:check": "npm run prettier:cli -- -l", "prettier:fix": "npm run prettier:cli -- --write", - "test": "nyc npm run mocha", - "mocha": "node bin/select-dist mocha --timeout 15000 --opts test/mocha.opts \"test/**/*.js\"", + "test": "npm run mocha", + "mocha": "node bin/select-dist mocha --timeout 30000 --opts test/mocha.opts \"test/integration/*.js\"", "posttest": "npm run lint" }, - "nyc": { - "extends": "./config/nyc.common.json" - }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } + "devDependencies": { + "fs-extra": "^4.0.2" } } diff --git a/packages/build/test/fixtures/.gitignore b/packages/build/test/fixtures/.gitignore index 3e21edb491ac..a29a9f4835a4 100644 --- a/packages/build/test/fixtures/.gitignore +++ b/packages/build/test/fixtures/.gitignore @@ -1,2 +1,2 @@ -tsconfig.build.json +tsconfig.json dist diff --git a/packages/build/test/fixtures/docs.json b/packages/build/test/fixtures/docs.json new file mode 100644 index 000000000000..d65457097d82 --- /dev/null +++ b/packages/build/test/fixtures/docs.json @@ -0,0 +1,5 @@ +{ + "content": ["src/index.ts"], + "codeSectionDepth": 4, + "assets": {} +} diff --git a/packages/build/test/fixtures/package.json b/packages/build/test/fixtures/package.json new file mode 100644 index 000000000000..624fb77ab295 --- /dev/null +++ b/packages/build/test/fixtures/package.json @@ -0,0 +1,10 @@ +{ + "name": "ts-test-proj", + "version": "1.0.0", + "description": "Test", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT" +} diff --git a/packages/build/test/fixtures/src/index.ts b/packages/build/test/fixtures/src/index.ts index d1b7d4f1e4cb..bbddc45ae3e0 100644 --- a/packages/build/test/fixtures/src/index.ts +++ b/packages/build/test/fixtures/src/index.ts @@ -1,12 +1,22 @@ -function log() { - return function(target: object | Function) {} +/** + * log decorator + */ +export function log() { + return function(target: object | Function) {}; } +/** + * Hello class + */ @log() export class Hello { constructor(public name: string) {} + /** + * Return a greeting + * @param msg Message + */ greet(msg: string) { return `Hello, ${this.name}: ${msg}`; } -} \ No newline at end of file +} diff --git a/packages/build/test/integration/scripts.test.js b/packages/build/test/integration/scripts.test.js new file mode 100644 index 000000000000..6f2960cf5fe5 --- /dev/null +++ b/packages/build/test/integration/scripts.test.js @@ -0,0 +1,217 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: loopback-next +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +'use strict'; + +const assert = require('assert'); +const path = require('path'); +const fs = require('fs-extra'); + +describe('build', () => { + var cwd = process.cwd(); + var projectDir = path.resolve(__dirname, '../fixtures'); + + function cleanup() { + var run = require('../../bin/run-clean'); + run(['node', 'bin/run-clean', 'tsconfig.json', 'dist', 'api-docs']); + } + + before(() => { + process.chdir(projectDir); + cleanup(); + }); + + after(() => { + cleanup(); + process.chdir(cwd); + }); + + it('compiles ts files', done => { + var run = require('../../bin/compile-package'); + var childProcess = run(['node', 'bin/compile-package']); + childProcess.on('close', code => { + assert.equal(code, 0); + assert( + fs.existsSync(path.join(projectDir, 'dist')), + 'dist should have been created' + ); + assert( + fs.existsSync(path.join(projectDir, 'tsconfig.json')), + 'tsconfig.json should have been created' + ); + done(); + }); + }); + + it('honors -p option for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run( + ['node', 'bin/compile-package', '-p', 'tsconfig.my.json'], + true + ); + assert( + command.indexOf('-p tsconfig.my.json') !== -1, + '-p should be honored' + ); + }); + + it('honors --project option for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run( + ['node', 'bin/compile-package', '--project', 'tsconfig.my.json'], + true + ); + assert( + command.indexOf('--project tsconfig.my.json') !== -1, + '--project should be honored' + ); + }); + + it('honors --target option for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run( + ['node', 'bin/compile-package', '--target', 'es2015'], + true + ); + assert( + command.indexOf('--target es2015') !== -1, + '--target should be honored' + ); + }); + + it('honors no-option as target for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run(['node', 'bin/compile-package', 'es2015'], true); + assert( + command.indexOf('--target es2015') !== -1, + '--target should be honored' + ); + }); + + it('honors no-option as target with -p for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run( + ['node', 'bin/compile-package', 'es2015', '-p', 'tsconfig.my.json'], + true + ); + assert( + command.indexOf('--target es2015') !== -1, + '--target should be honored' + ); + assert( + command.indexOf('-p tsconfig.my.json') !== -1, + '-p should be honored' + ); + }); + + it('honors --outDir option for tsc', () => { + var run = require('../../bin/compile-package'); + var command = run( + ['node', 'bin/compile-package', '--outDir', './dist'], + true + ); + assert( + command.indexOf('--outDir ./dist') !== -1, + '--outDir should be honored' + ); + }); + + it('generates apidocs', done => { + var run = require('../../bin/generate-apidocs'); + var childProcess = run(['node', 'bin/generate-apidocs']); + childProcess.on('close', code => { + assert.equal(code, 0); + assert( + fs.existsSync(path.join(projectDir, 'api-docs')), + 'api-docs should have been created' + ); + done(); + }); + }); + + it('runs tslint against ts files', done => { + var run = require('../../bin/run-tslint'); + var childProcess = run(['node', 'bin/run-tslint']); + childProcess.on('close', code => { + assert.equal(code, 0); + done(); + }); + }); + + it('honors -c option for tslint', () => { + var run = require('../../bin/run-tslint'); + var command = run(['node', 'bin/un-tslint', '-c', 'tslint.my.json'], true); + assert(command.indexOf('-c tslint.my.json') !== -1, '-c should be honored'); + }); + + it('honors --config option for tslint', () => { + var run = require('../../bin/run-tslint'); + var command = run( + ['node', 'bin/un-tslint', '--config', 'tslint.my.json'], + true + ); + assert( + command.indexOf('--config tslint.my.json') !== -1, + '--config should be honored' + ); + }); + + it('honors -p option for tslint', () => { + var run = require('../../bin/run-tslint'); + var command = run(['node', 'bin/un-tslint', '-p', 'tsonfig.my.json'], true); + assert(command.indexOf('-p tsonfig') !== -1, '-p should be honored'); + }); + + it('honors --project option for tslint', () => { + var run = require('../../bin/run-tslint'); + var command = run( + ['node', 'bin/un-tslint', '--project', 'tsonfig.my.json'], + true + ); + assert( + command.indexOf('--project tsonfig') !== -1, + '--project should be honored' + ); + }); + + it('runs prettier against ts files', done => { + var run = require('../../bin/run-prettier'); + var childProcess = run([ + 'node', + 'bin/run-prettier', + '**/src/*.ts', + '--', + '-l', + ]); + childProcess.on('close', code => { + assert.equal(code, 0); + done(); + }); + }); + + it('removes directories/files', () => { + var run = require('../../bin/run-clean'); + var command = run( + ['node', 'bin/run-clean', 'tsconfig.json', 'dist', 'api-docs'], + true + ); + assert(command.indexOf('tsconfig.json dist api-docs') !== -1); + }); + + it('does not remove directories/files outside the project', () => { + var run = require('../../bin/run-clean'); + var command = run( + [ + 'node', + 'bin/run-clean', + '../tsconfig.json', + './dist', + path.join(process.cwd(), '../../api-docs'), + ], + true + ); + assert(command.indexOf('rm -rf ./dist') !== -1); + }); +}); diff --git a/packages/build/test/integration/utils.test.js b/packages/build/test/integration/utils.test.js deleted file mode 100644 index 2175fb32968f..000000000000 --- a/packages/build/test/integration/utils.test.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright IBM Corp. 2013,2017. All Rights Reserved. -// Node module: loopback-next -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT - -'use strict'; - -const assert = require('assert'); -const path = require('path'); -const fs = require('fs'); - -const utils = require('../../bin/utils'); - -describe('utils', () => { - it('compiles ts files', (done) => { - var projectDir = path.resolve(__dirname, '../fixtures'); - process.chdir(projectDir); - try { - fs.unlinkSync(path.join(projectDir, 'tsconfig.build.json')); - } catch (e) { - // Ignore it - } - var run = require('../../bin/compile-package'); - var childProcess = run(['node', 'bin/compile-package']); - childProcess.on('close', code => { - assert.equal(code, 0); - assert(fs.existsSync(path.join(projectDir, 'dist'))); - assert(fs.existsSync(path.join(projectDir, 'tsconfig.build.json'))); - done(); - }); - }); - - it('runs tslint against ts files', (done) => { - var projectDir = path.resolve(__dirname, '../fixtures'); - process.chdir(projectDir); - var run = require('../../bin/run-tslint'); - var childProcess = run(['node', 'bin/run-tslint']); - childProcess.on('close', code => { - assert.equal(code, 0); - done(); - }); - }); - - it('runs prettier against ts files', (done) => { - var projectDir = path.resolve(__dirname, '../fixtures'); - process.chdir(projectDir); - var run = require('../../bin/run-prettier'); - var childProcess = run([ - 'node', - 'bin/run-prettier', - '**/src/*.ts', - '--', - '-l', - ]); - childProcess.on('close', code => { - assert.equal(code, 0); - done(); - }); - }); -}); diff --git a/packages/context/package.json b/packages/context/package.json index eadb3c1235ab..b1a6bd550db1 100644 --- a/packages/context/package.json +++ b/packages/context/package.json @@ -6,17 +6,17 @@ "node": ">=6" }, "scripts": { - "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-context*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", - "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", + "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -25,6 +25,7 @@ "reflect-metadata": "^0.1.10" }, "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1", "@loopback/testlab": "^4.0.0-alpha.10", "@types/bluebird": "^3.5.8", "bluebird": "^3.5.0" diff --git a/packages/context/tsconfig.build.json b/packages/context/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/context/tsconfig.build.json +++ b/packages/context/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/core/package.json b/packages/core/package.json index 0708b307fb5a..6fa07f9cd204 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-core*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", - "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", - "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", + "integration": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", + "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-core*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -27,6 +27,7 @@ "lodash": "^4.17.4" }, "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1", "@loopback/testlab": "^4.0.0-alpha.10" }, "files": [ diff --git a/packages/core/tsconfig.build.json b/packages/core/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/core/tsconfig.build.json +++ b/packages/core/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/openapi-spec-builder/package.json b/packages/openapi-spec-builder/package.json index a958e8b87c21..6f815c60d45d 100644 --- a/packages/openapi-spec-builder/package.json +++ b/packages/openapi-spec-builder/package.json @@ -7,26 +7,23 @@ }, "scripts": { "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-openapi-spec*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "verify": "npm pack && tar xf loopback-openapi-spec*.tgz && tree package && npm run clean" }, "author": "IBM", "license": "MIT", - "keywords": [ - "Swagger", - "OpenAPI Spec", - "TypeScript", - "Builder", - "Testing" - ], + "keywords": ["Swagger", "OpenAPI Spec", "TypeScript", "Builder", "Testing"], "dependencies": { "@loopback/openapi-spec": "^4.0.0-alpha.11" }, + "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1" + }, "files": [ "README.md", "index.js", diff --git a/packages/openapi-spec-builder/tsconfig.build.json b/packages/openapi-spec-builder/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/openapi-spec-builder/tsconfig.build.json +++ b/packages/openapi-spec-builder/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/openapi-spec/package.json b/packages/openapi-spec/package.json index 8fd5ed1207aa..7c35b1699eb1 100644 --- a/packages/openapi-spec/package.json +++ b/packages/openapi-spec/package.json @@ -5,24 +5,22 @@ "engines": { "node": ">=6" }, + "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1" + }, "scripts": { "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-openapi-spec*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "verify": "npm pack && tar xf loopback-openapi-spec*.tgz && tree package && npm run clean" }, "author": "IBM", "license": "MIT", - "keywords": [ - "Swagger", - "OpenAPI Spec", - "TypeScript", - "Typings" - ], + "keywords": ["Swagger", "OpenAPI Spec", "TypeScript", "Typings"], "files": [ "README.md", "index.js", diff --git a/packages/openapi-spec/tsconfig.build.json b/packages/openapi-spec/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/openapi-spec/tsconfig.build.json +++ b/packages/openapi-spec/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/repository/package.json b/packages/repository/package.json index af090ef42e89..4e408babac32 100644 --- a/packages/repository/package.json +++ b/packages/repository/package.json @@ -7,22 +7,23 @@ }, "main": "index", "scripts": { - "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-context*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", - "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", + "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-juggler*.tgz && tree package && npm run clean" }, "author": "IBM", "license": "MIT", "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1", "@loopback/core": "^4.0.0-alpha.17", "@loopback/testlab": "^4.0.0-alpha.10" }, diff --git a/packages/repository/tsconfig.build.json b/packages/repository/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/repository/tsconfig.build.json +++ b/packages/repository/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/rest/package.json b/packages/rest/package.json index ab1bd561b61c..47e2022c13f5 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", - "build:apidocs": "node ../../bin/generate-apidocs", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", + "build:apidocs": "lb-apidocs", "clean": "rm -rf loopback-rest*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", - "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", - "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", + "integration": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", + "test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-rest*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -37,6 +37,7 @@ "swagger2openapi": "^2.9.2" }, "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1", "@loopback/openapi-spec-builder": "^4.0.0-alpha.8", "@loopback/testlab": "^4.0.0-alpha.10" }, diff --git a/packages/rest/tsconfig.build.json b/packages/rest/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/rest/tsconfig.build.json +++ b/packages/rest/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/packages/testlab/package.json b/packages/testlab/package.json index aeab307b543a..107e4b32df4f 100644 --- a/packages/testlab/package.json +++ b/packages/testlab/package.json @@ -7,13 +7,13 @@ }, "scripts": { "build": "npm run build:dist && npm run build:dist6", - "build:current": "node ../../bin/compile-package", - "build:dist": "node ../../bin/compile-package es2017", - "build:dist6": "node ../../bin/compile-package es2015", + "build:current": "lb-tsc", + "build:dist": "lb-tsc es2017", + "build:dist6": "lb-tsc es2015", "clean": "rm -rf loopback-testlab*.tgz dist* package", "prepublish": "npm run build", "pretest": "npm run build:current", - "test": "node ../../bin/select-dist mocha --recursive DIST/test", + "test": "lb-dist mocha --recursive DIST/test", "verify": "npm pack && tar xf loopback-testlab*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -30,6 +30,9 @@ "supertest": "^3.0.0", "swagger-parser": "^3.4.1" }, + "devDependencies": { + "@loopback/build": "^4.0.0-alpha.1" + }, "files": [ "README.md", "index.js", diff --git a/packages/testlab/tsconfig.build.json b/packages/testlab/tsconfig.build.json index dc78331e392e..855e02848b35 100644 --- a/packages/testlab/tsconfig.build.json +++ b/packages/testlab/tsconfig.build.json @@ -1,11 +1,8 @@ { "$schema": "http://json.schemastore.org/tsconfig", - "extends": "../../tsconfig.common.json", + "extends": "../build/config/tsconfig.common.json", "compilerOptions": { "rootDir": "." }, - "include": [ - "src", - "test" - ] + "include": ["src", "test"] } diff --git a/tsconfig.common.json b/tsconfig.common.json deleted file mode 100644 index 1d8e30dea1ea..000000000000 --- a/tsconfig.common.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/tsconfig", - "compilerOptions": { - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "noImplicitAny": true, - "strictNullChecks": true, - - "lib": ["es2017", "dom"], - "module": "commonjs", - "moduleResolution": "node", - "target": "es6", - "sourceMap": true, - "declaration": true - } -} diff --git a/tsconfig.json b/tsconfig.json index fb1310ffa408..ff26cec4b612 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,5 @@ { - "extends": "./tsconfig.common.json", - "include": [ - "packages" - ], - "exclude": [ - "node_modules/**", - "packages/*/node_modules/**", - "**/*.d.ts" - ] + "extends": "./packages/build/config/tsconfig.common.json", + "include": ["packages"], + "exclude": ["node_modules/**", "packages/*/node_modules/**", "**/*.d.ts"] } diff --git a/tslint.full.json b/tslint.build.json similarity index 100% rename from tslint.full.json rename to tslint.build.json diff --git a/tslint.json b/tslint.json index 2580d16e72cc..97e9b8ee945c 100644 --- a/tslint.json +++ b/tslint.json @@ -1,28 +1,4 @@ { - // See https://palantir.github.io/tslint/rules/ - "rules": { - // These rules find errors related to TypeScript features. - "adjacent-overload-signatures": true, - "prefer-for-of": true, - "unified-signatures": true, - "no-any": true, - - // These rules catch common errors in JS programming or otherwise - // confusing constructs that are prone to producing bugs. - - "label-position": true, - "no-arg": true, - "no-construct": true, - "no-duplicate-variable": true, - - "no-invalid-this": true, - "no-misused-new": true, - "no-shadowed-variable": true, - "no-string-throw": true, - "no-unused-expression": true, - "no-unused-variable": true, - "no-var-keyword": true, - "triple-equals": [true, "allow-null-check", "allow-undefined-check"], - "typeof-compare": true - } + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./packages/build/config/tslint.common.json"] }