package-xml
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -10,3 +10,3 @@ { | ||
"stopOnEntry": false, | ||
"args": ["-m", "-D", "/Users/John/Github/esba/src/"], | ||
"args": ["-C", "clean-config.json", "-D", "/Users/John/Github/esba/src/"], | ||
"cwd": "${workspaceRoot}", | ||
@@ -33,3 +33,3 @@ "preLaunchTask": null, | ||
"runtimeExecutable": null, | ||
"args": ["test/*.spec.js", "--colors"], | ||
"args": ["test/clean-xml.spec.js", "--colors"], | ||
"env": { } | ||
@@ -36,0 +36,0 @@ } |
72
index.js
#!/usr/bin/env node | ||
var fs = require('fs-extra') | ||
var xml = require('libxmljs') | ||
var path = require('path') | ||
var argv = require('yargs') | ||
@@ -38,23 +39,62 @@ .option('D', { | ||
}) | ||
.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() | ||
require('./js/packageXmlGenerator')(argv.dir, argv.version, argv.name, argv.managed).then(markup => { | ||
return fs.outputFile(getPath(argv), markup, (err) => { | ||
console.log('Package.xml generated in ' + (Date.now() - start) + 'ms') | ||
if (err) console.log(err) | ||
}); | ||
}) | ||
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(argv) { | ||
if (argv.dir.startsWith('/')) { | ||
// Path is absolute | ||
return argv.dir + '/package.xml' | ||
} else if (argv.dir.startsWith('./')) { | ||
// Path is relative, or default | ||
return process.cwd() + '/' + argv.dir.substring(2) + '/package.xml' | ||
function getPath(filePath) { | ||
if (filePath.startsWith('/')) { | ||
// 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 { | ||
// path is relative, without the default ./ | ||
return process.cwd() + '/' + argv.dir + '/package.xml' | ||
// Dir is relative path.. try to normalize it | ||
try { | ||
var filePath = path.normalize(process.cwd() + '/' + 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') | ||
} |
@@ -8,14 +8,14 @@ var xml = require('libxmljs') | ||
module.exports = function (path, api_version, package_name, managed) { | ||
self.managed = managed | ||
module.exports = function (config) { | ||
self.managed = config.managed | ||
// Get/Set path and insure it actually exists | ||
try { | ||
self.path = fs.realpathSync(path) | ||
self.path = fs.realpathSync(config.dir) | ||
} catch (error) { | ||
console.error(path + ' is not a real path. Please check your path and try again') | ||
console.error(config.dir + ' is not a real path. Please check your path and try again') | ||
return Promise.reject(error) | ||
} | ||
if (package_name) { | ||
self.package_name = package_name | ||
if (config.name) { | ||
self.package_name = config.name | ||
} else { | ||
@@ -32,4 +32,4 @@ try { | ||
if (api_version) { | ||
self.api_version = api_version | ||
if (config.version) { | ||
self.api_version = version | ||
} else { | ||
@@ -36,0 +36,0 @@ try { |
{ | ||
"name": "package-xml", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Build a Salesforce Package.xml file from a src directory", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,12 +17,54 @@ # Package.xml generator in JavaScript | ||
``` | ||
-D, --dir The path to the source directory containing your SFDC files and | ||
metadata. Your package.xml file will end up here. | ||
[string] [default: "./src"] | ||
-v, --version The Saleforce API Version you wish to target with this package. | ||
[string] [default: "37.0"] | ||
-n, --name The name of the package. | ||
[string] | ||
-m Include Managed objects and fields | ||
[boolean] | ||
Options: | ||
-D, --dir The path to the source directory containing your SFDC | ||
files and metadata. Your package.xml file will end up | ||
here. [string] [required] [default: "./src"] | ||
-X, --destroy Create a destructiveChanges.xml file. | ||
[boolean] [default: false] | ||
-v, --version The Saleforce API Version you wish to target with this | ||
package. [string] | ||
-n, --name The name of the package. [string] | ||
-m, --managed Include Managed Package Fields. [boolean] [default: false] | ||
-c, --clean Clean the Metadata files [boolean] [default: false] | ||
-C, --clean-config Clean the Metadata files from a provided configuration | ||
file [string] [default: ""] | ||
-h Show help [boolean] | ||
``` | ||
## Clean Metadata | ||
The Clean Metadta option is available ass of version 2.1 | ||
This option will clean out boilerplate metadata that can sometimes cause problems with deploying between different orgs | ||
Also, if some metadata is not valid, visible, or enabled, then it shouldn't go in the package, hence we need to clean up the metadata. | ||
Below is the standard configuration for cleaning files. When using the "clean" option, this is the configuration that will be used. | ||
But we all know you will probably want a custom clean config. In that case, copy the config below and customie it. | ||
The selectors you see are simple xml path selectors. | ||
The `xmlns` namespace is required on element selectors, so if you create a custom clean configuration, be sure to include that on any element selectors. | ||
For tips on how to write selectors, you can go to w3c at [http://www.w3schools.com/xml/xml_syntax.asp](http://www.w3schools.com/xml/xml_syntax.asp) | ||
All options are optional, so you probably don't need to inlcude the namespace option unless you're doing something very unexpected | ||
``` | ||
{ | ||
"selectors": [ | ||
"./xmlns:packageVersions", | ||
"./xmlns:applicationVisibilities[xmlns:visible = 'false']", | ||
"./xmlns:classAccesses[xmlns:enabled='false']", | ||
"./xmlns:fieldPermissions[xmlns:editable='false' and xmlns:readable='false']", | ||
"./xmlns:fieldPermissions[editable = 'false' and readable = 'false']", | ||
"./xmlns:objectPermissions[xmlns:allowCreate = 'false' and xmlns:allowDelete = 'false' and xmlns:allowEdit = 'false' and xmlns:allowRead = 'false' and xmlns:modifyAllRecords = 'false' and xmlns:viewAllRecords = 'false']", | ||
"./xmlns:pageAccesses[xmlns:enabled = 'false']", | ||
"./xmlns:userPermissions[xmlns:enabled = 'false']", | ||
"./xmlns:recordTypeVisibilities[xmlns:visible = 'false']", | ||
"./xmlns:tabSettings[xmlns:visibility = 'None']" | ||
], | ||
"extensions": [ | ||
"-meta.xml", | ||
".profile", | ||
".permissionset" | ||
], | ||
"namespace": "http://soap.sforce.com/2006/04/metadata" | ||
} | ||
``` |
182018
80
2127
70
11