diff --git a/.profile b/.profile new file mode 100644 index 0000000..98c88b4 --- /dev/null +++ b/.profile @@ -0,0 +1,20 @@ +echo "Installing JQ for JSON parsing ..." + +# mkdir /app/.local/share/jq/bin +# cd /app/.local/share/jq/bin +wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 +chmod +x ./jq + +# echo "Updating PATH to include jq ..." +export PATH=$PATH:/app + +echo "Updating PATH to include Salesforce CLI ..." +export PATH=$PATH:/app/.local/share/sfdx/cli/bin/ + +echo "Updating Salesforce CLI plugin ..." +sfdx update + +echo "Creating local resources ..." +mkdir /app/tmp + +echo "Completed!" \ No newline at end of file diff --git a/app.js b/app.js index fbd68c4..002e821 100644 --- a/app.js +++ b/app.js @@ -160,6 +160,18 @@ app.get('/oauth/callback', (req, res) => { const router = express.Router(); +router.get('/test', (req, res) => { + + const script = `jq --help`; + + commands.run('test', script, (result) => { + res.json({ + message: result + }); + }); + +}); + router.post('/deploying', (req, res) => { const command = req.body.command; @@ -173,6 +185,8 @@ router.post('/deploying', (req, res) => { const startingDirectory = process.env.STARTINGDIRECTORY; const directory = `${tokenName}-${timestamp}`; + // const jqDirectory = '/app/.local/share/jq/bin/'; + let script; let sfdxurl; @@ -182,7 +196,8 @@ router.post('/deploying', (req, res) => { script = `${startingDirectory}mkdir ${directory};cd ${directory};git clone ${param} .`; - commands.run(command, script, () => { + commands.run(command, script, (result) => { + console.log('temp result', result); res.json({ message: `Successfully cloned ${param}` }); @@ -227,6 +242,18 @@ router.post('/deploying', (req, res) => { break; + case 'permset': + + script = `${startingDirectory}cd ${directory};export FORCE_SHOW_SPINNER=;sfdx force:user:permset:assign -n ${param}`; + + commands.run(command, script, (result) => { + res.json({ + message: `Permset assigned:\n\t${result}` + }); + }); + + break; + case 'test': script = `${startingDirectory}cd ${directory};export FORCE_SHOW_SPINNER=;sfdx force:apex:test:run -r human --json | jq -r .result | jq -r .summary | jq -r .outcome`; diff --git a/app.json b/app.json new file mode 100644 index 0000000..4e928bc --- /dev/null +++ b/app.json @@ -0,0 +1,36 @@ +{ + "name": "Deploy to Salesforce DX", + "description": "An application that will deploy an SFDX project from a public Github repo", + "repository": "https://github.com/wadewegner/deploy-to-sfdx", + "logo": "", + "keywords": ["deploy", "sfdx", "salesforcedx"], + "image": "", + "scripts": { + "postdeploy": "bin/deploy" + }, + "env": { + "CALLBACKURL": { + "description": "The callback URL for your Connected App", + "value": "" + }, + "CONSUMERKEY": { + "description": "The consumer key for your Connected App.", + "value": "" + }, + "CONSUMERSECRET": { + "description": "The consumer secret for your Connected App.", + "value": "" + }, + "STARTINGDIRECTORY": { + "description": "The base directory for the CLI", + "value": "" + } + }, + "buildpacks": [{ + "url": "https://github.com/wadewegner/salesforce-cli-buildpack" + }, + { + "url": "heroku/nodejs" + } + ] +} \ No newline at end of file diff --git a/bin/deploy b/bin/deploy new file mode 100644 index 0000000..20d602b --- /dev/null +++ b/bin/deploy @@ -0,0 +1,2 @@ +#!/usr/bin/env bash + diff --git a/lib/commands.js b/lib/commands.js index dba1fb1..b0fb9ac 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -4,6 +4,7 @@ const { module.exports = { run: (command, commandScript, result) => { + // console.log(command, commandScript); exec(commandScript, (err, stdout, stderr) => { if (stderr || err) { console.log(`${command}:err`, err); diff --git a/scripts/deploying.js b/scripts/deploying.js index e2af0a1..ac0a076 100644 --- a/scripts/deploying.js +++ b/scripts/deploying.js @@ -47,6 +47,7 @@ $(document).ready(() => { const timestamp = new Date().getTime().toString(); const assignPermset = doc['assign-permset']; + const permsetName = doc['permset-name']; const deleteScratchOrg = doc['delete-scratch-org']; const runApexTests = doc['run-apex-tests']; const scratchOrgDef = doc['scratch-org-def']; @@ -54,21 +55,29 @@ $(document).ready(() => { update_status(`Parsed the following values from the yaml file: \tassign-permset: ${assignPermset} +\tpermset-name: ${permsetName} \tdelete-scratch-org: ${deleteScratchOrg} \trun-apex-tests: ${runApexTests} \tscratch-org-def: ${scratchOrgDef} \tshow-scratch-org-url: ${showScratchOrgUrl}`); return deployingApi('clone', timestamp, githubRepo) - .then(() => { - return deployingApi('auth', timestamp); - }) + // .then(() => { + // return deployingApi('auth', timestamp); + // }) .then(() => { return deployingApi('create', timestamp, scratchOrgDef); }) .then(() => { return deployingApi('push', timestamp); }) + .then(() => { + if (permsetName) { + return deployingApi('permset', timestamp, permsetName); + } else { + return null; + } + }) .then(() => { return deployingApi('test', timestamp); }) @@ -98,20 +107,14 @@ $(document).ready(() => { commandData = {}; commandData.command = 'clean'; commandData.timestamp = timestamp; - - // return deployingApi('clean', timestamp).then(() => { - - // }; - - } }).then(() => { return deployingApi('clean', timestamp) .then(() => { - + message = `Finished. You have deploy the app to Salesforce DX!\n\n${message}`; $('textarea#status').val(message); - + }); }); });