Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/love1ace/taskl

A useful tool for managing asynchronous tasks and logs in CLI ๐Ÿš€
https://github.com/love1ace/taskl

cli listr log npm ora

Last synced: 3 months ago
JSON representation

A useful tool for managing asynchronous tasks and logs in CLI ๐Ÿš€

Awesome Lists containing this project

README

        

# Taskl

**Taskl**์€ ๋น„๋™๊ธฐ ์ž‘์—…์„ ํšจ๊ณผ์ ์œผ๋กœ ์ œ์–ดํ•˜๊ณ  CLI ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋กœ๊ทธ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž…๋‹ˆ๋‹ค.

![npm](https://img.shields.io/npm/v/taskl)
![license](https://img.shields.io/npm/l/taskl)

![taskl](./taskl.gif)

## ์„ค์น˜

์›ํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ **Taskl**์„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

### npm

```bash
npm install taskl
```

### Yarn

```bash
yarn add taskl
```

### pnpm

```bash
pnpm add taskl
```

### Bun

```bash
bun add taskl
```

## ์‚ฌ์šฉ๋ฒ•

ํ”„๋กœ์ ํŠธ์—์„œ **Taskl**์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”:

### 1. Taskl์—์„œ ํ•„์š”ํ•œ ๊ตฌ์„ฑ ์š”์†Œ ๊ฐ€์ ธ์˜ค๊ธฐ

๋จผ์ €, `taskl` ํŒจํ‚ค์ง€์—์„œ `Taskl`, `Task`, `TasklOptions`๋ฅผ import ํ•ฉ๋‹ˆ๋‹ค.

```typescript
import { Taskl, Task, TasklOptions } from 'taskl';
```

*JavaScript ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ, ๋Œ€์‹  `require`๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:*

```javascript
const { Taskl, Task, TasklOptions } = require('taskl');
```

### 2. ์ž‘์—… ์ •์˜ํ•˜๊ธฐ

์‹คํ–‰ํ•  ์ž‘์—… ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ž‘์—…์€ `text` ์„ค๋ช…๊ณผ `Promise`๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” `run` ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

```typescript
const tasks: Task[] = [
{
text: '๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ ์ค‘',
run: async () => {
// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ์‹ค์ œ ๋กœ์ง
await connectToDatabase();
},
},
{
text: 'API ์„œ๋ฒ„ ์‹œ์ž‘ ์ค‘',
run: async () => {
// ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ์‹ค์ œ ๋กœ์ง
await startApiServer();
},
}
];
```

*JavaScript ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ:*

```javascript
const tasks = [
{
text: '๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ ์ค‘',
run: async () => {
// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ์‹ค์ œ ๋กœ์ง
await connectToDatabase();
},
},
{
text: 'API ์„œ๋ฒ„ ์‹œ์ž‘ ์ค‘',
run: async () => {
// ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ์‹ค์ œ ๋กœ์ง
await startApiServer();
},
}
];
```

**Task ์ธํ„ฐํŽ˜์ด์Šค:**

- `text`: ์ž‘์—…์— ๋Œ€ํ•œ ์„ค๋ช….
- `run`: ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋น„๋™๊ธฐ ํ•จ์ˆ˜.

**ํŒ:** ๊ฐ `run` ํ•จ์ˆ˜๊ฐ€ ์ž์ฒด์ ์œผ๋กœ ์˜ค๋ฅ˜๋ฅผ ์ ์ ˆํžˆ ์ฒ˜๋ฆฌํ•˜์—ฌ Taskl์ด ์ž‘์—… ํ๋ฆ„์„ ์›ํ™œํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด:

```javascript
const tasks = [
{
text: '๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ ์ค‘',
run: async () => {
try {
await connectToDatabase();
} catch (error) {
console.error('๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ ์‹คํŒจ:', error);
throw error; // Taskl์ด ์‹คํŒจ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์žฌ์ „ํŒŒ
}
},
},
// ... ๋‹ค๋ฅธ ์ž‘์—…
];
```

### 3. TasklOptions ์„ค์ •

์ž‘์—…๊ณผ ํ”„๋กœ์„ธ์Šค ์ค‘ ํ‘œ์‹œํ•  ๋ฉ”์‹œ์ง€๋ฅผ ํฌํ•จํ•˜์—ฌ Taskl์˜ ์˜ต์…˜์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

```typescript
const options: TasklOptions = {
tasks: tasks,
startMessage: '๐Ÿ”„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค',
successMessage: 'ํ”„๋กœ์„ธ์Šค๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
failedMessage: 'ํ”„๋กœ์„ธ์Šค ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
};
```

*JavaScript ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ:*

```javascript
const options = {
tasks: tasks,
startMessage: '๐Ÿ”„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค',
successMessage: 'ํ”„๋กœ์„ธ์Šค๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
failedMessage: 'ํ”„๋กœ์„ธ์Šค ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
};
```

**์˜ต์…˜ ์„ค๋ช…:**

- `tasks`: ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰๋  `Task` ๊ฐ์ฒด๋“ค์˜ ๋ฐฐ์—ด.
- `startMessage`: ์ž‘์—… ์‹คํ–‰์ด ์‹œ์ž‘๋  ๋•Œ ํ‘œ์‹œ๋˜๋Š” ๋ฉ”์‹œ์ง€.
- `successMessage`: ๋ชจ๋“  ์ž‘์—…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ ํ›„ ํ‘œ์‹œ๋˜๋Š” ๋ฉ”์‹œ์ง€.
- `failedMessage`: ์ž‘์—… ์ค‘ ํ•˜๋‚˜๋ผ๋„ ์‹คํŒจํ•  ๊ฒฝ์šฐ ํ‘œ์‹œ๋˜๋Š” ๋ฉ”์‹œ์ง€.

### 4. Taskl ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์ž‘์—… ์‹คํ–‰

๊ตฌ์„ฑ๋œ ์˜ต์…˜์œผ๋กœ Taskl์„ ์ธ์Šคํ„ด์Šคํ™”ํ•˜๊ณ  ์ž‘์—…์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

```typescript
const taskl = new Taskl(options);
taskl.runTasks().catch(console.error);
```

*JavaScript ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ:*

```javascript
const taskl = new Taskl(options);
taskl.runTasks().catch(console.error);
```

**๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ผ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค:**

- Taskl์€ `startMessage`๋ฅผ ์‹œ์•ˆ ์ƒ‰์ƒ์œผ๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.
- ๊ฐ ์ž‘์—…์ด ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰๋˜๋ฉฐ, ์ž‘์—… ์„ค๋ช…๊ณผ ํ•จ๊ป˜ ์Šคํ”ผ๋„ˆ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
- ์ž‘์—…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜๋ฉด ์„ฑ๊ณต ์Šคํ”ผ๋„ˆ๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
- ์ž‘์—…์ด ์‹คํŒจํ•˜๋ฉด ์‹คํŒจ ์Šคํ”ผ๋„ˆ๊ฐ€ ํ‘œ์‹œ๋˜๊ณ , ๋งˆ์ง€๋ง‰์— `failedMessage`๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
- ๋งˆ์ง€๋ง‰์œผ๋กœ, Taskl์€ ์ „์ฒด ์‹คํ–‰ ์‹œ๊ฐ„์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

### ์ „์ฒด ์˜ˆ์ œ

๋ชจ๋“  ๋‹จ๊ณ„๋ฅผ ํ†ตํ•ฉํ•œ ์ „์ฒด ์˜ˆ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

```typescript
import { Taskl, Task, TasklOptions } from 'taskl';

// ์ž‘์—… ์ •์˜
const tasks: Task[] = [
{
text: '๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ ์ค‘',
run: async () => {
await connectToDatabase();
},
},
{
text: 'API ์„œ๋ฒ„ ์‹œ์ž‘ ์ค‘',
run: async () => {
await startApiServer();
},
}
];

// Taskl ์˜ต์…˜ ์„ค์ •
const options: TasklOptions = {
tasks: tasks,
startMessage: '๐Ÿ”„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค',
successMessage: 'ํ”„๋กœ์„ธ์Šค๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
failedMessage: 'ํ”„๋กœ์„ธ์Šค ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
};

// Taskl ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์ž‘์—… ์‹คํ–‰
const taskl = new Taskl(options);
taskl.runTasks().catch(console.error);

// ์˜ˆ์ œ ํ•จ์ˆ˜๋“ค (์‹ค์ œ ๋กœ์ง์œผ๋กœ ๋Œ€์ฒดํ•˜์„ธ์š”)
async function connectToDatabase() {
// ๋น„๋™๊ธฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
return new Promise((resolve) => setTimeout(resolve, 1000));
}

async function startApiServer() {
// ๋น„๋™๊ธฐ ์„œ๋ฒ„ ์‹œ์ž‘ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
return new Promise((resolve) => setTimeout(resolve, 1000));
}
```

*JavaScript ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ:*

```javascript
const { Taskl, Task, TasklOptions } = require('taskl');

// ์ž‘์—… ์ •์˜
const tasks = [
{
text: '๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ ์ค‘',
run: async () => {
await connectToDatabase();
},
},
{
text: 'API ์„œ๋ฒ„ ์‹œ์ž‘ ์ค‘',
run: async () => {
await startApiServer();
},
}
];

// Taskl ์˜ต์…˜ ์„ค์ •
const options = {
tasks: tasks,
startMessage: '๐Ÿ”„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค',
successMessage: 'ํ”„๋กœ์„ธ์Šค๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
failedMessage: 'ํ”„๋กœ์„ธ์Šค ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
};

// Taskl ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์ž‘์—… ์‹คํ–‰
const taskl = new Taskl(options);
taskl.runTasks().catch(console.error);

// ์˜ˆ์ œ ํ•จ์ˆ˜๋“ค (์‹ค์ œ ๋กœ์ง์œผ๋กœ ๋Œ€์ฒดํ•˜์„ธ์š”)
async function connectToDatabase() {
// ๋น„๋™๊ธฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
return new Promise((resolve) => setTimeout(resolve, 1000));
}

async function startApiServer() {
// ๋น„๋™๊ธฐ ์„œ๋ฒ„ ์‹œ์ž‘ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
return new Promise((resolve) => setTimeout(resolve, 1000));
}
```

**์˜ˆ์ œ ์‹คํ–‰ํ•˜๊ธฐ:**

1. ํ”„๋กœ์ ํŠธ์— **Taskl**์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.
2. ์˜ˆ์ œ์˜ `connectToDatabase` ๋ฐ `startApiServer` ํ•จ์ˆ˜๋ฅผ ์‹ค์ œ ๋กœ์ง์œผ๋กœ ๊ต์ฒดํ•˜์„ธ์š”.
3. **TypeScript ์‚ฌ์šฉ์ž:**
- `tsc`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ TypeScript ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•˜๊ฑฐ๋‚˜ `ts-node`์™€ ๊ฐ™์€ TypeScript ์‹คํ–‰๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰ํ•˜์„ธ์š”.
- ์ปดํŒŒ์ผ๋œ ๊ฒฝ์šฐ `node`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜, TypeScript ์‹คํ–‰๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ง์ ‘ ์‹คํ–‰ํ•˜์„ธ์š”.
4. **JavaScript ์‚ฌ์šฉ์ž:**
- ์Šคํฌ๋ฆฝํŠธ๋ฅผ `node`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰ํ•˜์„ธ์š”:
```bash
node your-script.js
```

์ฝ˜์†”์—์„œ ์ง„ํ–‰ ์ƒํ™ฉ ํ‘œ์‹œ๊ธฐ, ์„ฑ๊ณต/์‹คํŒจ ๋ฉ”์‹œ์ง€ ๋ฐ ์ „์ฒด ์‹คํ–‰ ์‹œ๊ฐ„์„ ํฌํ•จํ•œ ์ถœ๋ ฅ์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

## ๊ธฐ์—ฌ

**Taskl**์— ๋Œ€ํ•œ ๊ธฐ์—ฌ๋ฅผ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค! ๋ฒ„๊ทธ๋ฅผ ๋ณด๊ณ ํ•˜๊ฑฐ๋‚˜, ๊ธฐ๋Šฅ ํ–ฅ์ƒ์„ ์ œ์•ˆํ•˜๊ฑฐ๋‚˜, ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ์ œ์ถœํ•˜๋Š” ๋“ฑ ์—ฌ๋Ÿฌ๋ถ„์˜ ์˜๊ฒฌ์„ ์†Œ์ค‘ํžˆ ์—ฌ๊น๋‹ˆ๋‹ค.

## ๋ผ์ด์„ ์Šค

์ด ํ”„๋กœ์ ํŠธ๋Š” MIT ๋ผ์ด์„ ์Šค ํ•˜์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ [LICENSE](LICENSE) ํŒŒ์ผ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

## ์—ฐ๋ฝ์ฒ˜

์งˆ๋ฌธ, ์ œ์•ˆ ๋˜๋Š” ํ”ผ๋“œ๋ฐฑ์ด ์žˆ์œผ์‹œ๋ฉด [love1ace](mailto:[email protected])์œผ๋กœ ์—ฐ๋ฝ ์ฃผ์„ธ์š”.