1
0
mirror of https://github.com/lensapp/lens.git synced 2024-08-16 04:40:24 +03:00

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>
This commit is contained in:
Iku-turso 2023-05-31 17:43:47 +03:00 committed by Janne Savolainen
parent 28c9eeec36
commit 9a2d585e62
4 changed files with 22 additions and 10 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env node
const { doWebpackBuild } = require("../dist/index");
doWebpackBuild();
doWebpackBuild({ watch: process.argv.includes("--watch") });

View File

@ -1,10 +1,10 @@
import { getDi } from "./src/scripts/get-di";
import { doWebpackBuildInjectable } from "./src/scripts/do-webpack-build";
export const doWebpackBuild = () => {
export const doWebpackBuild = ({ watch }: { watch: boolean }) => {
const di = getDi();
const doWebpackBuild = di.inject(doWebpackBuildInjectable);
doWebpackBuild();
doWebpackBuild({ watch });
};

View File

@ -31,15 +31,27 @@ describe("do-webpack-build", () => {
doWebpackBuild = di.inject(doWebpackBuildInjectable);
});
describe("when called", () => {
it('given watching, when called, calls webpack with watch', () => {
doWebpackBuild({ watch: true});
expect(execMock).toHaveBeenCalledWith("webpack --watch");
});
it('given not watching, when called, calls webpack without watch', () => {
doWebpackBuild({ watch: false});
expect(execMock).toHaveBeenCalledWith("webpack");
});
describe("normally, when called", () => {
let actualPromise: Promise<void>;
beforeEach(() => {
actualPromise = doWebpackBuild();
actualPromise = doWebpackBuild({ watch: true});
});
it("calls webpack", () => {
expect(execMock).toHaveBeenCalledWith("webpack");
expect(execMock).toHaveBeenCalled();
});
it("data in stdout logs as success", () => {

View File

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