Skip to content

Commit

Permalink
build: support codesandbox when make env
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Aug 23, 2022
1 parent 8d5d6af commit 77ddf4c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions scripts/make-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,26 @@ 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',
});
execSync('pnpm --filter=@codeimage/api prisma:migrate:deploy-test', {
stdio: 'inherit',
});
execSync('pnpm --filter=@codeimage/api prisma:generate', {
stdio: 'inherit',
});
}
}

Expand All @@ -200,7 +206,7 @@ function writeEnv(env: Record<string, string | number | boolean>, dir: string) {
}

async function askForBackup(dir: string) {
if (!fs.existsSync(dir)) {
if (runOnCodeSandbox || !fs.existsSync(dir)) {
return;
}

Expand All @@ -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}>({
Expand Down

0 comments on commit 77ddf4c

Please sign in to comment.