forked from lost-pixel/lost-pixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.ts
executable file
·86 lines (73 loc) · 2.29 KB
/
bin.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
import path from 'node:path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import fs from 'fs-extra';
import { log } from './log';
import { getPlatformApiToken, platformRunner, runner } from './runner';
import { getVersion } from './utils';
import { sendFinalizeToAPI } from './api';
import { config, configure } from './config';
type CommandArgs = ['init-js', 'init-ts', 'finalize'];
const args = yargs(hideBin(process.argv)).parse();
// @ts-expect-error TBD
const commandArgs = args._ as CommandArgs;
const version = getVersion();
if (version) {
log.process('info', 'general', `Version: ${version}`);
}
// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
if (commandArgs.includes('init-js')) {
log.process('info', 'general', 'Initializing javascript lost-pixel config');
await fs.copy(
path.join(
__dirname,
'..',
'config-templates',
'example.lostpixel.config.js',
),
path.join(process.cwd(), './lostpixel.config.js'),
);
log.process('info', 'general', '✅ Config successfully initialized');
} else if (commandArgs.includes('init-ts')) {
log.process('info', 'general', 'Initializing typescript lost-pixel config');
// Replace local type resolution with module resolution
const file = fs.readFileSync(
path.join(
__dirname,
'..',
'config-templates',
'example.lostpixel.config.ts',
),
);
const modifiedFile = file.toString().replace('../src/config', 'lost-pixel');
fs.writeFileSync(
path.join(process.cwd(), './lostpixel.config.ts'),
modifiedFile,
);
log.process('info', 'general', '✅ Config successfully initialized');
} else {
await configure();
if (config.generateOnly) {
log.process(
'info',
'general',
`🚀 Starting Lost Pixel in 'generateOnly' mode`,
);
await runner(config);
} else {
log.process(
'info',
'general',
`🚀 Starting Lost Pixel in 'platform' mode`,
);
const apiToken = await getPlatformApiToken(config);
if (commandArgs.includes('finalize')) {
await sendFinalizeToAPI(config, apiToken);
} else {
await platformRunner(config, apiToken);
}
}
}
})();