From c1b8e8adb15ada66b33ded1a3d52a5ef46ceea21 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sun, 16 Oct 2022 01:19:45 +0200 Subject: [PATCH] New build script. --- .gitignore | 1 + build.ts | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 24 ++++++++++++++---------- tsconfig.json | 8 +++++++- 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 build.ts diff --git a/.gitignore b/.gitignore index d2e47b8..7514d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ lib/ .yarnrc* yarn-error.log .pnp* +node_modules/ yarn.lock diff --git a/build.ts b/build.ts new file mode 100644 index 0000000..c5a832e --- /dev/null +++ b/build.ts @@ -0,0 +1,38 @@ +import {build} from "esbuild"; + +/** + * Build the library. + * @param devMode - Dev mode. + */ +function buildLibrary(devMode: boolean = false): void +{ + // Compilation de l'application. + build({ + entryPoints: ["src/index.ts"], + outfile: "lib/index.js", + bundle: true, + minify: true, + sourcemap: true, + format: "esm", + loader: { + ".ts": "ts", + }, + watch: devMode ? { + // Affichage suite à une recompilation. + onRebuild(error, result) { + console.log(new Date()); + if (!error && result.errors.length == 0) + console.log("Successfully built."); + else + console.error("Error!"); + } + } : false, + }) + // Fonction lancée pour une compilation réussie. + .then(() => { console.log(new Date()); console.log("Success."); }) + // Fonction lancée pour une compilation échouée. + .catch((e) => console.error(e.message)); +} + +// @ts-ignore +buildLibrary(process.argv?.[2] == "dev"); diff --git a/package.json b/package.json index d3db004..037c594 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,24 @@ "name": "@sharkitek/core", "version": "1.2.0", "description": "Sharkitek core models library.", - "keywords": ["sharkitek", "model", "serialization", "diff", "dirty", "deserialization", "property"], + "keywords": [ + "sharkitek", + "model", + "serialization", + "diff", + "dirty", + "deserialization", + "property" + ], "repository": "https://git.madeorsk.com/Sharkitek/core", "author": "Madeorsk ", "license": "MIT", - "private": false, "scripts": { - "build": "parcel build", - "dev": "parcel watch", + "build": "ts-node build.ts && tsc --emitDeclarationOnly", "test": "jest" }, - "main": "lib/index.js", "source": "src/index.ts", + "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ "lib/**/*" @@ -22,13 +28,11 @@ "reflect-metadata": "^0.1.13" }, "devDependencies": { - "@parcel/packager-ts": "2.6.2", - "@parcel/transformer-typescript-types": "2.6.2", "@types/jest": "^28.1.6", + "esbuild": "^0.15.8", "jest": "^28.1.3", - "parcel": "^2.6.2", "ts-jest": "^28.0.7", + "ts-node": "^10.9.1", "typescript": "^4.7.4" - }, - "packageManager": "yarn@3.2.2" + } } diff --git a/tsconfig.json b/tsconfig.json index 7ee2891..62aa652 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,10 @@ { + "ts-node": { + "compilerOptions": { + "module": "CommonJS" + } + }, + "files": ["src/index.ts"], "compilerOptions": { "outDir": "./lib/", @@ -11,7 +17,7 @@ "sourceMap": true, "module": "ES6", "moduleResolution": "Node", - "target": "ES5", + "target": "ES6", "lib": [ "ESNext",