Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new build process #492

Merged
merged 13 commits into from
Dec 12, 2022
Merged
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ jobs:
run: yarn install --frozen-lockfile

- name: 🚀 Build Typescript
run: yarn build
run: yarn build:ts && yarn lerna run build:ts

- name: 🚀 Extra Packages Build
run: yarn lerna run build
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"alwatr",
"calt",
"currentcolor",
"esbuild",
"Kubernetes",
"mastmalize",
"mihandoost",
"nanoserver",
"nanoservice",
"noncallable",
"outdir",
"preconnect",
"preload",
"roundot",
Expand Down
7 changes: 4 additions & 3 deletions cloud/container/alwatr-services.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ WORKDIR /app
# Install tini for recive system signal in nodejs
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "index.js"]
CMD ["node", "index.*js"]

ENV NODE_ENV production
ENV NODE_OPTIONS --enable-source-maps
ENV ALWATR_DEBUG *
ENV HOST 0.0.0.0
ENV PORT 80
EXPOSE 80

# Tell nodejs to run as ESM Modules
RUN echo '{"type":"module"}' > package.json
# RUN echo '{"type":"module"}' > package.json

# Copy all deps from last stage (temporary until refactor build)
# Copy all deps from last stage
COPY --from=builder /app/node_modules/ ./node_modules/

# Copy builded files from last stage
Expand Down
2 changes: 1 addition & 1 deletion core/fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
CacheStrategy,
AlwatrDocumentObject,
AlwatrServiceResponse,
} from './type';
} from './type.js';

export {
FetchOptions,
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"scripts": {
"l": "yarn lint",
"b": "yarn build",
"br": "run-s build:ts build:r",
"c": "yarn clean",
"cb": "run-s clean build",
"s": "run-s build serve",
"w": "yarn watch",
Expand All @@ -30,8 +32,9 @@
"pp": "run-s pull clean build ver-patch push",
"lint": "run-s lint:*",
"lint:ts": "eslint . --config .eslintrc.json --ext .ts --ignore-path .gitignore",
"build": "run-s build:ts && lerna run build",
"build": "yarn build:ts",
"build:ts": "tsc --build",
"build:r": "lerna run build",
"format": "run-s format:prettier format:eslint",
"format:eslint": "yarn lint:ts --fix",
"format:prettier": "prettier . --ignore-path .gitignore --write",
Expand Down Expand Up @@ -65,5 +68,8 @@
"rimraf": "~3.0.2",
"ts-lit-plugin": "~1.2.1",
"typescript": "~4.9.4"
},
"resolutions": {
"esbuild": "~0.16.4"
}
}
28 changes: 16 additions & 12 deletions services/comment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,31 @@
},
"scripts": {
"b": "yarn build",
"c": "yarn clean",
"cb": "run-s clean build",
"s": "run-s clean build serve",
"w": "yarn watch",
"start": "yarn serve",
"build": "run-s build:*",
"build:es": "esbuild src/index.ts --bundle --format=esm --minify --target=es2022 --platform=node --outfile=dist/index.js",
"clean": "rimraf dist build .tsbuildinfo src/**/*.{js,d.ts,map}",
"serve": "node dist/index.js",
"serve:debug": "node --inspect dist/index.js",
"watch": "run-s clean build && run-p watch:ts watch:node",
"watch:node": "nodemon -w dist/ dist/index.js",
"watch:debug-node": "nodemon -w dist/ --inspect dist/index.js",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput"
"build": "yarn build:es --analyze=verbose",
"build:ts": "tsc --build",
"build:es": "esbuild src/index.ts --platform=node --target=node19 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs",
"clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}",
"serve": "node --enable-source-maps dist/index.*js",
"serve:debug": "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:ts": "yarn build:ts --watch --preserveWatchOutput",
"watch:es": "yarn build:es --watch"
},
"dependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0",
"@alwatr/storage-client": "~0.25.0"
},
"devDependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0",
"@alwatr/storage-client": "~0.25.0",
"@types/node": "~18.11.12",
"esbuild": "~0.16.4",
"nodemon": "~2.0.20",
"npm-run-all": "~4.1.5",
"rimraf": "~3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const config = {
},
};

logger.logProperty('config', {...config, token: '***'});
logger.logProperty('config', config);
2 changes: 1 addition & 1 deletion services/comment/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './route/home.js';
import './route/patch.js';
import './route/all.js';
import {logger} from './lib/config.js';
import {logger} from './config.js';

logger.logOther('..:: Alwatr Comment Nanoservice API ::..');
2 changes: 1 addition & 1 deletion services/comment/src/lib/nano-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AlwatrNanoServer} from '@alwatr/nano-server';

import {config} from './config.js';
import {config} from '../config.js';

export const nanoServer = new AlwatrNanoServer(config.nanoServer);
2 changes: 1 addition & 1 deletion services/comment/src/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AlwatrStorageClient} from '@alwatr/storage-client';

import {config} from './config.js';
import {config} from '../config.js';
import {Message} from './type.js';

export const storage = new AlwatrStorageClient<Message>(config.storage);
2 changes: 1 addition & 1 deletion services/comment/src/route/all.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {config, logger} from '../lib/config.js';
import {config, logger} from '../config.js';
import {nanoServer} from '../lib/nano-server.js';
import {storage} from '../lib/storage.js';

Expand Down
2 changes: 1 addition & 1 deletion services/comment/src/route/patch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {config, logger} from '../lib/config.js';
import {config, logger} from '../config.js';
import {nanoServer} from '../lib/nano-server.js';
import {storage} from '../lib/storage.js';
import {Message} from '../lib/type.js';
Expand Down
4 changes: 3 additions & 1 deletion services/comment/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"target": "ESNext",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "build"
"outDir": "build",
// "noEmit": true
},

"include": ["src/**/*.ts"],
Expand Down
30 changes: 17 additions & 13 deletions services/flight-crawler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@
},
"scripts": {
"b": "yarn build",
"c": "yarn clean",
"cb": "run-s clean build",
"s": "run-s clean build serve",
"w": "yarn watch",
"start": "yarn serve",
"build": "run-s build:*",
"build:es": "esbuild src/index.ts --bundle --format=esm --minify --target=es2022 --platform=node --outfile=dist/index.js",
"clean": "rimraf dist build .tsbuildinfo src/**/*.{js,d.ts,map}",
"serve": "node dist/index.js",
"serve:debug": "node --inspect dist/index.js",
"watch": "run-s clean build && run-p watch:ts watch:node",
"watch:node": "nodemon -w dist/ dist/index.js",
"watch:debug-node": "nodemon -w dist/ --inspect dist/index.js",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput"
"build": "yarn build:es --analyze=verbose",
"build:ts": "tsc --build",
"build:es": "esbuild src/index.ts --platform=node --target=node19 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs",
"clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}",
"serve": "node --enable-source-maps dist/index.*js",
"serve:debug": "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:ts": "yarn build:ts --watch --preserveWatchOutput",
"watch:es": "yarn build:es --watch"
},
"dependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0",
"@alwatr/storage-client": "~0.25.0"
},
"devDependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0",
"@alwatr/storage-client": "~0.25.0",
"@types/node": "~18.11.12",
"esbuild": "~0.16.4",
"nodemon": "~2.0.20",
"npm-run-all": "~4.1.5",
"rimraf": "~3.0.2",
"typescript": "4.9.4"
"typescript": "~4.9.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {createLogger} from '@alwatr/logger';

export const logger = createLogger('flight-crawler');

export const config = {
storage: {
host: process.env.STORAGE_HOST ?? '127.0.0.1',
Expand All @@ -14,6 +16,4 @@ export const config = {
},
};

export const logger = createLogger('flight-finder-crawler');

logger.logProperty('config', config);
2 changes: 1 addition & 1 deletion services/flight-crawler/src/crawl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {fetch} from '@alwatr/fetch';

import {config, logger} from './lib/config.js';
import {config, logger} from './config.js';
import {storage} from './lib/storage.js';

import type {Job, JobDetail, JobResult, SepehrResponse} from './lib/type.js';
Expand Down
4 changes: 2 additions & 2 deletions services/flight-crawler/src/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AlwatrStorageClient} from '@alwatr/storage-client';

import {config} from './config.js';
import {config} from '../config.js';

import type {Job} from './type';
import type {Job} from './type.js';

export const storage = new AlwatrStorageClient<Job>(config.storage);
4 changes: 3 additions & 1 deletion services/flight-crawler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"target": "ESNext",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "build"
"outDir": "build",
// "noEmit": true
},

"include": ["src/**/*.ts"],
Expand Down
26 changes: 15 additions & 11 deletions services/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@
},
"scripts": {
"b": "yarn build",
"c": "yarn clean",
"cb": "run-s clean build",
"s": "run-s clean build serve",
"w": "yarn watch",
"start": "yarn serve",
"build": "run-s build:*",
"build:es": "esbuild src/index.ts --bundle --format=esm --minify --target=es2022 --platform=node --outfile=dist/index.js",
"clean": "rimraf dist build .tsbuildinfo src/**/*.{js,d.ts,map}",
"serve": "node dist/index.js",
"serve:debug": "node --inspect dist/index.js",
"watch": "run-s clean build && run-p watch:ts watch:node",
"watch:node": "nodemon -w dist/ dist/index.js",
"watch:debug-node": "nodemon -w dist/ --inspect dist/index.js",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput"
"build": "yarn build:es --analyze=verbose",
"build:ts": "tsc --build",
"build:es": "esbuild src/index.ts --platform=node --target=node19 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs",
"clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}",
"serve": "node --enable-source-maps dist/index.*js",
"serve:debug": "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:ts": "yarn build:ts --watch --preserveWatchOutput",
"watch:es": "yarn build:es --watch"
},
"dependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0"
},
"devDependencies": {
"@alwatr/logger": "~0.25.0",
"@alwatr/nano-server": "~0.25.0",
"@types/node": "~18.11.12",
"esbuild": "~0.16.4",
"nodemon": "~2.0.20",
"npm-run-all": "~4.1.5",
"rimraf": "~3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const logger = createLogger('nanoservice-starter');

export const config = {
host: process.env.HOST ?? '0.0.0.0',
port: process.env.PORT != null ? +process.env.PORT : 80,
port: process.env.PORT != null ? +process.env.PORT : 8000,
};

logger.logProperty('config', config);
2 changes: 1 addition & 1 deletion services/starter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './route/home.js';
import './route/echo.js';
import {logger} from './lib/config.js';
import {logger} from './config.js';

logger.logOther('..:: Alwatr Nanoservice Starter Kit ::..');
4 changes: 2 additions & 2 deletions services/starter/src/lib/nano-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AlwatrNanoServer} from '@alwatr/nano-server';

import {config} from './config.js';
import {config} from '../config.js';

export const nanoServer = new AlwatrNanoServer({host: config.host, port: config.port});
export const nanoServer = new AlwatrNanoServer(config);
2 changes: 1 addition & 1 deletion services/starter/src/route/echo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {logger} from '../lib/config.js';
import {logger} from '../config.js';
import {nanoServer} from '../lib/nano-server.js';

import type {AlwatrConnection} from '@alwatr/nano-server';
Expand Down
4 changes: 3 additions & 1 deletion services/starter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"target": "ESNext",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "build"
"outDir": "build",
// "noEmit": true
},

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