Overview
tokript 의 설치, 사용법, 플러그인 개발 등에 대한 전반적인 내용을 담고 있습니다.
Installation
- npm
- yarn
- pnpm
npm i -D @toktokhan-dev/cli
yarn add -D @toktokhan-dev/cli
pnpm add -D @toktokhan-dev/cli
Run Script
tokript
명령어로 각 플러그인으로 등록된 기능들을 사용할 수 있습니다.
command 를 별도로 입력하지 않으면 대화형으로 실행되어 등록되어있는 스크립트 중 선택하여 사용이 가능합니다.
기존 tokript
와 혼용해서 사용하기 위해서 명령어를 일시적으로 tokript2
로 변경하였습니다.
npx tokript2
를 입력해주세요. (updated at 2024.05.23)
npx tokript
command 를 입력하면 해당 스크립트가 바로 실행됩니다.
npx tokript commit
자주 사용될 수 있는 스크립트는 협업간 편의성을 위해 package.json
에 등록하는걸 권장 드립니다.
{
...
"scripts": {
"commit": "tokript commit",
}
}
- yarn
- npm
- pnpm
yarn run commit
npm run commit
pnpm run commit
Configuration
tok-cli.config.ts
에서 config 정의가 가능합니다.
각 plugin 별로 option 을 정의하고, 해당 plugin 을 등록하여 사용할 수 있습니다.
// npm 에 등록된 플러그인을 사용할 경우
import { genTheme } from "@toktokhan-dev/cli-plugin-gen-theme-chakra";
// 로컬에 정의한 플러그인을 사용할 경우
import { print } from "./plugin/print";
const config: RootConfig<{
plugins: [typeof print, typeof genTheme]; // option 타입 정의
}> = {
// 플러그인 등록
plugins: [print, genTheme],
// 각 pulgin option 설정
print: {
text: "config text",
},
"gen:theme": {
input: "public/token.json",
output: "src/generated/theme",
tokenMode: {
light: "mode_1", // tokenMode 키 값 변경이 필요할 경우 추가해주세요.
},
},
};
export default config;
Run Plugin
config
에 따로 설정값이 존재 하지 않고 아무런 argument
를 넘기지 않을 경우 플러그인 내부적으로 정의된 default
값으로 실행됩니다.
tokript print
//output: default text
config
에 따로 설정값이 존재 하고 아무런 argument
를 넘기지 않을 경우 config
값으로 실행됩니다.
tokript print
//output: config text
argument
를 넘길 경우 argument
값으로 실행됩니다.
tokript print --text 'hello world'
//output: hello world
alias
가 등록 되어있는 경우, alias
로도 실행이 가능합니다.
tokript print -t 'hello world'
모든 command 는 help
커멘드를 통해 description
, options
, default
, alias
에 대한 정보를 확인 할 수 있습니다.
tokript help print
Create Plugin
plugin 을 defineCommand
api 를 사용하여 쉽게 정의할 수 있 습니다.
import { defineCommand } from "@toktokhan-dev/cli";
export interface PrintConfig {
text: string;
}
export const print = defineCommand<"print", GenImageConfig>({
name: "print",
description: "print text",
cliOptions: [
{
name: "text",
alias: "t",
type: "string",
description: "text to print",
},
],
default: {
text: "default text",
},
run: (config) => {
console.log(config.text);
},
});
defineCommand
api 에 대한 정보는 defineCommand
Api 문서를 참고해주세요.
더 자세한 plugin 제작에 관련한 정보는 Plugin Development를 참고해주세요.
Welcome To Tokript
@toktokhan-dev 패키지에는 gen:img, gen:route, gen:api 와 같은 이미 정의되어 있는 다양한 플러그인이 있습니다.
플러그인을 사용하여 프로젝트를 더욱 효율적으로 관리해보세요.
프로젝트내에서 사용했던 유용한 스크립트를, 간단한 설정으로 config, cli option, help 커멘드와 함께 다른 사람들에게 제공해보세요