Skip to content

Commit

Permalink
feat: update turbo and package for migrations to apply on vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike committed Nov 14, 2024
1 parent ff4702d commit d40ce80
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { execAsync } from '../../../utils/execAsync';
import { logger } from '../../../utils/logger';

export const createMigration = async () => {
logger.withSpinner('payload', 'Creating migration...', async (spinner) => {
try {
execAsync('mkdir migrations');
execAsync('npx payload migrate:create');
spinner.succeed('Migration created.');
} catch (error) {
spinner.fail('Failed to create migration.');
console.error(error);
}
});
};
8 changes: 5 additions & 3 deletions packages/core/installMachine/installSteps/payload/install.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { preparePayloadConfig } from './preparePayloadConfig';
import { prepareTsConfig } from './prepareTsConfig';
import { removeTurboFlag } from './removeTurboFlag';
import { updatePackages } from './updatePackages';
import { moveFilesToAppDir } from './moveFilesToAppDir';
import { runInstallCommand } from './runInstallCommand';
import { createMigration } from './createMigration';
import { updatePackageJson } from './updatePackageJson';
import { preparePayloadConfig } from './preparePayloadConfig';

export const preparePayload = async () => {
process.chdir('./apps/web/');
Expand All @@ -12,7 +13,8 @@ export const preparePayload = async () => {
await updatePackages();
await moveFilesToAppDir();
await runInstallCommand();
await removeTurboFlag();
await createMigration();
await updatePackageJson();
await preparePayloadConfig();

process.chdir('../../');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { promises as fs } from 'fs';
import path from 'path';
import { logger } from '../../../utils/logger';

export const updatePackageJson = async () => {
const packageJsonPath = path.resolve('package.json');
logger.withSpinner('payload', 'Updating package.json...', async (spinner) => {
try {
// Read and parse package.json
const packageData = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));

// Add db script to package.json
packageData.scripts = {
...packageData.scripts,
'db:migrate': 'npx payload migrate',
};

// Payload doesn't work with Turbopack yet
// Remove '--turbo' flag from the "dev" script
if (packageData.scripts && packageData.scripts.dev) {
packageData.scripts.dev = packageData.scripts.dev.replace('--turbo', '').trim();
}

// Write the modified package.json
await fs.writeFile(packageJsonPath, JSON.stringify(packageData, null, 2));
spinner.succeed('Updated package.json');
} catch (error) {
spinner.fail('Failed to update package.json');
console.error('Error updating files:', error);
}
});
};

0 comments on commit d40ce80

Please sign in to comment.