Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save renatoliveira/9a3a2a5731e21dedb5ea12646212c4b8 to your computer and use it in GitHub Desktop.

Select an option

Save renatoliveira/9a3a2a5731e21dedb5ea12646212c4b8 to your computer and use it in GitHub Desktop.
Setup fflib/at4dx via node script

fflib and at4dx should be pulled locally and pushed to your orgs.

They should NOT be backed up in git.

To install the packages run (from within your SFDX Project):

node --harmony setup.mjs -e ORG_ALIAS
import fs from 'fs'
import childProcess from 'child_process'
// run via `node --harmony setup-fflib.mjs -e ORG_ALIAS`
const REPOS = [
{
git: 'https://github.com/apex-enterprise-patterns/fflib-apex-mocks',
source: 'fflib-apex-mocks',
deployPath: 'sfdx-source',
},
{
git: 'https://github.com/apex-enterprise-patterns/fflib-apex-common',
source: 'fflib-apex-common',
deployPath: 'sfdx-source',
},
{
git: 'https://github.com/apex-enterprise-patterns/force-di',
source: 'force-di',
deployPath: 'force-di',
},
{
git: 'https://github.com/apex-enterprise-patterns/at4dx',
source: 'at4dx',
deployPath: 'sfdx-source',
},
]
const execute = async (command) => {
return new Promise(async (resolve, reject) => {
try {
resolve(childProcess.execSync(command, { stdio: 'inherit' }))
} catch (error) {
reject(error)
}
})
}
const cloneAndDeployToOrg = async (orgAlias) => {
const foldersToDeploy = []
await Promise.all(
REPOS.map(async (item) => {
const { source, git } = item
foldersToDeploy.push(item)
if (fs.existsSync(`./${source}`)) {
console.warn('\x1b[33m%s\x1b[0m ', `${source} already exists.`)
} else {
console.warn('\x1b[32m%s\x1b[0m ', `Cloning ${source} from ${git}`)
return execute(`git clone ${git} ${source}`)
}
})
)
if (foldersToDeploy.length > 0) {
console.log(
'Deploying ',
foldersToDeploy.map((item) => item.source)
)
await Promise.all(
foldersToDeploy.map(async ({ source, deployPath }) => {
console.warn(
'\x1b[32m%s\x1b[0m ',
`\nDeploying metadata ${source} to org.`
)
return execute(
`sf project deploy start --source-dir "./${source}/${deployPath}" --target-org ${orgAlias}`
)
})
)
console.log(`\nSuccessfully installed fflib into org ${orgAlias}\n`)
} else {
console.log(
'\x1b[32m%s\x1b[0m ',
'\nNo new folders cloned, no metadata updated'
)
}
}
const getArgs = () =>
process.argv.slice(2, process.argv.length).reduce((acc, arg, key) => {
// flags
if (arg[0] === '-') {
const flags = arg.slice(1, arg.length).split('')
flags.forEach((flag) => {
acc[flag] = process.argv[key + 3]
})
}
return acc
}, {})
const args = getArgs()
if (!args.e) {
console.error(
'\x1b[31m%s\x1b[0m ',
'Please provide org alias via the `-e` flag.'
)
} else {
cloneAndDeployToOrg(args.e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment