From 7e25a70a8c478be4868e7f370eaaebd4e982c8db Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Fri, 4 Oct 2024 15:26:25 +1000 Subject: [PATCH] Split out TS template generation to remove Jest --- packages/cli/src/generators/index.js | 50 +++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/generators/index.js b/packages/cli/src/generators/index.js index 9602a4686..4a8dfe9b8 100644 --- a/packages/cli/src/generators/index.js +++ b/packages/cli/src/generators/index.js @@ -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'), @@ -116,7 +141,6 @@ const writeForMinimalTemplate = (gen) => { // example directory const writeForStandaloneTemplate = (gen) => { writeGitignore(gen); - writeGenericReadme(gen); appendReadme(gen); @@ -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', @@ -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}'), @@ -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);