From 11509cf1cb954be61db28a5a4adc5ff01ef2a564 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sun, 11 Mar 2018 03:08:00 -0400 Subject: [PATCH] fix(CLI): automatically remove the CLI's dependencies --- src/cli/tests/cli.integration.spec.ts | 4 +-- src/cli/typescript-starter.ts | 47 +++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/cli/tests/cli.integration.spec.ts b/src/cli/tests/cli.integration.spec.ts index 776e6c8..634cd16 100644 --- a/src/cli/tests/cli.integration.spec.ts +++ b/src/cli/tests/cli.integration.spec.ts @@ -366,7 +366,7 @@ test(`${ 'test-5/LICENSE': 'd11b4dba04062af8bd80b052066daf1c', 'test-5/README.md': '8fc7ecb21d7d47289e4b2469eea4db39', 'test-5/bin/typescript-starter': 'a4ad3923f37f50df986b43b1adb9f6b3', - 'test-5/package.json': '862946a9f0efa84f37a5124e6f7e3aae', + 'test-5/package.json': '4095a1229e363a8f7152a18a5fd910db', 'test-5/src/index.ts': '5991bedc40ac87a01d880c6db16fe349', 'test-5/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589', 'test-5/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7', @@ -403,7 +403,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async t => { 'test-6/LICENSE': '1dfe8c78c6af40fc14ea3b40133f1fa5', 'test-6/README.md': 'd809bcbf240f44b51b575a3d49936232', 'test-6/bin/typescript-starter': 'a4ad3923f37f50df986b43b1adb9f6b3', - 'test-6/package.json': 'd411b162cf46ac1e49a5867a130a0b05', + 'test-6/package.json': '4e77e79b8944203aaaf11f28a69e4fce', 'test-6/src/index.ts': 'fbc67c2cbf3a7d37e4e02583bf06eec9', 'test-6/src/lib/async.spec.ts': '1e83b84de3f3b068244885219acb42bd', 'test-6/src/lib/async.ts': '9012c267bb25fa98ad2561929de3d4e2', diff --git a/src/cli/typescript-starter.ts b/src/cli/typescript-starter.ts index 826a350..0c47c53 100644 --- a/src/cli/typescript-starter.ts +++ b/src/cli/typescript-starter.ts @@ -39,22 +39,50 @@ export async function typescriptStarter( const projectPath = join(workingDirectory, projectName); const pkgPath = join(projectPath, 'package.json'); + const keptDevDeps: ReadonlyArray = [ + 'ava', + 'codecov', + 'cz-conventional-changelog', + 'gh-pages', + 'npm-run-all', + 'npm-scripts-info', + 'nsp', + 'nyc', + 'opn-cli', + 'prettier', + 'standard-version', + 'trash-cli', + 'tslint', + 'tslint-config-prettier', + 'tslint-immutable', + 'typedoc', + 'typescript' + ]; + // dependencies to retain for Node.js applications - const nodeKeptDeps: ReadonlyArray = ['sha.js']; + const nodeKeptDeps: ReadonlyArray = ['sha.js']; + + const filterAllBut = ( + keep: ReadonlyArray, + from: { readonly [module: string]: number } + ) => + keep.reduce<{ readonly [module: string]: number }>( + (acc, moduleName: string) => { + return { ...acc, [moduleName]: from[moduleName] }; + }, + {} + ); const pkg = readPackageJson(pkgPath); const newPkg = { ...pkg, - bin: {}, dependencies: nodeDefinitions - ? nodeKeptDeps.reduce((all, dep) => { - return { ...all, [dep]: pkg.dependencies[dep] }; - }, {}) + ? filterAllBut(nodeKeptDeps, pkg.dependencies) : {}, description, + devDependencies: filterAllBut(keptDevDeps, pkg.devDependencies), keywords: [], - projectName, - repository: `https:// github.com/${githubUsername}/${projectName}`, + repository: `https://github.com/${githubUsername}/${projectName}`, scripts: runner === Runner.Yarn ? { @@ -65,6 +93,11 @@ export async function typescriptStarter( version: '1.0.0' }; + // tslint:disable:no-delete no-object-mutation + delete newPkg.bin; + delete newPkg.NOTE; + // tslint:enable:no-delete no-object-mutation + writePackageJson(pkgPath, newPkg); spinnerPackage.succeed();