Browse Source

feat(create): Add ci option to test installs

Michael Bromley 6 years ago
parent
commit
c2c7b823dc

+ 2 - 13
.github/workflows/publish_and_install.yml

@@ -11,7 +11,6 @@ jobs:
   publish_install:
 
     runs-on: ubuntu-latest
-
     #services:
     #  verdaccio:
     #    image: verdaccio/verdaccio
@@ -19,7 +18,6 @@ jobs:
     #      - 4873
     #    # volumes:
     #    #   - "./verdaccio:/verdaccio/conf"
-
     steps:
     - uses: actions/checkout@v1
     - name: Use Node.js 12.x
@@ -39,11 +37,6 @@ jobs:
         cp -v ./.github/workflows/verdaccio/config.yaml $HOME/.config/verdaccio/config.yaml
         verdaccio --config $HOME/.config/verdaccio/config.yaml &
         sleep 10s
-    # - name: Bump version
-    #   env:
-    #     VERSION: 0.0.0-ci.${{ GITHUB_SHA }}
-    #   run: |
-    #     yarn lerna version $VERSION --no-push --no-commit-hooks
     - name: Publish to Verdaccio
       env:
         #VERDACCIO_URL: http://localhost:${{ job.services.verdaccio.ports['4873'] }}
@@ -53,13 +46,9 @@ jobs:
         npm set //localhost:4873/:_authToken=${{ secrets.VERDACCIO_AUTH_TOKEN }}
         npm set registry=http://localhost:4873/
         yarn lerna publish prepatch --preid ci --no-push --no-git-tag-version --no-commit-hooks --yes --dist-tag ci --registry http://localhost:4873/
-      # cd scripts
-      # chmod +x publish-to-verdaccio.sh
-      # ./publish-to-verdaccio.sh
-    - name: Install from Verdaccio
+    - name: Install via @vendure/create
       run: |
         mkdir -p $HOME/install
         cd $HOME/install
-        yarn init -y
-        yarn add @vendure/core@ci --registry http://localhost:4873/
+        npx @vendure/create test-app --ci --registry http://localhost:4873/
 

+ 12 - 11
packages/create/src/create-vendure-app.ts

@@ -8,7 +8,7 @@ import os from 'os';
 import path from 'path';
 import { Observable } from 'rxjs';
 
-import { gatherUserResponses } from './gather-user-responses';
+import { gatherCiUserResponses, gatherUserResponses } from './gather-user-responses';
 import {
     checkDbConnection,
     checkNodeVersion,
@@ -47,11 +47,17 @@ program
         'silent',
     )
     .option('--use-npm', 'Uses npm rather than Yarn as the default package manager')
+    .option('--ci', 'Runs without prompts for use in CI scenarios')
     .parse(process.argv);
 
-createApp(projectName, program.useNpm, program.logLevel || 'silent');
+createApp(projectName, program.useNpm, program.logLevel || 'silent', program.ci);
 
-async function createApp(name: string | undefined, useNpm: boolean, logLevel: CliLogLevel) {
+async function createApp(
+    name: string | undefined,
+    useNpm: boolean,
+    logLevel: CliLogLevel,
+    isCi: boolean = false,
+) {
     if (!runPreChecks(name, useNpm)) {
         return;
     }
@@ -63,14 +69,9 @@ async function createApp(name: string | undefined, useNpm: boolean, logLevel: Cl
 
     const root = path.resolve(name);
     const appName = path.basename(root);
-    const {
-        dbType,
-        usingTs,
-        configSource,
-        indexSource,
-        indexWorkerSource,
-        populateProducts,
-    } = await gatherUserResponses(root);
+    const { dbType, usingTs, configSource, indexSource, indexWorkerSource, populateProducts } = isCi
+        ? await gatherCiUserResponses(root)
+        : await gatherUserResponses(root);
 
     const useYarn = useNpm ? false : shouldUseYarn();
     const originalDirectory = process.cwd();

+ 29 - 1
packages/create/src/gather-user-responses.ts

@@ -105,10 +105,38 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
     };
 }
 
+/**
+ * Returns mock "user response" without prompting, for use in CI
+ */
+export async function gatherCiUserResponses(root: string): Promise<UserResponses> {
+    const ciAnswers = {
+        dbType: 'sqlite' as const,
+        dbHost: '',
+        dbPort: '',
+        dbName: 'vendure',
+        dbUserName: '',
+        dbPassword: '',
+        language: 'ts',
+        populateProducts: true,
+    };
+    const { indexSource, indexWorkerSource, configSource } = await generateSources(root, ciAnswers);
+    return {
+        indexSource,
+        indexWorkerSource,
+        configSource,
+        usingTs: ciAnswers.language === 'ts',
+        dbType: ciAnswers.dbType,
+        populateProducts: ciAnswers.populateProducts,
+    };
+}
+
 /**
  * Create the server index, worker and config source code based on the options specified by the CLI prompts.
  */
-async function generateSources(root: string, answers: any): Promise<{ indexSource: string; indexWorkerSource: string; configSource: string; }> {
+async function generateSources(
+    root: string,
+    answers: any,
+): Promise<{ indexSource: string; indexWorkerSource: string; configSource: string }> {
     const assetPath = (fileName: string) => path.join(__dirname, '../assets', fileName);
 
     const templateContext = {