-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·75 lines (65 loc) · 1.69 KB
/
index.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
#!/usr/bin/env node
const commander = require('commander');
const chalk = require('chalk');
const path = require('path')
const packageJson = require('./package.json');
const { download } = require('./src/download')
const getOutPath = require('./src/getOutPath')
let defulatConfigPath = '/.pulliconfontrc'
let defaultOutputPath = `${process.env.PWD}/iconfont`
const defaultConfig = {
downloadUrl:'',
cookie: '',
saveDemoFile: true, // 是否保存demo文件
outputPath: './iconfont',
iconPrefix: 'icon',
pickicons:[],
useSvg: false,
}
commander
.version(packageJson.version)
.option('-c, --config <config>', 'config.js path')
.action(function ({ config, output }) {
configPath = path.resolve(config || defulatConfigPath)
})
.allowUnknownOption()
.parse(process.argv)
// 解析项目类型与名称
// const processArgs = process.argv.slice(2)
// if (processArgs && processArgs[1]) {
// console.log(processArgs)
// }
async function main () {
let config = null
try {
config = require(configPath);
} catch (e) {
console.log(chalk.red(`load config file failed. \n file path: \n${configPath}`))
throw e;
}
console.log(__dirname)
await download({
...defaultConfig,
...config,
})
if (config.useSvg) {
const outPath = getOutPath(config)
console.log('useSvg', outPath)
}
}
main()
.then((res) => {
console.log('end')
})
.catch(err => {
console.log()
console.log('Aborting installation.')
if (err.command) {
console.log(` ${chalk.cyan(err.command)} has failed.`)
} else {
console.log(chalk.red('Unexpected error. Please report it as a bug:'))
console.log(err)
}
console.log()
process.exit(1)
})