From 983001d3238e622157e1b0ee41f506458825a8f6 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 12 九月 2024 13:55:49 +0800 Subject: [PATCH] 正式和测试服 --- scripts/build.js | 68 +++++++++++++++++++--------------- 1 files changed, 38 insertions(+), 30 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 8b88335..8df5a98 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,48 +1,56 @@ -const fs = require('fs-extra'); const path = require('path'); -const { copyFile, distDir, customerList, moveProjectsToBakDir, logError, restoreProjectDir } = require('./helper'); +const fs = require('fs-extra'); + +const { + copyFile, + distDir, + customerList, + updateImportGlob, + logError, + restoreImportGlob, + replaceFileContent, + exit, + firstCustomerName, + checkCustomer, + formatDate, + logSuccess, + logWarn, + rootDir, + publicDir, + changeBranch +} = require('./helper'); const { execSync } = require('child_process'); if (customerList?.length !== 1) { logError(`璇锋纭娇鐢ㄥ懡浠� 鈥渘pm run build customer鈥濓紙鐩墠鍙敮鎸佷竴娆¢儴缃蹭竴涓級`); - process.exit(1); // 閫�鍑鸿剼鏈� + exit(); // 閫�鍑鸿剼鏈� } -// 鍒犻櫎鍏朵綑椤圭洰鏂囦欢 -moveProjectsToBakDir('npm run build'); -try { - copyFile('npm run build'); -} catch (error) { - // 鎶ラ敊鏃惰鎭㈠鍏朵綑椤圭洰鏂囦欢 - restoreProjectDir(); - throw error; -} + +checkCustomer('npm run build', firstCustomerName); + +copyFile(); + + + +// 鏇存敼 import.meta.glob +updateImportGlob(); try { execSync('vite build', { stdio: 'inherit' }); -} catch (error) {}finally{ - // 鏋勫缓瀹屾垚涔嬪悗锛屾仮澶嶉」鐩枃浠跺す - restoreProjectDir(); +} catch (err) { + logError(err); +} finally { + // 鎭㈠鏂囦欢 + restoreImportGlob(); } //#region ====================== 淇敼 dist 鏂囦欢涓� index.html 涓殑寮曞叆 js 鐨� v 鍊� ====================== const htmlFile = path.join(distDir, 'index.html'); - -// 璇诲彇 index.html 鏂囦欢鍐呭 -fs.readFile(htmlFile, 'utf8', (err, data) => { - if (err) { - console.error(chalk.red(`璇诲彇鈥�${htmlFile}鈥濆け璐ワ細`, err)); - return; - } - +replaceFileContent(htmlFile, (data) => { // 鏇挎崲涓烘柊鐨� v 鍊� const currentStamp = new Date().getTime() + ''; const newData = data.replace(/(?<=\/static\/config\/.*.js\?v=).*(?=")/g, currentStamp); - // 灏嗕慨鏀瑰悗鐨勫唴瀹瑰啓鍥� index.html 鏂囦欢 - fs.writeFile(htmlFile, newData, 'utf8', (err) => { - if (err) { - console.error(chalk.red(`淇敼鈥�${htmlFile}鈥濅腑鐨� v 鍊煎け璐ワ細`, err)); - return; - } - }); + return newData; }); +logSuccess(`${formatDate(new Date(), 'HH:MM:SS')} > 馃帀馃帀馃帀銆�${customerList.join(',')}銆戦」鐩凡鎴愬姛鏋勫缓锛侌煄夝煄夝煄塦); //#endregion -- Gitblit v1.9.3