Skip to content

Commit

Permalink
feat(sdk): new build
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Nov 27, 2023
1 parent 2385e76 commit 08f00b5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
45 changes: 45 additions & 0 deletions packages/sdk/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -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;
})();
27 changes: 26 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,38 @@
"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",
"tslib": "^2.6.2"
},
"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"
}
}
4 changes: 3 additions & 1 deletion packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "."
"outDir": ".",
"emitDeclarationOnly": true,
// "noEmit": true,
},

"include": ["src/**/*.ts"],
Expand Down

0 comments on commit 08f00b5

Please sign in to comment.