appsnbcbweicheng 1.2.15 → 1.2.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appsnbcbweicheng",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,48 @@
1
+ const fs = require("fs")
2
+ const path = require("path")
3
+
4
+ // 匹配 this.$post(函数名, 参数)
5
+ const regex = /this\.\$post\s*\(\s*([a-zA-Z_$][\w$]*)\s*,/g
6
+
7
+ // 需要处理的文件类型
8
+ const exts = [".js", ".ts", ".vue"]
9
+
10
+ /**
11
+ * 处理单个文件
12
+ * @param {string} filePath - 文件路径
13
+ */
14
+ function processFile(filePath) {
15
+ if (!exts.includes(path.extname(filePath))) return
16
+
17
+ let code = fs.readFileSync(filePath, "utf8")
18
+ if (regex.test(code)) {
19
+ const newCode = code.replace(regex, "$1(")
20
+ fs.writeFileSync(filePath, newCode, "utf8")
21
+ console.log("✅ 已处理文件:", filePath)
22
+ }
23
+ }
24
+
25
+ /**
26
+ * 递归处理目录
27
+ * @param {string} dirPath - 目录路径
28
+ */
29
+ function processDir(dirPath) {
30
+ const files = fs.readdirSync(dirPath)
31
+ for (const file of files) {
32
+ const fullPath = path.join(dirPath, file)
33
+ const stat = fs.statSync(fullPath)
34
+
35
+ if (stat.isDirectory()) {
36
+ processDir(fullPath) // 递归子目录
37
+ } else {
38
+ processFile(fullPath)
39
+ }
40
+ }
41
+ }
42
+
43
+ // ========== 使用示例 ==========
44
+ // 处理单个文件
45
+ processFile(path.resolve(__dirname, "test.js"))
46
+
47
+ // 处理整个目录
48
+ // processDir(path.resolve(__dirname, "src"))
package/readme.md CHANGED
@@ -1,3 +1,4 @@
1
+ 1.2.16 replac$post
1
2
  1.2.15 replac '/addd/cddd'
2
3
  1.2.14 vuetools6.6
3
4
  1.2.13 vuetools7.7.7
@@ -1,40 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- /**
5
- * 把 "/xxx/yyy" 形式的路径转换成 PascalCase
6
- */
7
- function toPascalCase(str) {
8
- return str.split('/').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join('');
9
- }
10
-
11
- /**
12
- * 替换单个文件
13
- */
14
- function replaceInFile(filePath) {
15
- let content = fs.readFileSync(filePath, 'utf-8');
16
- const regex = /['"]\/([a-z][a-zA-Z0-9]*)\/([a-z][a-zA-Z0-9]*)['"]/g;
17
- const newContent = content.replace(regex, (_, g1, g2) => `"${toPascalCase(`${g1}/${g2}`)}"`);
18
- fs.writeFileSync(filePath, newContent, 'utf-8');
19
- console.log(`处理完成: ${filePath}`);
20
- }
21
-
22
- /**
23
- * 替换指定目录下所有文件(不递归子目录,可根据需要改)
24
- */
25
- function replaceInDirectory(dirPath) {
26
- const files = fs.readdirSync(dirPath);
27
- files.forEach(file => {
28
- const fullPath = path.join(dirPath, file);
29
- if (fs.statSync(fullPath).isFile() && /\.(js|ts|json|vue)$/.test(fullPath)) {
30
- replaceInFile(fullPath);
31
- }
32
- });
33
- }
34
-
35
- // ----------------- 配置区 -----------------
36
- // 处理单个文件:
37
- replaceInFile(path.resolve(__dirname, 'test.js'));
38
-
39
- // 处理目录下所有文件:
40
- // replaceInDirectory(path.resolve(__dirname, './src/components'));