forked from triestelaporte/package-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·105 lines (102 loc) · 3.23 KB
/
Copy pathindex.js
File metadata and controls
executable file
·105 lines (102 loc) · 3.23 KB
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
#!/usr/bin/env node
var fs = require('fs-extra')
var xml = require('libxmljs')
var path = require('path')
var argv = require('yargs')
.option('D', {
alias: 'dir',
demand: true,
default: './src',
describe: 'The path to the source directory containing your SFDC files and metadata. Your package.xml file will end up here.',
type: 'string'
})
.option('X', {
alias: 'destroy',
demand: false,
default: false,
describe: 'Create a destructiveChanges.xml file.',
type: 'boolean'
})
.option('v', {
alias: 'version',
demand: false,
describe: 'The Saleforce API Version you wish to target with this package.',
type: 'string'
})
.option('n', {
alias: 'name',
demand: false,
describe: 'The name of the package.',
type: 'string'
})
.option('i', {
alias: 'installScript',
demand: false,
describe: 'The name of the install script handler.',
type: 'string'
})
.option('m', {
alias: 'managed',
demand: false,
default: false,
describe: 'Include Managed Package Fields.',
type: 'boolean'
})
.option('c', {
alias: 'clean',
demand: false,
default: false,
describe: 'Clean the Metadata files',
type: 'boolean'
})
.option('C', {
alias: 'clean-config',
demand: false,
default: '',
describe: 'Clean the Metadata files from a provided configuration file',
type: 'string'
})
.help('h')
.argv
var start = Date.now()
argv.dir = getPath(argv.dir)
if (argv.clean) {
return require('./js/clean-xml')(argv).then((res) => reportFinished(null, 'Clean'))
} else if (argv['clean-config']) {
Object.assign(argv, fs.readJsonSync(getPath(argv['clean-config'])))
return require('./js/clean-xml')(argv).then((res) => reportFinished(null, 'Clean'))
} else {
return require('./js/packageXmlGenerator')(argv).then(markup => {
return fs.outputFile(argv.dir + '/package.xml', markup, (err) => reportFinished(err, 'Package.xml'));
})
}
function getPath(filePath) {
if (filePath.startsWith(path.sep)) {
// Dir is absolute path, make sure it's real
try {
if (fs.realpathSync(filePath)) {
return filePath
} else {
throw (filePath + ' is not a real path. Please check your path and try again')
}
} catch (error) {
throw (filePath + ' is not a real path. Please check your path and try again')
}
} else {
// Dir is relative path.. try to normalize it
try {
var filePath = path.normalize(process.cwd() + path.sep + filePath)
if (fs.realpathSync(filePath)) {
return filePath
} else {
throw (filePath + ' is not a real path. Please check your path and try again')
}
} catch (error) {
throw (filePath + ' is not a real path. Please check your path and try again')
}
}
}
function reportFinished(err, msg){
if (err) console.log(err)
console.log(msg + ' process completed in ' + (Date.now() - start) + 'ms')
}