buner 1.0.6 → 1.0.8
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.
- package/dist/buner.js +75 -92
- package/dist/integration.js +122 -112
- package/dist/prerender.js +144 -136
- package/dist/server.js +36 -26
- package/dist/states.js +44 -35
- package/dist/styles.js +145 -133
- package/index.html +1 -1
- package/package.json +1 -1
- package/xpack/alias.ts +3 -2
- package/xpack/hooks/options.ts +2 -2
- package/xpack/hooks/transform-index-html.ts +4 -2
- package/xpack/react-loader-init.tsx +1 -1
package/dist/buner.js
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { execSync, spawn } from "child_process";
|
|
4
3
|
import { fileURLToPath } from "url";
|
|
5
4
|
import { Command } from "commander";
|
|
6
5
|
import chalk from "chalk";
|
|
7
6
|
import fetch from "node-fetch";
|
|
8
7
|
import prompts from "prompts";
|
|
8
|
+
import { build } from "vite";
|
|
9
|
+
import { runStyles } from "./styles.js";
|
|
10
|
+
import { runStates } from "./states.js";
|
|
11
|
+
import { runServer } from "./server.js";
|
|
12
|
+
import { runPrerender } from "./prerender.js";
|
|
13
|
+
import { runIntegration } from "./integration.js";
|
|
14
|
+
import validateProjectName from "validate-npm-package-name";
|
|
9
15
|
import fs from "fs";
|
|
16
|
+
import { execSync } from "child_process";
|
|
10
17
|
import fs$1 from "fs/promises";
|
|
11
18
|
import os from "os";
|
|
12
19
|
import { globby } from "globby";
|
|
13
20
|
import { exec } from "node:child_process";
|
|
14
|
-
import
|
|
21
|
+
import "chokidar";
|
|
22
|
+
import "sass";
|
|
23
|
+
import "slash";
|
|
24
|
+
import "debounce";
|
|
25
|
+
import "glob";
|
|
26
|
+
import "postcss";
|
|
27
|
+
import "autoprefixer";
|
|
28
|
+
import "cssnano";
|
|
29
|
+
import "node:fs";
|
|
30
|
+
import "node:path";
|
|
31
|
+
import "express";
|
|
32
|
+
import "serve-static";
|
|
33
|
+
import "cheerio";
|
|
34
|
+
import "js-beautify";
|
|
35
|
+
import "node:crypto";
|
|
36
|
+
import "lodash";
|
|
15
37
|
const name = "buner";
|
|
16
|
-
const version = "1.0.
|
|
38
|
+
const version = "1.0.8";
|
|
17
39
|
const description = "Frontend build toolkit for Vite + React SSR projects — SCSS pipeline, prerender, SSR dev server, and backend integration.";
|
|
18
40
|
const type = "module";
|
|
19
41
|
const license = "MIT";
|
|
20
42
|
const repository = { "type": "git", "url": "https://github.com/precise-alloy/buner.git" };
|
|
21
43
|
const homepage = "https://www.npmjs.com/package/buner";
|
|
22
44
|
const keywords = ["vite", "react", "ssr", "scss", "prerender", "frontend", "build-tool", "cli"];
|
|
23
|
-
const bin
|
|
45
|
+
const bin = { "buner": "./dist/buner.js" };
|
|
24
46
|
const files = ["dist", "xpack", "public", "vite.config.ts", "index.html", "tsconfig.json", "eslint.config.mjs", "types.d.ts", ".env", ".env.development", ".env.eshn", "README.md"];
|
|
25
47
|
const scripts = { "start": "bun run dev", "predev": "bun upgrade", "dev": 'concurrently --kill-others "bun styles.ts --watch" "bun states.ts --watch" "cross-env scriptOnly=true vite build --mode development --watch" "bun server.ts --mode development"', "serve": "bun server.ts", "watch": "bun server.ts", "build": "bun run build:static && bun run build:server", "build:eshn": "bun run build:static:eshn && bun run build:server:eshn", "preview": "vite preview", "build:server": "vite build --ssr src/entry-server.tsx --outDir dist/server", "build:server:eshn": "vite build --ssr src/entry-server.tsx --outDir dist/server --mode eshn", "build:static": "vite build --outDir dist/static", "build:static:eshn": "vite build --outDir dist/static --mode eshn", "generate": "bun states.ts && bun run styles && bun run build && bun prerender.ts --add-hash", "eshn": "bun states.ts && bun run styles && bun run build:eshn && bun prerender.ts --add-hash --mode eshn", "inte": "bun run styles && bun run build && bun prerender.ts && bun integration.ts", "styles": "bun styles.ts", "format": "prettier --write .", "lint": "eslint --fix", "cli:start": "vite build -c vite.cli.config.ts --watch", "cli:build": "vite build -c vite.cli.config.ts" };
|
|
26
48
|
const engines = { "node": ">=20.0.0" };
|
|
@@ -37,7 +59,7 @@ const packageJson = {
|
|
|
37
59
|
repository,
|
|
38
60
|
homepage,
|
|
39
61
|
keywords,
|
|
40
|
-
bin
|
|
62
|
+
bin,
|
|
41
63
|
files,
|
|
42
64
|
scripts,
|
|
43
65
|
engines,
|
|
@@ -46,6 +68,16 @@ const packageJson = {
|
|
|
46
68
|
devDependencies,
|
|
47
69
|
msw
|
|
48
70
|
};
|
|
71
|
+
function validateNpmName(name2) {
|
|
72
|
+
const nameValidation = validateProjectName(name2);
|
|
73
|
+
if (nameValidation.validForNewPackages && !name2.startsWith("-")) {
|
|
74
|
+
return { valid: true };
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
valid: false,
|
|
78
|
+
problems: [...nameValidation.errors || [], ...nameValidation.warnings || []]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
49
81
|
const isWriteable = async (directory) => {
|
|
50
82
|
try {
|
|
51
83
|
await fs.promises.access(directory, fs.constants.W_OK);
|
|
@@ -418,55 +450,23 @@ Creating a new app in ${green$1(root)}.`);
|
|
|
418
450
|
console.log(`
|
|
419
451
|
${green$1("Success!")} Created ${appName} at ${appPath}`);
|
|
420
452
|
};
|
|
421
|
-
function validateNpmName(name2) {
|
|
422
|
-
const nameValidation = validateProjectName(name2);
|
|
423
|
-
if (nameValidation.validForNewPackages && !name2.startsWith("-")) {
|
|
424
|
-
return { valid: true };
|
|
425
|
-
}
|
|
426
|
-
return {
|
|
427
|
-
valid: false,
|
|
428
|
-
problems: [...nameValidation.errors || [], ...nameValidation.warnings || []]
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
453
|
const { green, yellow, bold, cyan, red } = chalk;
|
|
432
454
|
const packageName = "buner";
|
|
433
455
|
const packageDir = path.dirname(fileURLToPath(import.meta.url));
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
} catch {
|
|
456
|
+
const viteConfigPath = () => path.resolve(packageDir, "..", "vite.config.ts");
|
|
457
|
+
const viteBuild = async (opts) => {
|
|
458
|
+
const config = {
|
|
459
|
+
configFile: viteConfigPath(),
|
|
460
|
+
build: {
|
|
461
|
+
outDir: opts.outDir,
|
|
462
|
+
...opts.ssr ? { ssr: opts.ssr } : {},
|
|
463
|
+
...opts.watch ? { watch: {} } : {}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
if (opts.mode) {
|
|
467
|
+
config.mode = opts.mode;
|
|
447
468
|
}
|
|
448
|
-
|
|
449
|
-
};
|
|
450
|
-
const run = (cmd, args = [], options = {}) => {
|
|
451
|
-
return new Promise((resolve, reject) => {
|
|
452
|
-
const child = spawn(cmd, args, {
|
|
453
|
-
stdio: "inherit",
|
|
454
|
-
shell: true,
|
|
455
|
-
cwd: process.cwd(),
|
|
456
|
-
...options
|
|
457
|
-
});
|
|
458
|
-
child.on("close", (code) => {
|
|
459
|
-
if (code !== 0) {
|
|
460
|
-
reject(new Error(`Command "${cmd} ${args.join(" ")}" exited with code ${code}`));
|
|
461
|
-
} else {
|
|
462
|
-
resolve();
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
child.on("error", reject);
|
|
466
|
-
});
|
|
467
|
-
};
|
|
468
|
-
const runSync = (cmd) => {
|
|
469
|
-
execSync(cmd, { stdio: "inherit", cwd: process.cwd() });
|
|
469
|
+
await build(config);
|
|
470
470
|
};
|
|
471
471
|
const onPromptState = (state) => {
|
|
472
472
|
if (state?.aborted) {
|
|
@@ -530,62 +530,45 @@ For example:
|
|
|
530
530
|
await notifyUpdate();
|
|
531
531
|
});
|
|
532
532
|
program.command("dev").description("Start development mode with all watchers").action(async () => {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
`"${bin("cross-env")} scriptOnly=true ${bin("vite")} build --config ${viteConfig} --mode development --watch"`,
|
|
539
|
-
`"node ${pkg("server.js")} --mode development"`
|
|
540
|
-
]);
|
|
533
|
+
runStyles({ watch: true });
|
|
534
|
+
runStates({ watch: true });
|
|
535
|
+
process.env.scriptOnly = "true";
|
|
536
|
+
viteBuild({ outDir: "dist/static", mode: "development", watch: true });
|
|
537
|
+
runServer({ mode: "development" });
|
|
541
538
|
});
|
|
542
539
|
program.command("serve").description("Start the SSR dev server").option("--mode <mode>", "server mode", "development").action(async (opts) => {
|
|
543
|
-
|
|
540
|
+
runServer({ mode: opts.mode });
|
|
544
541
|
});
|
|
545
542
|
program.command("build").description("Build the project (static + SSR)").action(async () => {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server`);
|
|
543
|
+
await viteBuild({ outDir: "dist/static" });
|
|
544
|
+
await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx" });
|
|
549
545
|
});
|
|
550
546
|
program.command("generate").description("Full static site generation (states + styles + build + prerender)").option("--mode <mode>", "build mode", "production").action(async (opts) => {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server`);
|
|
557
|
-
} else {
|
|
558
|
-
runSync(`${bin("vite")} build --config ${viteConfig} --outDir dist/static --mode ${opts.mode}`);
|
|
559
|
-
runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server --mode ${opts.mode}`);
|
|
560
|
-
}
|
|
561
|
-
runSync(`node ${pkg("prerender.js")} --add-hash --mode ${opts.mode}`);
|
|
547
|
+
runStates();
|
|
548
|
+
runStyles();
|
|
549
|
+
await viteBuild({ outDir: "dist/static", mode: opts.mode !== "production" ? opts.mode : void 0 });
|
|
550
|
+
await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx", mode: opts.mode !== "production" ? opts.mode : void 0 });
|
|
551
|
+
await runPrerender({ addHash: true, mode: opts.mode });
|
|
562
552
|
});
|
|
563
553
|
program.command("eshn").description("Generate with --mode eshn").action(async () => {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
runSync(`node ${pkg("prerender.js")} --add-hash --mode eshn`);
|
|
554
|
+
runStates();
|
|
555
|
+
runStyles();
|
|
556
|
+
await viteBuild({ outDir: "dist/static", mode: "eshn" });
|
|
557
|
+
await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx", mode: "eshn" });
|
|
558
|
+
await runPrerender({ addHash: true, mode: "eshn" });
|
|
570
559
|
});
|
|
571
560
|
program.command("inte").description("Build and integrate with backend (styles + build + prerender + integration)").action(async () => {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
runSync(`node ${pkg("integration.js")}`);
|
|
561
|
+
runStyles();
|
|
562
|
+
await viteBuild({ outDir: "dist/static" });
|
|
563
|
+
await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx" });
|
|
564
|
+
await runPrerender();
|
|
565
|
+
runIntegration();
|
|
578
566
|
});
|
|
579
567
|
program.command("styles").description("Compile SCSS").option("--watch", "Watch for changes").action(async (opts) => {
|
|
580
|
-
|
|
581
|
-
if (opts.watch) args.push("--watch");
|
|
582
|
-
await run("node", args);
|
|
568
|
+
runStyles({ watch: opts.watch });
|
|
583
569
|
});
|
|
584
570
|
program.command("prerender").description("Pre-render HTML files").option("--add-hash", "Add content hashes to asset URLs").option("--mode <mode>", "build mode", "production").action(async (opts) => {
|
|
585
|
-
|
|
586
|
-
if (opts.addHash) args.push("--add-hash");
|
|
587
|
-
args.push("--mode", opts.mode);
|
|
588
|
-
await run("node", args);
|
|
571
|
+
await runPrerender({ addHash: opts.addHash, mode: opts.mode });
|
|
589
572
|
});
|
|
590
573
|
program.parseAsync(process.argv).catch(async (error) => {
|
|
591
574
|
console.log(red(error));
|
package/dist/integration.js
CHANGED
|
@@ -6,125 +6,135 @@ import slash from "slash";
|
|
|
6
6
|
import { glob } from "glob";
|
|
7
7
|
import { loadEnv } from "vite";
|
|
8
8
|
import chalk from "chalk";
|
|
9
|
-
const
|
|
10
|
-
const mode =
|
|
11
|
-
const projectRoot = process.cwd();
|
|
12
|
-
const xpackEnv = loadEnv(mode, projectRoot);
|
|
13
|
-
const toAbsolute = (p) => slash(path.resolve(projectRoot, p));
|
|
14
|
-
const log = console.log.bind(console);
|
|
15
|
-
const hashes = /* @__PURE__ */ new Map();
|
|
16
|
-
const staticBasePath = toAbsolute("dist/static");
|
|
17
|
-
const srcBasePath = toAbsolute("dist/static/assets");
|
|
18
|
-
const destBasePath = toAbsolute(xpackEnv.VITE_INTE_ASSET_DIR);
|
|
19
|
-
const patternPath = xpackEnv.VITE_INTE_PATTERN_DIR ? toAbsolute(xpackEnv.VITE_INTE_PATTERN_DIR) : void 0;
|
|
20
|
-
if (patternPath && fs.existsSync(patternPath)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const copyItems = [
|
|
25
|
-
{ from: "css" },
|
|
26
|
-
{ from: "fonts" },
|
|
27
|
-
{ from: "images" },
|
|
28
|
-
{ from: "js" },
|
|
29
|
-
{ from: "vendors" },
|
|
30
|
-
{ from: "hashes.json" },
|
|
31
|
-
{ from: "pages", to: patternPath }
|
|
32
|
-
];
|
|
33
|
-
const hashItems = ["css", "images", "js"];
|
|
34
|
-
copyItems.forEach((item) => {
|
|
35
|
-
const srcPath = slash(path.join(srcBasePath, item.from));
|
|
36
|
-
const destPath = slash(item.to ?? path.join(destBasePath, item.from));
|
|
37
|
-
if (!fs.existsSync(srcPath)) {
|
|
38
|
-
return;
|
|
9
|
+
const runIntegration = (options = {}) => {
|
|
10
|
+
const mode = options.mode ?? "production";
|
|
11
|
+
const projectRoot = process.cwd();
|
|
12
|
+
const xpackEnv = loadEnv(mode, projectRoot);
|
|
13
|
+
const toAbsolute = (p) => slash(path.resolve(projectRoot, p));
|
|
14
|
+
const log = console.log.bind(console);
|
|
15
|
+
const hashes = /* @__PURE__ */ new Map();
|
|
16
|
+
const staticBasePath = toAbsolute("dist/static");
|
|
17
|
+
const srcBasePath = toAbsolute("dist/static/assets");
|
|
18
|
+
const destBasePath = toAbsolute(xpackEnv.VITE_INTE_ASSET_DIR);
|
|
19
|
+
const patternPath = xpackEnv.VITE_INTE_PATTERN_DIR ? toAbsolute(xpackEnv.VITE_INTE_PATTERN_DIR) : void 0;
|
|
20
|
+
if (patternPath && fs.existsSync(patternPath)) {
|
|
21
|
+
fs.rmSync(patternPath, { recursive: true, force: true });
|
|
22
|
+
fs.mkdirSync(patternPath, { recursive: true });
|
|
39
23
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
const copyItems = [
|
|
25
|
+
{ from: "css" },
|
|
26
|
+
{ from: "fonts" },
|
|
27
|
+
{ from: "images" },
|
|
28
|
+
{ from: "js" },
|
|
29
|
+
{ from: "vendors" },
|
|
30
|
+
{ from: "hashes.json" },
|
|
31
|
+
{ from: "pages", to: patternPath }
|
|
32
|
+
];
|
|
33
|
+
const hashItems = ["css", "images", "js"];
|
|
34
|
+
copyItems.forEach((item) => {
|
|
35
|
+
const srcPath = slash(path.join(srcBasePath, item.from));
|
|
36
|
+
const destPath = slash(item.to ?? path.join(destBasePath, item.from));
|
|
37
|
+
if (!fs.existsSync(srcPath)) {
|
|
38
|
+
return;
|
|
51
39
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const relativePath = slash(file.substring(staticBasePath.length));
|
|
60
|
-
if (!/\.0x[a-z0-9_-]{8,12}\.\w+$/gi.test(file)) {
|
|
61
|
-
const content = fs.readFileSync(file);
|
|
62
|
-
const sha1Hash = crypto.createHash("sha1");
|
|
63
|
-
sha1Hash.update(content);
|
|
64
|
-
const hash = sha1Hash.digest("base64url").substring(0, 10);
|
|
65
|
-
hashes.set(relativePath, hash);
|
|
40
|
+
log(`Copy file ${srcPath} to ${destPath}`);
|
|
41
|
+
if (fs.statSync(srcPath).isDirectory()) {
|
|
42
|
+
if (fs.existsSync(destPath)) {
|
|
43
|
+
fs.rmSync(destPath, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
46
|
+
fs.cpSync(srcPath, destPath, { recursive: true, force: true });
|
|
66
47
|
} else {
|
|
67
|
-
|
|
48
|
+
const destDirPath = path.dirname(destPath);
|
|
49
|
+
if (!fs.existsSync(destDirPath)) {
|
|
50
|
+
fs.mkdirSync(destDirPath);
|
|
51
|
+
}
|
|
52
|
+
fs.copyFileSync(srcPath, destPath);
|
|
68
53
|
}
|
|
69
54
|
});
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
switch (segments.length) {
|
|
86
|
-
case 4:
|
|
87
|
-
basename = path.basename(slash(p).replaceAll(/(atoms|molecules|organisms|templates|pages)\/([\w._-]+)$/gi, "$1-$2"));
|
|
88
|
-
fs.copyFileSync(p, resolve(patternPath, basename));
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
segments.splice(0, 2);
|
|
92
|
-
fs$1.cpSync(p, resolve(patternPath, segments.join("-")), { recursive: true });
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
55
|
+
hashItems.forEach((item) => {
|
|
56
|
+
const srcPath = slash(path.join(srcBasePath, item));
|
|
57
|
+
const files = glob.sync(srcPath + "/**/*.{css,js,svg}");
|
|
58
|
+
files.forEach((file) => {
|
|
59
|
+
const relativePath = slash(file.substring(staticBasePath.length));
|
|
60
|
+
if (!/\.0x[a-z0-9_-]{8,12}\.\w+$/gi.test(file)) {
|
|
61
|
+
const content = fs.readFileSync(file);
|
|
62
|
+
const sha1Hash = crypto.createHash("sha1");
|
|
63
|
+
sha1Hash.update(content);
|
|
64
|
+
const hash = sha1Hash.digest("base64url").substring(0, 10);
|
|
65
|
+
hashes.set(relativePath, hash);
|
|
66
|
+
} else {
|
|
67
|
+
hashes.set(relativePath, "");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
95
70
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
71
|
+
const sortedHashes = Array.from(hashes).sort((a, b) => a[0].localeCompare(b[0])).reduce(
|
|
72
|
+
(obj, [key, value]) => {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
return obj;
|
|
75
|
+
},
|
|
76
|
+
{}
|
|
77
|
+
);
|
|
78
|
+
fs.writeFileSync(path.join(destBasePath, "hashes.json"), JSON.stringify(sortedHashes, null, " "));
|
|
79
|
+
if (patternPath) {
|
|
80
|
+
fs.mkdirSync(patternPath, { recursive: true });
|
|
81
|
+
glob.sync("./dist/static/{atoms,molecules,organisms,templates,pages}/**/*.*").forEach((p) => {
|
|
82
|
+
let basename = "";
|
|
83
|
+
const segments = slash(p).split("/");
|
|
84
|
+
if (segments.length < 4) return;
|
|
85
|
+
switch (segments.length) {
|
|
86
|
+
case 4:
|
|
87
|
+
basename = path.basename(slash(p).replaceAll(/(atoms|molecules|organisms|templates|pages)\/([\w._-]+)$/gi, "$1-$2"));
|
|
88
|
+
fs.copyFileSync(p, resolve(patternPath, basename));
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
segments.splice(0, 2);
|
|
92
|
+
fs$1.cpSync(p, resolve(patternPath, segments.join("-")), { recursive: true });
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
glob.sync(slash(path.resolve(patternPath + "/**/*.{htm,html}"))).forEach((p) => {
|
|
97
|
+
const text = fs.readFileSync(p, "utf-8");
|
|
98
|
+
const newText = text.replaceAll(/react-loader\.0x[a-z0-9_-]{8,12}\.js/gi, "react-loader.0x00000000.js").replaceAll(/\.svg\?v=[a-z0-9_-]+/gi, ".svg");
|
|
99
|
+
if (text !== newText) {
|
|
100
|
+
fs.writeFileSync(p, newText);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const checkExistFileList = [
|
|
105
|
+
{ fileName: "hashes.json" },
|
|
106
|
+
{ fileName: /react-loader\.0x[a-z0-9_-]{8,12}\.js/gi, folder: "js" },
|
|
107
|
+
{ fileName: "main.js", folder: "js" }
|
|
108
|
+
];
|
|
109
|
+
let isAllExist = true;
|
|
110
|
+
checkExistFileList.forEach((file) => {
|
|
111
|
+
if (typeof file.fileName === "string") {
|
|
112
|
+
const destPath = slash(path.join(destBasePath, file.folder ?? "", file.fileName.toString()));
|
|
113
|
+
if (!fs.existsSync(destPath)) {
|
|
114
|
+
log(chalk.yellow(`Cannot find: ${destPath}`));
|
|
115
|
+
isAllExist = false;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
const fileName = file.fileName;
|
|
119
|
+
const folderFiles = slash(path.join(destBasePath, file.folder ?? ""));
|
|
120
|
+
const files = fs.readdirSync(folderFiles);
|
|
121
|
+
const found = files.find((f) => fileName.test(f));
|
|
122
|
+
if (!found) {
|
|
123
|
+
log(chalk.yellow(`Cannot find: ${slash(path.join(folderFiles, fileName.toString()))}`));
|
|
124
|
+
isAllExist = false;
|
|
125
|
+
}
|
|
101
126
|
}
|
|
102
127
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{ fileName: "hashes.json" },
|
|
106
|
-
{ fileName: /react-loader\.0x[a-z0-9_-]{8,12}\.js/gi, folder: "js" },
|
|
107
|
-
{ fileName: "main.js", folder: "js" }
|
|
108
|
-
];
|
|
109
|
-
let isAllExist = true;
|
|
110
|
-
checkExistFileList.forEach((file) => {
|
|
111
|
-
if (typeof file.fileName === "string") {
|
|
112
|
-
const destPath = slash(path.join(destBasePath, file.folder ?? "", file.fileName.toString()));
|
|
113
|
-
if (!fs.existsSync(destPath)) {
|
|
114
|
-
log(chalk.yellow(`Cannot find: ${destPath}`));
|
|
115
|
-
isAllExist = false;
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
const fileName = file.fileName;
|
|
119
|
-
const folderFiles = slash(path.join(destBasePath, file.folder ?? ""));
|
|
120
|
-
const files = fs.readdirSync(folderFiles);
|
|
121
|
-
const found = files.find((f) => fileName.test(f));
|
|
122
|
-
if (!found) {
|
|
123
|
-
log(chalk.yellow(`Cannot find: ${slash(path.join(folderFiles, fileName.toString()))}`));
|
|
124
|
-
isAllExist = false;
|
|
125
|
-
}
|
|
128
|
+
if (!isAllExist) {
|
|
129
|
+
process.exit(1);
|
|
126
130
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
};
|
|
132
|
+
const isDirectRun = process.argv[1]?.endsWith("integration.js") || process.argv[1]?.endsWith("integration.ts");
|
|
133
|
+
if (isDirectRun) {
|
|
134
|
+
const argvModeIndex = process.argv.indexOf("--mode");
|
|
135
|
+
const mode = argvModeIndex >= 0 && argvModeIndex < process.argv.length - 1 && !process.argv[argvModeIndex + 1].startsWith("-") ? process.argv[argvModeIndex + 1] : "production";
|
|
136
|
+
runIntegration({ mode });
|
|
130
137
|
}
|
|
138
|
+
export {
|
|
139
|
+
runIntegration
|
|
140
|
+
};
|