From 4a4bc757602a4554b7fc0d38f9402663ddca9192 Mon Sep 17 00:00:00 2001
From: Jacob <hlnie@tohours.com>
Date: 星期一, 12 十月 2026 16:25:28 +0800
Subject: [PATCH] 移除不需要的文件
---
scripts/set-env.js | 42 +++++++++++++++++++++---------------------
1 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/scripts/set-env.js b/scripts/set-env.js
index 8db12f2..59f3188 100644
--- a/scripts/set-env.js
+++ b/scripts/set-env.js
@@ -6,9 +6,12 @@
* npm run env:prod 绛変环浜� node scripts/set-env.js prod
*
* 璇存槑锛�
- * appid 鏄紪璇戞湡鍊硷紙manifest.json 涓� HBuilderX 鍥哄畾杈撳叆銆佸井淇″紑鍙戣�呭伐鍏峰彧璁�
- * project.config.json 鐨� appid锛夛紝鏃犳硶鍍忔帴鍙e湴鍧�閭f牱杩愯鏃跺垏鎹紝鎵�浠ヨ繖閲屽仛
- * 鈥滀竴娆″懡浠ゅ啓鍥炩�濄�傛敼瀹屽繀椤婚噸鏂扮紪璇戜竴娆★紝dist 涓嬬殑 project.config.json 鎵嶄細鏇存柊銆�
+ * appid 鏄紪璇戞湡鍊硷紙HBuilderX 鐨勭紪璇戣緭鍏ュ氨鏄� manifest.json锛夛紝鏃犳硶鍍忔帴鍙e湴鍧�閭f牱
+ * 杩愯鏃跺垏鎹紝鎵�浠ヨ繖閲屽仛鈥滀竴娆″懡浠ゅ啓鍥炩�濄�傛敼瀹屽繀椤婚噸鏂扮紪璇戜竴娆★紝浜х墿閲岀殑
+ * project.config.json 鎵嶄細鏇存柊銆�
+ *
+ * 鏃ュ父鎺ㄨ崘锛歮p-weixin.appid 淇濇寔 null锛屽彧璁╁彂琛岃剼鏈洖鍐欎骇鐗� appid锛坓it 闆跺櫔闊筹級銆�
+ * 鏈剼鏈敤浜庨渶瑕佸湪 HBuilderX 閲岀洿鎺ヨ繍琛岃皟璇曘�佹垨瑕佸嚭 App 鍖咃紙椤跺眰 appid锛夌殑鍦烘櫙銆�
*
* 鍞竴鏁版嵁婧愶細config/env/<env>.js 涓殑 UNI_APPID锛圖Cloud 鏍囪瘑锛夈�丄PPID锛堝皬绋嬪簭 appid锛�
*/
@@ -18,9 +21,9 @@
const ROOT = path.resolve(__dirname, '..');
const ENV_DIR = path.join(ROOT, 'config', 'env');
+// 鏍圭洰褰� project.config.json 涓嶅弬涓� mp-weixin 缂栬瘧涓斿凡涓嶅叆搴擄紝杩欓噷鍙淮鎶� manifest.json
const files = {
- manifest: path.join(ROOT, 'manifest.json'),
- projectConfig: path.join(ROOT, 'project.config.json')
+ manifest: path.join(ROOT, 'manifest.json')
};
function fail(msg) {
@@ -28,10 +31,10 @@
process.exit(1);
}
-/** 鍙浛鎹㈢涓�澶� "appid" : "xxx"锛屼繚鐣欏師鏈夌┖鏍�/缂╄繘椋庢牸 */
+/** 鍙浛鎹㈢涓�澶� "appid" : <瀛楃涓叉垨 null>锛屼繚鐣欏師鏈夌┖鏍�/缂╄繘椋庢牸 */
function replaceAppId(text, value) {
let done = false;
- const result = text.replace(/"appid"(\s*:\s*)"[^"]*"/, function(match, sep) {
+ const result = text.replace(/"appid"(\s*:\s*)(?:"[^"]*"|null)/, function(match, sep) {
done = true;
return '"appid"' + sep + '"' + value + '"';
});
@@ -48,18 +51,17 @@
// 2) mp-weixin 涓嬬殑 appid锛堝井淇″皬绋嬪簭 appid锛夛紝鍙湪璇ュ尯鍧楀唴鏇挎崲绗竴澶�
const idx = text.indexOf('"mp-weixin"');
if (idx < 0) fail('manifest.json 涓湭鎵惧埌 "mp-weixin" 閰嶇疆鍧�');
- const scoped = replaceAppId(text.slice(idx), env.APPID);
- if (!scoped.done) fail('manifest.json 鐨� "mp-weixin" 涓湭鎵惧埌 "appid" 瀛楁');
- text = text.slice(0, idx) + scoped.text;
+ const head = text.slice(0, idx);
+ const body = text.slice(idx);
+ const scoped = replaceAppId(body, env.APPID);
+ if (scoped.done) return head + scoped.text;
- return text;
-}
-
-/** 鏇挎崲 project.config.json 鐨� appid锛堜繚鎸佸師鏍煎紡锛岄伩鍏嶆暣鏂囦欢閲嶆帓锛� */
-function patchProjectConfig(text, env) {
- const res = replaceAppId(text, env.APPID);
- if (!res.done) fail('project.config.json 涓湭鎵惧埌 "appid" 瀛楁');
- return res.text;
+ // 3) 瀛楁琚垹鎺夋椂锛屾寜鍚岀骇瀛愰」缂╄繘琛ヤ竴琛�
+ const m = body.match(/^("mp-weixin"\s*:\s*\{)(\r?\n)([ \t]*)/);
+ if (!m) fail('manifest.json 鐨� "mp-weixin" 鍧楁牸寮忓紓甯革紝鏃犳硶鍐欏叆 appid');
+ const nl = m[2];
+ const indent = m[3];
+ return head + m[1] + nl + indent + '"appid" : "' + env.APPID + '",' + nl + indent + body.slice(m[0].length);
}
function writeIfChanged(file, next) {
@@ -96,9 +98,7 @@
console.log(' 灏忕▼搴� appid : ' + env.APPID);
console.log(' 鎺ュ彛鍦板潃 : ' + env.HTTP_REQUEST_URL);
- const manifestChanged = writeIfChanged(files.manifest, patchManifest(fs.readFileSync(files.manifest, 'utf8'), env));
- const projectChanged = writeIfChanged(files.projectConfig, patchProjectConfig(fs.readFileSync(files.projectConfig, 'utf8'), env));
- const changed = manifestChanged || projectChanged;
+ const changed = writeIfChanged(files.manifest, patchManifest(fs.readFileSync(files.manifest, 'utf8'), env));
console.log(changed
? '[set-env] 瀹屾垚锛岃鍦� HBuilderX 涓噸鏂扮紪璇戜竴娆★紝骞跺湪寰俊寮�鍙戣�呭伐鍏蜂腑閲嶆柊鎵撳紑椤圭洰'
--
Gitblit v1.4.0