Last active
June 14, 2018 03:30
-
-
Save visualjeff/9c4aa07fa68e0a1863ca7cf78f376ba2 to your computer and use it in GitHub Desktop.
Basic detokenization script for a VSTS Release "Bash Task". Intended for inline execution. Uses handlebars syntax. Tested on Linux and Windows. Assumes Node V7.6+ is installed. Also assumes files are prefixed with B2C_1A_ and end with an extension of .xml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install handlebars form-data node-fetch | |
s="'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const handlebars = require('handlebars'); | |
const source = process.env.source || '.'; | |
const target = process.env.target || '.'; | |
const tokens = { | |
tenantId: process.env.tenantId || 'defaultTenantId', | |
buildId: process.env.buildId || '000' | |
} | |
const getLocalPolicies = ((path) => { | |
const files = fs.readdirSync(path); | |
return files.filter((file) => { | |
return (file.includes('B2C_1A_') && file.endsWith('.xml')); | |
}); | |
}); | |
const getFileContent = ((path) => { | |
return fs.readFileSync(path, 'utf8'); | |
}); | |
const detokenize = (source, data) => { | |
const template = handlebars.compile(source); | |
return template(data); | |
} | |
const persistExistingPolicy = (name, content) => { | |
fs.writeFileSync(name, content, (err) => { | |
if (err) throw err; | |
}); | |
} | |
getLocalPolicies(source).forEach(policy => { | |
const localPolicy = getFileContent(path.join(source, policy)); | |
const detokenizedPolicy = detokenize(localPolicy, tokens); | |
persistExistingPolicy(path.join(target, policy), detokenizedPolicy); | |
}); | |
" | |
node -e "$s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment