-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.ts
56 lines (43 loc) · 1.44 KB
/
runner.ts
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
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import { run } from './src/migration'
import { setup } from './src/versioning'
import { getEnvironment } from './src/contentful'
const runCommand = (argv: yargs.ArgumentsCamelCase<{ folder: string }>) => (async function () {
const { CONTENT_MANAGEMENT_TOKEN, SPACE_ID, ENVIRONMENT_ID } = process.env;
if (CONTENT_MANAGEMENT_TOKEN === undefined) {
throw new Error('The environment variable "CONTENT_MANAGEMENT_TOKEN" is missing')
}
if (SPACE_ID === undefined) {
throw new Error('The environment variable "SPACE_ID" is missing')
}
if (ENVIRONMENT_ID === undefined) {
throw new Error('The environment variable "ENVIRONMENT_ID" is missing')
}
const environment = await getEnvironment(ENVIRONMENT_ID)
if (environment === undefined) {
throw new Error(`Environment ${ENVIRONMENT_ID} not found`)
}
await setup(environment)
const result = await run({
accessToken: CONTENT_MANAGEMENT_TOKEN,
spaceId: SPACE_ID,
environment,
}, argv.folder)
if (result === false) {
console.info(`There are no new migrations!`)
}
}()).catch((error) => {
console.error(error)
process.exit(1)
})
yargs(hideBin(process.argv))
.command('run <folder>', 'Run migrations', (yargs) => {
yargs.positional('folder', {
type: 'string',
describe: 'Migration folder path'
})
}, runCommand)
.help().alias('help', 'h')
.demandCommand(1, '')
.argv