From 699b98e1a6bf6dcd142a99c9e461777f51e798e9 Mon Sep 17 00:00:00 2001 From: * <*> Date: Wed, 27 Sep 2023 10:11:35 +0800 Subject: [PATCH] Match-id-3723a639753eadeab5432d575a6aa33aa524e1d0 --- packages/inula-intl/build-type.js | 52 +++++++++++++++++++++++++++++++ packages/inula-intl/package.json | 12 ++++--- packages/inula-intl/tsconfig.json | 14 ++++++--- 3 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 packages/inula-intl/build-type.js diff --git a/packages/inula-intl/build-type.js b/packages/inula-intl/build-type.js new file mode 100644 index 00000000..f359f2c6 --- /dev/null +++ b/packages/inula-intl/build-type.js @@ -0,0 +1,52 @@ +import fs from 'fs'; +import path from 'path'; +import dts from 'rollup-plugin-dts'; + +function deleteFolder(filePath) { + if (fs.existsSync(filePath)) { + if (fs.lstatSync(filePath).isDirectory()) { + const files = fs.readdirSync(filePath); + files.forEach(file => { + const nextFilePath = path.join(filePath, file); + const states = fs.lstatSync(nextFilePath); + if (states.isDirectory()) { + deleteFolder(nextFilePath); + } else { + fs.unlinkSync(nextFilePath); + } + }); + fs.rmdirSync(filePath); + } else if (fs.lstatSync(filePath).isFile()) { + fs.unlinkSync(filePath); + } + } +} + + +/** + * + * @param folders {string[]} + * @returns {{buildEnd(): void, name: string}} + */ +export function cleanUp(folders) { + return { + name: 'clean-up', + buildEnd() { + folders.forEach(f => deleteFolder(f)); + }, + }; +} + + +function buildTypeConfig() { + return { + input: './build/@types/index.d.ts', + output: { + file: './build/index.d.ts', + format: 'es', + }, + plugins: [dts(), cleanUp(['./build/@types/example', './build/@types/src'])], + }; +} + +export default [buildTypeConfig()]; diff --git a/packages/inula-intl/package.json b/packages/inula-intl/package.json index 50ff08ae..6753f803 100644 --- a/packages/inula-intl/package.json +++ b/packages/inula-intl/package.json @@ -7,7 +7,8 @@ "types": "build/index.d.ts", "scripts": { "demo-serve": "webpack serve --mode=development", - "rollup-build": "rollup --config rollup.config.js", + "rollup-build": "rollup --config rollup.config.js && npm run build-types ", + "build-types": "tsc -p tsconfig.json && rollup -c build-type.js", "test": "jest --config jest.config.js", "test-c": "jest --coverage" }, @@ -16,8 +17,7 @@ "url": "" }, "files": [ - "build", - "example" + "build" ], "keywords": [], "author": "", @@ -50,6 +50,7 @@ "rollup-plugin-livereload": "^2.0.5", "rollup-plugin-serve": "^1.1.0", "rollup-plugin-terser": "^5.3.0", + "rollup-plugin-dts": "^6.0.1", "tslib": "^2.6.1", "ts-jest": "29.0.3", "ts-node": "10.9.1", @@ -57,7 +58,8 @@ "webpack": "^5.81.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^4.13.3", - "react": "18.2.0", - "react-dom": "18.2.0" + "react": "18.2.0-h3", + "react-dom": "18.2.0-h3", + "core-js": "3.31.0" } } diff --git a/packages/inula-intl/tsconfig.json b/packages/inula-intl/tsconfig.json index 2ea73c31..7bc1bfc6 100644 --- a/packages/inula-intl/tsconfig.json +++ b/packages/inula-intl/tsconfig.json @@ -31,6 +31,8 @@ "declaration": true, "experimentalDecorators": true, "downlevelIteration": true, + "emitDeclarationOnly": true, + "declarationDir": "./build/@types", // 赋值为空数组使@types/node不会起作用 "lib": [ "dom", @@ -53,19 +55,23 @@ } }, "include": [ - "./src/**/*", - "./src/format/**/*.ts", - "./example/**/*" + "./index.ts", + ], "exclude": [ "node_modules", "lib", "**/*.spec.ts", - "dev" + "dev", + "./example/**/*", + "./tsconfig.json" ], "types": [ "node", "jest", "@testing-library/jest-dom" + ], + "files": [ + "./index.ts" ] }