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

fix(CLI): automatically remove a CLI-related part of tsconfig.module.json

This commit is contained in:
Jason Dreyzehner
2018-03-11 01:16:18 -05:00
parent 325ebba0da
commit a8e33afe0b
2 changed files with 43 additions and 31 deletions

View File

@@ -147,7 +147,7 @@ test(`${
'test-1/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-1/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-1/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
'test-1/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-1/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});
@@ -189,7 +189,7 @@ test(`${
'test-2/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-2/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-2/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
'test-2/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-2/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});
@@ -231,23 +231,27 @@ async function testInteractive(
proc.stdout.once('data', resolve);
});
await ms(200);
checkBuffer(new RegExp(`typescript-starter.|s*Enter the new package name`));
checkBuffer(
new RegExp(`typescript-starter[\\s\\S]*Enter the new package name`)
);
clearBuffer();
type(`${projectName}${enter}`);
await ms(200);
checkBuffer(new RegExp(`${projectName}.|s*What are you making?`));
checkBuffer(new RegExp(`${projectName}[\\s\\S]*What are you making?`));
clearBuffer();
type(`${entry[0][0]}${enter}`);
await ms(200);
checkBuffer(new RegExp(`${entry[0][1]}.|s*Enter the package description`));
checkBuffer(
new RegExp(`${entry[0][1]}[\\s\\S]*Enter the package description`)
);
clearBuffer();
type(`${entry[1]}${enter}`);
await ms(200);
checkBuffer(new RegExp(`${entry[1]}.|s*npm or yarn?`));
checkBuffer(new RegExp(`${entry[1]}[\\s\\S]*npm or yarn?`));
clearBuffer();
type(`${entry[2][0]}${enter}`);
await ms(200);
const search = `${entry[2][1]}.|s*global type definitions`;
const search = `${entry[2][1]}[\\s\\S]*global type definitions`;
const exp = lastCheck
? new RegExp(`${search}`) // should match
: new RegExp(`(?!${search})`); // should not match
@@ -268,7 +272,7 @@ test(`${
t.plan(7);
const proc = await testInteractive(t, `${TestDirectories.three}`, [
[`${down}${up}${down}`, `Javascript library`],
`integration test 3 description${enter}`,
`integration test 3 description`,
[`${down}${up}${down}${enter}`, `yarn`],
[`${down}${down}${down}${enter}`, `Both Node.js and DOM`]
]);
@@ -282,7 +286,7 @@ test(`${
'test-3/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-3/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-3/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
'test-3/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-3/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-3/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});
@@ -293,7 +297,7 @@ test(`${
t.plan(6);
const proc = await testInteractive(t, `${TestDirectories.four}`, [
[`${down}${up}`, `Node.js application`],
`integration test 4 description${enter}`,
`integration test 4 description`,
[`${down}${up}${enter}`, `npm`]
]);
await proc;
@@ -306,7 +310,7 @@ test(`${
'test-4/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-4/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-4/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
'test-4/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-4/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});
@@ -361,7 +365,7 @@ test(`${
'test-5/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-5/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-5/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
'test-5/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-5/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-5/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});
@@ -399,7 +403,7 @@ test(`${TestDirectories.six}: Sandboxed: pretend to yarn`, async t => {
'test-6/src/lib/number.ts': '43756f90e6ac0b1c4ee6c81d8ab969c7',
'test-6/src/types/example.d.ts': '4221812f6f0434eec77ccb1fba1e3759',
'test-6/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
'test-6/tsconfig.module.json': 'e452fd6ff2580347077ae3fff2443e34',
'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
'test-6/tslint.json': '7ac167ffbcb724a6c270e8dc4e747067'
});
});

View File

@@ -35,7 +35,7 @@ export async function typescriptStarter(
${chalk.dim(`Cloned at commit: ${commitHash}`)}
`);
const spinner1 = ora('Updating package.json').start();
const spinnerPackage = ora('Updating package.json').start();
const projectPath = join(workingDirectory, projectName);
const pkgPath = join(projectPath, 'package.json');
@@ -66,9 +66,9 @@ export async function typescriptStarter(
};
writePackageJson(pkgPath, newPkg);
spinner1.succeed();
spinnerPackage.succeed();
const spinner2 = ora('Updating .gitignore').start();
const spinnerGitignore = ora('Updating .gitignore').start();
if (runner === Runner.Yarn) {
await replace({
files: join(projectPath, '.gitignore'),
@@ -76,25 +76,25 @@ export async function typescriptStarter(
to: 'package-lock.json'
});
}
spinner2.succeed();
spinnerGitignore.succeed();
const spinner3 = ora('Updating .npmignore').start();
const spinnerNpmignore = ora('Updating .npmignore').start();
await replace({
files: join(projectPath, '.npmignore'),
from: 'examples\n',
to: ''
});
spinner3.succeed();
spinnerNpmignore.succeed();
const spinner4 = ora('Updating LICENSE').start();
const spinnerLicense = ora('Updating LICENSE').start();
await replace({
files: join(projectPath, 'LICENSE'),
from: 'Jason Dreyzehner',
to: fullName
});
spinner4.succeed();
spinnerLicense.succeed();
const spinner5 = ora('Deleting unnecessary files').start();
const spinnerDelete = ora('Deleting unnecessary files').start();
await del([
join(projectPath, 'examples'),
join(projectPath, 'CHANGELOG.md'),
@@ -103,9 +103,17 @@ export async function typescriptStarter(
join(projectPath, 'src', 'cli'),
join(projectPath, 'src', 'types', 'cli.d.ts')
]);
spinner5.succeed();
spinnerDelete.succeed();
const spinner6 = ora('Creating README.md').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();
const spinnerReadme = ora('Creating README.md').start();
renameSync(
join(projectPath, 'README-starter.md'),
join(projectPath, 'README.md')
@@ -120,20 +128,20 @@ export async function typescriptStarter(
from: '[description]',
to: description
});
spinner6.succeed();
spinnerReadme.succeed();
if (!domDefinitions) {
const spinner6A = ora(`tsconfig: don't include "dom" lib`).start();
const spinnerDom = ora(`tsconfig: don't include "dom" lib`).start();
await replace({
files: join(projectPath, 'tsconfig.json'),
from: '"lib": ["es2017", "dom"]',
to: '"lib": ["es2017"]'
});
spinner6A.succeed();
spinnerDom.succeed();
}
if (!nodeDefinitions) {
const spinner6B = ora(`tsconfig: don't include "node" types`).start();
const spinnerNode = ora(`tsconfig: don't include "node" types`).start();
await replace({
files: join(projectPath, 'tsconfig.json'),
from: '"types": ["node"]',
@@ -150,7 +158,7 @@ export async function typescriptStarter(
join(projectPath, 'src', 'lib', 'async.ts'),
join(projectPath, 'src', 'lib', 'async.spec.ts')
]);
spinner6B.succeed();
spinnerNode.succeed();
}
if (install) {
@@ -158,9 +166,9 @@ export async function typescriptStarter(
}
if (fullName !== Placeholders.name && email !== Placeholders.email) {
const spinner7 = ora(`Initializing git repository...`).start();
const spinnerGitInit = ora(`Initializing git repository...`).start();
await tasks.initialCommit(commitHash, projectPath, fullName);
spinner7.succeed();
spinnerGitInit.succeed();
}
console.log(`\n${chalk.blue.bold(`Created ${projectName} 🎉`)}\n`);