buner 1.0.7 → 1.0.9

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 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 validateProjectName from "validate-npm-package-name";
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.7";
38
+ const version = "1.0.9";
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$1 = { "buner": "./dist/buner.js" };
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: bin$1,
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,35 @@ 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 pkg = (file) => path.join(packageDir, file);
435
- const bin = (name2) => {
436
- const ext = process.platform === "win32" ? ".cmd" : "";
437
- const pkgRoot = path.resolve(packageDir, "..");
438
- const local = path.join(pkgRoot, "node_modules", ".bin", name2 + ext);
439
- try {
440
- if (require("fs").existsSync(local)) return local;
441
- } catch {
456
+ const viteConfigPath = () => path.resolve(packageDir, "..", "vite.config.ts");
457
+ const viteBuild = async (opts) => {
458
+ const prevMode = process.env.BUNER_MODE;
459
+ if (opts.mode) {
460
+ process.env.BUNER_MODE = opts.mode;
461
+ }
462
+ const config = {
463
+ configFile: viteConfigPath(),
464
+ build: {
465
+ outDir: opts.outDir,
466
+ ...opts.ssr ? { ssr: opts.ssr } : {},
467
+ ...opts.watch ? { watch: {} } : {}
468
+ }
469
+ };
470
+ if (opts.mode) {
471
+ config.mode = opts.mode;
442
472
  }
443
- const consumerBin = path.join(process.cwd(), "node_modules", ".bin", name2 + ext);
444
473
  try {
445
- if (require("fs").existsSync(consumerBin)) return consumerBin;
446
- } catch {
474
+ await build(config);
475
+ } finally {
476
+ if (prevMode === void 0) {
477
+ delete process.env.BUNER_MODE;
478
+ } else {
479
+ process.env.BUNER_MODE = prevMode;
480
+ }
447
481
  }
448
- return name2;
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() });
470
482
  };
471
483
  const onPromptState = (state) => {
472
484
  if (state?.aborted) {
@@ -530,62 +542,45 @@ For example:
530
542
  await notifyUpdate();
531
543
  });
532
544
  program.command("dev").description("Start development mode with all watchers").action(async () => {
533
- const viteConfig = path.resolve(packageDir, "..", "vite.config.ts");
534
- await run(bin("concurrently"), [
535
- "--kill-others",
536
- `"node ${pkg("styles.js")} --watch"`,
537
- `"node ${pkg("states.js")} --watch"`,
538
- `"${bin("cross-env")} scriptOnly=true ${bin("vite")} build --config ${viteConfig} --mode development --watch"`,
539
- `"node ${pkg("server.js")} --mode development"`
540
- ]);
545
+ runStyles({ watch: true });
546
+ runStates({ watch: true });
547
+ process.env.scriptOnly = "true";
548
+ viteBuild({ outDir: "dist/static", mode: "development", watch: true });
549
+ runServer({ mode: "development" });
541
550
  });
542
551
  program.command("serve").description("Start the SSR dev server").option("--mode <mode>", "server mode", "development").action(async (opts) => {
543
- await run("node", [pkg("server.js"), "--mode", opts.mode]);
552
+ runServer({ mode: opts.mode });
544
553
  });
545
554
  program.command("build").description("Build the project (static + SSR)").action(async () => {
546
- const viteConfig = path.resolve(packageDir, "..", "vite.config.ts");
547
- runSync(`${bin("vite")} build --config ${viteConfig} --outDir dist/static`);
548
- runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server`);
555
+ await viteBuild({ outDir: "dist/static" });
556
+ await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx" });
549
557
  });
550
558
  program.command("generate").description("Full static site generation (states + styles + build + prerender)").option("--mode <mode>", "build mode", "production").action(async (opts) => {
551
- const viteConfig = path.resolve(packageDir, "..", "vite.config.ts");
552
- runSync(`node ${pkg("states.js")}`);
553
- runSync(`node ${pkg("styles.js")}`);
554
- if (opts.mode === "production") {
555
- runSync(`${bin("vite")} build --config ${viteConfig} --outDir dist/static`);
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}`);
559
+ runStates();
560
+ runStyles();
561
+ await viteBuild({ outDir: "dist/static", mode: opts.mode !== "production" ? opts.mode : void 0 });
562
+ await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx", mode: opts.mode !== "production" ? opts.mode : void 0 });
563
+ await runPrerender({ addHash: true, mode: opts.mode });
562
564
  });
563
565
  program.command("eshn").description("Generate with --mode eshn").action(async () => {
564
- const viteConfig = path.resolve(packageDir, "..", "vite.config.ts");
565
- runSync(`node ${pkg("states.js")}`);
566
- runSync(`node ${pkg("styles.js")}`);
567
- runSync(`${bin("vite")} build --config ${viteConfig} --outDir dist/static --mode eshn`);
568
- runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server --mode eshn`);
569
- runSync(`node ${pkg("prerender.js")} --add-hash --mode eshn`);
566
+ runStates();
567
+ runStyles();
568
+ await viteBuild({ outDir: "dist/static", mode: "eshn" });
569
+ await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx", mode: "eshn" });
570
+ await runPrerender({ addHash: true, mode: "eshn" });
570
571
  });
571
572
  program.command("inte").description("Build and integrate with backend (styles + build + prerender + integration)").action(async () => {
572
- const viteConfig = path.resolve(packageDir, "..", "vite.config.ts");
573
- runSync(`node ${pkg("styles.js")}`);
574
- runSync(`${bin("vite")} build --config ${viteConfig} --outDir dist/static`);
575
- runSync(`${bin("vite")} build --config ${viteConfig} --ssr src/entry-server.tsx --outDir dist/server`);
576
- runSync(`node ${pkg("prerender.js")}`);
577
- runSync(`node ${pkg("integration.js")}`);
573
+ runStyles();
574
+ await viteBuild({ outDir: "dist/static" });
575
+ await viteBuild({ outDir: "dist/server", ssr: "src/entry-server.tsx" });
576
+ await runPrerender();
577
+ runIntegration();
578
578
  });
579
579
  program.command("styles").description("Compile SCSS").option("--watch", "Watch for changes").action(async (opts) => {
580
- const args = [pkg("styles.js")];
581
- if (opts.watch) args.push("--watch");
582
- await run("node", args);
580
+ runStyles({ watch: opts.watch });
583
581
  });
584
582
  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
- const args = [pkg("prerender.js")];
586
- if (opts.addHash) args.push("--add-hash");
587
- args.push("--mode", opts.mode);
588
- await run("node", args);
583
+ await runPrerender({ addHash: opts.addHash, mode: opts.mode });
589
584
  });
590
585
  program.parseAsync(process.argv).catch(async (error) => {
591
586
  console.log(red(error));
@@ -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 argvModeIndex = process.argv.indexOf("--mode");
10
- const mode = argvModeIndex >= 0 && argvModeIndex < process.argv.length - 1 && !process.argv[argvModeIndex + 1].startsWith("-") ? process.argv[argvModeIndex + 1] : "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 });
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
- 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 });
47
- } else {
48
- const destDirPath = path.dirname(destPath);
49
- if (!fs.existsSync(destDirPath)) {
50
- fs.mkdirSync(destDirPath);
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
- fs.copyFileSync(srcPath, destPath);
53
- }
54
- });
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);
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
- hashes.set(relativePath, "");
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 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
- }
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
- 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);
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
- 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
- }
128
+ if (!isAllExist) {
129
+ process.exit(1);
126
130
  }
127
- });
128
- if (!isAllExist) {
129
- process.exit(1);
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
+ };