mirror of
https://github.com/lensapp/lens.git
synced 2024-09-11 09:25:26 +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:
parent
28c9eeec36
commit
9a2d585e62
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
const { doWebpackBuild } = require("../dist/index");
|
||||
|
||||
doWebpackBuild();
|
||||
doWebpackBuild({ watch: process.argv.includes("--watch") });
|
||||
|
@ -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 });
|
||||
};
|
||||
|
@ -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", () => {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user