-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmigrations.ts
More file actions
60 lines (48 loc) · 1.48 KB
/
migrations.ts
File metadata and controls
60 lines (48 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const workosOnlyMigrationsFlags = new Map([
['--api-key', true],
['--insecure-storage', false],
['--json', false],
['--mode', true],
]);
export function getMigrationsPassthroughArgs(rawArgs: string[]): string[] {
let migrationsIdx = rawArgs.indexOf('migrations');
for (let i = 0; i < rawArgs.length; i++) {
const arg = rawArgs[i];
const key = arg.split('=')[0];
const takesValue = workosOnlyMigrationsFlags.get(key);
if (takesValue !== undefined) {
if (takesValue && !arg.includes('=')) i++;
continue;
}
if (arg === 'migrations') {
migrationsIdx = i;
break;
}
}
const after = rawArgs.slice(migrationsIdx + 1);
const passthrough: string[] = [];
for (let i = 0; i < after.length; i++) {
const arg = after[i];
const key = arg.split('=')[0];
const takesValue = workosOnlyMigrationsFlags.get(key);
if (takesValue !== undefined) {
if (takesValue && !arg.includes('=')) i++;
continue;
}
passthrough.push(arg);
}
return passthrough;
}
export async function runMigrations(args: string[], apiKey?: string): Promise<void> {
if (apiKey) {
process.env.WORKOS_SECRET_KEY = apiKey;
}
const { program } = (await import('@workos/migrations/dist/cli/index.js')) as {
program: {
name(str: string): unknown;
parseAsync(argv: string[], options?: { from: 'user' }): Promise<unknown>;
};
};
program.name('workos migrations');
await program.parseAsync(args, { from: 'user' });
}