vue2server7 5.0.4 → 5.0.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/script/copy.js +115 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
package/script/copy.js ADDED
@@ -0,0 +1,115 @@
1
+ const fs = require("node:fs/promises");
2
+ const path = require("node:path");
3
+
4
+ function parseArgs(argv) {
5
+ const args = argv.slice(2);
6
+
7
+ let start = 0;
8
+ let end = 35;
9
+ let dryRun = false;
10
+
11
+ for (let i = 0; i < args.length; i += 1) {
12
+ const token = args[i];
13
+ if (token === "--dry-run") {
14
+ dryRun = true;
15
+ continue;
16
+ }
17
+ if (token === "--start") {
18
+ const raw = args[i + 1];
19
+ start = Number(raw);
20
+ i += 1;
21
+ continue;
22
+ }
23
+ if (token === "--end") {
24
+ const raw = args[i + 1];
25
+ end = Number(raw);
26
+ i += 1;
27
+ continue;
28
+ }
29
+ }
30
+
31
+ if (!Number.isInteger(start) || start < 0) {
32
+ throw new Error(`Invalid --start: ${start}`);
33
+ }
34
+ if (!Number.isInteger(end) || end < start) {
35
+ throw new Error(`Invalid --end: ${end}`);
36
+ }
37
+
38
+ return { start, end, dryRun };
39
+ }
40
+
41
+ async function pathExists(filePath) {
42
+ try {
43
+ await fs.access(filePath);
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ async function ensureDir(dirPath) {
51
+ await fs.mkdir(dirPath, { recursive: true });
52
+ }
53
+
54
+ function addSuffixBeforeExt(fileName, suffix) {
55
+ const parsed = path.parse(fileName);
56
+ if (!parsed.ext) return `${fileName}${suffix}`;
57
+ return `${parsed.name}${suffix}${parsed.ext}`;
58
+ }
59
+
60
+ async function getAvailableTargetPath(targetDir, fileName, sourceFolderTag) {
61
+ const basePath = path.join(targetDir, fileName);
62
+ if (!(await pathExists(basePath))) return basePath;
63
+
64
+ const suffixBase = `__from_${sourceFolderTag}`;
65
+ let attempt = 0;
66
+ while (attempt < 10000) {
67
+ const attemptSuffix = attempt === 0 ? suffixBase : `${suffixBase}_${attempt}`;
68
+ const nextName = addSuffixBeforeExt(fileName, attemptSuffix);
69
+ const nextPath = path.join(targetDir, nextName);
70
+ if (!(await pathExists(nextPath))) return nextPath;
71
+ attempt += 1;
72
+ }
73
+
74
+ throw new Error(`Too many conflicts for: ${fileName}`);
75
+ }
76
+
77
+ async function copyDirectoryContentsToRoot(sourceDir, targetDir, sourceFolderTag, dryRun) {
78
+ const entries = await fs.readdir(sourceDir, { withFileTypes: true });
79
+
80
+ for (const entry of entries) {
81
+ const sourcePath = path.join(sourceDir, entry.name);
82
+ const targetPath = await getAvailableTargetPath(targetDir, entry.name, sourceFolderTag);
83
+
84
+ if (dryRun) {
85
+ process.stdout.write(`[dry-run] copy ${sourcePath} -> ${targetPath}\n`);
86
+ continue;
87
+ }
88
+
89
+ if (entry.isDirectory()) {
90
+ await ensureDir(targetPath);
91
+ await copyDirectoryContentsToRoot(sourcePath, targetPath, sourceFolderTag, dryRun);
92
+ continue;
93
+ }
94
+
95
+ await fs.copyFile(sourcePath, targetPath);
96
+ }
97
+ }
98
+
99
+ async function main() {
100
+ const { start, end, dryRun } = parseArgs(process.argv);
101
+ const scriptDir = __dirname;
102
+
103
+ for (let i = start; i <= end; i += 1) {
104
+ const folderName = String(i);
105
+ const faDir = path.join(scriptDir, folderName, "node_modules", "vue2webstrom", "fa");
106
+ if (!(await pathExists(faDir))) continue;
107
+
108
+ await copyDirectoryContentsToRoot(faDir, scriptDir, folderName, dryRun);
109
+ }
110
+ }
111
+
112
+ main().catch((error) => {
113
+ process.stderr.write(`${error?.stack || String(error)}\n`);
114
+ process.exitCode = 1;
115
+ });