@adamhl8/bask 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +23 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/shell.d.ts +6 -0
- package/dist/shell.d.ts.map +1 -0
- package/dist/shell.js +19 -0
- package/dist/shell.js.map +1 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 adamhl8
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# bask
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A task runner for Bun where tasks are TypeScript functions.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- [Bun](https://bun.sh), because tasks run on Bun and shell out with Bun's `$`
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
bun add --dev @adamhl8/bask
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Export tasks from a `bask.ts` in your project root. The default export is the task that runs when you don't name one. Calling a task from another task makes it a dependency, and each task runs at most once per invocation.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { task } from "@adamhl8/bask"
|
|
21
|
+
|
|
22
|
+
export const lint = task(async ({ $ }) => {
|
|
23
|
+
await $`oxlint`
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const build = task({ desc: "Lint, then build" }, async ({ $ }) => {
|
|
27
|
+
await lint()
|
|
28
|
+
await $`tsdown`
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export default build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Run a task with `bunx`, because `bun bask` runs your `bask.ts` instead of the `bask` bin. Each command is printed before it runs.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
bunx bask build
|
|
38
|
+
```
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { isTask } from "./index.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/cli.ts
|
|
5
|
+
const isModule = (value) => typeof value === "object" && Boolean(value);
|
|
6
|
+
const main = async () => {
|
|
7
|
+
const taskName = process.argv[2] ?? "default";
|
|
8
|
+
const baskModule = await import(path.resolve("bask.ts"));
|
|
9
|
+
if (!isModule(baskModule)) throw new Error("failed to import bask.ts");
|
|
10
|
+
const selectedTask = baskModule[taskName];
|
|
11
|
+
if (!isTask(selectedTask)) {
|
|
12
|
+
const taskNames = Object.entries(baskModule).filter(([, value]) => isTask(value)).map(([name]) => name);
|
|
13
|
+
console.error(`Unknown task "${taskName}". Available tasks: ${taskNames.join(", ")}`);
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
await selectedTask();
|
|
18
|
+
};
|
|
19
|
+
await main();
|
|
20
|
+
//#endregion
|
|
21
|
+
export {};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env bun\n\nimport path from \"node:path\"\n\nimport { isTask } from \"#index.ts\"\n\nconst isModule = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && Boolean(value)\n\nconst main = async () => {\n const taskName = process.argv[2] ?? \"default\"\n\n const baskModule: unknown = await import(path.resolve(\"bask.ts\"))\n if (!isModule(baskModule)) throw new Error(\"failed to import bask.ts\")\n\n const selectedTask = baskModule[taskName]\n\n if (!isTask(selectedTask)) {\n const baskExports = Object.entries(baskModule)\n const taskExports = baskExports.filter(([, value]) => isTask(value))\n const taskNames = taskExports.map(([name]) => name)\n\n console.error(`Unknown task \"${taskName}\". Available tasks: ${taskNames.join(\", \")}`)\n process.exitCode = 1\n return\n }\n\n await selectedTask()\n}\n\nawait main()\n"],"mappings":";;;;AAMA,MAAM,YAAY,UAAqD,OAAO,UAAU,YAAY,QAAQ,KAAK;AAEjH,MAAM,OAAO,YAAY;CACvB,MAAM,WAAW,QAAQ,KAAK,MAAM;CAEpC,MAAM,aAAsB,MAAM,OAAO,KAAK,QAAQ,SAAS;CAC/D,IAAI,CAAC,SAAS,UAAU,GAAG,MAAM,IAAI,MAAM,0BAA0B;CAErE,MAAM,eAAe,WAAW;CAEhC,IAAI,CAAC,OAAO,YAAY,GAAG;EAGzB,MAAM,YAFc,OAAO,QAAQ,UACL,CAAC,CAAC,QAAQ,GAAG,WAAW,OAAO,KAAK,CACtC,CAAC,CAAC,KAAK,CAAC,UAAU,IAAI;EAElD,QAAQ,MAAM,iBAAiB,SAAS,sBAAsB,UAAU,KAAK,IAAI,GAAG;EACpF,QAAQ,WAAW;EACnB;CACF;CAEA,MAAM,aAAa;AACrB;AAEA,MAAM,KAAK"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ShellWrapper } from "./shell.js";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
interface TaskOptions {
|
|
4
|
+
desc?: string;
|
|
5
|
+
}
|
|
6
|
+
interface TaskContext {
|
|
7
|
+
$: typeof ShellWrapper;
|
|
8
|
+
}
|
|
9
|
+
type AsyncOrSyncReturn = Promise<void> | void;
|
|
10
|
+
type TaskFn = (ctx: TaskContext) => AsyncOrSyncReturn;
|
|
11
|
+
export interface Task {
|
|
12
|
+
(): Promise<void>;
|
|
13
|
+
options: TaskOptions;
|
|
14
|
+
}
|
|
15
|
+
export declare const isTask: (value: unknown) => value is Task;
|
|
16
|
+
/** Registers a task that runs at most once per bask invocation, however many times it's called. */
|
|
17
|
+
export declare function task(fn: TaskFn): Task;
|
|
18
|
+
export declare function task(options: TaskOptions, fn: TaskFn): Task;
|
|
19
|
+
//#endregion
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;UAEU;EACR;;UAGQ;EACR,UAAU;;KAGP,oBAAoB;KAEpB,UAAU,KAAK,gBAAgB;iBAEnB;MACX;EACJ,SAAS;;qBAKE,SAAM,mBAAqB,SAAS;;wBAGjC,KAAK,IAAI,SAAS;wBAClB,KAAK,SAAS,aAAa,IAAI,SAAS"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ShellWrapper } from "./shell.js";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const tasks = /* @__PURE__ */ new WeakSet();
|
|
4
|
+
const isTask = (value) => typeof value === "function" && tasks.has(value);
|
|
5
|
+
function task(optionsOrFn, maybeFn) {
|
|
6
|
+
const [options, fn] = typeof optionsOrFn === "function" ? [{}, optionsOrFn] : [optionsOrFn, maybeFn];
|
|
7
|
+
if (!fn) throw new Error("task() needs a callback");
|
|
8
|
+
const runFn = async () => fn({ $: ShellWrapper });
|
|
9
|
+
let taskFnPromise;
|
|
10
|
+
const run = async () => {
|
|
11
|
+
if (taskFnPromise) return taskFnPromise;
|
|
12
|
+
taskFnPromise = runFn();
|
|
13
|
+
return taskFnPromise;
|
|
14
|
+
};
|
|
15
|
+
const newTask = Object.assign(run, { options });
|
|
16
|
+
tasks.add(newTask);
|
|
17
|
+
return newTask;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isTask, task };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { ShellWrapper } from \"#shell.ts\"\n\ninterface TaskOptions {\n desc?: string\n}\n\ninterface TaskContext {\n $: typeof ShellWrapper\n}\n\ntype AsyncOrSyncReturn = Promise<void> | void\n\ntype TaskFn = (ctx: TaskContext) => AsyncOrSyncReturn\n\nexport interface Task {\n (): Promise<void>\n options: TaskOptions\n}\n\nconst tasks = new WeakSet<object>()\n\nexport const isTask = (value: unknown): value is Task => typeof value === \"function\" && tasks.has(value)\n\n/** Registers a task that runs at most once per bask invocation, however many times it's called. */\nexport function task(fn: TaskFn): Task\nexport function task(options: TaskOptions, fn: TaskFn): Task\nexport function task(optionsOrFn: TaskOptions | TaskFn, maybeFn?: TaskFn): Task {\n const [options, fn] = typeof optionsOrFn === \"function\" ? [{}, optionsOrFn] : [optionsOrFn, maybeFn]\n if (!fn) throw new Error(\"task() needs a callback\")\n\n // Wrap `fn` so a sync `fn` still returns a promise.\n const runFn = async () => fn({ $: ShellWrapper })\n\n // Store the first call's promise so overlapping and later calls share it instead of rerunning `fn`.\n let taskFnPromise: Promise<void> | undefined\n\n const run = async () => {\n if (taskFnPromise) return taskFnPromise\n taskFnPromise = runFn()\n return taskFnPromise\n }\n\n const newTask: Task = Object.assign(run, { options })\n tasks.add(newTask)\n return newTask\n}\n"],"mappings":";;AAmBA,MAAM,wBAAQ,IAAI,QAAgB;AAElC,MAAa,UAAU,UAAkC,OAAO,UAAU,cAAc,MAAM,IAAI,KAAK;AAKvG,SAAgB,KAAK,aAAmC,SAAwB;CAC9E,MAAM,CAAC,SAAS,MAAM,OAAO,gBAAgB,aAAa,CAAC,CAAC,GAAG,WAAW,IAAI,CAAC,aAAa,OAAO;CACnG,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,yBAAyB;CAGlD,MAAM,QAAQ,YAAY,GAAG,EAAE,GAAG,aAAa,CAAC;CAGhD,IAAI;CAEJ,MAAM,MAAM,YAAY;EACtB,IAAI,eAAe,OAAO;EAC1B,gBAAgB,MAAM;EACtB,OAAO;CACT;CAEA,MAAM,UAAgB,OAAO,OAAO,KAAK,EAAE,QAAQ,CAAC;CACpD,MAAM,IAAI,OAAO;CACjB,OAAO;AACT"}
|
package/dist/shell.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { $, ShellExpression } from "bun";
|
|
2
|
+
//#region src/shell.d.ts
|
|
3
|
+
/** Prints each command to stderr, then runs it with Bun's `$`. */
|
|
4
|
+
export declare const ShellWrapper: (strings: TemplateStringsArray, ...expressions: ShellExpression[]) => $.ShellPromise;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","names":["BunShell"],"sources":["../src/shell.ts"],"mappings":";;;qBAgBa,eAAY,SACd,yBAAoB,aACb,sBACfA,EAAS"}
|
package/dist/shell.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import bun from "bun";
|
|
3
|
+
//#region src/shell.ts
|
|
4
|
+
/** Formats an interpolated value the way Bun's shell escapes it. */
|
|
5
|
+
const formatExpression = (expression) => {
|
|
6
|
+
if (Array.isArray(expression)) return expression.map(formatExpression).join(" ");
|
|
7
|
+
if (typeof expression === "object" && expression !== null && "raw" in expression) return expression.raw;
|
|
8
|
+
return bun.$.escape(String(expression));
|
|
9
|
+
};
|
|
10
|
+
/** Prints each command to stderr, then runs it with Bun's `$`. */
|
|
11
|
+
const ShellWrapper = (strings, ...expressions) => {
|
|
12
|
+
const command = String.raw({ raw: strings.raw }, ...expressions.map(formatExpression));
|
|
13
|
+
process.stderr.write(`${styleText("bold", command.trim(), { stream: process.stderr })}\n`);
|
|
14
|
+
return bun.$(strings, ...expressions);
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ShellWrapper };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","names":[],"sources":["../src/shell.ts"],"sourcesContent":["import { styleText } from \"node:util\"\n\nimport bun from \"bun\"\nimport type { $ as BunShell, ShellExpression } from \"bun\"\n\n/** Formats an interpolated value the way Bun's shell escapes it. */\nconst formatExpression = (expression: ShellExpression): string => {\n if (Array.isArray(expression)) return expression.map(formatExpression).join(\" \")\n if (typeof expression === \"object\" && expression !== null && \"raw\" in expression) return expression.raw\n // Print streams, files, and subprocesses as their default string because they have no command text.\n // oxlint-disable-next-line typescript/no-base-to-string\n return bun.$.escape(String(expression))\n}\n\n/** Prints each command to stderr, then runs it with Bun's `$`. */\n// oxlint-disable-next-line typescript/promise-function-async - return Bun's `ShellPromise` as is, because an async function would wrap it and drop `.quiet()` and `.text()`.\nexport const ShellWrapper = (\n strings: TemplateStringsArray,\n ...expressions: ShellExpression[]\n): BunShell.ShellPromise => {\n // Use `String.raw` because Bun's `$` also reads the raw template strings.\n const command = String.raw({ raw: strings.raw }, ...expressions.map(formatExpression))\n // Write to `process.stderr` directly because Bun colors `console.error` output red in a terminal.\n process.stderr.write(`${styleText(\"bold\", command.trim(), { stream: process.stderr })}\\n`)\n return bun.$(strings, ...expressions)\n}\n"],"mappings":";;;;AAMA,MAAM,oBAAoB,eAAwC;CAChE,IAAI,MAAM,QAAQ,UAAU,GAAG,OAAO,WAAW,IAAI,gBAAgB,CAAC,CAAC,KAAK,GAAG;CAC/E,IAAI,OAAO,eAAe,YAAY,eAAe,QAAQ,SAAS,YAAY,OAAO,WAAW;CAGpG,OAAO,IAAI,EAAE,OAAO,OAAO,UAAU,CAAC;AACxC;;AAIA,MAAa,gBACX,SACA,GAAG,gBACuB;CAE1B,MAAM,UAAU,OAAO,IAAI,EAAE,KAAK,QAAQ,IAAI,GAAG,GAAG,YAAY,IAAI,gBAAgB,CAAC;CAErF,QAAQ,OAAO,MAAM,GAAG,UAAU,QAAQ,QAAQ,KAAK,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,EAAE,GAAG;CACzF,OAAO,IAAI,EAAE,SAAS,GAAG,WAAW;AACtC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamhl8/bask",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Write your tasks in TypeScript",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"build-tool",
|
|
7
|
+
"bun",
|
|
8
|
+
"cli",
|
|
9
|
+
"make",
|
|
10
|
+
"task-runner",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/adamhl8/bask",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/adamhl8/bask/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Adam Langbert",
|
|
20
|
+
"email": "adamhl@pm.me",
|
|
21
|
+
"url": "https://github.com/adamhl8"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/adamhl8/bask.git"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"bask": "./dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"imports": {
|
|
35
|
+
"#*": "./src/*"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"prepare": "just prepare"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@adamhl8/configs": "^2.8.2",
|
|
51
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
52
|
+
"@commitlint/cli": "^21.2.3",
|
|
53
|
+
"@commitlint/config-conventional": "^21.2.3",
|
|
54
|
+
"@types/bun": "^1.4.3",
|
|
55
|
+
"knip": "^6.41.0",
|
|
56
|
+
"markdown-toc": "^1.2.0",
|
|
57
|
+
"oxfmt": "^0.73.0",
|
|
58
|
+
"oxlint": "^1.88.0",
|
|
59
|
+
"oxlint-tsgolint": "^7.0.2004",
|
|
60
|
+
"publint": "^0.3.25",
|
|
61
|
+
"release-it": "^21.1.1",
|
|
62
|
+
"release-it-git-cliff": "^0.2.0",
|
|
63
|
+
"tsdown": "^0.23.1",
|
|
64
|
+
"typescript": "^7.0.2"
|
|
65
|
+
}
|
|
66
|
+
}
|