npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qat

v0.1.0

Published

Quickly automate coding tasks

Downloads

3

Readme

What is Qat?

Qat is Node Cli Tool for quickly automate workflow tasks using command line.

Q A T = Quickly Autmate Tasks

How to get started?

  1. run npm i -g qat or yarn add global qat

  2. add qat.config.js file to the root directory of the project, and start writing your custom commands

  3. run qat your-custom-command

  4. watch the magic automated :clap: :sparkles:

Examples

  • a simple command for adding tow numbers, and printing the the result

module.exports = {
	add: ({ agrs, log }) => {
		const [num1, num2] = args
		log(+num1 + +num2)
	}
}

then run qat sum 1 3 in the command line, 4 will be printed

  • an command for committing, and pushing changes
module.exports = {
	...
	commit: async ({ args, exec, log }) => {
		const [message] = agrs

		await  exec.command(['git add .', `git commit -m "${message}"`, 'git push origin main'])
		log.info('changes successfully committed')
	}
}

when you run qat commit 'your commit message' it will automatically add the changes, commit it, and push it to the origin remote, then it will print a green color message "changes successfully committed".

  • an command for automatically generate a component folder and starter files
module.exports = {
	...
	component: async ({ args, fs, log }) => {
		const [componentName] = agrs

		await fs.create(`components/${componentName}.jsx`)
	}
}

then run qat component Header, it will automatically create the Header component file.

Command Structure

	[command_topic]: async (toolset: { agrs, log, fs, applyTemplate, openUrl, exec }) => { ... }
  • args ( array of strings ) the arguments passed when running the command

  • log function, which is an advanced replacement of console.log

log('hello world') // default
log.error('Error occured') // red
log.info('Sucess') // green
log.warn('warning') // yellow
  • exec un object that contains tow methods: command and file

    • .command(string | array of strings) for executing cli commands
    • .file(path) for executing shell files
await  exec.command('npm install axios')
await  exec.command(['git add .', 'git commit', 'git push'])

await  exec.file('./deploy.sh')
  • openUrl(string) for opening URL in default browser
await  openUrl('http://localhost:3000')
  • applyTemplate(template, variables, marks?) for replacing template variables in a string
    • template (string)
    • varibales (object)
    • marks ( [opening_mark, closing_mark] | [same_mark] )
const stringTemplate = 'Hello {{ name }}'
log(applyTemplate(stringTemplate, { name: 'Mohamed' }))
// Hello Mohamed

const stringTemplate = 'Hello __name__'
log(applyTemplate(stringTemplate, { name: 'Ibrahim' }, ['__']))
// Hello Ibrahim
  • fs
    • .isExists(path) return boolean value.
    • .create(path | object | array[path | objects], parentPath?) for creating files and folders
      • path ( string ) if the path basename has an extension, it create a file, if not, it create a folder, for special cases, use an object as argument.
      • object
        • .path ( string )
        • .type? ( "file" | "folder" )
        • .content? ( string ) if the type is a file.
        • .children? if the type is a folder, and it will be passed as an argument of .create method with parent path of its parent object.
    • .readFile(path) return file content.
    • .readDir(path) return folder structure.
    • .readTemplate(path, variables, marks?) same as applyTemplate but with the template path in place of the template string.
    • .edit(path, editFunction) for editing files content, the editFunction take old content as an argument and should return the new content.
    • .delete(path | array of paths) for deleting files and folders.
    • .open(path | array of paths) for opening file or multiple files in new VS Code tabs.
    • .copy(srcDir, destDir, files?) for copy files from a directory to another.
      • srcDir ( string ) path of the source directory.
      • destDir ( string ) path of the destination directory.
      • files ( array of string ) names of specific files you want to copy. by default it copy all the files and folders .
    • .watch('file, dir, glob, or array')
/**** fs.create examples ****/

await fs.create('styles.css')
// will create file named style.css

await fs.create('wrapper')
// will create a folder named wrapper

await fs.create(['index.js'. 'components', 'style.css'])
// will create tow files: index.js and style.css, and one folder named components

await fs.create(
{
	path: 'Header',
	children: [
		{
			 path: 'index.jsx',
			 content: 'import React from react'
		 },
		 'style.css'
	]
}, 'components')
/*
	will create the next structure
	- components
		- Header
			- index.jsx ( filled with initial content "import React from react" )
			- style.css
*/
/**** fs.create example ****/

// Initialize watcher.
const watcher = fs.watch('file, dir, glob, or array')

// Add event listeners.
watcher
  .on('add', path => log(`File ${path} has been added`))
  .on('change', path => log(`File ${path} has been changed`))
  .on('unlink', path => log(`File ${path} has been removed`))

// More possible events.
watcher
  .on('addDir', path => log(`Directory ${path} has been added`))
  .on('unlinkDir', path => log(`Directory ${path} has been removed`))
  .on('error', error => log(`Watcher error: ${error}`))
  .on('ready', () => log('Initial scan complete. Ready for changes'))
  .on('raw', (event, path, details) => { // internal
    log('Raw event info:', event, path, details)
  })

// Stop watching.
// The method is async!
watcher.close().then(() => console.log('closed'))

Happy coding :smiley: