This commit is contained in:
Sébastien Colladon 2017-06-22 20:32:53 +02:00
Родитель 5bf394d018
Коммит 15ca97c773
6 изменённых файлов: 41 добавлений и 26 удалений

Просмотреть файл

@ -25,7 +25,7 @@ module.exports = (config,logger) => {
const xml = xmlbuilder.create('Package')
.att('xmlns', 'http://soap.sforce.com/2006/04/metadata')
.dec('1.0', 'UTF-8');
result.forEach(elem => xml.importDocument(elem));
result.forEach(elem => {if(!!elem) xml.importDocument(elem)});
xml.ele('version')
.t(config.apiVersion);
const xmlContent = xml.end({ pretty: true, indent: ' ', newline: '\n' });

Просмотреть файл

@ -5,7 +5,7 @@ const metadata = require('../utils/metadata');
// TODO CustomObject
// TODO Workflow
// TODO email template and report dashboard
// TODO email template and report dashboard and Document
const classes = {
'CustomLabels' : CustomLabels

Просмотреть файл

@ -1,7 +1,7 @@
const metadata = require('../../utils/metadata');
const xmlbuilder = require('xmlbuilder');
const xml2jsAsync = require('../../utils/async-xml-parser');
const fs = require('fs');
const readFileAsync = require('../../utils/async-read-file')
const AbstractTypeStrategy = require('./standard-type-strategy');
module.exports = class CustomLabelStrategy extends AbstractTypeStrategy {
@ -11,25 +11,28 @@ module.exports = class CustomLabelStrategy extends AbstractTypeStrategy {
build(){
const promise = new Promise((resolve, reject) => {
if(this.child.children.length > 0) {
const type = xmlbuilder.create('types');
Promise.all(
this.child.children
.sort((a,b) => a.name.localeCompare(b.name))
.map( aCustomLabelNode => fs.readFileSync(aCustomLabelNode.path,"utf8"))
.map(xml2jsAsync)
).then(result => {
result.forEach( customLabelFile =>
customLabelFile.CustomLabels.labels.forEach(customLabelDefinition => {
type.ele('members')
.t(customLabelDefinition.fullName[0]);
})
)
}).then(()=> {
type.ele('name').t(metadata[this.child.name].children[metadata[this.child.name].xmlName]);
resolve(type);
}).catch(reject);
if(this.child.children.length == 0) {
resolve();
}
Promise.all(
this.child.children
.sort((a,b) => a.name.localeCompare(b.name))
.map( aCustomLabelNode => readFileAsync(aCustomLabelNode.path,'utf8').then(xml2jsAsync))
).then(result => {
let isEmpty = true;
const type = xmlbuilder.create('types');
result.forEach( customLabelFile => {
const customLabelDefinitions = customLabelFile.CustomLabels.labels
.sort((a,b) => a.fullName[0].localeCompare(b.fullName[0]));
isEmpty &= customLabelDefinitions.length == 0;
customLabelDefinitions.forEach(customLabelDefinition => {
type.ele('members')
.t(customLabelDefinition.fullName[0]);
})
})
type.ele('name').t(metadata[this.child.name].children[metadata[this.child.name].xmlName]);
resolve(isEmpty ? undefined : type);
}).catch(reject);
});
return promise;
}

Просмотреть файл

@ -8,13 +8,12 @@ module.exports = class StandardStrategy {
build(){
const promise = new Promise((resolve, reject) => {
if(this.child.children.length == 0) {
const children = this.child.children.filter(elem => elem.extension && elem.extension != '.xml' && !elem.name.startsWith('.'))
if(children.length == 0) {
resolve();
}
const type = xmlbuilder.create('types');
this.child.children
.filter(elem => elem.extension && elem.extension != '.xml' && !elem.name.startsWith('.'))
.sort((a,b) => a.name.localeCompare(b.name))
children.sort((a,b) => a.name.localeCompare(b.name))
.forEach(subChild => {
type.ele('members')
.t(subChild.name.replace(/\.[^/.]+$/,''));

Просмотреть файл

@ -0,0 +1,12 @@
const fs = require('fs');
const readFileAsync = (path) => {
const promise = new Promise((resolve, reject) => {
fs.readFile(path, (err, data) => {
if (err) reject(err);
resolve(data);
});
});
return promise;
};
module.exports = readFileAsync;

Просмотреть файл

@ -1,12 +1,13 @@
const xml2js = require('xml2js');
const parseStringAsync = (fileContent) => {
return new Promise((resolve, reject) => {
const promise = new Promise((resolve, reject) => {
const parser = new xml2js.Parser();
parser.parseString(fileContent, (err, result) => {
if (err) reject(err);
resolve(result);
});
});
return promise;
};
module.exports = parseStringAsync;