Browse Source

feat(create): Generate README file with new projects

Michael Bromley 6 years ago
parent
commit
4e2784f5d1

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

@@ -76,6 +76,7 @@ async function createApp(
         indexSource,
         indexWorkerSource,
         migrationSource,
+        readmeSource,
         populateProducts,
     } = isCi ? await gatherCiUserResponses(root) : await gatherUserResponses(root);
 
@@ -148,20 +149,12 @@ async function createApp(
                     ctx.configFile = srcPathScript('vendure-config');
 
                     fs.writeFile(ctx.configFile, configSource)
+                        .then(() => fs.writeFile(srcPathScript('index'), indexSource))
+                        .then(() => fs.writeFile(srcPathScript('index-worker'), indexWorkerSource))
+                        .then(() => fs.writeFile(rootPathScript('migration'), migrationSource))
+                        .then(() => fs.writeFile(path.join(root, 'README.md'), readmeSource))
                         .then(() => {
-                            subscriber.next(`Created config file`);
-                            return fs.writeFile(srcPathScript('index'), indexSource);
-                        })
-                        .then(() => {
-                            subscriber.next(`Created index file`);
-                            return fs.writeFile(srcPathScript('index-worker'), indexWorkerSource);
-                        })
-                        .then(() => {
-                            subscriber.next(`Created worker file`);
-                            return fs.writeFile(rootPathScript('migration'), migrationSource);
-                        })
-                        .then(() => {
-                            subscriber.next(`Created migration file`);
+                            subscriber.next(`Created files`);
                             if (usingTs) {
                                 return fs.copyFile(
                                     assetPath('tsconfig.template.json'),
@@ -292,7 +285,6 @@ function runPreChecks(name: string | undefined, useNpm: boolean): name is string
  */
 async function createDirectoryStructure(root: string) {
     await fs.ensureDir(path.join(root, 'static', 'email', 'test-emails'));
-    await fs.ensureDir(path.join(root, 'static', 'import-assets'));
     await fs.ensureDir(path.join(root, 'static', 'assets'));
 }
 

+ 21 - 9
packages/create/src/gather-user-responses.ts

@@ -94,15 +94,19 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
         process.exit(0);
     }
 
-    const { indexSource, indexWorkerSource, configSource, migrationSource } = await generateSources(
-        root,
-        answers,
-    );
+    const {
+        indexSource,
+        indexWorkerSource,
+        configSource,
+        migrationSource,
+        readmeSource,
+    } = await generateSources(root, answers);
     return {
         indexSource,
         indexWorkerSource,
         configSource,
         migrationSource,
+        readmeSource,
         usingTs: answers.language === 'ts',
         dbType: answers.dbType,
         populateProducts: answers.populateProducts,
@@ -123,15 +127,19 @@ export async function gatherCiUserResponses(root: string): Promise<UserResponses
         language: 'ts',
         populateProducts: true,
     };
-    const { indexSource, indexWorkerSource, configSource, migrationSource } = await generateSources(
-        root,
-        ciAnswers,
-    );
+    const {
+        indexSource,
+        indexWorkerSource,
+        configSource,
+        migrationSource,
+        readmeSource,
+    } = await generateSources(root, ciAnswers);
     return {
         indexSource,
         indexWorkerSource,
         configSource,
         migrationSource,
+        readmeSource,
         usingTs: ciAnswers.language === 'ts',
         dbType: ciAnswers.dbType,
         populateProducts: ciAnswers.populateProducts,
@@ -149,11 +157,13 @@ async function generateSources(
     indexWorkerSource: string;
     configSource: string;
     migrationSource: string;
+    readmeSource: string;
 }> {
     const assetPath = (fileName: string) => path.join(__dirname, '../assets', fileName);
 
     const templateContext = {
         ...answers,
+        name: path.basename(root),
         isTs: answers.language === 'ts',
         isSQLite: answers.dbType === 'sqlite',
         isSQLjs: answers.dbType === 'sqljs',
@@ -170,7 +180,9 @@ async function generateSources(
     const indexWorkerSource = Handlebars.compile(indexWorkerTemplate)(templateContext);
     const migrationTemplate = await fs.readFile(assetPath('migration.hbs'), 'utf-8');
     const migrationSource = Handlebars.compile(migrationTemplate)(templateContext);
-    return { indexSource, indexWorkerSource, configSource, migrationSource };
+    const readmeTemplate = await fs.readFile(assetPath('readme.hbs'), 'utf-8');
+    const readmeSource = Handlebars.compile(readmeTemplate)(templateContext);
+    return { indexSource, indexWorkerSource, configSource, migrationSource, readmeSource };
 }
 
 function defaultDBPort(dbType: DbType): number {

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

@@ -8,6 +8,7 @@ export interface UserResponses {
     indexWorkerSource: string;
     configSource: string;
     migrationSource: string;
+    readmeSource: string;
 }
 
 export type CliLogLevel = 'silent' | 'info' | 'verbose';

+ 57 - 0
packages/create/templates/readme.hbs

@@ -0,0 +1,57 @@
+# {{ name }}
+
+This project was generated with [`@vendure/create`](https://github.com/vendure-ecommerce/vendure/tree/master/packages/create).
+
+## Directory structure
+
+* `/src` contains the source code of your Vendure server. All your custom code and plugins should reside here.
+* `/static` contains static (non-code) files such as assets (e.g. uploaded images) and email templates.
+
+## Development
+
+```
+yarn start
+# or
+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
+
+```
+yarn build
+# or
+npm run build
+```
+
+will compile the TypeScript sources into the `/dist` directory.{{/if}}
+
+## Migrations
+
+[Migrations](https://www.vendure.io/docs/developer-guide/migrations/) allow safe updates to the database schema.
+
+The following npm scripts can be used to generate migrations:
+
+```
+yarn migration:generate [name]
+# or
+npm run migration:generate [name]
+```
+
+run any pending migrations that have been generated:
+
+```
+yarn migration:run
+# or
+npm run migration:run
+```
+
+and revert the most recently-applied migration:
+
+```
+yarn migration:revert
+# or
+npm run migration:revert
+```