12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- const path = require('path');
- const fs = require('fs');
- // 获取当前命令行上下文路径
- const currentDirectory = process.cwd();
- // 获取配置文件
- const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
- const indexJsonContent = fs.readFileSync(indexJsonPath, 'utf8');
- //创建缓存文件
- const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
- fs.writeFileSync(cacheJsonPath, indexJsonContent, 'utf8');
- //修改配置文件
- const indexJson = JSON.parse(indexJsonContent);
- indexJson.version = dateFormat(new Date()); //版本号
- indexJson.target = "http://127.0.0.1:8090"; //接口地址
- indexJson.smsPhone = ""; //短信接口手机号
- indexJson.vite = {}; //vite配置
- //更新配置文件
- fs.writeFileSync(indexJsonPath, JSON.stringify(indexJson, null, 2));
- //时间格式化
- function dateFormat(date) {
- let format = 'yyyyMMddhhmmss';
- let o = {
- "M+": date.getMonth() + 1, //month
- "d+": date.getDate(), //day
- "h+": date.getHours(), //hour
- "m+": date.getMinutes(), //minute
- "s+": date.getSeconds(), //second
- "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
- "S": date.getMilliseconds() //millisecond
- }
- if (/(y+)/.test(format)) {
- format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (let k in o) {
- if (new RegExp("(" + k + ")").test(format)) {
- format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
- }
- }
- return format;
- }
|