From 983001d3238e622157e1b0ee41f506458825a8f6 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 12 九月 2024 13:55:49 +0800 Subject: [PATCH] 正式和测试服 --- customer_list/common/static/fonts/ywiconfont/iconfont.ttf | 0 scripts/publish.js | 12 customer_list/common/static/fonts/fontawesome/fontawesome-webfont.svg | 0 customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff | 0 customer_list/common/static/fonts/fontawesome/fontawesome-webfont.ttf | 0 customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff2 | 0 scripts/merge.js | 6 scripts/use.js | 6 scripts/utils/create.js | 3 customer_list/common/static/fonts/fontawesome/fontawesome.min.css | 0 customer_list/common/static/fonts/iconfont/iconfont.woff2 | 0 customer_list/common/static/fonts/iconfont/iconfont.ttf | 0 customer_list/common/static/fonts/iconfont/iconfont.css | 6 customer_list/common/static/fonts/ywiconfont/iconfont.woff2 | 0 scripts/deploy.js | 9 /dev/null | 0 customer_list/common/static/fonts/ywiconfont/iconfont.woff | 0 scripts/build.js | 68 ++++--- customer_list/common/static/fonts/iconfont/iconfont.woff | 0 scripts/helper.js | 249 ++++++++++++++++++--------- package.json | 21 + scripts/dev.js | 9 customer_list/common/static/fonts/fontawesome/fontawesome-webfont.eot | 0 customer_list/common/static/fonts/ywiconfont/iconfont.css | 100 +++++++++-- 24 files changed, 330 insertions(+), 159 deletions(-) diff --git a/customer_list/ch/static/fonts/ywiconfont/iconfont.woff b/customer_list/ch/static/fonts/ywiconfont/iconfont.woff deleted file mode 100644 index efff21d..0000000 --- a/customer_list/ch/static/fonts/ywiconfont/iconfont.woff +++ /dev/null Binary files differ diff --git a/customer_list/ch/static/fonts/ywiconfont/iconfont.woff2 b/customer_list/ch/static/fonts/ywiconfont/iconfont.woff2 deleted file mode 100644 index 14a9593..0000000 --- a/customer_list/ch/static/fonts/ywiconfont/iconfont.woff2 +++ /dev/null Binary files differ diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.eot b/customer_list/common/static/fonts/fontawesome/fontawesome-webfont.eot similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.eot rename to customer_list/common/static/fonts/fontawesome/fontawesome-webfont.eot Binary files differ diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.svg b/customer_list/common/static/fonts/fontawesome/fontawesome-webfont.svg similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.svg rename to customer_list/common/static/fonts/fontawesome/fontawesome-webfont.svg diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.ttf b/customer_list/common/static/fonts/fontawesome/fontawesome-webfont.ttf similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.ttf rename to customer_list/common/static/fonts/fontawesome/fontawesome-webfont.ttf Binary files differ diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.woff b/customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.woff rename to customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff Binary files differ diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.woff2 b/customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff2 similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome-webfont.woff2 rename to customer_list/common/static/fonts/fontawesome/fontawesome-webfont.woff2 Binary files differ diff --git a/customer_list/ch/static/fonts/fontawesome/fontawesome.min.css b/customer_list/common/static/fonts/fontawesome/fontawesome.min.css similarity index 100% rename from customer_list/ch/static/fonts/fontawesome/fontawesome.min.css rename to customer_list/common/static/fonts/fontawesome/fontawesome.min.css diff --git a/customer_list/ch/static/fonts/iconfont/iconfont.css b/customer_list/common/static/fonts/iconfont/iconfont.css similarity index 97% rename from customer_list/ch/static/fonts/iconfont/iconfont.css rename to customer_list/common/static/fonts/iconfont/iconfont.css index 4971d6f..7c43a42 100644 --- a/customer_list/ch/static/fonts/iconfont/iconfont.css +++ b/customer_list/common/static/fonts/iconfont/iconfont.css @@ -1,10 +1,10 @@ @font-face { - font-family: 'iconfont'; /* Project id 2298093 */ + font-family: 'myiconfont'; /* Project id 2298093 */ src: url('./iconfont.woff2') format('woff2'), url('./iconfont.woff') format('woff'), url('./iconfont.ttf') format('truetype'); } -.iconfont { - font-family: 'iconfont' !important; +.myiconfont { + font-family: 'myiconfont' !important; font-size: 16px; font-style: normal; -webkit-font-smoothing: antialiased; diff --git a/customer_list/ch/static/fonts/iconfont/iconfont.ttf b/customer_list/common/static/fonts/iconfont/iconfont.ttf similarity index 100% rename from customer_list/ch/static/fonts/iconfont/iconfont.ttf rename to customer_list/common/static/fonts/iconfont/iconfont.ttf Binary files differ diff --git a/customer_list/ch/static/fonts/iconfont/iconfont.woff b/customer_list/common/static/fonts/iconfont/iconfont.woff similarity index 100% rename from customer_list/ch/static/fonts/iconfont/iconfont.woff rename to customer_list/common/static/fonts/iconfont/iconfont.woff Binary files differ diff --git a/customer_list/ch/static/fonts/iconfont/iconfont.woff2 b/customer_list/common/static/fonts/iconfont/iconfont.woff2 similarity index 100% rename from customer_list/ch/static/fonts/iconfont/iconfont.woff2 rename to customer_list/common/static/fonts/iconfont/iconfont.woff2 Binary files differ diff --git a/customer_list/ch/static/fonts/ywiconfont/iconfont.css b/customer_list/common/static/fonts/ywiconfont/iconfont.css similarity index 78% rename from customer_list/ch/static/fonts/ywiconfont/iconfont.css rename to customer_list/common/static/fonts/ywiconfont/iconfont.css index 9a4fef7..5b653c4 100644 --- a/customer_list/ch/static/fonts/ywiconfont/iconfont.css +++ b/customer_list/common/static/fonts/ywiconfont/iconfont.css @@ -1,8 +1,8 @@ @font-face { - font-family: "ywifont"; /* Project id 4499025 */ - src: url('iconfont.woff2?t=1723268520074') format('woff2'), - url('iconfont.woff?t=1723268520074') format('woff'), - url('iconfont.ttf?t=1723268520074') format('truetype'); + font-family: "ywifont"; /* Project id 4655417 */ + src: url('iconfont.woff2?t=1725955398853') format('woff2'), + url('iconfont.woff?t=1725955398853') format('woff'), + url('iconfont.ttf?t=1725955398853') format('truetype'); } .ywifont { @@ -11,6 +11,70 @@ font-style: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; +} + +.ywicon-shujuzhongxin:before { + content: "\e631"; +} + +.ywicon-shujuguanli:before { + content: "\e63d"; +} + +.ywicon-changyonggongjuzhishisuoyin:before { + content: "\e6e9"; +} + +.ywicon-sjdj:before { + content: "\e98e"; +} + +.ywicon-01wenjianfenkuai:before { + content: "\ed47"; +} + +.ywicon-fenshu_an:before { + content: "\e624"; +} + +.ywicon-fabu:before { + content: "\e65f"; +} + +.ywicon-quxiaofabu:before { + content: "\e660"; +} + +.ywicon-ceshi:before { + content: "\e8ad"; +} + +.ywicon-didaima:before { + content: "\e636"; +} + +.ywicon-cshy-shizhong:before { + content: "\e635"; +} + +.ywicon-wendang:before { + content: "\e67c"; +} + +.ywicon-sql:before { + content: "\e65d"; +} + +.ywicon-yuyinshuru:before { + content: "\e633"; +} + +.ywicon-jianpanshuru:before { + content: "\e634"; +} + +.ywicon-shouye:before { + content: "\e603"; } .ywicon-xiaoxi1:before { @@ -121,6 +185,18 @@ content: "\e65b"; } +.ywicon-el-icon-scissors:before { + content: "\e74d"; +} + +.ywicon-a-zaizhiqingkuang1:before { + content: "\e6c8"; +} + +.ywicon-zhiwei1:before { + content: "\e6c9"; +} + .ywicon-shoucangxuanzhong:before { content: "\e6c0"; } @@ -169,11 +245,11 @@ content: "\e637"; } -.ywicon-el-ywicon-download:before { +.ywicon-el-icon-download:before { content: "\e6b1"; } -.ywicon-el-ywicon-magic-stick:before { +.ywicon-el-icon-magic-stick:before { content: "\e6b2"; } @@ -183,18 +259,6 @@ .ywicon-folder-opened:before { content: "\e6b4"; -} - -.ywicon-el-ywicon-scissors:before { - content: "\e74d"; -} - -.ywicon-a-zaizhiqingkuang1:before { - content: "\e6c8"; -} - -.ywicon-zhiwei1:before { - content: "\e6c9"; } .ywicon-xiaoxi:before { diff --git a/customer_list/ch/static/fonts/ywiconfont/iconfont.ttf b/customer_list/common/static/fonts/ywiconfont/iconfont.ttf similarity index 67% rename from customer_list/ch/static/fonts/ywiconfont/iconfont.ttf rename to customer_list/common/static/fonts/ywiconfont/iconfont.ttf index e9adef1..e0493bb 100644 --- a/customer_list/ch/static/fonts/ywiconfont/iconfont.ttf +++ b/customer_list/common/static/fonts/ywiconfont/iconfont.ttf Binary files differ diff --git a/customer_list/common/static/fonts/ywiconfont/iconfont.woff b/customer_list/common/static/fonts/ywiconfont/iconfont.woff new file mode 100644 index 0000000..7ffd187 --- /dev/null +++ b/customer_list/common/static/fonts/ywiconfont/iconfont.woff Binary files differ diff --git a/customer_list/common/static/fonts/ywiconfont/iconfont.woff2 b/customer_list/common/static/fonts/ywiconfont/iconfont.woff2 new file mode 100644 index 0000000..973af1a --- /dev/null +++ b/customer_list/common/static/fonts/ywiconfont/iconfont.woff2 Binary files differ diff --git a/package.json b/package.json index 621b624..02aaea4 100644 --- a/package.json +++ b/package.json @@ -6,15 +6,20 @@ "license": "MIT", "scripts": { "hmr": "node ./scripts/utils/hmr.js", - "use": "node ./scripts/use.js", - "dev": "node ./scripts/dev.js", - "deploy": "node ./scripts/deploy.js", - "publish": "node ./scripts/publish.js", + "create": "node ./scripts/utils/create.js", + "use": "node ./scripts/use.js ch", + "dev": "node ./scripts/dev.js ch", + "build": "node ./scripts/build.js ch", + "deploy": "node ./scripts/deploy.js ch", + "publish": "node ./scripts/publish.js ch", + "use:pro": "node ./scripts/use.js ch:pro", + "dev:pro": "node ./scripts/dev.js ch:pro", + "deploy:pro": "node ./scripts/deploy.js ch:pro", + "publish:pro": "node ./scripts/publish.js ch:pro", + "merge":"node ./scripts/merge.js", "preview": "vite preview", - "dev:yw": "vite --mode yw", - "serve": "vite", - "build": "node ./scripts/build.js", - "build:yw": "vite build --mode yw", + "vite:dev": "vite", + "vite:build": "vite build", "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/", "fix-memory-limit": "cross-env LIMIT=8048 increase-memory-limit" }, 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 diff --git a/scripts/deploy.js b/scripts/deploy.js index b66a607..ba03c1c 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -1,10 +1,13 @@ -const { uploadFiles, customerList } = require('./helper'); +const { uploadFiles, customerList, checkCustomer, changeBranch } = require('./helper'); if (!customerList || customerList.length === 0) { logError(`璇锋纭娇鐢ㄥ懡浠� 鈥渘pm run deploy [customer1,customer2,customer3,...]鈥濓紝 閮ㄧ讲鍒扮敓浜х幆澧冨啓娉曪細customer:pro `); - process.exit(1); // 閫�鍑鸿剼鏈� + exit(); // 閫�鍑鸿剼鏈� } +changeBranch(); -uploadFiles('npm run deploy'); +checkCustomer('npm run deploy'); + +uploadFiles(); diff --git a/scripts/dev.js b/scripts/dev.js index f2a3a3e..c3983b4 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -1,9 +1,10 @@ -const { copyFile,customerList ,checkCustomer,changeBranch} = require('./helper'); +const { copyFile, checkCustomer, firstCustomerName, isPro,changeBranch } = require('./helper'); const { execSync } = require('child_process'); -const customer = customerList[0]?.split(':')[0]; -checkCustomer('npm run dev', customer); changeBranch(); -copyFile('npm run dev'); + +checkCustomer('npm run dev', firstCustomerName); + +copyFile(); try { execSync('vite', { stdio: 'inherit' }); diff --git a/scripts/helper.js b/scripts/helper.js index e1daff8..91cc5e4 100644 --- a/scripts/helper.js +++ b/scripts/helper.js @@ -8,20 +8,20 @@ const scriptDir = __dirname; const rootDir = path.resolve(scriptDir, '..'); const argv2 = process.argv[2]; -const arg2 = argv2?.split(' '); - -const customerList = arg2?.[0] ? (arg2[0] === 'pro' ? ['ch:pro'] : ['ch']) : ['ch']; +const customerList = argv2?.split(' ') ?? ''; const publicDir = path.join(rootDir, 'public'); const distDir = path.join(rootDir, 'dist'); const customerListDir = path.join(rootDir, 'customer_list'); const customerProjectListDir = path.join(rootDir, 'src', 'views', 'project'); -const homeDir = os.homedir(); +const firstCustomerName = customerList[0]?.split(':')[0]; +/** 鍏叡鏂囦欢澶癸紝鎵�鏈夊鎴锋枃浠跺す鍏变韩鏂囦欢 */ +const commonDir = path.join(customerListDir, 'common'); -const item = customerList[0]; + const item = customerList[0]; const customerSplit = item?.split(':'); const deployEnv = customerSplit?.[1]; // 鏄惁涓虹敓浜х幆澧� -const isPro = deployEnv === 'pro'; +const isPro = deployEnv==='pro'; // const deployEnv = process.argv[3]; const logColor = (text, color) => { @@ -36,6 +36,30 @@ logColor(text, 'green'); }; +const logWarn = (text) => { + logColor(text, 'yellow'); +}; + +/** + * 閫�鍑鸿剼鏈� + */ +const exit = () => { + process.exit(1); // 閫�鍑鸿剼鏈� +}; + +/** + * 妫�鏌ユ枃浠舵槸鍚﹀瓨鍦� + * @param {*} file + * @param {*} fileText + */ +const checkFileExist = (file, fileText = '') => { + // 楠岃瘉婧愭枃浠跺す鏄惁瀛樺湪 + if (!fs.existsSync(file)) { + console.error(chalk.red(`${fileText ? fileText + ' ' : ''}"${file}" 涓嶅瓨鍦紒`)); + exit(); // 閫�鍑鸿剼鏈� + } +}; + const checkCustomerDirExist = (customer) => { const customerDir = path.join(customerListDir, customer); checkFileExist(customerDir, '瀹㈡埛鏂囦欢澶�'); @@ -46,53 +70,127 @@ * @param {*} command * @param {*} customer */ -const checkCustomer = (command, customer) => { +const checkCustomer = (command, customer = firstCustomerName) => { if (!customer) { console.error(chalk.red(`璇锋纭娇鐢ㄥ懡浠� 鈥�${command} [customer]鈥� `)); - process.exit(1); // 閫�鍑鸿剼鏈� + exit(); // 閫�鍑鸿剼鏈� } checkCustomerDirExist(customer); }; -let tmpBakDir = ''; -const moveProjectsToBakDir = (command) => { - const customer = customerList[0]?.split(':')[0]; - checkCustomer(command, customer); - //#region ====================== 鍒涘缓澶囦唤鏂囦欢澶� ====================== - let tmpBakRootDir = path.join(homeDir, 'Desktop'); - if (!fs.existsSync(tmpBakRootDir)) { - tmpBakRootDir = homeDir; - } - tmpBakDir = path.join(tmpBakRootDir, 'bak_project_list'); - - fs.ensureDirSync(tmpBakDir); - fs.emptyDirSync(tmpBakDir); - //#endregion - - const contents = fs.readdirSync(customerProjectListDir); - for (let index = 0; index < contents.length; index++) { - const item = contents[index]; - if (item === customer) { - continue; - } - const itemPath = path.join(customerProjectListDir, item); - const stats = fs.statSync(itemPath); - if (stats.isDirectory()) { - const destBakDir = path.join(tmpBakDir, item); - fs.moveSync(itemPath, destBakDir, { overwrite: true }); - } - } +const replaceFileContent = (path, callback) => { + const data = fs.readFileSync(path, 'utf8'); + if (!data) return; + const newData = callback(data); + fs.writeFileSync(path, newData, 'utf8'); }; -const restoreProjectDir = () => { - const contents = fs.readdirSync(tmpBakDir); - for (let index = 0; index < contents.length; index++) { - const item = contents[index]; - const itemPath = path.join(tmpBakDir, item); - const destProjectDir = path.join(customerProjectListDir, item); - fs.moveSync(itemPath, destProjectDir, { overwrite: true }); +const replaceGlobImportPattern = /import.meta.glob\s*\((\s*.*\/views\/\*\*.*)\)/; +const matchAllPattern = '../views/**/*.{vue,tsx}'; + +/** + * 淇敼 src/router/backEnd.ts 鏂囦欢锛屽彧瀵煎叆褰撳墠椤圭洰鏂囦欢 + * @param {*} command + */ +const updateImportGlob = () => { + const backEndFilePath = path.join(rootDir, 'src', 'router', 'backEnd.ts'); + checkFileExist(backEndFilePath, `${backEndFilePath}鏂囦欢`); + const subFile = fs.readdirSync(customerListDir); + const filterSubFile = subFile?.filter((item) => item !== firstCustomerName); + + replaceFileContent(backEndFilePath, (data) => { + const excludeCustomer = filterSubFile && filterSubFile.length > 0 ? `/(${filterSubFile.join('|')})` : ''; + const excludePattern = `!../views/project${excludeCustomer}/**/*`; + const replaceStr = `import.meta.glob(['${matchAllPattern}', '${excludePattern}'])`; + const newData = data.replace(replaceGlobImportPattern, replaceStr); + return newData; + }); +}; + +const restoreImportGlob = () => { + const backEndFilePath = path.join(rootDir, 'src', 'router', 'backEnd.ts'); + checkFileExist(backEndFilePath, `${backEndFilePath}鏂囦欢`); + + replaceFileContent(backEndFilePath, (data) => { + const replaceStr = `import.meta.glob('${matchAllPattern}')`; + const newData = data.replace(replaceGlobImportPattern, replaceStr); + return newData; + }); +}; + +/** + * 鑾峰彇褰撳墠鏃ユ湡鏄鍑犲懆 + * @param dateTime 褰撳墠浼犲叆鐨勬棩鏈熷�� + * @returns 杩斿洖绗嚑鍛ㄦ暟瀛楀�� + */ +const getWeek = (dateTime) => { + const temptTime = new Date(dateTime.getTime()); + // 鍛ㄥ嚑 + const weekday = temptTime.getDay() || 7; + // 鍛�1+5澶�=鍛ㄥ叚 + temptTime.setDate(temptTime.getDate() - weekday + 1 + 5); + let firstDay = new Date(temptTime.getFullYear(), 0, 1); + const dayOfWeek = firstDay.getDay(); + let spendDay = 1; + if (dayOfWeek != 0) spendDay = 7 - dayOfWeek + 1; + firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay); + const d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000); + const result = Math.ceil(d / 7); + return result; +}; + +/** + * 鏃堕棿鏃ユ湡杞崲 + * @param date 褰撳墠鏃堕棿锛宯ew Date() 鏍煎紡 + * @param format 闇�瑕佽浆鎹㈢殑鏃堕棿鏍煎紡瀛楃涓诧紝榛樿鍊糦YYY-mm-dd HH:MM:SS + * @description format 瀛楃涓查殢鎰忥紝濡� `YYYY-mm銆乊YYY-mm-dd` + * @description format 瀛e害锛�"YYYY-mm-dd HH:MM:SS QQQQ" + * @description format 鏄熸湡锛�"YYYY-mm-dd HH:MM:SS WWW" + * @description format 鍑犲懆锛�"YYYY-mm-dd HH:MM:SS ZZZ" + * @description format 瀛e害 + 鏄熸湡 + 鍑犲懆锛�"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ" + * @returns 杩斿洖鎷兼帴鍚庣殑鏃堕棿瀛楃涓� + */ +const formatDate = (date, format = 'YYYY-mm-dd HH:MM:SS') => { + const we = date.getDay(); // 鏄熸湡 + const z = getWeek(date); // 鍛� + const qut = Math.floor((date.getMonth() + 3) / 3).toString(); // 瀛e害 + const opt = { + 'Y+': date.getFullYear().toString(), // 骞� + 'm+': (date.getMonth() + 1).toString(), // 鏈�(鏈堜唤浠�0寮�濮嬶紝瑕�+1) + 'd+': date.getDate().toString(), // 鏃� + 'H+': date.getHours().toString(), // 鏃� + 'M+': date.getMinutes().toString(), // 鍒� + 'S+': date.getSeconds().toString(), // 绉� + 'q+': qut, // 瀛e害 + }; + // 涓枃鏁板瓧 (鏄熸湡) + const week = { + 0: '鏃�', + 1: '涓�', + 2: '浜�', + 3: '涓�', + 4: '鍥�', + 5: '浜�', + 6: '鍏�', + }; + // 涓枃鏁板瓧锛堝搴︼級 + const quarter = { + 1: '涓�', + 2: '浜�', + 3: '涓�', + 4: '鍥�', + }; + if (/(W+)/.test(format)) + format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '鏄熸湡' + week[we] : '鍛�' + week[we]) : week[we]); + if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? '绗�' + quarter[qut] + '瀛e害' : quarter[qut]); + if (/(Z+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? '绗�' + z + '鍛�' : z + ''); + for (const k in opt) { + const r = new RegExp('(' + k + ')').exec(format); + // 鑻ヨ緭鍏ョ殑闀垮害涓嶄负1锛屽垯鍓嶉潰琛ラ浂 + if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0')); } + return format; }; /** @@ -101,10 +199,7 @@ * @param {*} command * @param {*} customer */ -function copyFile(command) { - const customer = customerList[0]?.split(':')[0]; - checkCustomer(command, customer); - +function copyFile() { // 纭繚 public 鏂囦欢锛屼笉瀛樺湪鍒欏垱寤� fs.ensureDirSync(publicDir); // 娓呯┖ public 鏂囦欢澶� @@ -121,23 +216,12 @@ return true; }; - const customerDir = path.join(customerListDir, customer); - + const customerDir = path.join(customerListDir, firstCustomerName); // 澶嶅埗婧愭枃浠跺す涓殑鎵�鏈夋枃浠跺埌 public 鏂囦欢澶� fs.copySync(customerDir, publicDir, { filter }); + fs.copySync(commonDir, publicDir); } -/** - * 妫�鏌ユ枃浠舵槸鍚﹀瓨鍦� - * @param {*} file - * @param {*} fileText - */ -const checkFileExist = (file, fileText = '') => { - // 楠岃瘉婧愭枃浠跺す鏄惁瀛樺湪 - if (!fs.existsSync(file)) { - console.error(chalk.red(`${fileText ? fileText + ' ' : ''}"${file}" 涓嶅瓨鍦紒`)); - exit(); // 閫�鍑鸿剼鏈� - } -}; + /** * 涓婁紶鏂囦欢鍒版湇鍔″櫒 * @param {*} command @@ -155,7 +239,7 @@ // 璇诲彇 JSON 鏂囦欢 const config = await fs.readJson(deployJSON).catch((err) => { console.error(`璇诲彇閰嶇疆鏂囦欢鈥�${deployJSON}鈥濆嚭閿�:`, err); - process.exit(1); + exit(); }); let deployConfig = null; @@ -167,7 +251,7 @@ } if (!deployConfig || Object.values(deployConfig).some((item) => !item)) { console.error(chalk.red(`${customerName} ${deployEnv} 閰嶇疆涓嶅畬鏁达紒`)); - process.exit(1); // 閫�鍑鸿剼鏈� + exit(); // 閫�鍑鸿剼鏈� } // 缂撳瓨閮ㄧ讲閰嶇疆 customerConfig[item] = deployConfig; @@ -213,6 +297,9 @@ } try { + // 鎵归噺澶囦唤鏂囦欢澶瑰埌鏈湴 + // FIXME: 鏂囦欢澶瑰鏋滄槸涓枃锛屼細涔辩爜 + // uploadCommand=`get -r /D:/IStation.SQI.WebAirp E:\\139.224.246.185_bak\\IStation.SQI.WebAirp` fs.writeFileSync(uploadScriptFile, uploadCommand); const sftpArgs = [ `${deployConfig.username}@${deployConfig.host} -P ${deployConfig.port} -pw ${deployConfig.password} -b ${uploadScriptFile}`, @@ -230,13 +317,13 @@ } } } - logSuccess(`馃帀馃帀馃帀銆�${customerList.join(',')}銆戦」鐩凡鎴愬姛閮ㄧ讲锛侌煄夝煄夝煄塦); + logSuccess(`${formatDate(new Date(), 'HH:MM:SS')} > 馃帀馃帀馃帀銆�${customerList.join(',')}銆戦」鐩凡鎴愬姛閮ㄧ讲锛侌煄夝煄夝煄塦); }; /** * 鍒囨崲鍒嗘敮 */ -const changeBranch = () => { +const changeBranch = () =>{ if (isPro) { try { execSync('git checkout master', { stdio: 'inherit' }); @@ -246,25 +333,15 @@ execSync('git checkout test', { stdio: 'inherit' }); } catch (error) {} } -}; - -/** - * 閫�鍑鸿剼鏈� - */ -const exit = () => { - process.exit(1); // 閫�鍑鸿剼鏈� -}; - -const replaceFileContent = (path, callback) => { - const data = fs.readFileSync(path, 'utf8'); - if (!data) return; - const newData = callback(data); - fs.writeFileSync(path, newData, 'utf8'); -}; +} module.exports = { isPro, + firstCustomerName, + exit, customerList, + replaceFileContent, + checkFileExist, //#region ====================== 鏂囦欢璺緞 ====================== rootDir, scriptDir, @@ -283,14 +360,12 @@ //#region ====================== 鎵撳嵃 ====================== logError, logSuccess, + logWarn, //#endregion + formatDate, - moveProjectsToBakDir, - restoreProjectDir, - - exit, - checkFileExist, - replaceFileContent, - + updateImportGlob, + restoreImportGlob, + deployEnv, changeBranch }; diff --git a/scripts/merge.js b/scripts/merge.js new file mode 100644 index 0000000..e7ccff3 --- /dev/null +++ b/scripts/merge.js @@ -0,0 +1,6 @@ +const { execSync } = require('child_process'); + +// 鍚堝苟娴嬭瘯鍒嗘敮鍒颁富鍒嗘敮 +try { + execSync('git merge test master', { stdio: 'inherit' }); +} catch (error) {} diff --git a/scripts/publish.js b/scripts/publish.js index c948d49..7a47652 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -1,17 +1,19 @@ const { execSync } = require('child_process'); -const { customerList, checkCustomerDirExist, logError } = require('./helper'); +const { customerList, checkCustomerDirExist, logError,exit,firstCustomerName,changeBranch } = require('./helper'); // if (!customerList || customerList.length === 0) { // logError(`璇锋纭娇鐢ㄥ懡浠� 鈥渘pm run publish [customer1,customer2,customer3,...]鈥濓紝 // 閮ㄧ讲鍒扮敓浜х幆澧冨啓娉曪細customer:pro // `); -// process.exit(1); // 閫�鍑鸿剼鏈� // } + + if (customerList?.length !== 1) { logError(`璇锋纭娇鐢ㄥ懡浠� 鈥渘pm run publish customer鈥濓紙鐩墠鍙敮鎸佷竴娆¢儴缃蹭竴涓級`); - process.exit(1); // 閫�鍑鸿剼鏈� + exit(); // 閫�鍑鸿剼鏈� } +changeBranch(); customerList.forEach((item) => { const customerSplit = item.split(':'); @@ -19,9 +21,11 @@ checkCustomerDirExist(customerName); }); + + try { // 闅忎究鎷跨涓�涓敤浜� build - execSync(`npm run build ${customerList[0].split(':')[0]}`, { stdio: 'inherit' }); + execSync(`npm run build ${firstCustomerName}`, { stdio: 'inherit' }); } catch (error) {} try { diff --git a/scripts/use.js b/scripts/use.js index ba8248f..2808eaa 100644 --- a/scripts/use.js +++ b/scripts/use.js @@ -1,2 +1,4 @@ -const { copyFile } = require('./helper'); -copyFile('npm run use'); \ No newline at end of file +const { copyFile, checkCustomer, firstCustomerName,changeBranch } = require('./helper'); +changeBranch(); +checkCustomer('npm run use', firstCustomerName); +copyFile(); diff --git a/scripts/utils/create.js b/scripts/utils/create.js new file mode 100644 index 0000000..16366c5 --- /dev/null +++ b/scripts/utils/create.js @@ -0,0 +1,3 @@ +/** + * 娣诲姞鏂扮殑椤甸潰 + */ \ No newline at end of file -- Gitblit v1.9.3