Skip to content

Commit

Permalink
refactor: upgrade xmlBuilder to xmlBuilder2
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Mar 18, 2022
1 parent 99fdf9a commit d6cc654
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<details>
<summary>Table of Contents</summary>

- [TL;DR;](#tldr)
- [TL;DR](#tldr)
- [What is SFDX-Git-Delta?](#what-is-sfdx-git-delta)
- [Is SGD for you?](#is-sgd-for-you)
- [Getting Started](#getting-started)
Expand Down Expand Up @@ -453,7 +453,7 @@ console.log(JSON.stringify(work))
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) - Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
- [fs-extra](https://github.com/jprichardson/node-fs-extra) - Node.js: extra methods for the fs object like copy(), remove(), mkdirs().
- [ignore](https://github.com/kaelzhang/node-ignore#readme) - is a manager, filter and parser which implemented in pure JavaScript according to the .gitignore spec 2.22.1.
- [xmlbuilder](https://github.com/oozcitak/xmlbuilder-js) - An XML builder for node.js similar to java-xmlbuilder.
- [xmlbuilder2](https://github.com/oozcitak/xmlbuilder2) - An XML builder for node.js.
- [micromatch](https://github.com/micromatch/micromatch) - a file glob matcher utility

## Versioning
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"ignore": "^5.1.8",
"micromatch": "^4.0.4",
"tslib": "^2.3.1",
"xmlbuilder": "^15.1.1"
"xmlbuilder2": "^3.0.2"
},
"license": "MIT",
"bugs": {
Expand Down
24 changes: 9 additions & 15 deletions src/utils/packageConstructor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const xmlbuilder = require('xmlbuilder')
const xmlConf = { indent: ' ', newline: '\n', pretty: true }
const { create } = require('xmlbuilder2')
const xmlConf = { indent: ' ', newline: '\n', prettyPrint: true }

module.exports = class PackageConstructor {
constructor(config, metadata) {
Expand All @@ -14,11 +14,11 @@ module.exports = class PackageConstructor {
}

constructPackage(strucDiffPerType) {
if (!strucDiffPerType) {
return
}
if (!strucDiffPerType) return

const xml = getXML()
const xml = create({ version: '1.0', encoding: 'UTF-8' }).ele('Package', {
xmlns: 'http://soap.sforce.com/2006/04/metadata',
})
const sortTypes = sortTypesWithMetadata(this.metadata)
Object.keys(strucDiffPerType)
.filter(
Expand All @@ -31,13 +31,13 @@ module.exports = class PackageConstructor {
[...strucDiffPerType[metadataType]] // transform set to array
.sort()
.reduce((type, member) => {
type.ele('members').t(member)
type.ele('members').txt(member)
return type
}, xml.ele('types'))
.ele('name')
.t(this.metadata[metadataType]?.xmlName ?? metadataType)
.txt(this.metadata[metadataType]?.xmlName ?? metadataType)
)
xml.ele('version').t(`${this.config.apiVersion}.0`)
xml.ele('version').txt(`${this.config.apiVersion}.0`)
return xml.end(xmlConf)
}
}
Expand All @@ -48,9 +48,3 @@ const sortTypesWithMetadata = metadata => (x, y) => {
const yMeta = metadata[y]?.xmlName ?? y
return xMeta.localeCompare(yMeta)
}

const getXML = () =>
xmlbuilder
.create('Package')
.att('xmlns', 'http://soap.sforce.com/2006/04/metadata')
.dec('1.0', 'UTF-8')
51 changes: 47 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,35 @@
"@oclif/core" "^1.3.1"
fancy-test "^2.0.0"

"@oozcitak/dom@1.15.10":
version "1.15.10"
resolved "https://registry.yarnpkg.com/@oozcitak/dom/-/dom-1.15.10.tgz#dca7289f2b292cff2a901ea4fbbcc0a1ab0b05c2"
integrity sha512-0JT29/LaxVgRcGKvHmSrUTEvZ8BXvZhGl2LASRUgHqDTC1M5g1pLmVv56IYNyt3bG2CUjDkc67wnyZC14pbQrQ==
dependencies:
"@oozcitak/infra" "1.0.8"
"@oozcitak/url" "1.0.4"
"@oozcitak/util" "8.3.8"

"@oozcitak/infra@1.0.8":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@oozcitak/infra/-/infra-1.0.8.tgz#b0b089421f7d0f6878687608301fbaba837a7d17"
integrity sha512-JRAUc9VR6IGHOL7OGF+yrvs0LO8SlqGnPAMqyzOuFZPSZSXI7Xf2O9+awQPSMXgIWGtgUf/dA6Hs6X6ySEaWTg==
dependencies:
"@oozcitak/util" "8.3.8"

"@oozcitak/url@1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@oozcitak/url/-/url-1.0.4.tgz#ca8b1c876319cf5a648dfa1123600a6aa5cda6ba"
integrity sha512-kDcD8y+y3FCSOvnBI6HJgl00viO/nGbQoCINmQ0h98OhnGITrWR3bOGfwYCthgcrV8AnTJz8MzslTQbC3SOAmw==
dependencies:
"@oozcitak/infra" "1.0.8"
"@oozcitak/util" "8.3.8"

"@oozcitak/util@8.3.8":
version "8.3.8"
resolved "https://registry.yarnpkg.com/@oozcitak/util/-/util-8.3.8.tgz#10f65fe1891fd8cde4957360835e78fd1936bfdd"
integrity sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ==

"@salesforce/bunyan@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@salesforce/bunyan/-/bunyan-2.0.0.tgz#8dbe377f2cf7d35348a23260416fee15adba5f97"
Expand Down Expand Up @@ -5074,6 +5103,14 @@ js-tokens@^4.0.0:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@3.14.0:
version "3.14.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.13.1, js-yaml@^3.14.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537"
Expand Down Expand Up @@ -8119,10 +8156,16 @@ xml2js@^0.4.16, xml2js@^0.4.22:
sax ">=0.6.0"
xmlbuilder "~11.0.0"

xmlbuilder@^15.1.1:
version "15.1.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-15.1.1.tgz#9dcdce49eea66d8d10b42cae94a79c3c8d0c2ec5"
integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==
xmlbuilder2@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/xmlbuilder2/-/xmlbuilder2-3.0.2.tgz#fc499688b35a916f269e7b459c2fa02bb5c0822a"
integrity sha512-h4MUawGY21CTdhV4xm3DG9dgsqyhDkZvVJBx88beqX8wJs3VgyGQgAn5VreHuae6unTQxh115aMK5InCVmOIKw==
dependencies:
"@oozcitak/dom" "1.15.10"
"@oozcitak/infra" "1.0.8"
"@oozcitak/util" "8.3.8"
"@types/node" "*"
js-yaml "3.14.0"

xmlbuilder@~11.0.0:
version "11.0.1"
Expand Down

0 comments on commit d6cc654

Please sign in to comment.