-
Notifications
You must be signed in to change notification settings - Fork 1
/
wizard.js
executable file
·128 lines (107 loc) · 4.26 KB
/
wizard.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import chalk from 'chalk';
import { program, Option } from 'commander';
import prompts from 'prompts';
import { createClient } from './lib/create-client.js';
import { installPlugins, installLibs } from './lib/package-installer.js';
import { findDoc } from './lib/find-doc.js';
import { configInfos } from './lib/config-infos.js';
import { createEnv } from './lib/create-env.js';
import { ejectLauncher } from './lib/eject-launcher.js';
import { checkDeps } from './lib/check-deps.js';
import { upgradeConfig } from './lib/upgrade-config.js';
import { onCancel, getSelfVersion } from './lib/utils.js';
const tasks = {
createClient,
installPlugins,
installLibs,
findDoc,
configInfos,
createEnv,
ejectLauncher,
checkDeps,
upgradeConfig,
};
const version = getSelfVersion();
// allow to trigger specific taks from command line
program
.option('-c, --create-client', 'create a new soundworks client')
.option('-p, --install-plugins', 'install / uninstall soundworks plugins')
.option('-l, --install-libs', 'install / uninstall related libs')
.option('-f, --find-doc', 'find documentation about plugins and related libs')
.option('-i, --config-infos', 'get config informations about you application')
.option('-C, --create-env', 'create a new environment config file')
.option('-e, --eject-launcher', 'eject the launcher and default views from `@soundworks/helpers`')
.option('-d, --check-deps', 'check and update your dependencies')
.option('--upgrade-config', 'upgrade config files from JSON to YAML')
.addOption(new Option('-i, --init').hideHelp()) // launched by @soundworks/create
;
program.parse(process.argv);
const options = program.opts();
if (!fs.existsSync(path.join(process.cwd(), '.soundworks'))) {
console.error(chalk.red(`\
This project doesn't seem to be soundworks project.
Note that \`npx soundworks\` should be run at the root of your project
Aborting...
`));
process.exit();
}
const appInfos = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.soundworks')));
console.log(chalk.gray(`[@soundworks/wizard#v${version}]`));
console.log('');
// init wizard, called by @soundworks/create
if (options.init) {
console.log(chalk.yellow(`> soundworks init wizard`));
console.log('');
await installPlugins();
await installLibs();
await tasks.createClient(appInfos);
console.log(chalk.yellow(`> soundworks init wizard done`));
console.log('');
process.exit(0);
// handle options from command line
} else if (Object.keys(options).length > 0) {
delete options.init; // this is not a task
// execute all tasks one by one
for (let task in options) {
await tasks[task](appInfos);
}
process.exit(0);
// no options given from command line, launch interactive mode
} else {
console.log(`\
${chalk.yellow(`> welcome to the soundworks wizard`)}
${chalk.grey(`- you can exit the wizard at any moment by typing Ctrl+C or by choosing the "exit" option`)}
- documentation: ${chalk.cyan('https://soundworks.dev')}
- issues: ${chalk.cyan('https://github.com/collective-soundworks/soundworks/issues')}
`);
/* eslint-disable-next-line no-constant-condition */
while (true) {
const { task } = await prompts([
{
type: 'select',
name: 'task',
message: 'What do you want to do?',
choices: [
{ title: 'create a new soundworks client', value: 'createClient' },
{ title: 'install / uninstall soundworks plugins', value: 'installPlugins' },
{ title: 'install / uninstall related libs', value: 'installLibs' },
{ title: 'find documentation about plugins and libs', value: 'findDoc' },
{ title: 'get config informations about you application', value: 'configInfos' },
{ title: 'create a new environment config file', value: 'createEnv' },
{ title: 'eject the launcher and default init views', value: 'ejectLauncher' },
{ title: 'check and update your dependencies', value: 'checkDeps' },
{ title: 'upgrade config files from JSON to YAML', value: 'upgradeConfig' },
{ title: '→ exit', value: 'exit' },
],
},
], { onCancel });
if (task === 'exit') {
process.exit(0);
}
console.log('');
await tasks[task](appInfos);
}
}