Skip to content

Commit

Permalink
Split out TS template generation to remove Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
tkcranny committed Oct 4, 2024
1 parent abeac30 commit 7e25a70
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions packages/cli/src/generators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ const writeGenericPackageJson = (gen, packageJsonExtension) => {
);
};

const writeTypeScriptPackageJson = (gen, packageJsonExtension) => {
gen.fs.writeJSON(
gen.destinationPath('package.json'),
merge(
{
name: gen.options.packageName,
version: '1.0.0',
description: '',
main: 'src/index.js',
scripts: {
test: 'vitest',
},
dependencies: {
[PLATFORM_PACKAGE]: PACKAGE_VERSION,
},
devDependencies: {
vitest: '^2.1.2',
},
private: true,
},
packageJsonExtension
)
);
};

const writeGenericIndex = (gen, hasAuth) => {
gen.fs.copyTpl(
gen.templatePath('index.template.js'),
Expand Down Expand Up @@ -116,7 +141,6 @@ const writeForMinimalTemplate = (gen) => {
// example directory
const writeForStandaloneTemplate = (gen) => {
writeGitignore(gen);

writeGenericReadme(gen);
appendReadme(gen);

Expand All @@ -128,6 +152,22 @@ const writeForStandaloneTemplate = (gen) => {
'form-data': '4.0.0',
},
},
}[gen.options.template];

writeGenericPackageJson(gen, packageJsonExtension);

gen.fs.copy(
gen.templatePath(gen.options.template, '**', '*.{js,json,ts}'),
gen.destinationPath()
);
};

const writeForStandaloneTypeScriptTemplate = (gen) => {
writeGitignore(gen);
writeGenericReadme(gen);
appendReadme(gen);

const packageJsonExtension = {
typescript: {
scripts: {
test: 'vitest',
Expand All @@ -137,13 +177,13 @@ const writeForStandaloneTemplate = (gen) => {
},
devDependencies: {
rimraf: '^5.0.10',
typescript: '5.5.4',
vitest: '^2.0.5',
typescript: '5.6.2',
vitest: '^2.1.2',
},
},
}[gen.options.template];

writeGenericPackageJson(gen, packageJsonExtension);
writeTypeScriptPackageJson(gen, packageJsonExtension);

gen.fs.copy(
gen.templatePath(gen.options.template, '**', '*.{js,json,ts}'),
Expand All @@ -163,7 +203,7 @@ const TEMPLATE_ROUTES = {
oauth2: writeForAuthTemplate,
'search-or-create': writeForStandaloneTemplate,
'session-auth': writeForAuthTemplate,
typescript: writeForStandaloneTemplate,
typescript: writeForStandaloneTypeScriptTemplate,
};

const TEMPLATE_CHOICES = Object.keys(TEMPLATE_ROUTES);
Expand Down

0 comments on commit 7e25a70

Please sign in to comment.