-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathindex
executable file
·392 lines (358 loc) · 8.88 KB
/
index
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env node
const path = require('path')
const fs = require('fs-extra')
const program = require('commander')
const chalk = require('chalk')
const packageJson = require('../package.json')
const buildScript = require('../cli/index.js')
const {
// recordOptions,
returnOptions,
} = require('../cli/utils')
const alipayToBaidu = require('../cli/alipay-baidu/index')
const alipayToWx = require('../cli/alipay-wechat/index')
const wxToWx = require('../cli/wechat-wechat/index')
const wxToBaidu = require('../cli/wechat-baidu/index')
const wxToTouTiao = require('../cli/wechat-tt/index')
const wxToQq = require('../cli/wx-qq/index')
const alipayPolyfill = require('../cli/alipay-polyfill/index')
const wx2my = require('../cli/wx2my/index')
const wx2tt = require('../cli/wx2tt/index')
const wxToQuickapp = require('../cli/wechat-quickapp')
const entryProcess = require('./entry')
const alipayWxCli = require('./alipay-wx')
const alipayBaiduCli = require('./alipay-baidu')
const wxWxCli = require('./wx-wx')
const wxToBaiduCli = require('./wx-baidu')
const inputDirPath = `${process.cwd()}/`
/**
* read packageJson
*/
let specialtypeCmd = false
const options = {
input: '',
output: '',
env: 'production',
remote: false,
component2: true,
platform: 'alipay',
scope: true,
error: false,
empty: false,
isReport: true,
fromId: 0,
hooks: {},
babel: {},
plugins: [],
useRuntimeLog: false,
watch: false,
ignoreNpm: true,
libraryName: '',
useCompileLog: true
}
program
.version(packageJson.version)
.option('-t, --type <type>', 'Which plugin to be used.')
.option('-i, --input <type>', 'Input path of compiled code.')
.option('-o, --output <type>', 'Output path of compiled code.')
.option('-c, --component <type>', 'Which plugin to be used.')
.option(
'-e, --env <type>',
'Compiling in development mode or production mode.'
)
.option('-s, --scope <type>', 'Compiling component in scope mode.')
.option('-r, --remote <type>', 'Pull ployfill from remote sources.')
.option(
'--component2 <type>',
'Is support component2 for alipay miniprogram.'
)
.option('--error <type>', 'Whether to throw error.')
.option('--empty <type>', 'Empty directory or not.')
.option('-f --fromId <type>', 'Scene value.')
.option('--platform <type>', 'The platform of alipay miniprogram.')
.option('-p --isReport <type>', 'Report or not.')
.option('-w --watch <type>', 'Watch code changes')
.option('-d --ignoreNpm <type>', 'ignore npm detection')
.option('-u --useRuntimeLog <type>', 'open runtime log')
.option('-l --libraryName <type>', 'custom npm name')
.option('--useCompileLog <type>', 'open compile log')
program.parse(process.argv)
const antmoveOptions = returnOptions(process.cwd())
if (antmoveOptions) {
Object.keys(options).forEach((optName) => {
options[optName] = antmoveOptions[optName]
})
}
options.input = program.input
options.defaultInput = inputDirPath
options.output = program.output
options.env = program.env || options.env
options.remote = program.remote || options.remote
options.scope = program.scope || options.scope
options.type = program.type
options.component = program.component || options.component
options.component2 = program.component2 || options.component2
options.platform = program.platform || options.platform
options.error = program.error || options.error
options.empty = program.empty || options.empty
options.fromId = program.fromId || options.fromId
options.isReport = program.isReport || options.isReport
options.useRuntimeLog = program.useRuntimeLog || options.useRuntimeLog
options.watch = program.watch || options.watch
options.ignoreNpm = program.ignoreNpm || options.ignoreNpm
options.libraryName = program.libraryName || options.libraryName
options.useCompileLog = program.useCompileLog || options.useCompileLog
if (options.error === 'true' || options.error === true) {
options.error = true
} else {
options.error = false
}
if (options.empty === 'true' || options.empty === true) {
options.empty = true
} else {
options.empty = false
}
if (options.isReport === 'true' || options.isReport === true) {
options.isReport = true
} else {
options.isReport = false
}
// scope/component2 默认值为true
if (
options.component2 === 'false' ||
options.component2 === 0 ||
options.component2 === false
) {
options.component2 = false
} else {
options.component2 = true
}
if (
options.scope === 'false' ||
options.scope === 0 ||
options.scope === false
) {
options.scope = false
} else {
options.scope = true
}
if (options.useRuntimeLog === 'true' || options.useRuntimeLog === true) {
options.useRuntimeLog = true
} else {
options.useRuntimeLog = false
}
if (options.watch === 'true' || options.watch === true) {
options.watch = true
} else {
options.watch = false
}
if (options.ignoreNpm === 'false' || options.ignoreNpm === false) {
options.ignoreNpm = false
} else {
options.ignoreNpm = true
}
if (options.useCompileLog === 'false' || options.useCompileLog === false) {
options.useCompileLog = false
} else {
options.useCompileLog = true
}
if (antmoveOptions) {
Object.keys(options).forEach((optName) => {
if (options[optName] === undefined) {
options[optName] = antmoveOptions[optName]
}
})
}
/**
* $ antmove wx-alipay ../alipay-app
* */
program
.version(packageJson.version)
.command('wx-alipay')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx-alipay',
})
})
program
.version(packageJson.version)
.command('wx2my')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx2my',
})
})
program
.version(packageJson.version)
.command('wx2tt')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx2tt',
})
})
program
.version(packageJson.version)
.command('wx-amap')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx-amap',
})
})
program
.version(packageJson.version)
.command('wx-tt')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx-tt',
})
})
program
.version(packageJson.version)
.command('wx-qq')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx-qq',
})
})
program
.version(packageJson.version)
.command('alipay-compiler')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'alipay-compiler',
})
})
program
.version(packageJson.version)
.command('wx')
.action(() => {
specialtypeCmd = true
action({
...options,
type: 'wx',
})
})
/**
* antmove-cli alipay-wx ../wx-app
*/
alipayWxCli(program, () => {
specialtypeCmd = true
action({
...options,
type: 'alipay-wx',
})
})
/**
* antmove-cli alipay-baidu ../baidu-app
*/
alipayBaiduCli(program, () => {
specialtypeCmd = true
action({
...options,
type: 'alipay-baidu',
})
})
/**
* antmove-cli wx-compiler ../wx-app
*/
wxWxCli(program, () => {
specialtypeCmd = true
action({
...options,
type: 'wx',
})
})
wxToBaiduCli(program, () => {
specialtypeCmd = true
action({
...options,
type: 'wx-baidu',
})
})
program.parse(process.argv)
if (!specialtypeCmd) {
action(options)
}
/**
* cmd options
* @param params
*/
function action(params) {
/**
* preprocess ouput path
*/
const buildInfo = {
'wx-alipay': buildScript,
'wx-amap': buildScript,
'wx-tt': wxToTouTiao,
'wx-qq': wxToQq,
'alipay-wx': alipayToWx,
'alipay-baidu': alipayToBaidu,
wx: wxToWx,
'alipay-compiler': alipayPolyfill,
'wx-baidu': wxToBaidu,
'wx-my': wx2my,
wx2tt: wx2tt,
'wx-quickapp': wxToQuickapp,
}
entryProcess(params, (opts = {}) => {
// let _input = opts.input,
// _output = opts.output;
opts.input = toAbsolutePath(opts.input)
opts.output = toAbsolutePath(opts.output)
if (!opts.output) {
program.help()
return false
}
if (opts.input === opts.output) {
console.log(chalk.red('输入输出目录不能为同一个地址。'))
}
if (opts.type === 'wx2my') {
opts.type = 'wx-my'
}
if (buildInfo[opts.type]) {
if (opts.type === 'wx-amap') {
opts.aliType = 'amap'
process.env.aliType = 'amap'
}
if (opts.type === 'alipay-wx') {
if (
program.scope === 'true' ||
program.scope === 1 ||
program.scope === true
) {
opts.scope = true
} else {
opts.scope = false
}
}
// _input = './';
// _output = processPath(opts);
// recordOptions(opts, _input, _output);
buildInfo[opts.type](opts)
} else {
console.log(chalk.red('编译类型错误,请选择可用的转换类型。'))
}
})
}
function toAbsolutePath(target) {
let dist = target
if (!path.isAbsolute(target)) {
dist = path.join(inputDirPath, target)
}
return dist
}