Skip to content

Commit 3bf7a7e

Browse files
committed
feat(CLI): implement strict, immutable, and vscode options
1 parent 583915a commit 3bf7a7e

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

src/cli/tests/cli.integration.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ test(`${
146146
'test-1/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589',
147147
'test-1/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
148148
'test-1/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
149-
'test-1/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
149+
'test-1/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a',
150150
'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
151151
'test-1/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
152152
});
@@ -188,7 +188,7 @@ test(`${
188188
'test-2/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589',
189189
'test-2/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
190190
'test-2/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
191-
'test-2/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
191+
'test-2/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
192192
'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
193193
'test-2/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
194194
});
@@ -320,9 +320,9 @@ test(`${
320320
'test-4/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589',
321321
'test-4/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
322322
'test-4/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
323-
'test-4/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
323+
'test-4/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a',
324324
'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
325-
'test-4/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
325+
'test-4/tslint.json': '99f6f8fa763bfc2a32377739b3e5dd5c'
326326
});
327327
});
328328

@@ -423,7 +423,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async t => {
423423
'test-6/src/lib/number.spec.ts': '40ebb014eb7871d1f810c618aba1d589',
424424
'test-6/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
425425
'test-6/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
426-
'test-6/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
426+
'test-6/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
427427
'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
428428
'test-6/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
429429
});

src/cli/typescript-starter.ts

+40-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ export async function typescriptStarter(
1313
description,
1414
domDefinitions,
1515
email,
16-
install,
17-
projectName,
18-
nodeDefinitions,
19-
runner,
2016
fullName,
2117
githubUsername,
18+
immutable,
19+
install,
20+
nodeDefinitions,
21+
projectName,
2222
repoURL,
23+
runner,
24+
strict,
25+
vscode,
2326
workingDirectory
2427
}: TypescriptStarterOptions,
2528
tasks: Tasks
@@ -128,6 +131,7 @@ export async function typescriptStarter(
128131
spinnerLicense.succeed();
129132

130133
const spinnerDelete = ora('Deleting unnecessary files').start();
134+
131135
await del([
132136
join(projectPath, 'examples'),
133137
join(projectPath, 'CHANGELOG.md'),
@@ -136,15 +140,25 @@ export async function typescriptStarter(
136140
join(projectPath, 'src', 'cli'),
137141
join(projectPath, 'src', 'types', 'cli.d.ts')
138142
]);
143+
if (!vscode) {
144+
del([join(projectPath, '.vscode')]);
145+
}
139146
spinnerDelete.succeed();
140147

141-
const spinnertsconfigModule = ora('Removing traces of the CLI').start();
148+
const spinnerTsconfigModule = ora('Removing traces of the CLI').start();
142149
await replace({
143150
files: join(projectPath, 'tsconfig.module.json'),
144151
from: /,\s+\/\/ typescript-starter:[\s\S]*"src\/cli\/\*\*\/\*\.ts"/,
145152
to: ''
146153
});
147-
spinnertsconfigModule.succeed();
154+
if (vscode) {
155+
await replace({
156+
files: join(projectPath, '.vscode', 'launch.json'),
157+
from: /,[\s]*\/\/ --- cut here ---[\s\S]*]/,
158+
to: ']'
159+
});
160+
}
161+
spinnerTsconfigModule.succeed();
148162

149163
const spinnerReadme = ora('Creating README.md').start();
150164
renameSync(
@@ -163,6 +177,16 @@ export async function typescriptStarter(
163177
});
164178
spinnerReadme.succeed();
165179

180+
if (!strict) {
181+
const spinnerStrict = ora(`tsconfig: disable strict`).start();
182+
await replace({
183+
files: join(projectPath, 'tsconfig.json'),
184+
from: '"strict": true',
185+
to: '// "strict": true'
186+
});
187+
spinnerStrict.succeed();
188+
}
189+
166190
if (!domDefinitions) {
167191
const spinnerDom = ora(`tsconfig: don't include "dom" lib`).start();
168192
await replace({
@@ -194,6 +218,16 @@ export async function typescriptStarter(
194218
spinnerNode.succeed();
195219
}
196220

221+
if (!immutable) {
222+
const spinnerTslint = ora(`tslint: disable tslint-immutable`).start();
223+
await replace({
224+
files: join(projectPath, 'tslint.json'),
225+
from: /,[\s]*\/\* tslint-immutable rules \*\/[\s\S]*\/\* end tslint-immutable rules \*\//,
226+
to: ''
227+
});
228+
spinnerTslint.succeed();
229+
}
230+
197231
if (install) {
198232
await tasks.install(runner, projectPath);
199233
}

0 commit comments

Comments
 (0)