Browse Source

feat(create): Set an env variable during the create process

Michael Bromley 6 years ago
parent
commit
b085e495db

+ 5 - 0
packages/common/src/shared-constants.ts

@@ -14,3 +14,8 @@ export const CUSTOMER_ROLE_CODE = '__customer_role__';
 export const CUSTOMER_ROLE_DESCRIPTION = 'Customer';
 export const ROOT_COLLECTION_NAME = '__root_collection__';
 
+// An environment variable which is set when the @vendure/create
+// script is run. Can be used to modify normal behaviour
+// to fit with the initial create task.
+export type CREATING_VENDURE_APP = 'CREATING_VENDURE_APP';
+export const CREATING_VENDURE_APP: CREATING_VENDURE_APP = 'CREATING_VENDURE_APP';

+ 7 - 0
packages/create/src/create-vendure-app.ts

@@ -27,6 +27,11 @@ checkNodeVersion(REQUIRED_NODE_VERSION);
 
 let projectName: string | undefined;
 
+// Set the environment variable which can then be used to
+// conditionally modify behaviour of core or plugins.
+const createEnvVar: import('@vendure/common/src/shared-constants').CREATING_VENDURE_APP = 'CREATING_VENDURE_APP';
+process.env[createEnvVar] = 'true';
+
 program
     .version(packageJson.version)
     .arguments('<project-directory>')
@@ -50,6 +55,8 @@ async function createApp(name: string | undefined, useNpm: boolean, logLevel: Lo
         return;
     }
 
+    console.log(`Welcome to @vendure/create v${packageJson.version}!`);
+    console.log();
     console.log(`Let's configure a new Vendure project. First a few questions:`);
     console.log();