Commit f0cb3ba6 authored by 范雪寒's avatar 范雪寒

feat: 解决脚手架中的scene与js文件的uuid相同的问题

parent a6251a04
let fs = require('fs'); const fs = require('fs');
const { v4, parse } = require('uuid');
const { Base64 } = require('js-base64');
const path = '../play/assets' function getFolderName(path) {
let folderName = '';
let folderName = ''; fs.readdirSync(path).find(fileName => {
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`); const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) { if (st.isDirectory()) {
folderName = fileName; folderName = fileName;
} }
}); });
const metaPath = `${path}/${folderName}.meta`; return folderName;
const metaDataStr = fs.readFileSync(metaPath); }
const metaData = JSON.parse(metaDataStr); function editFolderMeta(path, folderName) {
metaData.isBundle = false; const metaPath = `${path}/${folderName}.meta`;
fs.writeFileSync(metaPath, JSON.stringify(metaData)); const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = false;
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
function fileReplace(path, replaceStr, newStr) {
const fileStr = fs.readFileSync(path);
const newFileStr = fileStr.toString().replace(replaceStr, newStr);
fs.writeFileSync(path, newFileStr);
}
const path = '../play/assets'
const folderName = getFolderName(path);
editFolderMeta(path, folderName);
const oldFireUuid = '57ea7c61-9b8b-498a-b024-c98ee9124beb';
const newFireUuid = v4();
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire.meta`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace('../play/settings/builder.json', oldFireUuid, newFireUuid);
function getShortUuid(uuid) {
const bytes = parse(uuid).subarray(1);
return uuid.substring(0, 5) + Base64.fromUint8Array(bytes).substring(2);
}
const oldJsUuid = 'f4ede462-f8d7-4069-ba80-915611c058ca';
const oldJsShortUuid = 'f4edeRi+NdAabqAkVYRwFjK';
const oldJsId = 'e687yyoRBIzZAOVRL8Sseh';
const newJsUuid = v4();
const newJsShortUuid = getShortUuid(newJsUuid);
const newJsId = v4().replace(/-/g, '').substring(0, oldJsId.length);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.js.meta`, oldJsUuid, newJsUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsShortUuid, newJsShortUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsId, newJsId);
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"base-64": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
},
"bl": { "bl": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.3.tgz", "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.3.tgz",
...@@ -107,6 +112,11 @@ ...@@ -107,6 +112,11 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
}, },
"js-base64": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.2.tgz",
"integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ=="
},
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
...@@ -222,6 +232,11 @@ ...@@ -222,6 +232,11 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
}, },
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"compressing": "^1.5.1" "base-64": "^1.0.0",
"compressing": "^1.5.1",
"js-base64": "^3.7.2",
"uuid": "^8.3.2"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment