-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·75 lines (64 loc) · 2.67 KB
/
Copy pathindex.js
File metadata and controls
executable file
·75 lines (64 loc) · 2.67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
import { Command } from 'commander';
import dotenv from 'dotenv';
import { initClient, fetchAvailableConfigurations } from './src/lib/client.js';
import { registerList } from './src/commands/list.js';
import { registerCreate } from './src/commands/create.js';
import { registerEdit } from './src/commands/edit.js';
import { registerUpdate } from './src/commands/update.js';
import { registerConfig } from './src/commands/config.js';
import { registerRun } from './src/commands/run.js';
import { registerCreateProfile } from './src/commands/create-profile.js';
import { registerEditProfile } from './src/commands/edit-profile.js';
import { registerWatch } from './src/commands/watch.js';
import { registerPackage } from './src/commands/package.js';
export { loadConfigFromFile } from './src/lib/config.js';
export { showApplicationLink, listInstalledApplications, printBanner } from './src/lib/ui.js';
export { splitConfigurationsResponse } from './src/lib/client.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
const VERSION = packageJson.version;
const originalConsoleLog = console.log;
console.log = () => {};
dotenv.config({ silent: true, debug: false, override: false, path: '.env' });
console.log = originalConsoleLog;
process.on('SIGINT', () => {
console.log(chalk.yellow('\nOperation cancelled by user.'));
process.exit(0);
});
const program = new Command();
program.version(VERSION, '-v, --version', 'Display the version number');
program.hook('preAction', async (thisCommand, actionCommand) => {
if (actionCommand.name() === 'watch') return;
const options = actionCommand.opts();
if (options.server) {
actionCommand.client = initClient(options);
const { configurations, invalidConfigurations } = await fetchAvailableConfigurations(
actionCommand.client,
actionCommand.name(),
);
actionCommand.allConfigurations = configurations;
actionCommand.invalidConfigurations = invalidConfigurations;
}
});
registerList(program);
registerCreate(program);
registerEdit(program);
registerUpdate(program);
registerConfig(program);
registerRun(program);
registerCreateProfile(program);
registerEditProfile(program);
registerWatch(program);
registerPackage(program);
const isMainModule = import.meta.url === `file://${process.argv[1]}` ||
process.argv[1]?.endsWith('index.js') ||
process.argv[1]?.endsWith('jinks');
if (isMainModule) {
program.parse();
}