1
0
mirror of synced 2025-11-08 12:57:47 +00:00

fix(CLI): automatically remove the CLI's dependencies

This commit is contained in:
Jason Dreyzehner
2018-03-11 03:08:00 -04:00
parent b08c6384de
commit 11509cf1cb
2 changed files with 42 additions and 9 deletions

View File

@@ -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',

View File

@@ -39,22 +39,50 @@ export async function typescriptStarter(
const projectPath = join(workingDirectory, projectName);
const pkgPath = join(projectPath, 'package.json');
const keptDevDeps: ReadonlyArray<string> = [
'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<any> = ['sha.js'];
const nodeKeptDeps: ReadonlyArray<string> = ['sha.js'];
const filterAllBut = (
keep: ReadonlyArray<string>,
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();