-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
137 lines (125 loc) · 3.05 KB
/
index.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
129
130
131
132
133
134
135
136
137
'use strict'
/** @type {import('./type.js')} */
import * as runner from './runner/index.js'
import { ALIASES, FRAMEWORK, GENERAL_FLAG, HELP_MANUAL } from './constants/index.js'
import path, { dirname } from 'path'
import arg from 'arg'
import chalk from 'chalk'
import { fileURLToPath } from 'url'
import fs from 'fs'
import inquirer from 'inquirer'
// Get the filename of the current module
export const __filename = fileURLToPath(import.meta.url)
// Get the directory name of the current module
export const __dirname = dirname(__filename)
/**
* parse CLI arguments into options
* @param {string[]} rawArgs - arguments from stdin
* @returns {Options}
*/
function parseArgumentsIntoOptions(rawArgs) {
let args = arg(
{
...GENERAL_FLAG,
...ALIASES,
},
{
argv: rawArgs.slice(2),
}
)
return {
directoryName: args._[0],
help: args['--help'] || false,
version: args['--version'] || false,
pm: args['--package-manager'] || args['--pm'] || 'npm',
fw: args['--framework'] || args['--fw'],
template: args['--template'],
}
}
/**
* main function
* @param {string[]} args
* @returns {Promise<void>}
*/
export async function cli(args) {
let options = parseArgumentsIntoOptions(args)
if (options.help) {
console.log(HELP_MANUAL)
return
}
if (options.version) {
const pkgJSON = fs.readFileSync(path.resolve(__dirname + '/package.json'), {
encoding: 'utf-8',
})
console.log(JSON.parse(pkgJSON).version)
return
}
if (!options.fw) {
const result = await inquirer.prompt([
{
type: 'list',
name: 'fw',
message: chalk.blueBright.bold('Choose your framework'),
choices: Object.values(FRAMEWORK),
},
])
options.fw = result.fw
}
switch (options.fw.trim().toLowerCase()) {
case 'analog':
await runner.runAnalog(options)
return
case 'astro':
await runner.runAstro(options)
return
case 'epic':
await runner.runEpic(options)
return
case 'next':
await runner.runNext(options)
return
case 'nuxt':
await runner.runNuxt(options)
return
case 'one':
await runner.runOne(options)
return
// case 'phoenix':
// await runner.runPhoenix(options)
// return
case 'preact':
await runner.runPreact(options)
return
case 'qwik':
await runner.runQwik(options)
return
case 'reactnative':
await runner.runReactNative(options)
return
case 'redwood':
await runner.runRedwood(options)
return
case 'remix':
await runner.runRemix(options)
return
case 'solidstart':
await runner.runSolidStart(options)
return
// case 'superkit':
// await runner.runSuperkit(options)
// return
case 'sveltekit':
await runner.runSvelteKit(options)
return
case 'umi':
await runner.runUmi(options)
return
case 'waku':
await runner.runWaku(options)
return
case 'vite':
default:
await runner.runVite(options)
}
return
}