From c857f56df24f492bd826215d0afebce2acc3f639 Mon Sep 17 00:00:00 2001 From: Felix Ranesberger Date: Mon, 14 Oct 2024 17:18:50 +0200 Subject: [PATCH] feat: add typescript build feature --- build.config.ts | 1 + package.json | 13 +++++++++---- pnpm-lock.yaml | 6 +++--- src/build.ts | 41 +++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/build.ts diff --git a/build.config.ts b/build.config.ts index 0bd008c..ea5caa2 100644 --- a/build.config.ts +++ b/build.config.ts @@ -3,6 +3,7 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ entries: [ 'src/index', + 'src/build', ], declaration: true, clean: true, diff --git a/package.json b/package.json index 6ddccb4..9ba2999 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "easy-ckeditor", "type": "module", - "version": "0.0.5", + "version": "0.0.6-beta.9", "packageManager": "pnpm@9.9.0", "description": "Provides utility functions for easier plugin development for CKEditor 5", "author": "Felix Ranesberger ", @@ -19,6 +19,11 @@ "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs" + }, + "./build": { + "types": "./dist/build.d.ts", + "import": "./dist/build.mjs", + "require": "./dist/build.cjs" } }, "main": "./dist/index.mjs", @@ -48,14 +53,14 @@ "@ckeditor/ckeditor5-engine": "^43.1.0", "@ckeditor/ckeditor5-typing": "^43.1.0", "@ckeditor/ckeditor5-ui": "^43.1.0", - "@ckeditor/ckeditor5-utils": "^43.1.0" + "@ckeditor/ckeditor5-utils": "^43.1.0", + "unbuild": "^2.0.0" }, "devDependencies": { "@antfu/eslint-config": "^3.3.2", "@types/node": "^22.5.4", "bumpp": "^9.5.2", "eslint": "^9.9.1", - "typescript": "^5.5.4", - "unbuild": "^2.0.0" + "typescript": "^5.5.4" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2b90491..baf7db3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: '@ckeditor/ckeditor5-utils': specifier: ^43.1.0 version: 43.1.0 + unbuild: + specifier: ^2.0.0 + version: 2.0.0(typescript@5.5.4) devDependencies: '@antfu/eslint-config': specifier: ^3.3.2 @@ -39,9 +42,6 @@ importers: typescript: specifier: ^5.5.4 version: 5.5.4 - unbuild: - specifier: ^2.0.0 - version: 2.0.0(typescript@5.5.4) packages: diff --git a/src/build.ts b/src/build.ts new file mode 100644 index 0000000..70bf133 --- /dev/null +++ b/src/build.ts @@ -0,0 +1,41 @@ +import { build } from 'unbuild' +import type { BuildConfig } from 'unbuild' + +interface Options { + plugins: { + input: `${string}.ts` + outDir: string + }[] +} + +/** + * Converts your CKEditor typescript plugin files to javascript. + */ +export function buildCkEditorPlugins(args: Options): void { + (async () => { + for await (const plugin of args.plugins) { + const config: BuildConfig = { + entries: [{ + builder: 'rollup', + input: plugin.input, + }], + externals: [ + '@ckeditor/ckeditor5-core', + '@ckeditor/ckeditor5-engine', + '@ckeditor/ckeditor5-typing', + '@ckeditor/ckeditor5-ui', + '@ckeditor/ckeditor5-utils', + ], + rollup: { + inlineDependencies: true, + output: { + dir: plugin.outDir, + }, + }, + clean: false, + } + + await build('.', false, config) + } + })() +} diff --git a/tsconfig.json b/tsconfig.json index 7d4fcab..ae707cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,6 @@ "noEmit": true, "esModuleInterop": true, "skipDefaultLibCheck": true, - "skipLibCheck": true, + "skipLibCheck": true } }