From 77ddf4c5b37f8e311abec0164188b8f9c7d1773c Mon Sep 17 00:00:00 2001 From: Riccardo Perra Date: Tue, 23 Aug 2022 18:27:39 +0000 Subject: [PATCH] build: support codesandbox when make env --- scripts/make-env.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/make-env.ts b/scripts/make-env.ts index 3e20d669a..1aac0983b 100644 --- a/scripts/make-env.ts +++ b/scripts/make-env.ts @@ -175,13 +175,16 @@ async function buildApiTestEnv() { } async function askForPrismaMigrations() { - const {runMigrations} = await prompt<{runMigrations: boolean}>({ - type: 'confirm', - name: 'runMigrations', - message: 'Do you want to run prisma migrations? (recommended)', - initial: true, - }); - + let runMigrations = true; + if (!runOnCodeSandbox) { + const data = await prompt<{runMigrations: boolean}>({ + type: 'confirm', + name: 'runMigrations', + message: 'Do you want to run prisma migrations? (recommended)', + initial: true, + }); + runMigrations = data.runMigrations; + } if (runMigrations) { execSync('pnpm --filter=@codeimage/api prisma:migrate:deploy', { stdio: 'inherit', @@ -189,6 +192,9 @@ async function askForPrismaMigrations() { execSync('pnpm --filter=@codeimage/api prisma:migrate:deploy-test', { stdio: 'inherit', }); + execSync('pnpm --filter=@codeimage/api prisma:generate', { + stdio: 'inherit', + }); } } @@ -200,7 +206,7 @@ function writeEnv(env: Record, dir: string) { } async function askForBackup(dir: string) { - if (!fs.existsSync(dir)) { + if (runOnCodeSandbox || !fs.existsSync(dir)) { return; } @@ -220,6 +226,13 @@ async function askForBackup(dir: string) { async function askIfWantOverride( filePath: string, ): Promise<{override: boolean; exists: boolean}> { + if (runOnCodeSandbox) { + return { + exists: false, + override: true, + }; + } + if (fs.existsSync(filePath)) { const fileName = path.basename(filePath); const result = await prompt<{override: boolean}>({