Skip to content

Commit

Permalink
Inital Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejlv committed Oct 23, 2024
0 parents commit 817dac1
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 0 deletions.
176 changes: 176 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache
build

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Actionfile

An fast and idiot proof task runner. Use a basic TOML file to define your tasks and run them with ease.

## Installation

Check the latest release for your platform and download the binary. You can also build from source. By downloading [Bun Runtime](https://bun.sh)

```bash
git clone https://github.com/lassejlv/better-actionfile && cd actionfile && bun run build --compile --minify index.ts --outfile build/actionfile
```

## Usage

**action.toml**
```toml
[hello]
cmd = "echo Hello World"
```

```bash
action # Will run the first command in action.toml otherwiese use action <command>
```

A better guide is coming soon.
5 changes: 5 additions & 0 deletions action.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hello]
cmd = "echo 'Hello, world!'"

[build]
cmd = "bun -v"
Binary file added bun.lockb
Binary file not shown.
82 changes: 82 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import fs from 'fs';
import { z } from 'zod';
import { version } from './package.json';

import child_process from 'child_process';

const CONFIG_FILE = 'action.toml';

if (!fs.existsSync(CONFIG_FILE)) {
console.error(`failed to find config file: ${CONFIG_FILE}`);
process.exit(1);
}

const commandSchema = z.object({
cmd: z.string().min(1),
});

const cliCommands = ['list', 'version', 'help']

let cmd;

try {
const commands = await import(`${process.cwd()}/${CONFIG_FILE}`);
const commandToRun = process.argv[2];


if (commandToRun && cliCommands.includes(commandToRun)) {


switch (commandToRun) {
case 'list':
console.log('Available commands:');
Object.keys(commands.default).forEach((command) => {
console.log(
` ${command}`
)

});
break;
case 'version':
console.log(`v${version}`);
break;
case 'help':
console.log('Usage: action <command>');
console.log('Available commands:');
cliCommands.forEach((command) => {
console.log(
` ${command}`
)

}
);
}

process.exit(0);
}



if (!commandToRun) {
// Access the first command from the default export
// @ts-ignore
cmd = Object.values(commands.default)[0].cmd;
} else {
// Access the specified command from the default export
cmd = commands.default[commandToRun]?.cmd;
}

if (!cmd) {
throw new Error('Command not found');
}

commandSchema.parse({ cmd });

// Execute the command
child_process.execSync(cmd, { stdio: 'inherit' });

console.log('Program executed successfully');
} catch (error: any) {
console.error(`failed to execute program: ${error.message}`);
process.exit(1);
}
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "actionfile",
"version": "2.0.0",
"description": "Fast & idiot proof task runner",
"module": "index.ts",
"type": "module",
"scripts": {
"build:macos:arm64": "bun build --compile --minify --target=bun-darwin-arm64 index.ts --outfile build/actionfile-darwin-arm64",
"build:macos:x64": "bun build --compile --minify --target=bun-darwin-x64 index.ts --outfile build/actionfile-darwin-x64",
"build:linux:arm64": "bun build --compile --minify --target=bun-linux-arm64 index.ts --outfile build/actionfile-linux-arm64",
"build:linux:x64": "bun build --compile --minify --target=bun-linux-x64 index.ts --outfile build/actionfile-linux-x64",
"build:win:x64": "bun build --compile --minify --target=bun-windows-x64 index.ts --outfile build/actionfile-win-x64",
"build:all": "bun build:macos:arm64 && bun build:macos:x64 && bun build:linux:arm64 && bun build:linux:x64 && bun build:win:x64"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"zod": "^3.23.8"
}
}
27 changes: 27 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}

0 comments on commit 817dac1

Please sign in to comment.