Browse Source

feat(create): Simplify create steps - remove JS option

Offering JS as an option doesn't make much sense - sure the initial project will build, but actually
creating anything non-trivial in JS without decorators support is, in practical terms, painful.

We don't provide _any_ documentation on e.g. how to define a plugin with pure JS - it's just not
practical. So offering the JS option on project creation is a red herring and is also dishonest
in the sense that it seems to suggest we support it.
Michael Bromley 3 years ago
parent
commit
73b4671388

+ 14 - 22
packages/create/src/create-vendure-app.ts

@@ -87,7 +87,6 @@ async function createApp(
     }
     const {
         dbType,
-        usingTs,
         configSource,
         indexSource,
         indexWorkerSource,
@@ -108,13 +107,13 @@ async function createApp(
         version: '0.1.0',
         private: true,
         scripts: {
-            'run:server': usingTs ? 'ts-node ./src/index.ts' : 'node ./src/index.js',
-            'run:worker': usingTs ? 'ts-node ./src/index-worker.ts' : 'node ./src/index-worker.js',
+            'run:server': 'ts-node ./src/index.ts',
+            'run:worker': 'ts-node ./src/index-worker.ts',
             start: useYarn ? 'concurrently yarn:run:*' : 'concurrently npm:run:*',
-            ...(usingTs ? { build: 'tsc' } : undefined),
-            'migration:generate': usingTs ? 'ts-node migration generate' : 'node migration generate',
-            'migration:run': usingTs ? 'ts-node migration run' : 'node migration run',
-            'migration:revert': usingTs ? 'ts-node migration revert' : 'node migration revert',
+            build: 'tsc',
+            'migration:generate': 'ts-node migration generate',
+            'migration:run': 'ts-node migration run',
+            'migration:revert': 'ts-node migration revert',
         },
     };
 
@@ -123,10 +122,8 @@ async function createApp(
     console.log('This may take a few minutes...');
     console.log();
 
-    const rootPathScript = (fileName: string): string =>
-        path.join(root, `${fileName}.${usingTs ? 'ts' : 'js'}`);
-    const srcPathScript = (fileName: string): string =>
-        path.join(root, 'src', `${fileName}.${usingTs !== false ? 'ts' : 'js'}`);
+    const rootPathScript = (fileName: string): string => path.join(root, `${fileName}.ts`);
+    const srcPathScript = (fileName: string): string => path.join(root, 'src', `${fileName}.ts`);
 
     const listrTasks: Listr.ListrTask[] = [];
     if (scaffoldExists) {
@@ -143,7 +140,6 @@ async function createApp(
                             JSON.stringify(packageJsonContents, null, 2) + os.EOL,
                         );
                         const { dependencies, devDependencies } = getDependencies(
-                            usingTs,
                             dbType,
                             isCi ? `@${packageJson.version}` : '',
                         );
@@ -186,12 +182,10 @@ async function createApp(
                             )
                             .then(() => {
                                 subscriber.next(`Created files`);
-                                if (usingTs) {
-                                    return fs.copyFile(
-                                        assetPath('tsconfig.template.json'),
-                                        path.join(root, 'tsconfig.json'),
-                                    );
-                                }
+                                return fs.copyFile(
+                                    assetPath('tsconfig.template.json'),
+                                    path.join(root, 'tsconfig.json'),
+                                );
                             })
                             .then(() => createDirectoryStructure(root))
                             .then(() => {
@@ -212,10 +206,8 @@ async function createApp(
         title: 'Initializing server',
         task: async ctx => {
             try {
-                if (usingTs) {
-                    // register ts-node so that the config file can be loaded
-                    require(path.join(root, 'node_modules/ts-node')).register();
-                }
+                // register ts-node so that the config file can be loaded
+                require(path.join(root, 'node_modules/ts-node')).register();
                 const { populate } = await import(path.join(root, 'node_modules/@vendure/core/cli/populate'));
                 const { bootstrap, DefaultLogger, LogLevel, JobQueueService } = await import(
                     path.join(root, 'node_modules/@vendure/core/dist/index')

+ 0 - 19
packages/create/src/gather-user-responses.ts

@@ -87,16 +87,6 @@ export async function gatherUserResponses(root: string, alreadyRanScaffold: bool
     ];
 
     const initPrompts: Array<prompts.PromptObject<any>> = [
-        {
-            type: 'select',
-            name: 'language',
-            message: 'Which programming language will you be using?',
-            choices: [
-                { title: 'TypeScript', value: 'ts' },
-                { title: 'JavaScript', value: 'js' },
-            ],
-            initial: 0 as any,
-        },
         {
             type: 'toggle',
             name: 'populateProducts',
@@ -114,11 +104,6 @@ export async function gatherUserResponses(root: string, alreadyRanScaffold: bool
         },
     });
 
-    if (!answers.language) {
-        console.log('Setup aborted. No changes made');
-        process.exit(0);
-    }
-
     const { indexSource, indexWorkerSource, configSource, migrationSource, readmeSource } =
         await generateSources(root, answers);
     return {
@@ -127,7 +112,6 @@ export async function gatherUserResponses(root: string, alreadyRanScaffold: bool
         configSource,
         migrationSource,
         readmeSource,
-        usingTs: answers.language !== 'js',
         dbType: answers.dbType,
         populateProducts: answers.populateProducts,
         superadminIdentifier: answers.superadminIdentifier,
@@ -146,7 +130,6 @@ export async function gatherCiUserResponses(root: string): Promise<UserResponses
         dbName: 'vendure',
         dbUserName: '',
         dbPassword: '',
-        language: 'ts',
         populateProducts: true,
         superadminIdentifier: SUPER_ADMIN_USER_IDENTIFIER,
         superadminPassword: SUPER_ADMIN_USER_PASSWORD,
@@ -159,7 +142,6 @@ export async function gatherCiUserResponses(root: string): Promise<UserResponses
         configSource,
         migrationSource,
         readmeSource,
-        usingTs: ciAnswers.language === 'ts',
         dbType: ciAnswers.dbType,
         populateProducts: ciAnswers.populateProducts,
         superadminIdentifier: ciAnswers.superadminIdentifier,
@@ -195,7 +177,6 @@ async function generateSources(
         ...answers,
         dbType: answers.dbType === 'sqlite' ? 'better-sqlite3' : answers.dbType,
         name: path.basename(root),
-        isTs: answers.language === 'ts',
         isSQLite: answers.dbType === 'sqlite',
         isSQLjs: answers.dbType === 'sqljs',
         requiresConnection: answers.dbType !== 'sqlite' && answers.dbType !== 'sqljs',

+ 2 - 7
packages/create/src/helpers.ts

@@ -239,7 +239,6 @@ export function installPackages(
 }
 
 export function getDependencies(
-    usingTs: boolean,
     dbType: DbType,
     vendurePkgVersion = '',
 ): { dependencies: string[]; devDependencies: string[] } {
@@ -249,13 +248,9 @@ export function getDependencies(
         `@vendure/asset-server-plugin${vendurePkgVersion}`,
         `@vendure/admin-ui-plugin${vendurePkgVersion}`,
         dbDriverPackage(dbType),
+        `typescript@${TYPESCRIPT_VERSION}`,
     ];
-    const devDependencies = ['concurrently'];
-    if (usingTs) {
-        devDependencies.push('ts-node');
-        dependencies.push(`typescript@${TYPESCRIPT_VERSION}`);
-    }
-
+    const devDependencies = ['concurrently', 'ts-node'];
     return { dependencies, devDependencies };
 }
 

+ 0 - 1
packages/create/src/types.ts

@@ -1,7 +1,6 @@
 export type DbType = 'mysql' | 'mariadb' | 'postgres' | 'sqlite' | 'sqljs' | 'mssql' | 'oracle';
 
 export interface UserResponses {
-    usingTs: boolean;
     dbType: DbType;
     populateProducts: boolean;
     indexSource: string;

+ 6 - 7
packages/create/templates/index-worker.hbs

@@ -1,9 +1,8 @@
-{{#if isTs }}import { bootstrapWorker } from '@vendure/core';{{else}}const { bootstrapWorker } = require('@vendure/core');{{/if}}
-{{#if isTs }}import { config } from './vendure-config';{{else}}const { config } = require('./vendure-config');{{/if}}
+import { bootstrapWorker } from '@vendure/core';
+import { config } from './vendure-config';
 
 bootstrapWorker(config)
-.then(worker => worker.startJobQueue())
-.catch(err => {
-    // tslint:disable-next-line:no-console
-    console.log(err);
-});
+    .then(worker => worker.startJobQueue())
+    .catch(err => {
+        console.log(err);
+    });

+ 2 - 3
packages/create/templates/index.hbs

@@ -1,7 +1,6 @@
-{{#if isTs }}import { bootstrap } from '@vendure/core';{{else}}const { bootstrap } = require('@vendure/core');{{/if}}
-{{#if isTs }}import { config } from './vendure-config';{{else}}const { config } = require('./vendure-config');{{/if}}
+import { bootstrap } from '@vendure/core';
+import { config } from './vendure-config';
 
 bootstrap(config).catch(err => {
-    // tslint:disable-next-line:no-console
     console.log(err);
 });

+ 3 - 3
packages/create/templates/migration.hbs

@@ -1,7 +1,7 @@
-{{#if isTs }}import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';{{else}}const { generateMigration, revertLastMigration, runMigrations } = require('@vendure/core');{{/if}}
-{{#if isTs }}import program from 'commander';{{else}}const program = require('commander');{{/if}}
+import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';
+import program from 'commander';
 
-{{#if isTs }}import { config } from './src/vendure-config';{{else}}const { config } = require('./src/vendure-config');{{/if}}
+import { config } from './src/vendure-config';
 
 program
     .command('generate <name>')

+ 2 - 2
packages/create/templates/readme.hbs

@@ -18,7 +18,7 @@ npm run start
 will start the Vendure server and [worker](https://www.vendure.io/docs/developer-guide/vendure-worker/) processes from
 the `src` directory.
 
-{{#if isTs}}## Build
+## Build
 
 ```
 yarn build
@@ -26,7 +26,7 @@ yarn build
 npm run build
 ```
 
-will compile the TypeScript sources into the `/dist` directory.{{/if}}
+will compile the TypeScript sources into the `/dist` directory.
 
 ## Migrations
 

+ 7 - 28
packages/create/templates/vendure-config.hbs

@@ -1,45 +1,29 @@
-{{#if isTs }}import{{ else }}const{{/if}} {
+import {
     dummyPaymentHandler,
     DefaultJobQueuePlugin,
-    DefaultSearchPlugin,{{#if isTs}}
-    VendureConfig,{{/if}}
-} {{#if isTs}}from '@vendure/core'; {{ else }}= require('@vendure/core');{{/if}}
-{{#if isTs }}
+    DefaultSearchPlugin,
+    VendureConfig,
+} from '@vendure/core';
 import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
-{{ else }}
-const { defaultEmailHandlers, EmailPlugin } = require('@vendure/email-plugin');
-{{/if}}
-{{#if isTs }}
 import { AssetServerPlugin } from '@vendure/asset-server-plugin';
-{{ else }}
-const { AssetServerPlugin } = require('@vendure/asset-server-plugin');
-{{/if}}
-{{#if isTs }}
 import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
-{{ else }}
-const { AdminUiPlugin } = require('@vendure/admin-ui-plugin');
-{{/if}}
-{{#if isTs }}
 import path from 'path';
-{{ else }}
-const path = require('path');
-{{/if}}
 
-{{#if isTs}}export {{/if}}const config{{#if isTs}}: VendureConfig{{/if}} = {
+export const config: VendureConfig = {
     apiOptions: {
         port: 3000,
         adminApiPath: 'admin-api',
         adminApiPlayground: {
             settings: {
                 'request.credentials': 'include',
-            }{{#if isTs}} as any{{/if}},
+            } as any,
         },// turn this off for production
         adminApiDebug: true, // turn this off for production
         shopApiPath: 'shop-api',
         shopApiPlayground: {
             settings: {
                 'request.credentials': 'include',
-            }{{#if isTs}} as any{{/if}},
+            } as any,
         },// turn this off for production
         shopApiDebug: true,// turn this off for production
     },
@@ -103,8 +87,3 @@ const path = require('path');
         }),
     ],
 };
-{{#if isTs}}
-{{else}}
-
-module.exports = { config };
-{{/if}}