forked from SimulatedGREG/electron-vue
-
Notifications
You must be signed in to change notification settings - Fork 2
/
meta.js
223 lines (214 loc) · 6.57 KB
/
meta.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
'use strict'
const { join } = require('path')
const { readFileSync, writeFileSync } = require('fs')
const { get } = require('https')
function getCurrentSHA (author) {
return new Promise((resolve, reject) => {
let isBranch = process.argv[2].indexOf('#') > -1
get({
host: 'api.github.com',
path: `/repos/simulatedgreg/electron-vue/commits${isBranch ? '?sha=' + process.argv[2].split('#')[1] : ''}`,
headers: {
'User-Agent': author
}
}, res => {
res.setEncoding('utf8')
let rawData = ''
res.on('data', chunk => {
rawData += chunk
})
res.on('end', () => {
try {
let parsed = JSON.parse(rawData)
resolve(parsed[0].sha)
} catch (e) {
reject(e)
}
})
}).on('error', e => {
reject(e)
})
})
}
function appendSHALink (sha, destDirName) {
let readmePath = join(destDirName, '/README.md')
let md = readFileSync(readmePath, 'utf8')
md = md.replace(
' using',
`@[${sha.substring(0, 7)}](https://github.com/SimulatedGREG/electron-vue/tree/${sha}) using`
)
writeFileSync(readmePath, md, 'utf8')
}
module.exports = {
prompts: {
name: {
type: 'string',
required: true,
message: 'Application Name',
default: 'your-app'
},
appid: {
type: 'string',
required: true,
message: 'Application Id (no dash)',
default: 'com.example.yourapp'
},
appver: {
type: 'string',
required: true,
message: 'Application Version',
default: '0.0.1'
},
description: {
type: 'string',
required: false,
message: 'Project description',
default: 'An electron-vue project'
},
usesass: {
type: 'confirm',
message: 'Use Sass / Scss?',
required: true
},
plugins: {
type: 'checkbox',
message: 'Select which Vue plugins to install (vuex-electron not supported with vue-spacebro-client)',
choices: ['axios', 'vue-electron', 'vue-router', 'vuex', 'vuex-router-sync', 'vuex-electron', 'vue-spacebro-client', 'standard-settings'],
default: ['axios', 'vue-electron', 'vue-router', 'vuex', 'vuex-router-sync', 'vue-spacebro-client', 'standard-settings']
},
eslint: {
type: 'confirm',
require: true,
message: 'Use linting with ESLint?',
default: true
},
eslintConfig: {
when: 'eslint',
type: 'list',
message: 'Which ESLint config would you like to use?',
choices: [
{
name: 'Standard (https://github.com/feross/standard)',
value: 'standard',
short: 'Standard'
},
{
name: 'Airbnb (https://github.com/airbnb/javascript)',
value: 'airbnb',
short: 'Airbnb'
},
{
name: 'none (configure it yourself)',
value: 'none',
short: 'none'
}
]
},
unit: {
type: 'confirm',
message: 'Set up unit testing with Karma + Mocha?',
required: true,
default: false
},
e2e: {
type: 'confirm',
message: 'Set up end-to-end testing with Spectron + Mocha?',
require: true,
default: false
},
builder: {
type: 'list',
message: 'What build tool would you like to use? Should be Electron packager for Interactive App',
choices: [
{
name: 'electron-packager (https://github.com/electron-userland/electron-packager)',
value: 'packager',
short: 'packager'
},
{
name: 'electron-builder (https://github.com/electron-userland/electron-builder)',
value: 'builder',
short: 'builder'
}
]
},
serviceWorker: {
type: 'confirm',
message: 'Setup service-worker?',
require: true,
default: true
}
},
helpers: {
isEnabled (list, check, opts) {
if (list[check]) return opts.fn(this)
else return opts.inverse(this)
},
deps (plugins) {
let output = ''
let dependencies = {
'axios': '^0.18.0',
'vue-electron': '^1.0.6',
'vue-router': '^3.0.1',
'vuex': '^3.0.1',
'vuex-router-sync': '^5.0.0',
'vuex-electron': '^1.0.0',
'vue-spacebro-client': '^1.0.0',
'standard-settings': '^1.1.15'
}
if (Object.keys(plugins).length > 0) output += ',\n'
Object.keys(plugins).forEach((p, i) => {
output += ` "${p}": "${dependencies[p]}"`
if (i !== Object.keys(plugins).length - 1) output += ',\n'
})
return output
},
testing (unit, e2e, opts) {
if (unit || e2e) {
return opts.fn(this)
}
}
},
filters: {
'src/renderer/routes.js': 'plugins[\'vue-router\']',
'src/renderer/components/LandingPageView/CurrentPage.vue': 'plugins[\'vue-router\']',
'src/renderer/router/**/*': 'plugins[\'vue-router\']',
'src/renderer/store/**/*': 'plugins[\'vuex\']',
'src/renderer/store/modules/Media.js': 'plugins[\'vuex\'] && plugins[\'vue-spacebro-client\']',
'src/renderer/lib/sw-register.js': 'serviceWorker',
'src/renderer/lib/service-worker.js': 'serviceWorker',
'src/renderer/components/LandingPage/service-worker.vue': 'serviceWorker',
'test/e2e/**/*': 'e2e',
'test/unit/**/*': 'unit',
'.electron-vue/build.config.js': 'builder === \'packager\'',
'test/.eslintrc': 'e2e || unit',
'.eslintignore': 'eslint',
'.eslintrc.js': 'eslint',
'appveyor.yml': 'builder === \'builder\'',
'.travis.yml': 'builder === \'builder\'',
'settings/**': 'plugins[\'standard-settings\']',
'src/renderer/lib/settings.js': 'plugins[\'standard-settings\']',
'test/unit/specs/settings.spec.js': 'unit && plugins[\'standard-settings\']',
'test/e2e/specs/settings.spec.js': 'e2e && plugins[\'standard-settings\']'
},
complete (data) {
getCurrentSHA(data.author).then(sha => {
let path = !data.inPlace ? data.destDirName : null
if (path !== null) appendSHALink(sha, path)
console.log([
'\n---',
'',
'All set. Welcome to your new electron-vue project!',
'',
'Make sure to check out the documentation for this boilerplate at',
'\x1b[33mhttps://simulatedgreg.gitbooks.io/electron-vue/content/\x1b[0m.',
'',
`Next Steps:\n${!data.inPlace ? '\n \x1b[33m$\x1b[0m cd ' + data.destDirName : ''}`,
' \x1b[33m$\x1b[0m yarn (or `npm install`)',
' \x1b[33m$\x1b[0m yarn run dev (or `npm run dev`)'
].join('\n'))
}, () => {
console.log('\x1b[33mwarning\x1b[0m Failed to append commit SHA on README.md')
})
}
}