Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/wrenfield/scripts/stage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PUBLIC = [
"models",
"data",
];
const BARE_KIT_IMPORT = /"@excom\/nucleus-kit\//g;
const BARE_KIT_IMPORT = /"@excom\/nucleus-kit\/([^"]+)"/g;
const REWRITTEN_FILES = ["index.html", "shell.css"];

export const stage = async ({
Expand All @@ -38,15 +38,21 @@ export const stage = async ({
cp(join(root, name), join(out, name), { recursive: true })
)
);
const cdnPrefix = `"https://unpkg.com/@excom/nucleus-kit@${version}/`;
const cdnBase = `https://unpkg.com/@excom/nucleus-kit@${version}/dist`;
let rewrites = 0;
for (const file of REWRITTEN_FILES) {
const filePath = join(out, file);
const content = await readFile(filePath, "utf8");
const matches = content.match(BARE_KIT_IMPORT);
if (matches) {
rewrites += matches.length;
await writeFile(filePath, content.replaceAll(BARE_KIT_IMPORT, cdnPrefix));
await writeFile(
filePath,
content.replaceAll(BARE_KIT_IMPORT, (_, path) => {
const cdnPath = /\.css$/.test(path) ? path : `${path}.min.js`;
return `"${cdnBase}/${cdnPath}"`;
})
);
}
}
if (rewrites === 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/wrenfield/shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ label {
}
}
@keyframes wf-skeleton {
to {
from {
opacity: 0.45;
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/wrenfield/support/tests/stage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ describe("stage", () => {
expect(await stage({ out })).toBe(version);
const html = await read(out, "index.html");
const css = await read(out, "shell.css");
const htmlPinned = html.match(/unpkg\.com\/@excom\/nucleus-kit@[^/]+\//g);
const cssPinned = css.match(/unpkg\.com\/@excom\/nucleus-kit@[^/]+\//g);
expect(htmlPinned).toEqual([`unpkg.com/@excom/nucleus-kit@${version}/`]);
expect(cssPinned).toEqual([`unpkg.com/@excom/nucleus-kit@${version}/`]);
const htmlPinned = html.match(/unpkg\.com\/@excom\/nucleus-kit@[^/]+\/dist\//g);
const cssPinned = css.match(/unpkg\.com\/@excom\/nucleus-kit@[^/]+\/dist\//g);
expect(htmlPinned).toEqual([`unpkg.com/@excom/nucleus-kit@${version}/dist/`]);
expect(cssPinned).toEqual([`unpkg.com/@excom/nucleus-kit@${version}/dist/`]);
});

it("rewrites bare Kit imports and no other line", async () => {
Expand All @@ -48,13 +48,13 @@ describe("stage", () => {
const afterHtml = (await read(out, "index.html")).split("\n");
expect(afterHtml).toHaveLength(beforeHtml.length);
expect(afterHtml.filter((line, i) => line !== beforeHtml[i])).toEqual([
expect.stringContaining("unpkg.com/@excom/nucleus-kit@1.0.0-rc.1/nucleus-kit.progressive"),
expect.stringContaining("unpkg.com/@excom/nucleus-kit@1.0.0-rc.1/dist/nucleus-kit.progressive.min.js"),
]);
const beforeCss = (await read(PACKAGE, "shell.css")).split("\n");
const afterCss = (await read(out, "shell.css")).split("\n");
expect(afterCss).toHaveLength(beforeCss.length);
expect(afterCss.filter((line, i) => line !== beforeCss[i])).toEqual([
expect.stringContaining("unpkg.com/@excom/nucleus-kit@1.0.0-rc.1/basic.css"),
expect.stringContaining("unpkg.com/@excom/nucleus-kit@1.0.0-rc.1/dist/basic.css"),
]);
});

Expand Down
Loading