From 3bf7a7ea0b291b85d41c9ec59058c8eaf1320ab5 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sun, 11 Mar 2018 17:00:50 -0400 Subject: [PATCH] feat(CLI): implement strict, immutable, and vscode options --- src/cli/tests/cli.integration.spec.ts | 10 +++--- src/cli/typescript-starter.ts | 46 +++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/cli/tests/cli.integration.spec.ts b/src/cli/tests/cli.integration.spec.ts index a43d770..813d27e 100644 --- a/src/cli/tests/cli.integration.spec.ts +++ b/src/cli/tests/cli.integration.spec.ts @@ -146,7 +146,7 @@ test(`${ 'test-1/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589', 'test-1/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7', 'test-1/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759', - 'test-1/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884', + 'test-1/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a', 'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d', 'test-1/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067' }); @@ -188,7 +188,7 @@ test(`${ 'test-2/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589', 'test-2/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7', 'test-2/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759', - 'test-2/tsconfig.json': '43817952d399db9e44977b3703edd7cf', + 'test-2/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4', 'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d', 'test-2/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067' }); @@ -320,9 +320,9 @@ test(`${ 'test-4/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589', 'test-4/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7', 'test-4/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759', - 'test-4/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884', + 'test-4/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a', 'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d', - 'test-4/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067' + 'test-4/tslint.json': '99f6f8fa763bfc2a32377739b3e5dd5c' }); }); @@ -423,7 +423,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async t => { 'test-6/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589', 'test-6/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7', 'test-6/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759', - 'test-6/tsconfig.json': '43817952d399db9e44977b3703edd7cf', + 'test-6/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4', 'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d', 'test-6/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067' }); diff --git a/src/cli/typescript-starter.ts b/src/cli/typescript-starter.ts index 0c47c53..6279cb9 100644 --- a/src/cli/typescript-starter.ts +++ b/src/cli/typescript-starter.ts @@ -13,13 +13,16 @@ export async function typescriptStarter( description, domDefinitions, email, - install, - projectName, - nodeDefinitions, - runner, fullName, githubUsername, + immutable, + install, + nodeDefinitions, + projectName, repoURL, + runner, + strict, + vscode, workingDirectory }: TypescriptStarterOptions, tasks: Tasks @@ -128,6 +131,7 @@ export async function typescriptStarter( spinnerLicense.succeed(); const spinnerDelete = ora('Deleting unnecessary files').start(); + await del([ join(projectPath, 'examples'), join(projectPath, 'CHANGELOG.md'), @@ -136,15 +140,25 @@ export async function typescriptStarter( join(projectPath, 'src', 'cli'), join(projectPath, 'src', 'types', 'cli.d.ts') ]); + if (!vscode) { + del([join(projectPath, '.vscode')]); + } spinnerDelete.succeed(); - const spinnertsconfigModule = ora('Removing traces of the CLI').start(); + const spinnerTsconfigModule = ora('Removing traces of the CLI').start(); await replace({ files: join(projectPath, 'tsconfig.module.json'), from: /,\s+\/\/ typescript-starter:[\s\S]*"src\/cli\/\*\*\/\*\.ts"/, to: '' }); - spinnertsconfigModule.succeed(); + if (vscode) { + await replace({ + files: join(projectPath, '.vscode', 'launch.json'), + from: /,[\s]*\/\/ --- cut here ---[\s\S]*]/, + to: ']' + }); + } + spinnerTsconfigModule.succeed(); const spinnerReadme = ora('Creating README.md').start(); renameSync( @@ -163,6 +177,16 @@ export async function typescriptStarter( }); spinnerReadme.succeed(); + if (!strict) { + const spinnerStrict = ora(`tsconfig: disable strict`).start(); + await replace({ + files: join(projectPath, 'tsconfig.json'), + from: '"strict": true', + to: '// "strict": true' + }); + spinnerStrict.succeed(); + } + if (!domDefinitions) { const spinnerDom = ora(`tsconfig: don't include "dom" lib`).start(); await replace({ @@ -194,6 +218,16 @@ export async function typescriptStarter( spinnerNode.succeed(); } + if (!immutable) { + const spinnerTslint = ora(`tslint: disable tslint-immutable`).start(); + await replace({ + files: join(projectPath, 'tslint.json'), + from: /,[\s]*\/\* tslint-immutable rules \*\/[\s\S]*\/\* end tslint-immutable rules \*\//, + to: '' + }); + spinnerTslint.succeed(); + } + if (install) { await tasks.install(runner, projectPath); }