-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·84 lines (76 loc) · 2.22 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
76
77
78
79
80
81
82
83
84
#! /usr/bin/env node
const { makeDebugXML, makeManifestXML } = require('./xml')
const { validate, format } = require('./utils')
const { description, version } = require('./package.json')
const example = require('./example.json')
const argv = require('minimist')(process.argv.slice(2))
const fs = require('fs-extra')
const path = require('path')
const cwd = process.cwd()
let dest = cwd
if (argv.help) {
console.log(
`
${description}
Usage
$ cepgen [options]
Options
--init Adds config to package.json
--debug Generates .debug file
--dest <path> Relative path to destination
`)
process.exit(0)
}
if (argv.init) {
try {
const pkgPath = `${cwd}/package.json`
const exists = fs.existsSync(pkgPath)
const pkg = exists ? fs.readJSONSync(pkgPath) : {}
pkg.cep = example
fs.outputJSONSync(pkgPath, pkg, { spaces: '\t' })
process.exit(0)
} catch (error) {
console.log(error)
process.exit(-1)
}
}
if (argv.dest) {
if (typeof argv.dest !== 'string' || argv.dest === '/') {
console.log('"dest" is not of type string')
process.exit(-1)
} else {
dest = path.resolve(cwd, argv.dest)
}
}
if (argv.v) {
console.log(version)
process.exit(0)
}
try {
if (!fs.existsSync(`${cwd}/package.json`)) {
console.log(`Missing "package.json" in\n ${cwd}`)
process.exit(-1)
} else {
const pkg = fs.readFileSync(`${cwd}/package.json`, 'utf8')
const json = JSON.parse(pkg)
validate(json, argv.debug)
const settings = json.cep
const pkgVersion = json.version
const xml = makeManifestXML({
...settings,
pkgVersion
})
fs.outputFileSync(`${dest}/CSXS/manifest.xml`, format(xml))
const rel = path.relative(cwd, dest)
console.log(`Manifest written to .${rel}/CSXS/manifest.xml`)
if (argv.debug) {
const xml = makeDebugXML(settings.extensions)
fs.outputFileSync(`${dest}/.debug`, format(xml))
console.log(`Debug file written to .${rel}/.debug`)
}
process.exit(0)
}
} catch (error) {
console.log(error)
process.exit(-1)
}