Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JJ39
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
JJ39
Commits
df15648a
Commit
df15648a
authored
Nov 03, 2022
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加替换UUID的工具
parent
07f51503
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
366 additions
and
0 deletions
+366
-0
.DS_Store
.DS_Store
+0
-0
README.md
README.md
+10
-0
main.js
packages/replace-uuid/main.js
+41
-0
package-lock.json
packages/replace-uuid/package-lock.json
+30
-0
package.json
packages/replace-uuid/package.json
+15
-0
file.js
packages/replace-uuid/util/file.js
+164
-0
uuidUtils.js
packages/replace-uuid/util/uuidUtils.js
+106
-0
No files found.
.DS_Store
View file @
df15648a
No preview for this file type
README.md
View file @
df15648a
...
...
@@ -57,10 +57,20 @@ npm start
*
下载模板调试专用app
安卓下载:
http://download-iplayabc.oss-cn-beijing.aliyuncs.com/iDebugABC.apk

iOS下载:
由于调试APP没有上架App Store 所以需要先获取手机的UDID 发送给我们的技术支持,加入后才可以扫码下载安装
获取UDID:https://www.pgyer.com/tools/udid
下载iOS: https://www.pgyer.com/gS0X
*
启动本地服务
```
...
...
packages/replace-uuid/main.js
0 → 100644
View file @
df15648a
var
fs
=
require
(
'
fs-extra
'
);
var
file
=
require
(
'
./util/file
'
);
module
.
exports
=
{
load
()
{
},
unload
()
{
},
replaceDirUuid
:
function
(
path
,
dbpath
)
{
Editor
.
log
(
'
开始处理:
'
+
path
);
file
.
findDirUuid
(
path
);
file
.
replaceDirUuid
(
path
);
Editor
.
log
(
'
开始刷新:
'
+
dbpath
);
Editor
.
assetdb
.
refresh
(
dbpath
,
function
(
err
,
results
)
{
Editor
.
log
(
'
资源刷新完成, 请重新打开该项目工程!
'
);
});
},
messages
:
{
'
replace
'
()
{
var
uuids
=
Editor
.
Selection
.
curSelection
(
'
asset
'
);
uuids
.
forEach
((
uuid
)
=>
{
var
dir_path
=
Editor
.
assetdb
.
_uuid2path
[
uuid
];
if
(
fs
.
existsSync
(
dir_path
))
{
this
.
replaceDirUuid
(
dir_path
,
Editor
.
assetdb
.
uuidToUrl
(
uuid
));
}
});
},
'
replace-path
'
:
function
(
event
,
dir_path
,
refresh_path
)
{
if
(
fs
.
existsSync
(
dir_path
))
{
this
.
replaceDirUuid
(
dir_path
,
refresh_path
);
// Editor.assetdb.fspathToUrl(refresh_path)
if
(
event
.
reply
)
{
event
.
reply
(
null
,
null
);
}
}
},
},
}
\ No newline at end of file
packages/replace-uuid/package-lock.json
0 → 100644
View file @
df15648a
{
"name"
:
"replace-uuid"
,
"version"
:
"0.0.1"
,
"lockfileVersion"
:
2
,
"requires"
:
true
,
"packages"
:
{
""
:
{
"version"
:
"0.0.1"
,
"dependencies"
:
{
"node-uuid"
:
"1.4.8"
}
},
"node_modules/node-uuid"
:
{
"version"
:
"1.4.8"
,
"resolved"
:
"https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz"
,
"integrity"
:
"sha1-sEDrCSOWivq/jTL7HxfxFn/auQc="
,
"deprecated"
:
"Use uuid module instead"
,
"bin"
:
{
"uuid"
:
"bin/uuid"
}
}
},
"dependencies"
:
{
"node-uuid"
:
{
"version"
:
"1.4.8"
,
"resolved"
:
"https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz"
,
"integrity"
:
"sha1-sEDrCSOWivq/jTL7HxfxFn/auQc="
}
}
}
packages/replace-uuid/package.json
0 → 100644
View file @
df15648a
{
"name"
:
"replace-uuid"
,
"version"
:
"0.0.1"
,
"description"
:
"replace-uuid"
,
"author"
:
"Cocos Creator"
,
"main"
:
"main.js"
,
"main-menu"
:
{
"i18n:MAIN_MENU.package.title/replace-uuid"
:
{
"message"
:
"replace-uuid:replace"
}
},
"dependencies"
:
{
"node-uuid"
:
"1.4.8"
}
}
packages/replace-uuid/util/file.js
0 → 100644
View file @
df15648a
/**
* 一、建立目录中所有meta文件中uuid和新生成uuid的映射关系
* 二、替换目录中指定类型文件中的uuid成新的uuid
*/
var
fs
=
require
(
"
fs-extra
"
);
var
path
=
require
(
"
path
"
);
var
uuidUtils
=
require
(
"
./uuidUtils
"
);
var
uuidMap
=
{};
var
Reg_Uuid
=
/^
[
0-9a-fA-F-
]{36}
$/
;
module
.
exports
=
{
/**
* 递归目录找到所有meta文件的uuid
* 参考 https://docs.cocos.com/creator/manual/zh/advanced-topics/meta.html
*/
findDirUuid
:
function
(
dir
)
{
var
stat
=
fs
.
statSync
(
dir
);
if
(
!
stat
.
isDirectory
())
{
return
;
}
var
subpaths
=
fs
.
readdirSync
(
dir
),
subpath
;
for
(
var
i
=
0
;
i
<
subpaths
.
length
;
++
i
)
{
if
(
subpaths
[
i
][
0
]
===
"
.
"
)
{
continue
;
}
subpath
=
path
.
join
(
dir
,
subpaths
[
i
]);
stat
=
fs
.
statSync
(
subpath
);
if
(
stat
.
isDirectory
())
{
this
.
findDirUuid
(
subpath
);
}
else
if
(
stat
.
isFile
())
{
var
metastr
=
subpath
.
substr
(
subpath
.
length
-
5
,
5
);
if
(
metastr
==
"
.meta
"
)
{
var
jstr
=
fs
.
readFileSync
(
subpath
,
"
utf-8
"
);
var
json
=
JSON
.
parse
(
jstr
);
if
(
uuidUtils
.
isUuid
(
json
[
"
uuid
"
]))
{
this
.
updateUuidMap
(
json
);
if
(
json
[
"
subMetas
"
]
&&
typeof
json
[
"
subMetas
"
]
==
"
object
"
)
{
for
(
var
bb
in
json
[
"
subMetas
"
])
{
this
.
updateUuidMap
(
json
[
"
subMetas
"
][
bb
]);
}
}
}
}
}
}
},
updateUuidMap
:
function
(
json
)
{
if
(
uuidUtils
.
isUuid
(
json
[
"
uuid
"
])
&&
!
uuidMap
[
json
[
"
uuid
"
]])
{
uuidMap
[
json
[
"
uuid
"
]]
=
{
uuid
:
uuidUtils
.
uuidv4
(),
};
if
(
uuidUtils
.
isUuid
(
json
[
"
rawTextureUuid
"
]))
{
uuidMap
[
json
[
"
rawTextureUuid
"
]]
=
{
uuid
:
uuidUtils
.
uuidv4
(),
};
}
}
},
isReplaceFile
:
function
(
subpath
)
{
let
conf
=
[
"
.anim
"
,
"
.prefab
"
,
"
.fire
"
,
"
.meta
"
];
for
(
let
i
=
0
;
i
<
conf
.
length
;
i
++
)
{
let
count
=
conf
[
i
].
length
;
if
(
subpath
.
substr
(
subpath
.
length
-
count
,
count
)
==
conf
[
i
])
{
return
true
;
}
}
return
false
;
},
//递归目录找到所有需要替换uuid的文件
replaceDirUuid
:
function
(
dir
)
{
var
stat
=
fs
.
statSync
(
dir
);
if
(
!
stat
.
isDirectory
())
{
return
;
}
var
subpaths
=
fs
.
readdirSync
(
dir
),
subpath
;
for
(
var
i
=
0
;
i
<
subpaths
.
length
;
++
i
)
{
if
(
subpaths
[
i
][
0
]
===
"
.
"
)
{
continue
;
}
subpath
=
path
.
join
(
dir
,
subpaths
[
i
]);
stat
=
fs
.
statSync
(
subpath
);
if
(
stat
.
isDirectory
())
{
this
.
replaceDirUuid
(
subpath
);
}
else
if
(
stat
.
isFile
())
{
if
(
this
.
isReplaceFile
(
subpath
))
{
var
jstr
=
fs
.
readFileSync
(
subpath
,
"
utf-8
"
);
var
json
;
try
{
json
=
JSON
.
parse
(
jstr
);
}
catch
(
error
)
{
console
.
log
(
subpath
);
}
if
(
json
)
{
this
.
replaceFileUuid
(
json
);
fs
.
writeFileSync
(
subpath
,
JSON
.
stringify
(
json
,
null
,
2
));
}
}
}
}
},
//递归json对象找到所有需要替换uuid
replaceFileUuid
:
function
(
json
)
{
if
(
json
&&
typeof
json
==
"
object
"
)
{
if
(
json
[
"
uuid
"
]
&&
uuidUtils
.
isUuid
(
json
[
"
uuid
"
]))
{
json
[
"
uuid
"
]
=
uuidMap
[
json
[
"
uuid
"
]].
uuid
;
}
if
(
json
[
"
rawTextureUuid
"
]
&&
uuidUtils
.
isUuid
(
json
[
"
rawTextureUuid
"
]))
{
json
[
"
rawTextureUuid
"
]
=
uuidMap
[
json
[
"
rawTextureUuid
"
]].
uuid
;
}
if
(
json
[
"
textureUuid
"
]
&&
uuidUtils
.
isUuid
(
json
[
"
textureUuid
"
]))
{
json
[
"
textureUuid
"
]
=
uuidMap
[
json
[
"
textureUuid
"
]].
uuid
;
}
var
uuidStr
=
json
[
"
__uuid__
"
];
if
(
uuidStr
&&
uuidUtils
.
isUuid
(
uuidStr
))
{
//资源
if
(
Reg_Uuid
.
test
(
uuidStr
))
{
if
(
uuidMap
[
uuidStr
])
{
json
[
"
__uuid__
"
]
=
uuidMap
[
uuidStr
].
uuid
;
}
}
else
{
var
uuidStr
=
uuidUtils
.
decompressUuid
(
uuidStr
);
if
(
uuidMap
[
uuidStr
])
{
json
[
"
__uuid__
"
]
=
UuidUtils
.
compressUuid
(
uuidMap
[
uuidStr
],
false
);
}
}
}
var
typeStr
=
json
[
"
__type__
"
];
if
(
typeStr
&&
uuidUtils
.
isUuid
(
typeStr
))
{
//自定义脚本
if
(
Reg_Uuid
.
test
(
typeStr
))
{
if
(
uuidMap
[
typeStr
])
{
json
[
"
__type__
"
]
=
uuidMap
[
typeStr
].
uuid
;
}
}
else
{
//cocos为了减少数据量,做了一次特殊的 base64 编码
var
de__type__
=
uuidUtils
.
decompressUuid
(
typeStr
);
if
(
uuidMap
[
de__type__
])
{
json
[
"
__type__
"
]
=
uuidUtils
.
compressUuid
(
uuidMap
[
de__type__
].
uuid
,
false
);
}
}
}
if
(
Object
.
prototype
.
toString
.
call
(
json
)
===
"
[object Array]
"
)
{
for
(
var
prebidx
=
0
;
prebidx
<
json
.
length
;
prebidx
++
)
{
if
(
json
[
prebidx
]
&&
typeof
json
[
prebidx
]
==
"
object
"
)
{
this
.
replaceFileUuid
(
json
[
prebidx
]);
}
}
}
else
if
(
Object
.
prototype
.
toString
.
call
(
json
)
===
"
[object Object]
"
)
{
for
(
var
prebidx
in
json
)
{
if
(
json
[
prebidx
]
&&
typeof
json
[
prebidx
]
==
"
object
"
)
{
this
.
replaceFileUuid
(
json
[
prebidx
]);
}
}
}
}
},
};
packages/replace-uuid/util/uuidUtils.js
0 → 100644
View file @
df15648a
/**
* 2.0之后才有Editor.Utils.UuidUtils.compressUuid | decompressUuid的转换
* 这里主要处理base和uuid转换,其他由node-uuid库提供
*/
var
Uuid
=
require
(
"
node-uuid
"
);
var
Base64KeyChars
=
"
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
"
;
var
AsciiTo64
=
new
Array
(
128
);
for
(
var
i
=
0
;
i
<
128
;
++
i
)
{
AsciiTo64
[
i
]
=
0
;
}
for
(
i
=
0
;
i
<
64
;
++
i
)
{
AsciiTo64
[
Base64KeyChars
.
charCodeAt
(
i
)]
=
i
;
}
var
Reg_Dash
=
/-/g
;
var
Reg_Uuid
=
/^
[
0-9a-fA-F-
]{36}
$/
;
var
Reg_NormalizedUuid
=
/^
[
0-9a-fA-F
]{32}
$/
;
var
Reg_CompressedUuid
=
/^
[
0-9a-zA-Z+
/]{22,23}
$/
;
var
UuidUtils
=
{
compressUuid
:
function
(
uuid
,
min
)
{
if
(
Reg_Uuid
.
test
(
uuid
))
{
uuid
=
uuid
.
replace
(
Reg_Dash
,
""
);
}
else
if
(
!
Reg_NormalizedUuid
.
test
(
uuid
))
{
return
uuid
;
}
var
reserved
=
min
===
true
?
2
:
5
;
return
UuidUtils
.
compressHex
(
uuid
,
reserved
);
},
compressHex
:
function
(
hexString
,
reservedHeadLength
)
{
var
length
=
hexString
.
length
;
var
i
;
if
(
typeof
reservedHeadLength
!==
"
undefined
"
)
{
i
=
reservedHeadLength
;
}
else
{
i
=
length
%
3
;
}
var
head
=
hexString
.
slice
(
0
,
i
);
var
base64Chars
=
[];
while
(
i
<
length
)
{
var
hexVal1
=
parseInt
(
hexString
[
i
],
16
);
var
hexVal2
=
parseInt
(
hexString
[
i
+
1
],
16
);
var
hexVal3
=
parseInt
(
hexString
[
i
+
2
],
16
);
base64Chars
.
push
(
Base64KeyChars
[(
hexVal1
<<
2
)
|
(
hexVal2
>>
2
)]);
base64Chars
.
push
(
Base64KeyChars
[((
hexVal2
&
3
)
<<
4
)
|
hexVal3
]);
i
+=
3
;
}
return
head
+
base64Chars
.
join
(
""
);
},
decompressUuid
:
function
(
str
)
{
if
(
str
.
length
===
23
)
{
// decode base64
var
hexChars
=
[];
for
(
var
i
=
5
;
i
<
23
;
i
+=
2
)
{
var
lhs
=
AsciiTo64
[
str
.
charCodeAt
(
i
)];
var
rhs
=
AsciiTo64
[
str
.
charCodeAt
(
i
+
1
)];
hexChars
.
push
((
lhs
>>
2
).
toString
(
16
));
hexChars
.
push
((((
lhs
&
3
)
<<
2
)
|
(
rhs
>>
4
)).
toString
(
16
));
hexChars
.
push
((
rhs
&
0xf
).
toString
(
16
));
}
//
str
=
str
.
slice
(
0
,
5
)
+
hexChars
.
join
(
""
);
}
else
if
(
str
.
length
===
22
)
{
// decode base64
var
hexChars
=
[];
for
(
var
i
=
2
;
i
<
22
;
i
+=
2
)
{
var
lhs
=
AsciiTo64
[
str
.
charCodeAt
(
i
)];
var
rhs
=
AsciiTo64
[
str
.
charCodeAt
(
i
+
1
)];
hexChars
.
push
((
lhs
>>
2
).
toString
(
16
));
hexChars
.
push
((((
lhs
&
3
)
<<
2
)
|
(
rhs
>>
4
)).
toString
(
16
));
hexChars
.
push
((
rhs
&
0xf
).
toString
(
16
));
}
//
str
=
str
.
slice
(
0
,
2
)
+
hexChars
.
join
(
""
);
}
return
[
str
.
slice
(
0
,
8
),
str
.
slice
(
8
,
12
),
str
.
slice
(
12
,
16
),
str
.
slice
(
16
,
20
),
str
.
slice
(
20
),
].
join
(
"
-
"
);
},
isUuid
:
function
(
str
)
{
if
(
typeof
str
==
"
string
"
)
{
return
(
Reg_CompressedUuid
.
test
(
str
)
||
Reg_NormalizedUuid
.
test
(
str
)
||
Reg_Uuid
.
test
(
str
)
);
}
else
{
return
false
;
}
},
uuid
:
function
()
{
var
uuid
=
Uuid
.
v4
();
return
UuidUtils
.
compressUuid
(
uuid
,
true
);
},
uuidv4
:
function
()
{
var
uuid
=
Uuid
.
v4
();
return
uuid
;
},
};
module
.
exports
=
UuidUtils
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment