Skip to content

Commit

Permalink
Merge pull request #3 from privatenumber/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Jun 14, 2021
2 parents 9330bb1 + 541d7b2 commit 0bcc3d7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
Binary file removed .github/tasuku.png
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
run: npm run test --if-present
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<p align="center">
<img src=".github/tasuku.svg">
<br>
<i>The minimal task runner</i>
<i>The minimal task runner for Node.js</i>
</p>

### Features
Expand All @@ -11,6 +11,8 @@
- Unopinionated
- Type-safe

[Try it out online](https://stackblitz.com/edit/tasuku-demo?file=index.js)

<sub>Support this project by starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on.</sub>

## Install
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"scripts": {
"lint": "eslint .",
"test": "jest",
"typecheck": "tsc --noEmit",
"typecheck": "tsc --noEmit && :",
"build": "rm -rf dist && tsup src/index.ts --dts --minify --no-splitting --external 'yoga-layout-prebuilt'"
},
"husky": {
Expand All @@ -44,7 +44,6 @@
"@types/jest": "^26.0.23",
"@types/node": "^15.6.1",
"@types/react": "^17.0.4",
"dts": "^0.1.1",
"es-jest": "^1.2.0",
"eslint": "^7.24.0",
"esno": "^0.5.0",
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,35 @@ const createTaskInnerApi = (taskState: TaskObject) => {
return api;
};

type TaskFunction = (taskHelpers: ReturnType<typeof createTaskInnerApi>) => Promise<unknown>;
// Until full ESM
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace task {
export type TaskInnerApi = ReturnType<typeof createTaskInnerApi>;
export type TaskFunction = (taskHelpers: TaskInnerApi) => Promise<unknown>;
}

type TaskAPI<T extends TaskFunction> = {
type TaskApi<T extends task.TaskFunction> = {
run: () => Promise<Awaited<ReturnType<T>>>;
clear: () => void;
};
type TaskResults<
T extends TaskFunction,
Tasks extends TaskAPI<T>[]
T extends task.TaskFunction,
Tasks extends TaskApi<T>[]
> = {
[key in keyof Tasks]: (
Tasks[key] extends TaskAPI<T>
Tasks[key] extends TaskApi<T>
? Awaited<ReturnType<Tasks[key]['run']>>
: Tasks[key]
);
};

let app: ReturnType<typeof createApp>;

function registerTask<T extends TaskFunction>(
function registerTask<T extends task.TaskFunction>(
taskList: TaskList,
taskTitle: string,
taskFunction: T,
): TaskAPI<T> {
): TaskApi<T> {
if (!app) {
app = createApp(taskList);
taskList.isRoot = true;
Expand Down Expand Up @@ -105,7 +110,7 @@ function registerTask<T extends TaskFunction>(
function createTaskFunction(
taskList: TaskList,
) {
async function task<T extends TaskFunction>(
async function task<T extends task.TaskFunction>(
title: string,
taskFunction: T,
) {
Expand All @@ -118,7 +123,7 @@ function createTaskFunction(
);
}

const createTask = <T extends TaskFunction>(
const createTask = <T extends task.TaskFunction>(
title: string,
taskFunction: T,
) => registerTask(
Expand All @@ -128,8 +133,8 @@ function createTaskFunction(
);

task.group = async <
T extends TaskFunction,
Tasks extends TaskAPI<T>[]
T extends task.TaskFunction,
Tasks extends TaskApi<T>[]
>(
createTasks: (taskCreator: typeof createTask) => readonly [...Tasks],
options?: Options,
Expand Down

0 comments on commit 0bcc3d7

Please sign in to comment.