MCPcopy Create free account
hub / github.com/MathMan05/Fermi / moveFiles

Function moveFiles

build.ts:76–151  ·  view source on GitHub ↗
(curPath: string, newPath: string, first = true)

Source from the content-addressed store, hash-verified

74 );
75}
76async function moveFiles(curPath: string, newPath: string, first = true) {
77 async function processFile(file: string) {
78 const Prom: Promise<unknown>[] = [];
79 if ((await fs.stat(path.join(curPath, file))).isDirectory()) {
80 await fs.mkdir(path.join(newPath, file));
81 Prom.push(moveFiles(path.join(curPath, file), path.join(newPath, file), false));
82 } else {
83 if (!file.endsWith(".ts")) {
84 if (file.endsWith(".html")) {
85 for (const [, match] of (await fs.readFile(path.join(curPath, file)))
86 .toString()
87 .matchAll(/<script.*?src="(.*?)"/gm)) {
88 const sPathTemp = path.format({
89 root: path.join(__dirname, "src", "webpage"),
90 base: match,
91 });
92 const newPath = path.join(
93 path.format({
94 root: path.join(__dirname, "dist", "webpage"),
95 base: match,
96 }),
97 "../",
98 );
99 const temp2 = path.parse(sPathTemp);
100 //@ts-ignore
101 delete temp2.base;
102 temp2.ext = ".ts";
103 const sPath = path.format(temp2);
104 entryPoints.push({sPath, newPath});
105 }
106 }
107 if (file.includes("sitemap")) {
108 if (urlMaybe) {
109 let map = (await fs.readFile(path.join(curPath, file))).toString();
110 //@ts-expect-error I don't know TS just doesn't seem to know I'm on modern JS
111 map = map.replaceAll("$$$", urlMaybe);
112
113 await fs.writeFile(path.join(newPath, file), map);
114 }
115 } else if (file.includes("robots.txt") && urlMaybe) {
116 let robots = (await fs.readFile(path.join(curPath, file))).toString();
117 robots += "\n\nSitemap: " + urlMaybe + "/sitemap.xml";
118 await fs.writeFile(path.join(newPath, file), robots);
119 } else {
120 await fs.copyFile(path.join(curPath, file), path.join(newPath, file));
121 }
122 } else {
123 const plainname = file.split(".ts")[0];
124 const newfileDir = path.join(newPath, plainname);
125 let mod = first
126 ? await swc.transformFile(path.join(curPath, file), {
127 minify: true,
128 sourceMaps: true,
129 isModule: true,
130 jsc: {
131 minify: {
132 mangle: !process.argv.includes("watch"),
133 },

Callers 2

processFileFunction · 0.85
buildFunction · 0.85

Calls 1

processFileFunction · 0.85

Tested by

no test coverage detected