Skip to content

Commit c87f303

Browse files
committed
chore: add copying old widget step to Pusher
1 parent ba8c686 commit c87f303

2 files changed

Lines changed: 49 additions & 20 deletions

File tree

automation/utils/src/steps.ts

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile, writeFile } from "node:fs/promises";
22
import { dirname, join, parse, relative, resolve } from "path";
3+
import chalk from "chalk";
34
import {
45
CommonBuildConfig,
56
getModuleConfigs,
@@ -13,7 +14,6 @@ import { createModuleMpkInDocker } from "./mpk";
1314
import { ModuleInfo, PackageInfo, WidgetInfo } from "./package-info";
1415
import { addFilesToPackageXml, PackageType } from "./package-xml";
1516
import { chmod, cp, ensureFileExists, exec, find, mkdir, popd, pushd, rm, unzip, zip } from "./shell";
16-
import chalk from "chalk";
1717

1818
type Step<Info, Config> = (params: { info: Info; config: Config }) => Promise<void>;
1919

@@ -164,36 +164,63 @@ export async function createModuleMpk({ info, config }: ModuleStepParams): Promi
164164
);
165165
}
166166

167-
export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise<void> {
168-
logStep("Add widgets to mpk");
169-
170-
const mpk = config.output.files.modulePackage;
171-
const widgets = await getMpkPaths(config.dependencies);
167+
async function insertWidgetsIntoMpk(
168+
mpk: string,
169+
widgetPaths: string[],
170+
tmpDir: string,
171+
additionalFiles?: Array<{ src: string; destRelative: string }>
172+
): Promise<void> {
172173
const mpkEntry = parse(mpk);
173-
const target = join(mpkEntry.dir, "tmp");
174-
const widgetsOut = join(target, "widgets");
175-
const packageXml = join(target, "package.xml");
176-
const packageFilePaths = widgets.map(path => `widgets/${parse(path).base}`);
177-
178-
rm("-rf", target);
174+
const widgetsOut = join(tmpDir, "widgets");
175+
const packageXml = join(tmpDir, "package.xml");
176+
const packageFilePaths = widgetPaths.map(p => `widgets/${parse(p).base}`);
179177

178+
rm("-rf", tmpDir);
180179
console.info("Unzip module mpk");
181-
await unzip(mpk, target);
180+
await unzip(mpk, tmpDir);
182181
mkdir("-p", widgetsOut);
183-
chmod("-R", "a+rw", target);
182+
chmod("-R", "a+rw", tmpDir);
183+
184+
console.info(`Add ${widgetPaths.length} widgets to ${mpkEntry.base}`);
185+
cp(widgetPaths, widgetsOut);
184186

185-
console.info(`Add ${widgets.length} widgets to ${mpkEntry.base}`);
186-
cp(widgets, widgetsOut);
187+
if (additionalFiles) {
188+
for (const { src, destRelative } of additionalFiles) {
189+
cp(src, join(tmpDir, destRelative));
190+
}
191+
}
187192

188193
console.info(`Add file entries to package.xml`);
189194
await addFilesToPackageXml(packageXml, packageFilePaths, "modelerProject");
190-
console.log(`Copying License.txt...`);
191-
cp(join(config.paths.package, "LICENSE"), join(target, "License.txt"));
192195
rm(mpk);
193196

194197
console.info("Create module zip archive");
195-
await zip(target, mpk);
196-
rm("-rf", target);
198+
await zip(tmpDir, mpk);
199+
rm("-rf", tmpDir);
200+
}
201+
202+
export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise<void> {
203+
logStep("Add widgets to mpk");
204+
205+
const mpk = config.output.files.modulePackage;
206+
const widgets = await getMpkPaths(config.dependencies);
207+
const tmpDir = join(parse(mpk).dir, "tmp");
208+
209+
await insertWidgetsIntoMpk(mpk, widgets, tmpDir, [
210+
{ src: join(config.paths.package, "LICENSE"), destRelative: "License.txt" }
211+
]);
212+
}
213+
214+
export function addTestProjectWidgetsToMpk(widgetFileNames: string[]): (params: ModuleStepParams) => Promise<void> {
215+
return async ({ config }) => {
216+
logStep("Add test project widgets to mpk");
217+
218+
const mpk = config.output.files.modulePackage;
219+
const widgetPaths = widgetFileNames.map(name => join(config.output.dirs.widgets, name));
220+
const tmpDir = join(parse(mpk).dir, "tmp_local_widgets");
221+
222+
await insertWidgetsIntoMpk(mpk, widgetPaths, tmpDir);
223+
};
197224
}
198225

199226
export async function moveModuleToDist({ info, config }: ModuleStepParams): Promise<void> {

packages/modules/pusher/scripts/release.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env ts-node-script
22

33
import {
4+
addTestProjectWidgetsToMpk,
45
addWidgetsToMpk,
56
cloneTestProject,
67
copyModuleLicense,
@@ -23,6 +24,7 @@ async function main(): Promise<void> {
2324
copyWidgetsToProject,
2425
createModuleMpk,
2526
addWidgetsToMpk,
27+
addTestProjectWidgetsToMpk(["Pusher.mpk"]),
2628
moveModuleToDist
2729
]
2830
});

0 commit comments

Comments
 (0)