1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts
Iku-turso 9a2d585e62 feat: Add support for lens-webpack-build --watch
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2023-06-01 08:57:01 +03:00

28 lines
916 B
TypeScript

import { getInjectable } from "@ogre-tools/injectable";
import { execInjectable } from "./exec.injectable";
import { logSuccessInjectable } from "./log-success.injectable";
import { logWarningInjectable } from "./log-warning.injectable";
export type DoWebpackBuild = ({ watch }: { watch: boolean }) => Promise<void>;
export const doWebpackBuildInjectable = getInjectable({
id: "do-webpack-build",
instantiate: (di): DoWebpackBuild => {
const exec = di.inject(execInjectable);
const logSuccess = di.inject(logSuccessInjectable);
const logWarning = di.inject(logWarningInjectable);
return async ({ watch }) => {
const execResult = exec(watch ? "webpack --watch" : "webpack");
execResult.stdout?.on("data", logSuccess);
execResult.stderr?.on("data", logWarning);
return new Promise<void>((resolve) => {
execResult.on("exit", resolve);
});
};
},
});