GIST for embed in Enhance CLI with ZX article on Medium
Last active
May 2, 2022 12:34
-
-
Save bsorrentino/a5da4ce0ca7208bcd9d00a5ab90ec053 to your computer and use it in GitHub Desktop.
Enhance CLI with ZX
This file contains 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
export const askForAuthProfile = async () => { | |
// Since 'minimist' is integrated a 'argv' is available out-of-box | |
if( argv.authindex ) { | |
// If a 'authindex' is provided as argument | |
// select the given authentication profile | |
await $`pac auth select --index ${argv.authindex}` | |
return | |
} | |
// list all available authentication profile | |
await $`pac auth list` | |
// interactively ask for a profile | |
const choice = await question('choose profile index (enter for confirm active one): ') | |
// select the given authentication profile | |
await $`pac auth select --index ${choice}` | |
} |
This file contains 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
export const askForSolutionFolder = async () => { | |
let solution | |
// Since 'minimist' is integrated a 'argv' is available out-of-box | |
if( argv.solution ) { | |
// If a 'solution' is provided as argument use it | |
solution = argv.solution | |
} | |
else { | |
// otherwise ask for it | |
solution = await question('solution folder: ') | |
} | |
// Since 'fs-extra' and 'chalk' are integrated 'fs' and 'chalk' are available out-of-box | |
try { | |
// Folder validation | |
const stats = await fs.stat( solution ) | |
if( stats.isDirectory() ) | |
return solution | |
console.log( chalk.red(`solution folder '${solution}' is not a directory!`)) | |
} | |
catch( e ) { | |
console.log( chalk.red(`solution folder '${solution}' doesn't exist!`)) | |
} | |
} | |
This file contains 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
try { | |
await askForAuthProfile() | |
const solution = await askForSolutionFolder() | |
// import Solution as 'Managed' into selected profile | |
await $`pac solution pack --zipfile /tmp/${solution}_managed.zip -f ${solution} -p Managed -aw` | |
await $`pac solution import -p /tmp/${solution}_managed.zip -f -pc -a` | |
} catch (p) { | |
if (p.exitCode) | |
console.log(`error occurred code: ${p.exitCode} error: ${p.stderr}`) | |
else | |
console.error(p) | |
} |
function | description |
---|---|
cd() |
Changes the current working directory. |
fetch() |
A wrapper around the node-fetch package. |
question() |
A wrapper around the readline package. |
sleep() |
A wrapper around the setTimeout function. |
nothrow() |
Changes behavior of $ to not throw an exception on non-zero exit codes. |
quiet() |
Changes behavior of $ to disable verbose output. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment