Skip to content

Commit

Permalink
chore: build_services script
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Oct 30, 2024
1 parent 4071bf9 commit edf5c70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@
"prepare": "husky install",
"prepublishOnly": "npm run build",
"generate_services": "ts-node scripts/generate_services",
"build:services": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack",
"build:services": "ts-node scripts/build_services",
"build:mono-service": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" tsc -p .",
"build": "npm run build:mono-service && npm run build:services",
"typecheck:clients": "tsc -p ./clients --noEmit"
"typecheck:clients": "tsc -p ./clients --noEmit",
"qwe": "ts-node ./webpack.config.ts"
},
"engines": {
"node": ">=18.0.0"
Expand Down
31 changes: 24 additions & 7 deletions webpack.config.ts → scripts/build_services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';
import { Options } from 'ts-loader';

const getServices = () => {
const files = fs.readdirSync(path.resolve(__dirname, './clients'), { withFileTypes: true });
const files = fs.readdirSync(path.resolve('./clients'), { withFileTypes: true });
return files.filter((file) => file.isDirectory()).map((file) => file.name);
};

Expand Down Expand Up @@ -51,7 +51,7 @@ const getConfig = (tsLoaderOptions: Partial<Options>): webpack.Configuration =>
const getServiceConfig = (serviceName: string): webpack.Configuration => {
const tsLoaderOptions: Partial<Options> = {
compilerOptions: {
outDir: path.resolve(__dirname, `./${serviceName}`),
outDir: path.resolve(`./${serviceName}`),
},
onlyCompileBundledFiles: true,
};
Expand All @@ -61,18 +61,35 @@ const getServiceConfig = (serviceName: string): webpack.Configuration => {
return {
...config,
name: serviceName,
entry: path.resolve(__dirname, `./clients/${serviceName}/index.ts`),
entry: path.resolve(`./clients/${serviceName}/index.ts`),
output: {
path: path.resolve(__dirname, serviceName),
path: path.resolve(serviceName),
filename: 'index.js',
libraryTarget: 'umd',
library: serviceName,
umdNamedDefine: true,
},
stats: {
colors: true,
logging: 'log',
},
};
};

const serviceConfigList = getServices().map(getServiceConfig);
(async () => {
const serviceConfigList = getServices().map(getServiceConfig);

for (let i = 0; i !== serviceConfigList.length; i++) {
const config = serviceConfigList[i];

console.log('Started', config.name);

await new Promise<null>((res) => {
webpack(config, (err) => {
console.log('Ended', config.name, err);

module.exports = serviceConfigList;
module.exports.parallelism = 1;
res(null);
});
});
}
})();
7 changes: 0 additions & 7 deletions tsconfig-for-webpack-config.json

This file was deleted.

0 comments on commit edf5c70

Please sign in to comment.