|
1 |
| -const path = require('path'); |
2 |
| -const fs = require('fs'); |
3 |
| - |
4 |
| -function sortObject(object) { |
5 |
| - // Based on https://github.com./yarnpkg/yarn/blob/v1.3.2/src/config.js#L79-L85 |
6 |
| - const sortedObject = {}; |
7 |
| - Object.keys(object).sort().forEach(item => { |
8 |
| - sortedObject[item] = object[item]; |
9 |
| - }); |
10 |
| - return sortedObject; |
11 |
| -} |
| 1 | +const path = require('path') |
| 2 | +const fs = require('fs') |
| 3 | +const { |
| 4 | + sortDependencies, |
| 5 | + installDependencies, |
| 6 | + runLintFix, |
| 7 | + printMessage, |
| 8 | +} = require('./utils') |
12 | 9 |
|
13 | 10 | module.exports = {
|
14 |
| - "helpers": { |
15 |
| - "if_or": function (v1, v2, options) { |
| 11 | + helpers: { |
| 12 | + if_or: function(v1, v2, options) { |
16 | 13 | if (v1 || v2) {
|
17 |
| - return options.fn(this); |
| 14 | + return options.fn(this) |
18 | 15 | }
|
19 | 16 |
|
20 |
| - return options.inverse(this); |
21 |
| - } |
| 17 | + return options.inverse(this) |
| 18 | + }, |
22 | 19 | },
|
23 |
| - "prompts": { |
24 |
| - "name": { |
25 |
| - "type": "string", |
26 |
| - "required": true, |
27 |
| - "message": "Project name" |
| 20 | + prompts: { |
| 21 | + name: { |
| 22 | + type: 'string', |
| 23 | + required: true, |
| 24 | + message: 'Project name', |
28 | 25 | },
|
29 |
| - "description": { |
30 |
| - "type": "string", |
31 |
| - "required": false, |
32 |
| - "message": "Project description", |
33 |
| - "default": "A Vue.js project" |
| 26 | + description: { |
| 27 | + type: 'string', |
| 28 | + required: false, |
| 29 | + message: 'Project description', |
| 30 | + default: 'A Vue.js project', |
34 | 31 | },
|
35 |
| - "author": { |
36 |
| - "type": "string", |
37 |
| - "message": "Author" |
| 32 | + author: { |
| 33 | + type: 'string', |
| 34 | + message: 'Author', |
38 | 35 | },
|
39 |
| - "build": { |
40 |
| - "type": "list", |
41 |
| - "message": "Vue build", |
42 |
| - "choices": [ |
| 36 | + build: { |
| 37 | + type: 'list', |
| 38 | + message: 'Vue build', |
| 39 | + choices: [ |
43 | 40 | {
|
44 |
| - "name": "Runtime + Compiler: recommended for most users", |
45 |
| - "value": "standalone", |
46 |
| - "short": "standalone" |
| 41 | + name: 'Runtime + Compiler: recommended for most users', |
| 42 | + value: 'standalone', |
| 43 | + short: 'standalone', |
47 | 44 | },
|
48 | 45 | {
|
49 |
| - "name": "Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere", |
50 |
| - "value": "runtime", |
51 |
| - "short": "runtime" |
52 |
| - } |
53 |
| - ] |
| 46 | + name: |
| 47 | + 'Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere', |
| 48 | + value: 'runtime', |
| 49 | + short: 'runtime', |
| 50 | + }, |
| 51 | + ], |
54 | 52 | },
|
55 |
| - "router": { |
56 |
| - "type": "confirm", |
57 |
| - "message": "Install vue-router?" |
| 53 | + router: { |
| 54 | + type: 'confirm', |
| 55 | + message: 'Install vue-router?', |
58 | 56 | },
|
59 |
| - "eslint": { |
60 |
| - "type": "confirm", |
61 |
| - "message": "Use ESLint to lint your code?" |
| 57 | + eslint: { |
| 58 | + type: 'confirm', |
| 59 | + message: 'Use ESLint to lint your code?', |
62 | 60 | },
|
63 |
| - "eslintConfig": { |
64 |
| - "when": "eslint", |
65 |
| - "type": "list", |
66 |
| - "message": "Pick an ESLint preset", |
67 |
| - "choices": [ |
| 61 | + eslintConfig: { |
| 62 | + when: 'eslint', |
| 63 | + type: 'list', |
| 64 | + message: 'Pick an ESLint preset', |
| 65 | + choices: [ |
68 | 66 | {
|
69 |
| - "name": "Standard (https://github.com./standard/standard)", |
70 |
| - "value": "standard", |
71 |
| - "short": "Standard" |
| 67 | + name: 'Standard (https://github.com./standard/standard)', |
| 68 | + value: 'standard', |
| 69 | + short: 'Standard', |
72 | 70 | },
|
73 | 71 | {
|
74 |
| - "name": "Airbnb (https://github.com./airbnb/javascript)", |
75 |
| - "value": "airbnb", |
76 |
| - "short": "Airbnb" |
| 72 | + name: 'Airbnb (https://github.com./airbnb/javascript)', |
| 73 | + value: 'airbnb', |
| 74 | + short: 'Airbnb', |
77 | 75 | },
|
78 | 76 | {
|
79 |
| - "name": "none (configure it yourself)", |
80 |
| - "value": "none", |
81 |
| - "short": "none" |
| 77 | + name: 'none (configure it yourself)', |
| 78 | + value: 'none', |
| 79 | + short: 'none' |
82 | 80 | }
|
83 | 81 | ]
|
84 | 82 | },
|
85 |
| - "stylelint": { |
86 |
| - "type": "confirm", |
87 |
| - "message": "Use stylelint to lint your code?" |
| 83 | + stylelint: { |
| 84 | + type: 'confirm', |
| 85 | + message: 'Use stylelint to lint your code?' |
88 | 86 | },
|
89 |
| - "stylelintConfig": { |
90 |
| - "when": "stylelint", |
91 |
| - "type": "list", |
92 |
| - "message": "Pick a stylelint preset", |
93 |
| - "choices": [ |
| 87 | + stylelintConfig: { |
| 88 | + when: 'stylelint', |
| 89 | + type: 'list', |
| 90 | + message: 'Pick a stylelint preset', |
| 91 | + choices: [ |
94 | 92 | {
|
95 |
| - "name": "Standard (https://github.com./stylelint/stylelint-config-standard)", |
96 |
| - "value": "standard", |
97 |
| - "short": "Standard" |
| 93 | + name: 'Standard (https://github.com./stylelint/stylelint-config-standard)', |
| 94 | + value: 'standard', |
| 95 | + short: 'Standard' |
98 | 96 | },
|
99 | 97 | {
|
100 |
| - "name": "Recommended (https://github.com./stylelint/stylelint-config-recommended)", |
101 |
| - "value": "recommended", |
102 |
| - "short": "Recommended" |
| 98 | + name: 'Recommended (https://github.com./stylelint/stylelint-config-recommended)', |
| 99 | + value: 'recommended', |
| 100 | + short: 'Recommended' |
103 | 101 | },
|
104 | 102 | {
|
105 |
| - "name": "Wikimedia (https://github.com./wikimedia/stylelint-config-wikimedia)", |
106 |
| - "value": "wikimedia", |
107 |
| - "short": "Wikimedia" |
| 103 | + name: 'Wikimedia (https://github.com./wikimedia/stylelint-config-wikimedia)', |
| 104 | + value: 'wikimedia', |
| 105 | + short: 'Wikimedia' |
108 | 106 | },
|
109 | 107 | {
|
110 |
| - "name": "none (configure it yourself)", |
111 |
| - "value": "none", |
112 |
| - "short": "none" |
113 |
| - } |
114 |
| - ] |
| 108 | + name: 'none (configure it yourself)', |
| 109 | + value: 'none', |
| 110 | + short: 'none', |
| 111 | + }, |
| 112 | + ], |
115 | 113 | },
|
116 |
| - "unit": { |
117 |
| - "type": "confirm", |
118 |
| - "message": "Set up unit tests" |
| 114 | + unit: { |
| 115 | + type: 'confirm', |
| 116 | + message: 'Set up unit tests', |
119 | 117 | },
|
120 |
| - "runner": { |
121 |
| - "when": "unit", |
122 |
| - "type": "list", |
123 |
| - "message": "Pick a test runner", |
124 |
| - "choices": [ |
| 118 | + runner: { |
| 119 | + when: 'unit', |
| 120 | + type: 'list', |
| 121 | + message: 'Pick a test runner', |
| 122 | + choices: [ |
125 | 123 | {
|
126 |
| - "name": "Jest", |
127 |
| - "value": "jest", |
128 |
| - "short": "jest" |
| 124 | + name: 'Jest', |
| 125 | + value: 'jest', |
| 126 | + short: 'jest', |
129 | 127 | },
|
130 | 128 | {
|
131 |
| - "name": "Karma and Mocha", |
132 |
| - "value": "karma", |
133 |
| - "short": "karma" |
| 129 | + name: 'Karma and Mocha', |
| 130 | + value: 'karma', |
| 131 | + short: 'karma', |
134 | 132 | },
|
135 | 133 | {
|
136 |
| - "name": "none (configure it yourself)", |
137 |
| - "value": "noTest", |
138 |
| - "short": "noTest" |
139 |
| - } |
140 |
| - ] |
| 134 | + name: 'none (configure it yourself)', |
| 135 | + value: 'noTest', |
| 136 | + short: 'noTest', |
| 137 | + }, |
| 138 | + ], |
| 139 | + }, |
| 140 | + e2e: { |
| 141 | + type: 'confirm', |
| 142 | + message: 'Setup e2e tests with Nightwatch?', |
| 143 | + }, |
| 144 | + autoInstall: { |
| 145 | + type: 'list', |
| 146 | + message: |
| 147 | + 'Should we run `npm install` for you after the project has been created? (recommended)', |
| 148 | + choices: [ |
| 149 | + { |
| 150 | + name: 'Yes, use NPM', |
| 151 | + value: 'npm', |
| 152 | + short: 'npm', |
| 153 | + }, |
| 154 | + { |
| 155 | + name: 'Yes, use Yarn', |
| 156 | + value: 'yarn', |
| 157 | + short: 'yarn', |
| 158 | + }, |
| 159 | + { |
| 160 | + name: 'No, I will handle that myself', |
| 161 | + value: false, |
| 162 | + short: 'no', |
| 163 | + }, |
| 164 | + ], |
141 | 165 | },
|
142 |
| - "e2e": { |
143 |
| - "type": "confirm", |
144 |
| - "message": "Setup e2e tests with Nightwatch?" |
145 |
| - } |
146 | 166 | },
|
147 |
| - "filters": { |
148 |
| - ".eslintrc.js": "eslint", |
149 |
| - ".eslintignore": "eslint", |
150 |
| - ".stylelintrc.js": "stylelint", |
151 |
| - ".stylelintignore": "stylelint", |
152 |
| - "config/test.env.js": "unit || e2e", |
153 |
| - "build/webpack.test.conf.js": "unit && runner === 'karma'", |
154 |
| - "test/unit/**/*": "unit", |
155 |
| - "test/unit/index.js": "unit && runner === 'karma'", |
156 |
| - "test/unit/jest.conf.js": "unit && runner === 'jest'", |
157 |
| - "test/unit/karma.conf.js": "unit && runner === 'karma'", |
158 |
| - "test/unit/specs/index.js": "unit && runner === 'karma'", |
159 |
| - "test/unit/setup.js": "unit && runner === 'jest'", |
160 |
| - "test/e2e/**/*": "e2e", |
161 |
| - "src/router/**/*": "router" |
| 167 | + filters: { |
| 168 | + '.eslintrc.js': 'eslint', |
| 169 | + '.eslintignore': 'eslint', |
| 170 | + '.stylelintrc.js': 'stylelint', |
| 171 | + '.stylelintignore': 'stylelint', |
| 172 | + 'config/test.env.js': 'unit || e2e', |
| 173 | + 'build/webpack.test.conf.js': "unit && runner === 'karma'", |
| 174 | + 'test/unit/**/*': 'unit', |
| 175 | + 'test/unit/index.js': "unit && runner === 'karma'", |
| 176 | + 'test/unit/jest.conf.js': "unit && runner === 'jest'", |
| 177 | + 'test/unit/karma.conf.js': "unit && runner === 'karma'", |
| 178 | + 'test/unit/specs/index.js': "unit && runner === 'karma'", |
| 179 | + 'test/unit/setup.js': "unit && runner === 'jest'", |
| 180 | + 'test/e2e/**/*': 'e2e', |
| 181 | + 'src/router/**/*': 'router', |
162 | 182 | },
|
163 |
| - "complete": function (data) { |
164 |
| - const packageJsonFile = path.join( |
165 |
| - data.inPlace ? "" : data.destDirName, |
166 |
| - "package.json" |
167 |
| - ); |
168 |
| - const packageJson = JSON.parse(fs.readFileSync(packageJsonFile)); |
169 |
| - packageJson.devDependencies = sortObject(packageJson.devDependencies); |
170 |
| - packageJson.dependencies = sortObject(packageJson.dependencies); |
171 |
| - fs.writeFileSync( |
172 |
| - packageJsonFile, |
173 |
| - JSON.stringify(packageJson, null, 2) + "\n" |
174 |
| - ); |
| 183 | + complete: function(data, { chalk }) { |
| 184 | + const green = chalk.green |
| 185 | + |
| 186 | + sortDependencies(data, green) |
| 187 | + |
| 188 | + const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName) |
175 | 189 |
|
176 |
| - const message = `To get started:\n\n ${data.inPlace ? '' : `cd ${data.destDirName}\n `}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack`; |
177 |
| - console.log("\n" + message.split(/\r?\n/g).map(line => " " + line).join("\n")); |
178 |
| - } |
179 |
| -}; |
| 190 | + if (data.autoInstall) { |
| 191 | + installDependencies(cwd, data.autoInstall, green) |
| 192 | + .then(() => { |
| 193 | + return runLintFix(cwd, data, green) |
| 194 | + }) |
| 195 | + .then(() => { |
| 196 | + printMessage(data, green) |
| 197 | + }) |
| 198 | + .catch(e => { |
| 199 | + console.log(chalk.red('Error:'), e) |
| 200 | + }) |
| 201 | + } else { |
| 202 | + printMessage(data, chalk) |
| 203 | + } |
| 204 | + }, |
| 205 | +} |
0 commit comments