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
const withList = async ({ directory }) => await filesystem.list(directory) | |
const withFilter = async ({ directory, matching }) => | |
await filesystem.find(directory, { matching }) |
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
const useChooseFile = finder => async ({ directory, message, matching }) => { | |
const candidateFiles = await finder({ directory, matching }) | |
const promptOptions = { | |
name: 'chosenFile', | |
message, | |
choices: ['all', prompt.separator(), ...candidateFiles] | |
} | |
const { chosenFile } = await prompt.ask(promptOptions) | |
return chosenFile | |
} |
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
function useChooseFile(finder) { | |
return function({ directory, message, matching }) { | |
const candidateFiles = await finder({ directory, matching }) | |
const promptOptions = { | |
name: 'chosenFile', | |
message, | |
choices: ['all', prompt.separator(), ...candidateFiles] | |
} | |
const { chosenFile } = await prompt.ask(promptOptions) | |
return chosenFile |
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
const listDirectory = useChooseFile(withList) | |
const filterInDirectory = useChooseFile(withFilter) | |
//usage | |
listDirectory({ directory: './tests' }) | |
filterInDirectory({ directory: 'server', matching '*.Dockerfile' }) | |
//same as | |
useChooseFile(withList)({ directory: './tests' }) | |
useChooseFile(withFilter)({ directory: 'server', matching '*.Dockerfile' }) |
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
const withList = async ({ directory }) => await filesystem.list(directory) | |
const withFilter = async ({ directory, matching }) => | |
await filesystem.find(directory, { matching }) | |
const useChooseFile = finder => async ({ directory, message, matching }) => { | |
const candidateFiles = await finder({ directory, matching }) | |
const promptConfig = { | |
type: 'list', | |
name: 'chosenFile', |
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
const numbers = [1,2,4,5,6,9] | |
const isEven = (number) => number % 2 === 0 | |
const even = numbers.filter(isEven) |
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
const runCommand = (command, options) => new Promise((resolve, reject) => { | |
const cmd = spawn(command, { | |
shell: true, | |
...options | |
}); | |
cmd.stdout.on('data', data => print.info(data.toString())); | |
cmd.stdout.on('end', () => resolve(command)); | |
cmd.stderr.on('data', data => print.info(data.toString())); |
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
const runCommand = (command, options) => new Promise((resolve, reject) => { | |
const { shouldPrint, ...rest } = options; | |
//prints | |
if(shouldPrint) | |
print.info(command); | |
//and runs | |
const cmd = spawn(command, { | |
shell: true, |
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
const runCommand = (command, options) => new Promise((resolve, reject) => { | |
const { shouldPrint, shouldMemoize, ...rest } = options; | |
//prints | |
if(shouldPrint) | |
print.info(command); | |
if(shouldMemoize) | |
memoize(command); | |
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
const withCommandLogger = func => (command, options) => { | |
print.info(`Running command: ${command}`) | |
return func(command, options) | |
} | |
export default withCommandLogger(runCommand); |