From eda1e1632577e7210dff0ad6985577bb327f6097 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 9 Feb 2023 22:53:55 +0000 Subject: [PATCH] Merged PR 72: add index.d.ts file add index.d.ts file --- scripts/copy-files.js | 20 +++++++++++++++++++- src/index.d.ts | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/index.d.ts diff --git a/scripts/copy-files.js b/scripts/copy-files.js index 99379e2..26f437e 100644 --- a/scripts/copy-files.js +++ b/scripts/copy-files.js @@ -43,6 +43,19 @@ const srcPath = path.join(packagePath, "./src"); // ); // } +async function typescriptCopy({ from, to }) { + if (!(await fse.exists(to))) { + console.warn(`path ${to} does not exists`); + return []; + } + + const files = glob.sync("**/*.d.ts", { cwd: from }); + const cmds = files.map(file => + fse.copy(path.resolve(from, file), path.resolve(to, file)) + ); + return Promise.all(cmds); +} + async function createPackageFile() { const packageData = await fse.readFile( path.resolve(packagePath, "./package.json"), @@ -54,7 +67,9 @@ async function createPackageFile() { const newPackageData = { ...packageDataOther, private: false, - main: "./index.js" + main: "./index.js", + //module: "./esm/index.js", + typings: "./index.d.ts" }; const targetPath = path.resolve(buildPath, "./package.json"); @@ -77,6 +92,9 @@ async function run() { try { await createPackageFile(); + // TypeScript + await typescriptCopy({ from: srcPath, to: buildPath }); + //await createModulePackages({ from: srcPath, to: buildPath }); } catch (err) { console.error(err); diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..25297f6 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,4 @@ +import * as typeValidator from "./data/typeValidator"; +import * as localStorage from "./storage/localStorage"; + +export { typeValidator, localStorage };