⚡️ Makes writing scripts absurdly easy

Overview

haxx

easily create and run scripts using javascript


getting startedcommandsapi

Features

  • 🔀 Process DX - easily manage and run processes
  • 📦 Javascript ESM - makes writing scripts easier, through javascript
  • 🔌 Great IO - provides easy to use IO functions, for known formats
  • 🧑‍💻 Opinionated - it's a great tool for writing tools, with tools inside

Getting started

It's as simple as creating a script file with a .mjs extension

#!/usr/bin/env haxx

const lastTag = await $`git tag | tail -n 1`
const tagMessage = String(await $`git tag -l -n9 ${lastTag}`)
    .match(/\s{2,}(.+)/)[1]
console.log(`Last tag message: ${tagMessage}`)

And running it

haxx my-script.mjs

Installation

You can either install it globally

npm i -g haxx
haxx my-script.mjs

Or run it through npx or any other package manager execute

npx -y haxx my-script.mjs

API

$

Executes a given command and returns a promise of the output.

Everything passed through ${...} will be automatically escaped and quoted.

const dirToRemove = 'my nice dir'
await $`rm -rf ${dirToRemove}` // rm -rf 'my nice dir'

You can pass arrays as arguments

const dirs = ['dir1', 'dir2']
await $`ls ${dirs}` // ls dir1 dir2

You can catch process exit codes upon a failing

try {
    await $`exit 1`
} catch (process) {
    console.log(`Exit code: ${process.exitCode}`)
    console.log(`Error: ${process.stderr}`)
}

You can pipe directly from the promise to any other stream

$`watch -n1 ls`.pipe(process.stdout)

read

Lets you read files easily, and specify formats

const content = await read`my-file.txt`

const package = await read.json`package.json`
console.log(package.version)

const deployment = await read.yaml`deployment.yaml`
console.log(deployment.metadata.name)

write

Lets you write files easily, and specify formats

await write('my-file', 'Hello world') 
// Hello World

await write.json('object.json', { hello: 'world' })
// { "hello": "world" }

await write.yaml('object.yaml', { hello: 'world' })
// hello: world

io

Gives you a nice interface for reading and saving files

const { data: pkg, save } = await io.json`package.json`
pkg.version = '1.0.1'
await save()

const { data: deployment, save: saveDeployment } = await io.yaml`deployment.yaml`
deployment.spec.template.spec.containers[0].image = 'my-new-image'
await saveDeployment()

exists

Checks if a file or directory exists

if (!exists('key')) {
    await write('key', Math.random().toString().slice(2))
}

remove

Removes a file or directory

remove('my-file')

cd

Changes the directory

await $`ls`
cd('another-directory')
await $`ls`

template

Lets you replace variables in a template

const phrase = template({ name: 'world'}, 'Hello {{ name }}')

const filled = template.file({ GITHUB_TOKEN: '...' }, 'my-template')

Included batteries

  • kleur - a nice color library
  • kleur-template - easier coloring through templating
  • glob - utility for globbing files
  • yaml - a yaml parser
  • os - the os package
  • path - the path package
  • minimist - your arguments parsed, availabe through the global constant argv

Acknowledgements

This project is heavily inspired by zx and fsxx, down to the code.

Check them out!

You might also like...

SigmaFit makes workout tracking easy!

SigmaFit makes workout tracking easy!

SigmaFit ⚡️ Features Track Everything: Log all your workouts on SigmaFit. It's simpler and more rugged than any notes-taking app out there. It will he

Oct 28, 2022

Million is a lightweight (1kb) Virtual DOM. It's really fast and makes it easy to create user interfaces.

🎦 Watch Video 📚 Read the docs 💬 Join our Discord What is Million? Million is a lightweight (1kb) Virtual DOM. It's really fast and makes it easy t

Aug 24, 2022

Lavanstax project - Makes it easy and fun to use İnstagram. Also first userbot for İnstagram

Lavanstax project - Makes it easy and fun to use İnstagram. Also first userbot for İnstagram

Lavanstax Lavanstax project - Makes it easy and fun to use İnstagram. Also first userbot for İnstagram | İnstagram | Telegram Channel | Telegram Group

Oct 15, 2022

Buildable's core open-source offering for actions that makes it easy to collect, centralize and action your backend system activity

Buildable's core open-source offering for actions that makes it easy to collect, centralize and action your backend system activity

What are Action Templates? Action Templates are open-source functions that save developers hundreds of hours when integrating databases, apps and othe

Nov 5, 2022

A kickstarter guide to writing ES6

A kickstarter guide to writing ES6

ES6 for Humans 📢 The complete guide is now available on Amazon Table of Contents let, const and block scoping Arrow Functions Default Function Parame

Jan 4, 2023

This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing.

Obsidian Phrasebank This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing. Example :intro_pr

Jan 1, 2023

An ESLint plugin for writing Remix.js Apps

eslint-plugin-remix An ESLint plugin for Remix Installing Firstly, install the dependency with Yarn yarn add eslint-plugin-remix --dev or with npm npm

Nov 15, 2022

Transpile TypeScript to Espruino flavor of JavaScript for ESP8266/ESP32 microcontrollers template project. Writing safe, maintainable, and testable code is the projects goal.

Transpile TypeScript to Espruino flavor of JavaScript for ESP8266/ESP32 microcontrollers template project. Writing safe, maintainable, and testable code is the projects goal.

ESP-TypeScript Transpile TypeScript to Espruino flavor of JavaScript for ESP8266/ESP32 microcontrollers template project. Writing safe, maintainable,

Dec 20, 2022

AdsPower supports Local API, which has functions like reading and writing account configuration information, opening and closing browsers, searching for accounts.

AdsPower supports Local API, which has functions like reading and writing account configuration information, opening and closing browsers, searching for accounts. Besides, it can cooperate with Selenium and Puppeteer to execute browser operations automatically.

Dec 1, 2022
Comments
  • Package and release binaries

    Package and release binaries

    Use vercel/pkg to package binaries to the following platforms

    • [ ] Windows (node16-win-x64)
      • Release to scoop
    • [ ] MacOS (node16-macos-x64 node16-macos-arm64)
      • Release to homebrew
    • [ ] Linux (node-alpine-x64 node-linux-x64)
      • Release to apt apk pacman
    opened by henrycunh 0
Releases(0.1.0)
Owner
henrycunh
tech lead @ clicampo
henrycunh
A Browser extension that not only makes your browsing experience safe but makes it optimized

Sia Sia is a browser extension that not only makes your browsing experience safe but makes it optimized Table of Contents About The Project Built With

Arun Govind M 14 Feb 23, 2022
A JavaScript module that shortens your code, makes life easier, and makes development faster!

Quxt A JavaScript module that shortens your code, makes life easier, and makes development faster! Installation npm install quxt Quick Start Check ind

Qux App 5 May 8, 2022
Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and easy to use it

Digispark_Overmaster Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and

Yehia Elborma 5 Nov 14, 2022
Jaxit is an easy-to-use library that makes an interactive terminal for your programs.

Jaxit Jaxit is an easy-to-use library that makes an interactive terminal for your programs. Jaxit was made by Codeverse, so check on Codeverse's Profi

null 3 Dec 11, 2022
Brew-Near-You - An app that makes it easy to find a brewery near you

Brew Near You An app that makes it easy to find a brewery near you Built With HT

Taylor Vaughn 1 Aug 3, 2022
Inferrd makes Machine Learning deployment easy and scalable.

Introduction ML Deployment made simple, scalable and collaborative The new open-source standard to deploy, monitor and secure Machine Learning service

Inferrd 17 Dec 16, 2022
Makes downloading Scratch projects easy. Simply enter two project IDs and click start.

Makes downloading Scratch projects easy. Simply enter two project IDs and click start. No need to pick the right format or include the assets, all of this is done automatically and in the browser.

null 6 May 27, 2022
🤖 Makes it easy to create bots on discord through a simple command handler

MyBotHelper.JS ?? About facilitates the creation of bots via discord.js, the repository already has a main script that automatically synchronizes and

Marcus Rodrigues 4 Dec 31, 2022
An abstraction layer on top of @replit/crosis that makes Repl connection management and operations so easy, a Furret could do it! 🎉

Crosis4Furrets An abstraction layer on top of @replit/crosis that makes Repl connection management and operations so easy, a Furret could do it! ?? In

Ray 18 Dec 29, 2022
Flutter makes it easy and fast to build beautiful apps for mobile and beyond

Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing

Flutter 148.1k Jan 7, 2023