File tree Expand file tree Collapse file tree 1 file changed +5
-27
lines changed Expand file tree Collapse file tree 1 file changed +5
-27
lines changed Original file line number Diff line number Diff line change @@ -183,33 +183,11 @@ const createServerAndOpenPage = async () => {
183183
184184// 判断本地配置是否与远程配置一致
185185const remoteUserConfigs = JSON . parse ( fs . readFileSync ( configPath , "utf8" ) ) ;
186- // 逐个元素对比
187- const isEqual = (
188- localUserConfigs : UserConfig [ ] ,
189- remoteUserConfigs : UserConfig [ ]
190- ) => {
191- let result = true ;
192- if ( localUserConfigs . length !== remoteUserConfigs . length ) {
193- result = false ;
194- return result ;
195- }
196- for ( let i = 0 ; i < localUserConfigs . length ; i ++ ) {
197- const localUserConfig = localUserConfigs [ i ] ;
198- const remoteUserConfig = remoteUserConfigs [ i ] ;
199- if ( localUserConfig . alias !== remoteUserConfig . alias ) {
200- result = false ;
201- }
202- if ( localUserConfig . name !== remoteUserConfig . name ) {
203- result = false ;
204- }
205- if ( localUserConfig . email !== remoteUserConfig . email ) {
206- result = false ;
207- }
208- if ( localUserConfig . origin !== remoteUserConfig . origin ) {
209- result = false ;
210- }
211- }
212- return result ;
186+ // 对比远程和本地配置是否一致
187+ const isEqual = ( local : UserConfig [ ] , remote : UserConfig [ ] ) => {
188+ const hash = ( arr : UserConfig [ ] ) =>
189+ arr . map ( c => `${ c . alias } :${ c . name } :${ c . email } :${ c . origin } ` ) . join ( '|' ) ;
190+ return hash ( local ) === hash ( remote ) ;
213191} ;
214192if ( ! remoteUserConfigs ?. length ) {
215193 // 远程配置不存在,直接写入本地配置
You can’t perform that action at this time.
0 commit comments