Skip to content

Commit

Permalink
feat(api): new build
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Nov 27, 2023
1 parent 6637bc4 commit 41691f4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 80 deletions.
2 changes: 1 addition & 1 deletion packages/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENV HOST 0.0.0.0
ENV PORT 80
EXPOSE 80

CMD ["node", "main.js"]
CMD ["node", "main.mjs"]

LABEL org.opencontainers.image.base.name="ghcr.io/alwatr/node:20.10.0" \
org.opencontainers.image.documentation="https://github.com/Alwatr/storage"
64 changes: 0 additions & 64 deletions packages/api/build.js

This file was deleted.

45 changes: 45 additions & 0 deletions packages/api/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;
})();
31 changes: 16 additions & 15 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,27 @@
"bugs": {
"url": "https://github.com/Alwatr/storage/issues"
},
"esbuild": {
"entryPoints": [
"src/main.ts"
],
"outbase": "src",
"outfile": "dist/main.mjs",
"sourcemap": true,
"sourcesContent": true
},
"scripts": {
"s": "yarn run start",
"b": "yarn run build",
"w": "yarn run watch:es",
"c": "yarn run clean",
"cb": "run-s clean build",
"cw": "run-s clean watch",
"s": "yarn run start",
"w": "yarn run watch",
"l": "yarn lint",
"lint": "run-s 'lint:*'",
"lint:ts": "tsc --build",
"start": "NODE_OPTIONS=--enable-source-maps run-s clean build serve",
"build": "yarn run build:es",
"build:es": "yarn node ./build.js",
"clean": "rm -rf dist .tsbuildinfo",
"serve": "yarn node --enable-source-maps dist/index.js",
"start": "run-s clean build serve",
"build": "yarn node ./esbuild.mjs",
"clean": "rm -rfv dist .tsbuildinfo",
"serve": "yarn node --enable-source-maps dist/main.js",
"serve:debug": "yarn node --inspect --enable-source-maps dist/index.js",
"watch": "run-s clean build && run-p watch:es watch:node",
"watch:node": "nodemon -w dist/ --enable-source-maps dist/index.js",
"watch:debug-node": "nodemon -w dist/ --inspect --enable-source-maps dist/index.js",
"watch:es": "yarn run build:es --watch"
"watch:es": "yarn run build --watch"
},
"devDependencies": {
"@alwatr/logger": "^2.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": ".",
"noEmit": true
},

Expand Down

0 comments on commit 41691f4

Please sign in to comment.