Qat is Node Cli Tool for quickly automate coding tasks using command line.
Q A T = Quickly Autmate Tasks
- run
npm i -g qat
- add qat.config.js file to the root directory of the project, and start writing your custom automated tasks
- run
qat your-custom-command
- watch the magic automated 👏 ✨
- a simple task for adding tow numbers, and printing the the result
module.exports = {
tasks: [
{
command: 'sum num1 num2',
run: (args, helpers) => {
const { num1, num2 } = agrs
const { print } = helpers
print(+num1 + +num2)
},
},
],
}
then run qat sum 1 3
in the command line, 4
will be printed
- a task for committing, and pushing changes
tasks: [
...{
command: 'commit message',
run: async (args, helpers) => {
const { message } = args
const { execute, print } = helpers
await execute(['git add .', `git commit -m "${message}"`, 'git push origin master'])
print('changes successfully committed', 'green')
},
},
]
when you run qat commit 'your commit message'
it will automaticly add the changes, commit it, and push it to the origin remote, then it will print a green color message "changes successfully committed".
- a task for automaticly generate a commponent folder and starter files
tasks: [
...{
command: 'add-component componentName',
run: async (args, helpers) => {
const { componentName } = args
const { createFolder, createFile, print } = helpers
const folderPath = `./src/components/${componentName}`
const compoPath = folderPath + `/${componentName}.jsx`
const stylesPath = folderPath + `/${componentName}.css`
await createFolder(folderPath)
await createFile(compoPath, '')
await createFile(stylesPath, '')
print(`${componentName} added successfully`, 'green')
},
},
]
then run qat add-component header
it will automaticly generate the Header component directory, and its styles files with the content provided as the second argument of createFile function, then it will print a green color message "Header added successfully".
every task object contains the command
property and run
method
-
command
property contains tow parts: the command name ( sum ) and the command arguments ( num1, num2 ) the command arguments will get passed as properties of the first argument of the run method -
run
method is the function will be execute when the command get run, the method accept tow params:
object of command arguments
- example:
{
command: "commit message",
run: ({ message }, helpers) => { /* some logic */ }
}
a set of utilities:
- print: it is a replacement of console.log with the color of the printed message, and the color of its background * colors: black - red - green - yellow - blue - magenta - cyan - white - crimson * example:
print('hello world!', 'yellow', 'blue')
// "hello world!" will be printed with yellow color and blue background
- createFolder: create a folder/directory with the given path
- exapmle:
await createFolder('./src')
- deleteFolder: delete a folder/directory by the given path
- exapmle:
await deleteFolder('./src')
- createFile: create a file with the given path and content
- exapmle:
await createFile('./message.txt', 'Hi there')
- readFile: get file content by its path
- exapmle:
const message = await readFile('./message.txt')
print(message) // "hi there" will be printed
- editFile: edit file content
- exapmle:
await readFile('./message.txt', (oldContent) => {
// some logic ...
return newContent
})
- deleteFile: remove file content by its path
- exapmle:
await deleteFile('path/to/file.js')
- openFiles: open files in new tabs ( VS Code )
- exapmle:
await openFiles('path/to/file.js')
// or
await openFiles(['path/to/file1.js', 'path/to/file2.js'])
- openURL: open the given URL in th edefault browser
- exapmle:
openURL('http://localhost:3000')
- execute: excute cli commands, accept one argument, it can be a string ( command ) or an array of strings ( commands )
- exapmle:
execute("echo 'hello world'")
execute(['cd src', 'touch newFile.js'])
- executeFile: excute shell scripts file
- exapmle:
executeFile('./script.sh')
- applyTemplate: generate Text based on template
- exapmle:
const template = `
import React from 'react'
const {{ functionName }} = () => {
return (
<div>
Hi {{ personName }}
</div>
)
}
export default {{ functionName }}
`
const text = applyTemplate(template, {
functionName: 'Hello',
personName: 'Mohamed',
})
print(text)
/*
import React from 'react'
const Hello = () => {
return (
<div>
Hi Mohamed
</div>
)
}
export default Hello
*/
Happy coding 😃