1 | const chalk = require('chalk')
|
2 | const inquirer = require('inquirer')
|
3 | const execa = require('execa')
|
4 | const { clearConsole } = require('./util/clearConsole')
|
5 | const shouldBackend = require('./util/shouldBackend')
|
6 | const loadUserOptions = require('./loadUserOptions')
|
7 | const { installDeps, installComposerDeps, injectedScripts } = require('./util/installDeps')
|
8 | const { error, stopSpinner, log, hasYarn, hasPnpm3OrLater, logWithSpinner } = require('@vue/cli-shared-utils')
|
9 |
|
10 | async function start (options = {}, context = process.cwd()) {
|
11 | const isTestOrDebug = process.env.CONTROLLA_CLI_TEST || process.env.CONTROLLA_CLI_DEBUG
|
12 | const packageManagerChoices = []
|
13 |
|
14 | await clearConsole(true)
|
15 | packageManagerChoices.push({
|
16 | name: 'Use NPM',
|
17 | value: 'npm',
|
18 | short: 'NPM'
|
19 | })
|
20 |
|
21 |
|
22 | if (hasYarn() || hasPnpm3OrLater()) {
|
23 | if (hasYarn()) {
|
24 | packageManagerChoices.push({
|
25 | name: 'Use Yarn',
|
26 | value: 'yarn',
|
27 | short: 'Yarn'
|
28 | })
|
29 | }
|
30 |
|
31 | if (hasPnpm3OrLater()) {
|
32 | packageManagerChoices.push({
|
33 | name: 'Use PNPM',
|
34 | value: 'pnpm',
|
35 | short: 'PNPM'
|
36 | })
|
37 | }
|
38 | }
|
39 |
|
40 | const packageManager = options.packageManager || await inquirer.prompt([
|
41 | {
|
42 | name: 'packageManager',
|
43 | type: 'list',
|
44 | message: 'Pick the package manager to use when installing dependencies:',
|
45 | choices: packageManagerChoices
|
46 | }
|
47 | ]).then(list => list.packageManager)
|
48 |
|
49 | const userOptions = await loadUserOptions(context)
|
50 |
|
51 | const isShouldBackend = await shouldBackend(userOptions.type)
|
52 |
|
53 | const frontendPath = isShouldBackend ? `${context}/frontend` : context
|
54 |
|
55 | stopSpinner()
|
56 | log('🚀 Installing CLI plugins. This might take a while...')
|
57 | log()
|
58 | if (isTestOrDebug) {
|
59 |
|
60 | await require('./util/setupDevProject')(context)
|
61 | } else {
|
62 | await installDeps(frontendPath, packageManager, options.registry)
|
63 | }
|
64 |
|
65 |
|
66 | if (isShouldBackend) {
|
67 | log()
|
68 | log(`🚀 Installing additional dependencies...`)
|
69 | log()
|
70 | await installDeps(context, packageManager, options.registry)
|
71 | }
|
72 |
|
73 |
|
74 | if (isShouldBackend) {
|
75 | log()
|
76 | log(`🚀 Installing Composer dependencies...`)
|
77 | log()
|
78 | await installComposerDeps(context, 'composer')
|
79 | }
|
80 |
|
81 |
|
82 | if (isShouldBackend) {
|
83 | log()
|
84 | log(`📦 Injected additional scripts...`)
|
85 | log()
|
86 | await injectedScripts(context, 'composer')
|
87 | }
|
88 |
|
89 |
|
90 | log()
|
91 | logWithSpinner('âš“', `Running completion hooks...`)
|
92 | await execa.shell('find . -type f -name ".controllaignore" -execdir mv {} .gitignore ";"', { cwd: this.context }).then(result => {
|
93 | stopSpinner()
|
94 | })
|
95 |
|
96 | stopSpinner()
|
97 | log()
|
98 | log(`🎉 Successfully started project ${chalk.yellow(userOptions.siteName)}.`)
|
99 | log(
|
100 | `👉 Get started with the following commands:\n\n` +
|
101 | chalk.cyan(` ${chalk.gray('$')} ${packageManager === 'yarn' ? 'yarn serve' : packageManager === 'pnpm' ? 'pnpm run serve' : 'npm run serve'}`)
|
102 | )
|
103 | log()
|
104 | }
|
105 |
|
106 | module.exports = (...args) => {
|
107 | return start(...args).catch(err => {
|
108 | stopSpinner(false)
|
109 | error(err)
|
110 | if (!process.env.CONTROLLA_CLI_TEST) {
|
111 | process.exit(1)
|
112 | }
|
113 | })
|
114 | }
|