From 08f00b54a33493c4938975251ea8660fe58346fd Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Mon, 27 Nov 2023 21:28:03 +0330 Subject: [PATCH] feat(sdk): new build --- packages/sdk/esbuild.mjs | 45 ++++++++++++++++++++++++++++++++++++++ packages/sdk/package.json | 27 ++++++++++++++++++++++- packages/sdk/tsconfig.json | 4 +++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 packages/sdk/esbuild.mjs diff --git a/packages/sdk/esbuild.mjs b/packages/sdk/esbuild.mjs new file mode 100755 index 00000000..d8994f34 --- /dev/null +++ b/packages/sdk/esbuild.mjs @@ -0,0 +1,45 @@ +import {createLogger} from '@alwatr/logger'; +import {readJsonFileSync} from '@alwatr/util/node.js'; + +import {context, build} from 'esbuild'; +// import packageJson from './package.json' assert { type: 'json' }; + +const packageJson = readJsonFileSync('./package.json'); + +const logger = createLogger('esbuild', true); +const watchMode = process.argv.includes('--watch'); + +(async () => { + logger.logProperty?.('packageJson.esbuild', packageJson.esbuild); + + /** + * @type {import('esbuild').BuildOptions} + */ + const esbuildOptions = { + logLevel: 'info', + platform: 'node', + target: 'es2020', + format: 'esm', + minify: true, + treeShaking: true, + sourcemap: false, + sourcesContent: false, + bundle: true, + splitting: false, + charset: 'utf8', + legalComments: 'none', + ...packageJson.esbuild, + }; + + if (watchMode) { + logger.logOther?.('👀 Watching...'); + const esbuildContext = await context(esbuildOptions); + esbuildContext.watch(); + return; + } + + // else + logger.logOther?.('🚀 Building...'); + await build(esbuildOptions); + return; +})(); diff --git a/packages/sdk/package.json b/packages/sdk/package.json index e2dfc749..a10f9027 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -35,6 +35,27 @@ "bugs": { "url": "https://github.com/Alwatr/storage/issues" }, + "esbuild": { + "entryPoints": [ + "src/*.ts" + ], + "outbase": "src", + "outdir": ".", + "minify": false, + "bundle": false, + "sourcemap": true, + "sourcesContent": true + }, + "scripts": { + "b": "yarn run build", + "c": "yarn run clean", + "cb": "run-s clean build", + "build": "run-p -l 'build:*'", + "build:es": "yarn node ./esbuild.mjs", + "build:ts": "tsc --build", + "clean": "rm -rfv *.js *.d.ts *.d.ts.map *.js.map .tsbuildinfo", + "watch:es": "yarn run build --watch" + }, "dependencies": { "@alwatr/fetch": "^2.1.1", "@alwatr/logger": "^2.3.0", @@ -42,6 +63,10 @@ }, "devDependencies": { "@alwatr/type": "^1.2.1", - "@types/node": "^20.10.0" + "@alwatr/util": "^1.3.1", + "@types/node": "^20.10.0", + "esbuild": "^0.19.8", + "npm-run-all": "^4.1.5", + "typescript": "^5.3.2" } } diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index 51646795..34afe0d5 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -4,7 +4,9 @@ "composite": true, "tsBuildInfoFile": ".tsbuildinfo", "rootDir": "src", - "outDir": "." + "outDir": ".", + "emitDeclarationOnly": true, + // "noEmit": true, }, "include": ["src/**/*.ts"],