mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
build: allow node package depends on workspace packages (#11892)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { appendFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, parse } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { Logger } from '@nestjs/common';
|
||||
@@ -45,15 +45,21 @@ export class CreateCommand extends CommandRunner {
|
||||
|
||||
const timestamp = Date.now();
|
||||
const content = this.createScript(upperFirst(camelCase(name)) + timestamp);
|
||||
const fileName = `${timestamp}-${kebabCase(name)}.ts`;
|
||||
const filePath = join(
|
||||
const migrationDir = join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'../../migrations',
|
||||
fileName
|
||||
'../../migrations'
|
||||
);
|
||||
const fileName = `${timestamp}-${kebabCase(name)}.ts`;
|
||||
const filePath = join(migrationDir, fileName);
|
||||
|
||||
this.logger.log(`Creating ${fileName}...`);
|
||||
writeFileSync(filePath, content);
|
||||
const indexFile = join(migrationDir, 'index.ts');
|
||||
appendFileSync(
|
||||
indexFile,
|
||||
`export * from './${parse(fileName).name}';`,
|
||||
'utf-8'
|
||||
);
|
||||
this.logger.log(`Migration file created at ${filePath}`);
|
||||
this.logger.log('Done');
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { once } from 'lodash-es';
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
|
||||
import * as migrations from '../migrations';
|
||||
|
||||
interface Migration {
|
||||
file: string;
|
||||
name: string;
|
||||
always?: boolean;
|
||||
up: (db: PrismaClient, injector: ModuleRef) => Promise<void>;
|
||||
@@ -17,33 +14,15 @@ interface Migration {
|
||||
}
|
||||
|
||||
export const collectMigrations = once(async () => {
|
||||
const folder = join(fileURLToPath(import.meta.url), '../../migrations');
|
||||
|
||||
const migrationFiles = readdirSync(folder)
|
||||
.filter(desc =>
|
||||
desc.endsWith(import.meta.url.endsWith('.ts') ? '.ts' : '.js')
|
||||
)
|
||||
.map(desc => join(folder, desc));
|
||||
|
||||
migrationFiles.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
const migrations: Migration[] = await Promise.all(
|
||||
migrationFiles.map(async file => {
|
||||
return import(pathToFileURL(file).href).then(mod => {
|
||||
const migration = mod[Object.keys(mod)[0]];
|
||||
|
||||
return {
|
||||
file,
|
||||
name: migration.name,
|
||||
always: migration.always,
|
||||
up: migration.up,
|
||||
down: migration.down,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return migrations;
|
||||
return Object.values(migrations).map(migration => {
|
||||
return {
|
||||
name: migration.name,
|
||||
// @ts-expect-error optional
|
||||
always: migration.always,
|
||||
up: migration.up,
|
||||
down: migration.down,
|
||||
};
|
||||
}) as Migration[];
|
||||
});
|
||||
|
||||
@Command({
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { CommandFactory } from 'nest-commander';
|
||||
|
||||
async function bootstrap() {
|
||||
process.env.SERVER_FLAVOR = 'script';
|
||||
|
||||
await import('../prelude');
|
||||
const { CliAppModule } = await import('./app');
|
||||
await CommandFactory.run(CliAppModule, new Logger()).catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
await bootstrap();
|
||||
7
packages/backend/server/src/data/migrations/index.ts
Normal file
7
packages/backend/server/src/data/migrations/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from './0001-refresh-features';
|
||||
export * from './1698398506533-guid';
|
||||
export * from './1703756315970-unamed-account';
|
||||
export * from './1721299086340-refresh-unnamed-user';
|
||||
export * from './1732861452428-migrate-invite-status';
|
||||
export * from './1733125339942-universal-subscription';
|
||||
export * from './1738590347632-feature-redundant';
|
||||
Reference in New Issue
Block a user