forked from scolladon/sfdc-merge-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 1.04 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
'use strict';
const fs = require('fs');
const packageBuilder = require('./lib/utils/package-builder');
const asyncReadFile = require('./lib/utils/async-read-file');
const asyncXmlParser = require('./lib/utils/async-xml-parser');
// Plugin to merge package.xml.
module.exports = (config,logger) => {
// Check if we have enough config options
if(typeof config.packages === 'undefined' || config.packages === null) {
throw new Error('Not enough config options');
}
// The module return this promise
// This is where the job is done
return new Promise((resolve, reject) => {
Promise.all(config.packages.map(x=>asyncReadFile(x).then(asyncXmlParser)))
.then(pkgs => {
// Store max version;
const pkg = {};
pkg.version = Math.max(...pkgs.map(p=>p.Package.version[0]));
pkgs.forEach(p=>p.Package.types.reduce((r,e)=>pkg[e.name[0]] = [...new Set((pkg[e.name[0]] || []).concat(e.members))],pkg))
fs.writeFileSync(config.output, packageBuilder(pkg));
})
.catch(err =>
reject(new Error(err))
);
});
};