forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.js
41 lines (35 loc) · 1.27 KB
/
1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('node:fs');
const path = require('node:path');
const glob = require('glob').sync;
// 定义要添加的字符串和src目录的路径
const lineToAdd = "'use client';\n";
const srcPath = path.join(__dirname, 'src');
// 使用glob查找所有的.tsx文件
const files= glob(`${srcPath}/**/*.tsx`);
// glob(`${srcPath}/**/*.tsx`, (err, files) => {
console.log(13_123,files)
files.forEach(file => {
// 读取每个文件的内容
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file: ${file}`, err);
return;
}
// 检查文件是否已经包含'use client'
if (data.startsWith(lineToAdd)) {
console.log(`'use client' already added in ${file}`);
return;
}
// 将'use client'添加到文件内容的开始
const updatedData = lineToAdd + data;
// 写回文件
fs.writeFile(file, updatedData, 'utf8', err => {
if (err) {
console.error(`Error writing file: ${file}`, err);
} else {
console.log(`Updated file: ${file}`);
}
});
});
});
// });