1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const chalk = require('chalk')
|
11 | const inquirer = require('inquirer')
|
12 | const { json, ini } = require('mrm-core')
|
13 | const { execSync } = require('child_process')
|
14 | const debug = require('debug')('adonis:mrm-init')
|
15 |
|
16 | const gitOrigin = {
|
17 | type: 'input',
|
18 | message: 'Enter git origin url',
|
19 | validate (input) {
|
20 | return !input ? 'Please create a git project and enter it\'s remote origin' : true
|
21 | },
|
22 | when () {
|
23 | const gitFile = ini('.git/config')
|
24 | if (!gitFile.exists()) {
|
25 | return true
|
26 | }
|
27 | const origin = gitFile.get('remote "origin"')
|
28 | return !origin || !origin.url
|
29 | },
|
30 | name: 'gitOrigin'
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | const isCore = {
|
39 | type: 'confirm',
|
40 | message: 'Is it a package written by the AdonisJS core team',
|
41 | name: 'core'
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | const minNodeVersion = {
|
50 | type: 'list',
|
51 | message: 'Select the minimum node version your project will support',
|
52 | name: 'minNodeVersion',
|
53 | choices: [
|
54 | {
|
55 | name: '14.17.0 (LTS)',
|
56 | value: '14.17.0',
|
57 | },
|
58 | {
|
59 | name: 'latest',
|
60 | value: 'latest'
|
61 | }
|
62 | ]
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | const license = {
|
71 | type: 'list',
|
72 | choices: ['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause', 'MIT', 'Unlicense'],
|
73 | message: 'Select project license. Select Unlicense if not sure',
|
74 | name: 'license'
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | const services = {
|
83 | type: 'checkbox',
|
84 | message: 'Select the CI services you want to use',
|
85 | choices: [
|
86 | {
|
87 | name: 'Appveyor',
|
88 | value: 'appveyor'
|
89 | },
|
90 | {
|
91 | name: 'Circle CI',
|
92 | value: 'circleci'
|
93 | },
|
94 | {
|
95 | name: 'Github actions',
|
96 | value: 'github-actions'
|
97 | },
|
98 | ],
|
99 | name: 'services'
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | const appveyorUsername = {
|
109 | type: 'input',
|
110 | message: 'Enter appveyor username',
|
111 | when: function (answers) {
|
112 | return answers.services.indexOf('appveyor') > -1
|
113 | },
|
114 | name: 'appveyorUsername'
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | const runGhActionsOnWindows = {
|
123 | type: 'confirm',
|
124 | message: 'Run github actions on windows?',
|
125 | when: function (answers) {
|
126 | return answers.services.indexOf('github-actions') > -1
|
127 | },
|
128 | name: 'runGhActionsOnWindows'
|
129 | }
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | const probotApps = {
|
136 | type: 'checkbox',
|
137 | message: 'Select the probot applications you want to use',
|
138 | choices: [
|
139 | {
|
140 | name: 'Stale Issues',
|
141 | value: 'stale'
|
142 | },
|
143 | {
|
144 | name: 'Lock Issues',
|
145 | value: 'lock'
|
146 | }
|
147 | ],
|
148 | name: 'probotApps'
|
149 | }
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | async function task () {
|
160 | const file = json('config.json')
|
161 | const existingAnswers = file.get()
|
162 |
|
163 | |
164 |
|
165 |
|
166 | if (existingAnswers.minNodeVersion) {
|
167 | minNodeVersion.choices.unshift({
|
168 | name: `${existingAnswers.minNodeVersion} (from ./config.json)`,
|
169 | value: existingAnswers.minNodeVersion,
|
170 | })
|
171 | minNodeVersion.default = 0
|
172 | }
|
173 |
|
174 | isCore.default = existingAnswers.core
|
175 | license.default = existingAnswers.license
|
176 | services.default = existingAnswers.services
|
177 | appveyorUsername.default = existingAnswers.appveyorUsername
|
178 | runGhActionsOnWindows.default = existingAnswers.runGhActionsOnWindows
|
179 | probotApps.default = existingAnswers.probotApps
|
180 |
|
181 | const answers = await inquirer.prompt([
|
182 | gitOrigin,
|
183 | minNodeVersion,
|
184 | isCore,
|
185 | license,
|
186 | services,
|
187 | appveyorUsername,
|
188 | probotApps,
|
189 | runGhActionsOnWindows
|
190 | ])
|
191 |
|
192 | const fileContent = {
|
193 | core: answers.core,
|
194 | license: answers.license,
|
195 | services: answers.services,
|
196 | appveyorUsername: answers.appveyorUsername,
|
197 | minNodeVersion: answers.minNodeVersion,
|
198 | probotApps: answers.probotApps,
|
199 | runGhActionsOnWindows: answers.runGhActionsOnWindows
|
200 | }
|
201 |
|
202 | debug('init %o', fileContent)
|
203 |
|
204 | file.set(fileContent)
|
205 | file.save()
|
206 |
|
207 | |
208 |
|
209 |
|
210 | if (answers.gitOrigin) {
|
211 | console.log(chalk.yellow('git init'))
|
212 | execSync('git init')
|
213 |
|
214 | console.log(chalk.yellow(`git remote add origin ${answers.gitOrigin}`))
|
215 | execSync(`git remote add origin ${answers.gitOrigin}`)
|
216 | }
|
217 | }
|
218 |
|
219 | task.description = 'Initiate the project config file'
|
220 | module.exports = task
|