⭐️ npm run ts-build
이 문서는 npm run ts-build 명령어로 실행되는 TypeScript 선언 파일 생성 자동화 파이프라인을 설명합니다.
이 빌드 과정은 JSDoc + JavaScript 기반의 코드로부터 .d.ts 파일을 생성하고, 추가적으로 구조 보정 및 포맷 정리를 수행합니다.
npm run ts-build"ts-build": "(npx tsc || true) && barrelsby --config .barrelsby.json && node scripts/format-index.cjs && node scripts/fix-langs.cjs && node scripts/wrap-dts.cjs && node scripts/rename-index.cjs && node scripts/remove-this-params.cjs && node scripts/gen-options-dts.cjs && npm run lint:fix-ts"-
tsc- JSDoc 기반으로 작성된
.js파일로부터.d.ts타입 선언 파일을 생성 - 오류가 발생해도
|| true처리로 중단되지 않음
- JSDoc 기반으로 작성된
-
barrelsbytypes/폴더 내 선언 파일들을 정리된index.ts(모듈 통합 진입점)로 자동 생성.barrelsby.json설정 파일을 기반으로 동작
-
format-index.cjsbarrelsby가 생성한types/index.ts를 프로젝트 구조에 맞게 재구성- 모듈 re-export:
helper,langs,modules,plugins - 공개 API 타입 export:
SunEditorOptions,SunEditorCore등 10개 타입 - 메인 default export 추가
- 최종적으로 공개 API 진입점 생성
-
fix-langs.cjslangs/폴더의 언어 파일들은 UMD 스타일 IIFE 패턴으로 작성되어 있음- 이들을 TypeScript에 맞는
export형태로 자동 변환 - 각 언어별
.d.ts파일이 정상적으로 타입 추론되도록 수정
-
wrap-dts.cjstypedef.js에서 생성된typedef.d.ts파일을global {}블록 안에 감쌈- 프로젝트 전역에서
__se__로 시작하는 타입들을 글로벌 타입으로 노출함
-
rename-index.cjsformat-index.cjs가 생성한index.ts파일을index.d.ts로 이름 변경- 타입 선언 전용 파일로 구분
-
remove-this-params.cjscore/디렉터리는prototype기반 구조이므로constructor에this: any파라미터가 잘못 생성됨- 이를 찾아 제거해주는 후처리 스크립트
-
gen-options-dts.cjscore/config/options.js > DEFAULTS객체의 실제 값들을 기반으로options.d.ts내export namespace DEFAULTS타입 정의를 덮어씀- 문자열, 배열, 객체 등의 값을 정확히 리터럴 타입으로 유지하여 자동으로 타입 갱신
-
lint:fix-ts- 최종
.d.ts파일에 대해 ESLint를 적용하여 포맷팅 및 스타일 정리 수행
- 최종
types/
├── core/
│ ├── editor.d.ts
│ └── ...
├── langs/
│ ├── en.d.ts <-- fix-langs에서 변환됨
│ └── ko.d.ts
├── plugins/
│ └── index.d.ts
├── modules/
│ └── index.d.ts
├── helper/
│ └── index.d.ts
├── typedef.d.ts <-- wrap-dts로 global {} 처리됨
├── suneditor.d.ts <-- 공개 타입 정의 (10개)
└── index.d.ts <-- format-index → rename-index로 최종 생성 (공개 API 진입점)
| 스크립트 파일 | 설명 |
|---|---|
format-index.cjs |
barrelsby가 생성한 index.ts를 재구성, 모듈 re-export 및 공개 API 타입 10개 export |
fix-langs.cjs |
UMD 스타일 langs/*.js → TypeScript 형식으로 export 구조 변환 |
wrap-dts.cjs |
typedef.d.ts에 global {} 래핑 추가 |
rename-index.cjs |
index.ts → index.d.ts 이름 변경 |
remove-this-params.cjs |
prototype 기반 constructor의 잘못된 this 파라미터 제거 |
gen-options-dts.cjs |
DEFAULTS 객체 기반으로 options.d.ts 타입 정의 자동 갱신 |
typedef.js는 반드시 JSDoc 기반으로 정확하게 작성되어야 합니다.suneditor.js의 타입 정의(@typedef)는format-index.cjs를 통해 자동으로types/index.d.ts에 export됩니다.- 공개 API 타입을 추가하려면
suneditor.js에@typedef추가 후format-index.cjs의 export 목록도 업데이트해야 합니다.
- 공개 API 타입을 추가하려면
langs/*.js는 반드시 IIFE 패턴을 따라야 하며, 내부const lang = {...}구조를 가져야 정상 변환됩니다.core/디렉터리는prototype기반으로 동작하며, TypeScript 변환 후 후처리가 필요합니다.- 이 스크립트는
.d.ts타입 정의만 생성하므로 실제 코드 번들에는 영향을 주지 않습니다.