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 { executeCommands } = require('./util/installDeps')
|
8 | const { error, stopSpinner, log, hasYarn, hasPnpm3OrLater, logWithSpinner } = require('@vue/cli-shared-utils')
|
9 |
|
10 | async function release (options = {}, context = process.cwd()) {
|
11 | const packageManagerChoices = []
|
12 |
|
13 | await clearConsole(true)
|
14 | packageManagerChoices.push({
|
15 | name: 'Use NPM',
|
16 | value: 'npm',
|
17 | short: 'NPM'
|
18 | })
|
19 |
|
20 |
|
21 | if (hasYarn() || hasPnpm3OrLater()) {
|
22 | if (hasYarn()) {
|
23 | packageManagerChoices.push({
|
24 | name: 'Use Yarn',
|
25 | value: 'yarn',
|
26 | short: 'Yarn'
|
27 | })
|
28 | }
|
29 |
|
30 | if (hasPnpm3OrLater()) {
|
31 | packageManagerChoices.push({
|
32 | name: 'Use PNPM',
|
33 | value: 'pnpm',
|
34 | short: 'PNPM'
|
35 | })
|
36 | }
|
37 | }
|
38 |
|
39 | const packageManager = options.packageManager || await inquirer.prompt([
|
40 | {
|
41 | name: 'packageManager',
|
42 | type: 'list',
|
43 | message: 'Pick the package manager to use in this project:',
|
44 | choices: packageManagerChoices
|
45 | }
|
46 | ]).then(list => list.packageManager)
|
47 |
|
48 | const userOptions = await loadUserOptions(context)
|
49 |
|
50 | const isShouldBackend = await shouldBackend(userOptions.type)
|
51 |
|
52 | const frontendPath = isShouldBackend ? `${context}/frontend` : context
|
53 |
|
54 | if (!options.force) {
|
55 |
|
56 | log()
|
57 | logWithSpinner('🚨', 'Running frontend tests...')
|
58 | await executeCommands(frontendPath, packageManager, 'test')
|
59 | stopSpinner()
|
60 |
|
61 | log()
|
62 | if (isShouldBackend) {
|
63 | logWithSpinner('🚨', 'Running backend tests...')
|
64 | await executeCommands(context, 'composer', 'test')
|
65 | log()
|
66 | stopSpinner()
|
67 | }
|
68 | }
|
69 |
|
70 | log()
|
71 | if (isShouldBackend) {
|
72 | logWithSpinner('🚨', 'Running lang files...')
|
73 | await executeCommands(context, 'composer', 'lang:generate')
|
74 | log()
|
75 | stopSpinner()
|
76 | }
|
77 |
|
78 | log()
|
79 | logWithSpinner('🔥', `Generating release...`)
|
80 | console.log(context)
|
81 | if (userOptions.type === 'landing') {
|
82 | await executeCommands(frontendPath, packageManager, 'generate')
|
83 | } else {
|
84 | await execa
|
85 | .shell(
|
86 | 'vue-cli-service build',
|
87 | { cwd: frontendPath }
|
88 | )
|
89 | .then(result => {
|
90 | stopSpinner()
|
91 | })
|
92 | }
|
93 |
|
94 |
|
95 | log()
|
96 | if (!options.force) {
|
97 | logWithSpinner('🚀', 'Update version')
|
98 | await executeCommands(frontendPath, packageManager, 'update')
|
99 | if (isShouldBackend) {
|
100 | await executeCommands(context, packageManager, 'update')
|
101 | }
|
102 | stopSpinner()
|
103 | }
|
104 |
|
105 | stopSpinner()
|
106 | log()
|
107 | log(`🎉 Successfully released project ${chalk.yellow(userOptions.siteName)}.`)
|
108 | log()
|
109 | }
|
110 |
|
111 | module.exports = (...args) => {
|
112 | return release(...args).catch(err => {
|
113 | stopSpinner(false)
|
114 | error(err)
|
115 | if (!process.env.CONTROLLA_CLI_TEST) {
|
116 | process.exit(1)
|
117 | }
|
118 | })
|
119 | }
|