|
1 | 1 | const path = require('path'); |
2 | 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 | | -} |
| 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 | 14 | return options.fn(this); |
18 | 15 | } |
19 | 16 |
|
20 | 17 | return options.inverse(this); |
21 | 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" |
| 46 | + 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', |
| 47 | + value: 'runtime', |
| 48 | + short: 'runtime' |
52 | 49 | } |
53 | 50 | ] |
54 | 51 | }, |
55 | | - "router": { |
56 | | - "type": "confirm", |
57 | | - "message": "Install vue-router?" |
| 52 | + router: { |
| 53 | + type: 'confirm', |
| 54 | + message: 'Install vue-router?' |
58 | 55 | }, |
59 | | - "lint": { |
60 | | - "type": "confirm", |
61 | | - "message": "Use ESLint to lint your code?" |
| 56 | + lint: { |
| 57 | + type: 'confirm', |
| 58 | + message: 'Use ESLint to lint your code?' |
62 | 59 | }, |
63 | | - "lintConfig": { |
64 | | - "when": "lint", |
65 | | - "type": "list", |
66 | | - "message": "Pick an ESLint preset", |
67 | | - "choices": [ |
| 60 | + lintConfig: { |
| 61 | + when: 'lint', |
| 62 | + type: 'list', |
| 63 | + message: 'Pick an ESLint preset', |
| 64 | + choices: [ |
68 | 65 | { |
69 | | - "name": "Standard (https://github.com/standard/standard)", |
70 | | - "value": "standard", |
71 | | - "short": "Standard" |
| 66 | + name: 'Standard (https://github.com/standard/standard)', |
| 67 | + value: 'standard', |
| 68 | + short: 'Standard' |
72 | 69 | }, |
73 | 70 | { |
74 | | - "name": "Airbnb (https://github.com/airbnb/javascript)", |
75 | | - "value": "airbnb", |
76 | | - "short": "Airbnb" |
| 71 | + name: 'Airbnb (https://github.com/airbnb/javascript)', |
| 72 | + value: 'airbnb', |
| 73 | + short: 'Airbnb' |
77 | 74 | }, |
78 | 75 | { |
79 | | - "name": "none (configure it yourself)", |
80 | | - "value": "none", |
81 | | - "short": "none" |
| 76 | + name: 'none (configure it yourself)', |
| 77 | + value: 'none', |
| 78 | + short: 'none' |
82 | 79 | } |
83 | 80 | ] |
84 | 81 | }, |
85 | | - "unit": { |
86 | | - "type": "confirm", |
87 | | - "message": "Set up unit tests" |
| 82 | + unit: { |
| 83 | + type: 'confirm', |
| 84 | + message: 'Set up unit tests' |
88 | 85 | }, |
89 | | - "runner": { |
90 | | - "when": "unit", |
91 | | - "type": "list", |
92 | | - "message": "Pick a test runner", |
93 | | - "choices": [ |
| 86 | + runner: { |
| 87 | + when: 'unit', |
| 88 | + type: 'list', |
| 89 | + message: 'Pick a test runner', |
| 90 | + choices: [ |
94 | 91 | { |
95 | | - "name": "Jest", |
96 | | - "value": "jest", |
97 | | - "short": "jest" |
| 92 | + name: 'Jest', |
| 93 | + value: 'jest', |
| 94 | + short: 'jest' |
98 | 95 | }, |
99 | 96 | { |
100 | | - "name": "Karma and Mocha", |
101 | | - "value": "karma", |
102 | | - "short": "karma" |
| 97 | + name: 'Karma and Mocha', |
| 98 | + value: 'karma', |
| 99 | + short: 'karma' |
103 | 100 | }, |
104 | 101 | { |
105 | | - "name": "none (configure it yourself)", |
106 | | - "value": "noTest", |
107 | | - "short": "noTest" |
| 102 | + name: 'none (configure it yourself)', |
| 103 | + value: 'noTest', |
| 104 | + short: 'noTest' |
108 | 105 | } |
109 | 106 | ] |
110 | 107 | }, |
111 | | - "e2e": { |
112 | | - "type": "confirm", |
113 | | - "message": "Setup e2e tests with Nightwatch?" |
| 108 | + e2e: { |
| 109 | + type: 'confirm', |
| 110 | + message: 'Setup e2e tests with Nightwatch?' |
| 111 | + }, |
| 112 | + autoInstall: { |
| 113 | + type: 'list', |
| 114 | + message: 'Should we run `npm install` for you after the project has been created? (recommended)', |
| 115 | + choices: [ |
| 116 | + { |
| 117 | + name: 'Yes, use NPM', |
| 118 | + value: 'npm', |
| 119 | + short: 'npm' |
| 120 | + }, |
| 121 | + { |
| 122 | + name: 'Yes, use Yarn', |
| 123 | + value: 'yarn', |
| 124 | + short: 'yarn' |
| 125 | + }, |
| 126 | + { |
| 127 | + name: 'No, I will handle that myself', |
| 128 | + value: false, |
| 129 | + short: 'no' |
| 130 | + } |
| 131 | + ] |
114 | 132 | } |
115 | 133 | }, |
116 | | - "filters": { |
117 | | - ".eslintrc.js": "lint", |
118 | | - ".eslintignore": "lint", |
119 | | - "config/test.env.js": "unit || e2e", |
120 | | - "build/webpack.test.conf.js": "e2e || (unit && runner === 'karma')", |
121 | | - "test/unit/**/*": "unit", |
122 | | - "test/unit/index.js": "unit && runner === 'karma'", |
123 | | - "test/unit/jest.conf.js": "unit && runner === 'jest'", |
124 | | - "test/unit/karma.conf.js": "unit && runner === 'karma'", |
125 | | - "test/unit/specs/index.js": "unit && runner === 'karma'", |
126 | | - "test/unit/setup.js": "unit && runner === 'jest'", |
127 | | - "test/e2e/**/*": "e2e", |
128 | | - "src/router/**/*": "router" |
| 134 | + filters: { |
| 135 | + '.eslintrc.js': 'lint', |
| 136 | + '.eslintignore': 'lint', |
| 137 | + 'config/test.env.js': 'unit || e2e', |
| 138 | + 'build/webpack.test.conf.js': "unit && runner === 'karma'", |
| 139 | + 'test/unit/**/*': 'unit', |
| 140 | + 'test/unit/index.js': "unit && runner === 'karma'", |
| 141 | + 'test/unit/jest.conf.js': "unit && runner === 'jest'", |
| 142 | + 'test/unit/karma.conf.js': "unit && runner === 'karma'", |
| 143 | + 'test/unit/specs/index.js': "unit && runner === 'karma'", |
| 144 | + 'test/unit/setup.js': "unit && runner === 'jest'", |
| 145 | + 'test/e2e/**/*': 'e2e', |
| 146 | + 'src/router/**/*': 'router' |
129 | 147 | }, |
130 | | - "complete": function (data) { |
131 | | - const packageJsonFile = path.join( |
132 | | - data.inPlace ? "" : data.destDirName, |
133 | | - "package.json" |
134 | | - ); |
135 | | - const packageJson = JSON.parse(fs.readFileSync(packageJsonFile)); |
136 | | - packageJson.devDependencies = sortObject(packageJson.devDependencies); |
137 | | - packageJson.dependencies = sortObject(packageJson.dependencies); |
138 | | - fs.writeFileSync( |
139 | | - packageJsonFile, |
140 | | - JSON.stringify(packageJson, null, 2) + "\n" |
141 | | - ); |
| 148 | + 'complete': function (data, { chalk }) { |
| 149 | + |
| 150 | + const green = chalk.green |
142 | 151 |
|
143 | | - 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`; |
144 | | - console.log("\n" + message.split(/\r?\n/g).map(line => " " + line).join("\n")); |
| 152 | + sortDependencies(data, green) |
| 153 | + |
| 154 | + const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName) |
| 155 | + |
| 156 | + if (data.autoInstall) { |
| 157 | + installDependencies(cwd, data.autoInstall, green) |
| 158 | + .then(() => { |
| 159 | + return runLintFix(cwd, data, green) |
| 160 | + }) |
| 161 | + .then(() => { |
| 162 | + printMessage(data, green) |
| 163 | + }) |
| 164 | + } else { |
| 165 | + printMessage(data, chalk) |
| 166 | + } |
| 167 | + |
145 | 168 | } |
146 | 169 | }; |
0 commit comments