@michijs/dev-server 0.8.2 → 0.8.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,6 @@ import { minifyXMLLike } from "../../utils/minify.js";
|
|
|
3
3
|
import { workerTransformer } from "../../utils/workerTransformer.js";
|
|
4
4
|
import { transformSync as esbuild } from "esbuild";
|
|
5
5
|
export const jsAndTsRegex = /.*\.(?:ts|js)/;
|
|
6
|
-
export const notJsAndTsRegex = /.*\.(?!ts|js)/;
|
|
7
6
|
export const jsonTransformer = {
|
|
8
7
|
fileRegex: /.*\.(?:json)/,
|
|
9
8
|
transformer: (fileContent) => config.public.minify
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { config, connections } from "../config.js";
|
|
2
|
-
import { jsAndTsRegex,
|
|
2
|
+
import { jsAndTsRegex, transformers, } from "../../actions/start/transformers.js";
|
|
3
3
|
import { syncDirs } from "../../utils/syncDirs.js";
|
|
4
4
|
import { copy } from "../../utils/copy.js";
|
|
5
5
|
import fs from "fs";
|
|
@@ -34,13 +34,11 @@ export const publicFolderPlugin = {
|
|
|
34
34
|
fs.writeFileSync(getPath(`${wellKnownDir}/web-app-origin-association`), transformedFile);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
copy(config.public.path, outdir, transformers, [jsAndTsRegex]);
|
|
37
|
+
copy(config.public.path, outdir, transformers);
|
|
39
38
|
let firstLoad = true;
|
|
40
39
|
build.onEnd(() => {
|
|
41
|
-
// first-load sw - Omit to copy any other non-js file
|
|
42
40
|
if (firstLoad) {
|
|
43
|
-
copy(config.public.path, outdir, transformers
|
|
41
|
+
copy(config.public.path, outdir, transformers);
|
|
44
42
|
if (config.watch)
|
|
45
43
|
syncDirs(config.public.path, config.esbuildOptions.outdir, transformers, undefined, undefined, (event, fileChangedPath) => {
|
|
46
44
|
connections.forEach((x) => x.write(`event: change\ndata: ${JSON.stringify({
|
package/bin/utils/copy.js
CHANGED
|
@@ -2,30 +2,25 @@ import fs from "fs";
|
|
|
2
2
|
import { getPath } from "./getPath.js";
|
|
3
3
|
export function copyFile(src, fileName, dest, transformers, omit) {
|
|
4
4
|
const srcPath = getPath(`${src}/${fileName}`);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const destPath = getPath(`${dest}/${fileName}`);
|
|
6
|
+
if (fs.lstatSync(srcPath).isDirectory())
|
|
7
|
+
return copy(srcPath, destPath, transformers, omit);
|
|
8
|
+
if (omit?.find((x) => x.test(srcPath)))
|
|
9
|
+
return;
|
|
10
|
+
const fileTransformer = transformers?.filter((x) => x.fileRegex.test(fileName));
|
|
11
|
+
if (fileTransformer.length === 0)
|
|
12
|
+
return fs.copyFileSync(srcPath, destPath, fs.constants.COPYFILE_FICLONE);
|
|
13
|
+
fileTransformer.forEach(async (x) => {
|
|
14
|
+
const srcFileContent = fs.readFileSync(srcPath, {
|
|
15
|
+
encoding: "utf-8",
|
|
16
|
+
});
|
|
17
|
+
const finalDestPath = x.pathTransformer?.(destPath) ?? destPath;
|
|
18
|
+
try {
|
|
19
|
+
const transformedFile = x.transformer(srcFileContent, srcPath);
|
|
20
|
+
fs.writeFileSync(finalDestPath, transformedFile);
|
|
9
21
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (fileTransformer.length > 0) {
|
|
13
|
-
fileTransformer.forEach(async (x) => {
|
|
14
|
-
const srcFileContent = fs.readFileSync(srcPath, {
|
|
15
|
-
encoding: "utf-8",
|
|
16
|
-
});
|
|
17
|
-
const finalDestPath = x.pathTransformer?.(destPath) ?? destPath;
|
|
18
|
-
try {
|
|
19
|
-
const transformedFile = x.transformer(srcFileContent, srcPath);
|
|
20
|
-
fs.writeFileSync(finalDestPath, transformedFile);
|
|
21
|
-
}
|
|
22
|
-
catch { }
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else
|
|
26
|
-
fs.copyFileSync(srcPath, destPath, fs.constants.COPYFILE_FICLONE);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
22
|
+
catch { }
|
|
23
|
+
});
|
|
29
24
|
}
|
|
30
25
|
export function copy(src, dest, transformers, omit) {
|
|
31
26
|
const srcDir = fs.readdirSync(src);
|