From f8540eba92e7c1dd0341cd50c05c128b6bc5667d Mon Sep 17 00:00:00 2001 From: ByungJoon Lee Date: Wed, 15 Nov 2023 01:30:14 +0900 Subject: [PATCH] Add: Add content about the programming interface to the `README.md` --- README.md | 13 ++++++++ doc/CHANAGELOG.md | 7 ---- doc/PROGRAMMING_INTERFACE.md | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 7 deletions(-) delete mode 100644 doc/CHANAGELOG.md create mode 100644 doc/PROGRAMMING_INTERFACE.md diff --git a/README.md b/README.md index ef08fe0..af4decf 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ In addition, `ctix` will auto-generate `barrel` files so that a single `index.d. - [Installation](#installation) - [Usage](#usage) - [How can I exclude unwanted files?](#how-can-i-exclude-unwanted-files) + - [Programming interface](#programming-interface) - [Requirement](#requirement) - [Important](#important) - [More information](#more-information) @@ -139,6 +140,18 @@ const Button = () => { } ``` +### Programming interface + +When using task runners like Gulp and Just, as well as bundlers like webpack and rollup, you need a programming interface to add ctix. + +| function | option | descryption | +| - | - | - | +| building | [TCommandBuildOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandBuildOptions.ts) | Execute the `build` command | +| initializing | [TCommandInitOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandInitOptions.ts) | Execute the `init` command | +| removing | [TCommandRemoveOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandRemoveOptions.ts), [TCommandBuildOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandBuildOptions.ts) | Execute the `remove` command | + +Check out the [example code](https://github.com/imjuni/ctix/blob/master/doc/PROGRAMMING_INTERFACE.md). + ## Requirement - Node.js 18 diff --git a/doc/CHANAGELOG.md b/doc/CHANAGELOG.md deleted file mode 100644 index f000a21..0000000 --- a/doc/CHANAGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -# 왜 rootDir 옵션이 삭제 되었습니까? - -ctix는 이제 output 디렉터리를 기준으로 상대경로를 생성합니다. tsconfig.json에서 rootDir이 있는 이유는 전체 프로젝트 빌드 결과에서 특정 디렉터리를 기준점으로 삼기 위함입니다. 예를들면 src 디렉터리를 rootDir으로 설정하면 빌드 결과에서 src 디렉터리가 . 디렉터리로 사용됩니다. 하지만 ctix는 최종 결과물인 js 파일이 아니라 ts 파일을 생성하기 때문에 output 디렉터리가 아닌 다른 디렉터리를 rootDir로 설정하면 빌드 실패가 발생할 확률이 높습니다. - -만약 tsconfig.json에 rootDir을 설정한 경우에도 ctix는 이 것을 사용하지 않아도 무방합니다. ctix는 tsc를 실행하기 전에 ctix를 실행하는 것을 전제로 개발되고 있습니다. bundler 또는 type bundler를 실행할 때 올바른 entrypoint를 알려주기 위해서 사용하는 것으로 빌드 과정 전 단계에서 실행하는 것을 목표로 합니다. 그렇기 때문에 output 디렉터리에 상대 경로를 설정하면 tsc가 rootDir에 적합하게 js 파일을 생생할 것입니다. - -처음 rootDir 옵션을 도입할 때 output 디렉터리 기준으로 상대경로가 잘 설정되지 않아서 적용한 것으로, 현재는 output 디렉터리 기준으로 상대경로가 잘 생성되기 때문에 중요성이 낮아져서 제거하였습니다. rootDir 옵션은 별도 문서를 생성할 정도로 설정하기 까다롭고 동작 방식도 복잡한 반면 중요성이 높지 않아 제거 되었습니다. diff --git a/doc/PROGRAMMING_INTERFACE.md b/doc/PROGRAMMING_INTERFACE.md new file mode 100644 index 0000000..339e2bd --- /dev/null +++ b/doc/PROGRAMMING_INTERFACE.md @@ -0,0 +1,62 @@ +# Programming interface + +When using task runners like Gulp and Just, as well as bundlers like webpack and rollup, you need a programming interface to add ctix. + +| function | option | descryption | +| - | - | - | +| building | [TCommandBuildOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandBuildOptions.ts) | Execute the `build` command | +| initializing | [TCommandInitOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandInitOptions.ts) | Execute the `init` command | +| removing | [TCommandRemoveOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandRemoveOptions.ts), [TCommandBuildOptions](https://github.com/imjuni/ctix/blob/master/src/configs/interfaces/TCommandBuildOptions.ts) | Execute the `remove` command | + +## CommonJS Example + +```js +const fs = require('node:fs'); +const ctix = require('ctix'); + +const handle = async () => { + const options = ctix.parseConfig(await fs.promises.readFile('.ctirc')); + await ctix.building(options); +}; + +handle(); +``` + +## ESM, TypeScript Example + +> esm + +```js +import { building, parseConfig, TCommandBuildOptions } from 'ctix'; +import fs from 'node:fs'; + +const handle = async () => { + const options = parseConfig(await fs.promises.readFile('.ctirc')); + await building(options); +}; + +handle(); +``` + +> TypeScript + +```ts +import { building, parseConfig, TCommandBuildOptions } from 'ctix'; +import fs from 'node:fs'; + +const handle = async () => { + const options = parseConfig(await fs.promises.readFile('.ctirc')) as TCommandBuildOptions; + await building(options); +}; + +handle(); +``` + +## Gulp Example + +```js +gulp.task('ctix', async () => { + const options = parseConfig(await fs.promises.readFile('.configs/.ctirc')); + await building(options); +}); +```