From 1236039b333492c5e153b3386eb9237b03fbef6e Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Mon, 6 Feb 2017 19:56:11 +0100 Subject: [PATCH 1/4] feat(standard-version): make tagPrefix configurable --- package.json | 2 +- src/index.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d4bf48d..3b6ede0 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "breeze-dag": "^0.1.0", - "standard-version": "^3.0.0", + "standard-version": "^4.0.0", "through2": "^2.0.0", "typedoc": "^0.5.1", "yargs": "^6.3.0" diff --git a/src/index.js b/src/index.js index 5344af9..76ebca8 100755 --- a/src/index.js +++ b/src/index.js @@ -193,7 +193,8 @@ const argv = require('yargs') standardVersion({ infile: argv._[1] || path.resolve(process.cwd(), 'doc/CHANGELOG.md'), message: 'chore(release): prepare release %s', - firstRelease: argv.firstRelease + firstRelease: argv.firstRelease, + tagPrefix: "" }, function (err) { process.exit(1); }); From 0cc605f46294c0eee2fe21cd797a11d1f6d81f9f Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Mon, 6 Feb 2017 20:22:19 +0100 Subject: [PATCH 2/4] feat(cli): extract cli to own file --- package.json | 2 +- src/cli.js | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 183 +------------------------------------------------ 3 files changed, 189 insertions(+), 183 deletions(-) create mode 100644 src/cli.js diff --git a/package.json b/package.json index 3b6ede0..c2f638d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "url": "http://github.com/aurelia/tools" }, "bin": { - "aurelia-tools": "src/index.js" + "aurelia-tools": "src/cli.js" }, "dependencies": { "breeze-dag": "^0.1.0", diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..2f2e79d --- /dev/null +++ b/src/cli.js @@ -0,0 +1,187 @@ +#!/usr/bin/env node +"use strict"; +process.title = 'aurelia-tools'; + +const path = require('path'); +const rimraf = require('rimraf').sync; +const spawn = require('child_process').spawn; +const proxySpawned = require('./cli-util').proxySpawned; +const projectDir = process.cwd(); +const docShape = require('./doc-shape'); +const docShapeDefs = require('./doc-shape-defs'); + +let tscPath; +try { + tscPath = require.resolve(path.join(projectDir, 'node_modules', 'typescript/bin/tsc')); +} catch (_) { + tscPath = require.resolve('typescript/bin/tsc'); +} + +const argv = require('yargs') + .command('ts-build-all', 'Build multiple versions of the project', { + project: { + alias: 'p', + describe: 'TypeScript project file or folder', + type: 'string', + default: 'tsconfig.build.json' + }, + outDir: { + alias: 'out', + describe: 'Output directory for compilations', + type: 'string', + default: 'dist' + }, + 'continue-when-failed': { + describe: 'Do not bail when one compilation fails', + type: 'boolean', + default: false + }, + 'clean-before': { + describe: 'Clean outdir before compiling', + type: 'boolean', + default: false + }, + 'variation': { + describe: 'Which variation to compile (or all if not defined)', + type: 'array' + } + }, + function(argv) { + if (argv.cleanBefore) { + rimraf(argv.outDir); + } + + let variations = [ + { module: "amd" }, + { module: "commonjs" }, + { module: "es2015", directory: "native-modules" }, + { module: "system" }, + { module: "es2015", target: "es2015" }, + { module: "es2015", target: "es2017" } + ]; + + if (argv.variation && argv.variation.length) { + variations = variations.filter(v => + (v.target && argv.variation.includes(v.target)) || + (v.directory && argv.variation.includes(v.directory)) || + argv.variation.includes(v.module) + ) + } + + variations.forEach(variation => { + const outDir = variation.directory || variation.target || variation.module; + const args = [ tscPath, '--project', argv.project, '--outDir', path.join(argv.outDir, outDir), '--module', variation.module ]; + if (variation.target) { + args.push('--target', variation.target); + } + console.log(`Running TypeScript compiler: ${args.join(' ')}`); + const tsc = spawn('node', args); + proxySpawned(tsc, outDir, argv.continueWhenFailed); + }); + }) + .command('doc-jsonshape', 'Shape docs', {}, function(argv) { + docShape.shape(argv._[1], argv._[2]); + }) + .command('doc-shape-defs', 'Shape doc defs', {}, function(argv) { + docShapeDefs.shapeDefs(argv._[1], argv._[2]); + }) + .command('doc-build', 'Creates a single .d.ts from TS project', { + project: { + alias: 'p', + describe: 'TypeScript project file or folder', + type: 'string', + default: 'tsconfig.build.json' + }, + outDir: { + alias: 'out', + describe: 'Output for compilation', + type: 'string', + default: 'dist/doc-temp' + }, + 'continue-when-failed': { + describe: 'Do not bail when one compilation fails', + type: 'boolean', + default: false + } + }, function(argv) { + const packageJsonPath = path.resolve(projectDir, 'package.json'); + try { + const packageName = require(packageJsonPath).name; + rimraf('dist/doc-temp/**'); + const tsc = spawn( './node_modules/.bin/tsc', [ '--project', argv.project, '--outFile', path.join(argv.outDir, packageName + '.js') ] ); + proxySpawned(tsc, undefined, argv.continueWhenFailed); + } catch (e) { + console.error(e.message); + process.exit(1); + } + }) + .command('typedoc', 'Creates a typedoc file', { + inDir: { + alias: 'in', + describe: 'Input d.ts files directory', + type: 'string', + default: 'dist/doc-temp' + }, + outFile: { + alias: 'o', + describe: 'api.json output path', + type: 'string', + default: 'doc/api.json' + }, + cleanUpInDir: { + alias: 'clean', + describe: 'removes the outdir', + type: 'boolean', + default: true + }, + 'continue-when-failed': { + describe: 'Do not bail when one compilation fails', + type: 'boolean', + default: false + }, + project: { + alias: 'p', + describe: 'TypeScript project file', + type: 'string', + default: path.resolve(__dirname, '../tsc/tsconfig.json') + } + }, function(argv) { + const projectDir = process.cwd(); + const packageJsonPath = path.resolve(projectDir, 'package.json'); + try { + const packageName = require(packageJsonPath).name; + const typeDocPath = require.resolve('typedoc/bin/typedoc'); + rimraf('doc/api.json'); + + const spawn = require( 'child_process' ).spawn; + const typedoc = spawn( 'node', [ typeDocPath, '--json', argv.outFile, '--excludeExternals', '--includeDeclarations', '--mode', 'modules', '--target', 'ES6', '--name', packageName, '--ignoreCompilerErrors', '--tsconfig', argv.project, argv.inDir ] ); + proxySpawned(typedoc, undefined, argv.continueWhenFailed, function(code) { + if (code === 0) { + if (argv.cleanUpInDir) { + rimraf(argv.inDir); + } + } + }); + } catch (e) { + console.error(e.message); + process.exit(1); + } + }) + .command('changelog', 'Generate changelog from commits', { + 'first-release': { + alias: 'f', + describe: 'Is this the first release?', + type: 'boolean', + default: false + } + }, function(argv) { + const standardVersion = require('standard-version'); + standardVersion({ + infile: argv._[1] || path.resolve(process.cwd(), 'doc/CHANGELOG.md'), + message: 'chore(release): prepare release %s', + firstRelease: argv.firstRelease, + tagPrefix: "" + }, function (err) { + process.exit(1); + }); + }).argv; diff --git a/src/index.js b/src/index.js index 76ebca8..deff835 100755 --- a/src/index.js +++ b/src/index.js @@ -1,22 +1,9 @@ -#!/usr/bin/env node -"use strict"; -process.title = 'aurelia-tools'; const doc = require('./doc'); const dev = require('./dev'); const build = require('./build'); const docShape = require('./doc-shape'); const docShapeDefs = require('./doc-shape-defs'); -const path = require('path'); -const rimraf = require('rimraf').sync; -const spawn = require('child_process').spawn; -const proxySpawned = require('./cli-util').proxySpawned; -const projectDir = process.cwd(); -let tscPath; -try { - tscPath = require.resolve(path.join(projectDir, 'node_modules', 'typescript/bin/tsc')); -} catch (_) { - tscPath = require.resolve('typescript/bin/tsc'); -} + module.exports = { transformAPIModel:doc.transformAPIModel, @@ -31,171 +18,3 @@ module.exports = { docShape: docShape.shape }; -const argv = require('yargs') - .command('ts-build-all', 'Build multiple versions of the project', { - project: { - alias: 'p', - describe: 'TypeScript project file or folder', - type: 'string', - default: 'tsconfig.build.json' - }, - outDir: { - alias: 'out', - describe: 'Output directory for compilations', - type: 'string', - default: 'dist' - }, - 'continue-when-failed': { - describe: 'Do not bail when one compilation fails', - type: 'boolean', - default: false - }, - 'clean-before': { - describe: 'Clean outdir before compiling', - type: 'boolean', - default: false - }, - 'variation': { - describe: 'Which variation to compile (or all if not defined)', - type: 'array' - } - }, - function(argv) { - if (argv.cleanBefore) { - rimraf(argv.outDir); - } - - let variations = [ - { module: "amd" }, - { module: "commonjs" }, - { module: "es2015", directory: "native-modules" }, - { module: "system" }, - { module: "es2015", target: "es2015" }, - { module: "es2015", target: "es2017" } - ]; - - if (argv.variation && argv.variation.length) { - variations = variations.filter(v => - (v.target && argv.variation.includes(v.target)) || - (v.directory && argv.variation.includes(v.directory)) || - argv.variation.includes(v.module) - ) - } - - variations.forEach(variation => { - const outDir = variation.directory || variation.target || variation.module - const args = [ tscPath, '--project', argv.project, '--outDir', path.join(argv.outDir, outDir), '--module', variation.module ]; - if (variation.target) { - args.push('--target', variation.target); - } - console.log(`Running TypeScript compiler: ${args.join(' ')}`) - const tsc = spawn('node', args); - proxySpawned(tsc, outDir, argv.continueWhenFailed); - }); - }) - .command('doc-jsonshape', 'Shape docs', {}, function(argv) { - docShape.shape(argv._[1], argv._[2]); - }) - .command('doc-shape-defs', 'Shape doc defs', {}, function(argv) { - docShapeDefs.shapeDefs(argv._[1], argv._[2]); - }) - .command('doc-build', 'Creates a single .d.ts from TS project', { - project: { - alias: 'p', - describe: 'TypeScript project file or folder', - type: 'string', - default: 'tsconfig.build.json' - }, - outDir: { - alias: 'out', - describe: 'Output for compilation', - type: 'string', - default: 'dist/doc-temp' - }, - 'continue-when-failed': { - describe: 'Do not bail when one compilation fails', - type: 'boolean', - default: false - } - }, function(argv) { - const packageJsonPath = path.resolve(projectDir, 'package.json'); - try { - const packageName = require(packageJsonPath).name; - rimraf('dist/doc-temp/**'); - const tsc = spawn( './node_modules/.bin/tsc', [ '--project', argv.project, '--outFile', path.join(argv.outDir, packageName + '.js') ] ); - proxySpawned(tsc, undefined, argv.continueWhenFailed); - } catch (e) { - console.error(e.message); - process.exit(1); - } - }) - .command('typedoc', 'Creates a typedoc file', { - inDir: { - alias: 'in', - describe: 'Input d.ts files directory', - type: 'string', - default: 'dist/doc-temp' - }, - outFile: { - alias: 'o', - describe: 'api.json output path', - type: 'string', - default: 'doc/api.json' - }, - cleanUpInDir: { - alias: 'clean', - describe: 'removes the outdir', - type: 'boolean', - default: true - }, - 'continue-when-failed': { - describe: 'Do not bail when one compilation fails', - type: 'boolean', - default: false - }, - project: { - alias: 'p', - describe: 'TypeScript project file', - type: 'string', - default: path.resolve(__dirname, '../tsc/tsconfig.json') - } - }, function(argv) { - const projectDir = process.cwd(); - const packageJsonPath = path.resolve(projectDir, 'package.json'); - try { - const packageName = require(packageJsonPath).name; - const typeDocPath = require.resolve('typedoc/bin/typedoc'); - rimraf('doc/api.json'); - - const spawn = require( 'child_process' ).spawn; - const typedoc = spawn( 'node', [ typeDocPath, '--json', argv.outFile, '--excludeExternals', '--includeDeclarations', '--mode', 'modules', '--target', 'ES6', '--name', packageName, '--ignoreCompilerErrors', '--tsconfig', argv.project, argv.inDir ] ); - proxySpawned(typedoc, undefined, argv.continueWhenFailed, function(code) { - if (code === 0) { - if (argv.cleanUpInDir) { - rimraf(argv.inDir); - } - } - }); - } catch (e) { - console.error(e.message); - process.exit(1); - } - }) - .command('changelog', 'Generate changelog from commits', { - 'first-release': { - alias: 'f', - describe: 'Is this the first release?', - type: 'boolean', - default: false - } - }, function(argv) { - const standardVersion = require('standard-version'); - standardVersion({ - infile: argv._[1] || path.resolve(process.cwd(), 'doc/CHANGELOG.md'), - message: 'chore(release): prepare release %s', - firstRelease: argv.firstRelease, - tagPrefix: "" - }, function (err) { - process.exit(1); - }); - }).argv; From 6a19be0513c8961078cee161a1205379067be19f Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Mon, 6 Feb 2017 20:50:25 +0100 Subject: [PATCH 3/4] fix(cli): added rimraf to package.json because it's used in cli --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index c2f638d..6a70f74 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "breeze-dag": "^0.1.0", + "rimraf": "^2.5.4", "standard-version": "^4.0.0", "through2": "^2.0.0", "typedoc": "^0.5.1", From 0254d509d8f9e77b59be798fb099ffab85398d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brz=C3=B3ska?= Date: Wed, 8 Feb 2017 19:25:29 +0100 Subject: [PATCH 4/4] fix(index): add "use strict" --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index deff835..e7aea0d 100755 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +"use strict"; const doc = require('./doc'); const dev = require('./dev'); const build = require('./build'); @@ -17,4 +18,3 @@ module.exports = { docShapeDefs: docShapeDefs.shapeDefs, docShape: docShape.shape }; -