@@ -25,6 +25,8 @@ const currentPath = path.resolve(__dirname, '../')
2525
2626
2727const pluginsList = [ ]
28+ // 记录需要更新的插件
29+ const pluginsNeedUpdate = [ ]
2830
2931fs . readdirSync ( pluginsPath ) . forEach ( file => {
3032 const fullPath = path . join ( pluginsPath , file )
@@ -41,8 +43,30 @@ console.log(`[INFO] Source directory: ${currentPath}`)
4143console . log ( `[INFO] Total files to sync: ${ GENERAL_FILE_LIST . length } ` )
4244console . log ( `[INFO] Target plugins: ${ pluginsList . length } \n` )
4345
46+ // 检查文件是否相同
47+ function areFilesIdentical ( sourceFile , targetFile ) {
48+ if ( ! fs . existsSync ( targetFile ) ) {
49+ return false
50+ }
51+
52+ try {
53+ const sourceContent = fs . readFileSync ( sourceFile )
54+ const targetContent = fs . readFileSync ( targetFile )
55+ return Buffer . compare ( sourceContent , targetContent ) === 0
56+ } catch ( error ) {
57+ console . error ( `[ERROR] Error comparing files ${ sourceFile } and ${ targetFile } : ${ error . message } ` )
58+ return false
59+ }
60+ }
61+
4462function copyFile ( sourceFile , targetFile ) {
4563 try {
64+ // 先检查文件是否相同
65+ if ( areFilesIdentical ( sourceFile , targetFile ) ) {
66+ console . log ( `[INFO] Skipped: ${ path . basename ( sourceFile ) } (identical)` )
67+ return false // 返回false表示未复制(文件相同)
68+ }
69+
4670 const targetDir = path . dirname ( targetFile )
4771 if ( ! fs . existsSync ( targetDir ) ) {
4872 fs . mkdirSync ( targetDir , { recursive : true } )
@@ -55,33 +79,48 @@ function copyFile(sourceFile, targetFile) {
5579
5680 fs . copyFileSync ( sourceFile , targetFile )
5781 console . log ( `[SUCCESS] Copied: ${ path . basename ( sourceFile ) } (${ fileSizeKB } KB) to ${ targetFile } ` )
82+ return true // 返回true表示已复制(文件不同)
5883 } catch ( error ) {
5984 console . error ( `[ERROR] Failed to copy ${ sourceFile } to ${ targetFile } : ${ error . message } ` )
85+ return true // 出错时默认需要更新
6086 }
6187}
6288
63- let fileCounter = 0 ;
64- GENERAL_FILE_LIST . forEach ( file => {
65- fileCounter ++ ;
66- console . log ( `\n[INFO] Processing file ${ fileCounter } /${ GENERAL_FILE_LIST . length } : ${ file } ` )
67- const sourceFile = path . join ( currentPath , file )
68-
69- if ( ! fs . existsSync ( sourceFile ) ) {
70- console . warn ( `[WARNING] Source file does not exist: ${ sourceFile } ` )
71- return
72- }
89+ let pluginCounter = 0 ;
90+ pluginsList . forEach ( pluginPath => {
91+ pluginCounter ++ ;
92+ console . log ( `\n[INFO] Processing plugin ${ pluginCounter } /${ pluginsList . length } : ${ path . basename ( pluginPath ) } ` )
93+
94+ let fileCounter = 0 ;
95+ let needUpdate = false ;
96+
97+ GENERAL_FILE_LIST . forEach ( file => {
98+ fileCounter ++ ;
99+ const sourceFile = path . join ( currentPath , file )
100+
101+ if ( ! fs . existsSync ( sourceFile ) ) {
102+ console . warn ( `[WARNING] Source file does not exist: ${ sourceFile } ` )
103+ return
104+ }
73105
74- let pluginCounter = 0 ;
75- pluginsList . forEach ( pluginPath => {
76- pluginCounter ++ ;
77- console . log ( `[INFO] Syncing to plugin ${ pluginCounter } /${ pluginsList . length } : ${ path . basename ( pluginPath ) } ` )
106+ console . log ( `[INFO] Syncing file ${ fileCounter } /${ GENERAL_FILE_LIST . length } : ${ file } ` )
78107 const targetFile = path . join ( pluginPath , file )
79- copyFile ( sourceFile , targetFile )
108+ const fileCopied = copyFile ( sourceFile , targetFile )
109+ if ( fileCopied ) {
110+ needUpdate = true ;
111+ }
80112 } )
113+
114+ if ( needUpdate ) {
115+ pluginsNeedUpdate . push ( pluginPath ) ;
116+ console . log ( `[INFO] Plugin ${ path . basename ( pluginPath ) } marked for update` ) ;
117+ } else {
118+ console . log ( `[INFO] Plugin ${ path . basename ( pluginPath ) } has identical files, will be skipped for update` ) ;
119+ }
81120} )
82121
83122console . log ( '\n[INFO] File synchronization completed successfully!' )
84-
123+ console . log ( `[INFO] Plugins requiring updates: ${ pluginsNeedUpdate . length } / ${ pluginsList . length } ` )
85124
86125
87126function getCurrentVersion ( projectPath ) {
@@ -141,29 +180,32 @@ function executeGitPush(projectPath) {
141180 }
142181}
143182
144- pluginsList . forEach ( pluginPath => {
145- const currentVersion = getCurrentVersion ( pluginPath )
146- const newVersion = incrementVersion ( currentVersion )
147-
148- console . log ( '\n\n[INFO] Committing:' , path . basename ( pluginPath ) )
149- console . log ( `[INFO] Incremented version: ${ currentVersion } -> ${ newVersion } ` )
150-
151- updateVersion ( pluginPath , newVersion )
152-
153- console . log ( '' )
154- executeGitCommit ( pluginPath , COMMIT_MESSAGE )
155- createGitTag ( pluginPath , newVersion )
156- } )
157-
158- console . log ( '\n\n[SUCCESS] All plugins have been committed and tagged.' )
159-
160- pluginsList . forEach ( pluginPath => {
161-
162- console . log ( '\n\n[INFO] Pushing:' , path . basename ( pluginPath ) )
163-
164- executeGitPush ( pluginPath )
165- } )
166-
167- console . log ( '\n\n[SUCCESS] All plugins have been pushed to the remote repository.' )
183+ // 取消注释版本更新、提交和推送代码
184+ if ( pluginsNeedUpdate . length > 0 ) {
185+ pluginsNeedUpdate . forEach ( pluginPath => {
186+ const currentVersion = getCurrentVersion ( pluginPath )
187+ const newVersion = incrementVersion ( currentVersion )
188+
189+ console . log ( '\n\n[INFO] Committing:' , path . basename ( pluginPath ) )
190+ console . log ( `[INFO] Incremented version: ${ currentVersion } -> ${ newVersion } ` )
191+
192+ updateVersion ( pluginPath , newVersion )
193+
194+ console . log ( '' )
195+ executeGitCommit ( pluginPath , COMMIT_MESSAGE )
196+ createGitTag ( pluginPath , newVersion )
197+ } )
198+
199+ console . log ( '\n\n[SUCCESS] All updated plugins have been committed and tagged.' )
200+
201+ pluginsNeedUpdate . forEach ( pluginPath => {
202+ console . log ( '\n\n[INFO] Pushing:' , path . basename ( pluginPath ) )
203+ executeGitPush ( pluginPath )
204+ } )
205+
206+ console . log ( '\n\n[SUCCESS] All updated plugins have been pushed to the remote repository.' )
207+ } else {
208+ console . log ( '\n\n[INFO] No plugins need updates, skipping version increment and commit process.' )
209+ }
168210
169211
0 commit comments