MCPcopy Create free account
hub / github.com/ThatOpen/engine_clay / restructureExamples

Function restructureExamples

vite.config-examples.ts:7–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { globSync } from "glob";
6
7const restructureExamples = () => {
8 return {
9 name: "examples-refactor",
10 async writeBundle() {
11 const outDir = "examples/packages";
12 const files = globSync(`${outDir}/**/example.html`);
13
14 for (const file of files) {
15 const directory = path.dirname(file);
16 const exampleName = path.basename(directory);
17 const rootFolder = directory.split(path.sep)[0];
18 const targetDirectory = path.join(rootFolder, exampleName);
19 if (!fs.existsSync(targetDirectory)) fs.mkdirSync(targetDirectory);
20
21 const buffer = fs.readFileSync(file);
22 const newBuffer = buffer
23 .toString()
24 .replace(/(\.\.\/)+assets/g, "../assets")
25 .replace(/(\.\.\/)+resources/g, "../../resources");
26 fs.writeFileSync(path.join(targetDirectory, "index.html"), newBuffer);
27 }
28
29 if (fs.existsSync(outDir)) fs.rmSync(outDir, { recursive: true });
30 },
31 };
32};
33
34const entries = globSync("packages/**/src/**/example.html").map((file) => {
35 const directory = path.dirname(file);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected