Skip to content

Commit

Permalink
Gtihub action 자동 npm 배포 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
love1ace committed Sep 20, 2024
1 parent 70df61b commit c7bdb09
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 45 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Taskl Publish

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest

steps:
# 1. 저장소 체크아웃
- name: Check out the repository
uses: actions/checkout@v3

# 2. Node.js 설치 (원하는 Node 버전을 설정 가능)
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

# 3. npm 인증 설정 (NPM_TOKEN을 이용해 자동 로그인)
- name: Authenticate to npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

# 4. npm 설치
- name: Install dependencies
run: npm install

# 5. npm publish 실행
- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25 changes: 25 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export declare const ANSI_COLORS: {
cyan: string;
gray: string;
green: string;
red: string;
blue: string;
yellow: string;
white: string;
reset: string;
};
export interface Task {
text: string;
run: () => Promise<void>;
}
export interface TasklOptions {
tasks: Task[];
startMessage: string;
successMessage: string;
failedMessage: string;
}
export declare class Taskl {
private options;
constructor(options: TasklOptions);
runTasks(): Promise<void>;
}
82 changes: 42 additions & 40 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import ora from 'ora';
export const ANSI_COLORS = {
cyan: '\x1b[36m',
gray: '\x1b[90m',
green: '\x1b[32m',
red: '\x1b[31m',
blue: '\x1b[34m',
yellow: '\x1b[33m',
white: '\x1b[37m',
reset: '\x1b[0m'
cyan: '\x1b[36m',
gray: '\x1b[90m',
green: '\x1b[32m',
red: '\x1b[31m',
blue: '\x1b[34m',
yellow: '\x1b[33m',
white: '\x1b[37m',
reset: '\x1b[0m'
};
export class Taskl {
constructor(options) {
this.options = options;
}
async runTasks() {
console.log();
console.log(`${ANSI_COLORS.cyan}${this.options.startMessage}${ANSI_COLORS.reset}`);
const startTime = Date.now();
const totalTasks = this.options.tasks.length;
let allTasksSucceeded = true;
for (let i = 0; i < totalTasks; i++) {
const task = this.options.tasks[i];
const progressText = `[${i + 1}/${totalTasks}]`;
const spinner = ora({
text: `${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`,
color: 'yellow'
}).start();
try {
await task.run();
spinner.succeed(`${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`);
} catch (error) {
spinner.fail(`${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`);
allTasksSucceeded = false;
}
constructor(options) {
this.options = options;
}
if (allTasksSucceeded) {
console.log(`${ANSI_COLORS.green}Success!${ANSI_COLORS.white} ${this.options.successMessage}${ANSI_COLORS.reset}`);
} else {
console.log(`${ANSI_COLORS.red}Failed!${ANSI_COLORS.white} ${this.options.failedMessage}${ANSI_COLORS.reset}`);
async runTasks() {
console.log();
console.log(`${ANSI_COLORS.cyan}${this.options.startMessage}${ANSI_COLORS.reset}`);
const startTime = Date.now();
const totalTasks = this.options.tasks.length;
let allTasksSucceeded = true;
for (let i = 0; i < totalTasks; i++) {
const task = this.options.tasks[i];
const progressText = `[${i + 1}/${totalTasks}]`;
const spinner = ora({
text: `${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`,
color: 'yellow'
}).start();
try {
await task.run();
spinner.succeed(`${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`);
}
catch (error) {
spinner.fail(`${ANSI_COLORS.gray}${progressText} ${task.text}${ANSI_COLORS.reset}`);
allTasksSucceeded = false;
}
}
if (allTasksSucceeded) {
console.log(`${ANSI_COLORS.green}Success!${ANSI_COLORS.white} ${this.options.successMessage}${ANSI_COLORS.reset}`);
}
else {
console.log(`${ANSI_COLORS.red}Failed!${ANSI_COLORS.white} ${this.options.failedMessage}${ANSI_COLORS.reset}`);
}
const endTime = Date.now();
const duration = (endTime - startTime) / 1000;
console.log(`${ANSI_COLORS.blue}✨ Done in ${duration.toFixed(2)}s.${ANSI_COLORS.reset}`);
console.log();
}
const endTime = Date.now();
const duration = (endTime - startTime) / 1000;
console.log(`${ANSI_COLORS.blue}✨ Done in ${duration.toFixed(2)}s.${ANSI_COLORS.reset}`);
console.log();
}
}
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "taskl",
"version": "1.0.0",
"version": "1.0.2",
"description": "Easy set up beautiful logs for CLI",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"type": "module",
"author": "love1ace",
Expand All @@ -22,7 +23,7 @@
"url": "https://github.com/love1ace/taskl/issues"
},
"files": [
"index.js",
"dist",
"README.md",
"LICENSE"
],
Expand All @@ -36,5 +37,12 @@
},
"scripts": {
"build": "tsc"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
}
Binary file modified taskl.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true
"strict": true,
"declaration": true
}
}

0 comments on commit c7bdb09

Please sign in to comment.