From f0cb3ba6f39262bc010de5496579a58c4eceb0fb Mon Sep 17 00:00:00 2001
From: fanxuehan <fanxuehan@qq.com>
Date: Mon, 27 Sep 2021 11:28:51 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=A3=E5=86=B3=E8=84=9A=E6=89=8B?=
 =?UTF-8?q?=E6=9E=B6=E4=B8=AD=E7=9A=84scene=E4=B8=8Ejs=E6=96=87=E4=BB=B6?=
 =?UTF-8?q?=E7=9A=84uuid=E7=9B=B8=E5=90=8C=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 publish/build_step_0.js   | 65 +++++++++++++++++++++++++++++++--------
 publish/package-lock.json | 15 +++++++++
 publish/package.json      |  5 ++-
 3 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/publish/build_step_0.js b/publish/build_step_0.js
index dff2b7f..5d11e5a 100644
--- a/publish/build_step_0.js
+++ b/publish/build_step_0.js
@@ -1,16 +1,55 @@
-let fs = require('fs');
+const fs = require('fs');
+const { v4, parse } = require('uuid');
+const { Base64 } = require('js-base64');
+
+function getFolderName(path) {
+  let folderName = '';
+  fs.readdirSync(path).find(fileName => {
+    const st = fs.statSync(`${path}/${fileName}`);
+    if (st.isDirectory()) {
+      folderName = fileName;
+    }
+  });
+  return folderName;
+}
+function editFolderMeta(path, folderName) {
+  const metaPath = `${path}/${folderName}.meta`;
+  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);
+}
 
-let folderName = '';
-fs.readdirSync(path).find(fileName => {
-  const st = fs.statSync(`${path}/${fileName}`);
-  if (st.isDirectory()) {
-    folderName = fileName;
-  }
-});
-const metaPath = `${path}/${folderName}.meta`;
-const metaDataStr = fs.readFileSync(metaPath);
-const metaData = JSON.parse(metaDataStr);
-metaData.isBundle = false;
-fs.writeFileSync(metaPath, JSON.stringify(metaData));
+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);
diff --git a/publish/package-lock.json b/publish/package-lock.json
index 05a1722..8d76ee9 100644
--- a/publish/package-lock.json
+++ b/publish/package-lock.json
@@ -4,6 +4,11 @@
   "lockfileVersion": 1,
   "requires": true,
   "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": {
       "version": "1.2.3",
       "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.3.tgz",
@@ -107,6 +112,11 @@
       "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
       "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": {
       "version": "1.2.5",
       "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
@@ -222,6 +232,11 @@
       "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
       "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": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
diff --git a/publish/package.json b/publish/package.json
index dd6a002..2942f39 100644
--- a/publish/package.json
+++ b/publish/package.json
@@ -9,6 +9,9 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
-    "compressing": "^1.5.1"
+    "base-64": "^1.0.0",
+    "compressing": "^1.5.1",
+    "js-base64": "^3.7.2",
+    "uuid": "^8.3.2"
   }
 }
-- 
2.21.0