Skip to content

Instantly share code, notes, and snippets.

View maciejcieslar's full-sized avatar
🐰
Working

Maciej Cieślar maciejcieslar

🐰
Working
  • Warsaw, Poland
View GitHub Profile
const message = (content: string, color: string) => {
const msg = emoji.emojify(content)
if (colors[color]) {
return colors[color](msg)
}
return msg
}
const createScriptExec = (script: string) => {
let instance = null
return async function execute() {
if (instance) {
await kill(instance, 'SIGKILL')
}
instance = spawn(script, [], { shell: true })
fromEvent(chokidar.watch(process.cwd()), 'all').pipe(
debounceTime(delay || 1000),
// ...
)
const isInDirectory = (directories: string[]) => (filePath: string) =>
directories.some(filePath.startsWith.bind(filePath))
const isExpectedExtension = (extensions: string[]) => (extension: string) =>
extensions.some(is(extension))
// ...
const shouldPathBeIgnored = isInDirectory(ignoredDirectories)
const shouldPathBeWatched = isInDirectory(watchedDirectories)
fromEvent(chokidar.watch(process.cwd()), 'all').pipe(
// ...
map(([event, filePath]: string[]) => {
const filename = path.basename(filePath)
const extension = path.extname(filename)
return {
event,
filename,
extension,
fromEvent(chokidar.watch(process.cwd()), 'all').pipe(
// ...
)
const parseArguments = (execution: program.Command) => {
const { ext = [], watch = [], ignore = [], delay = 0, exe } = execution
if (!exe) {
throw new Error('No script provided')
}
return {
delay,
extensions: ext.map((e) => `.${e}`),
const parsers = {
int: (number: string) => parseInt(number, 10),
float: (number: string) => parseFloat(number),
list: (val: string) => val.split(','),
collect: (val, memo) => {
memo.push(val)
return memo
},
}
const commandArguments = program
.version('1.0.0')
.option('-e, --ext <items>', 'Extensions to watch', parsers.list)
.option('-w, --watch <items>', 'Directories to watch', parsers.list)
.option('-i, --ignore <items>', 'Directories to ignore', parsers.list)
.option('-d, --delay <n>', 'Delay before the execution', parsers.int)
.option('-x, --exe <script>', 'Execute script on restart')
.parse(process.argv)
interface Config {
transports?: Transport[];
level?: Level;
}
const defaultConfig: Config = {
transports: [new transports.console({ level: 'info' })],
level: 'info',
};