const fs = require('fs'); const path = require('path') const inquirer = require('inquirer'); const child_process = require('child_process'); const config = require('../package.json') const argv = process.argv; const env = require('dotenv').config({ path: './.env' }) /** * 删除文件夹及文件 * @param path */ function deleteFile(path) { let files = []; if (fs.existsSync(path)) { files = fs.readdirSync(path); files.forEach(function (file, index) { let curPath = path + "/" + file; if (fs.statSync(curPath).isDirectory()) { deleteFile(curPath); } else { fs.unlinkSync(curPath); } }); fs.rmdirSync(path); } } /** * 复制文件 * @param srcPath * @param tarPath * @param cb */ function copyFile(srcPath, tarPath, cb) { let rs = fs.createReadStream(srcPath) rs.on('error', function (err) { if (err) { console.log('read error', srcPath) } cb && cb(err) }) let ws = fs.createWriteStream(tarPath) ws.on('error', function (err) { if (err) { console.log('write error', tarPath) } cb && cb(err) }) ws.on('close', function (ex) { cb && cb(ex) }) rs.pipe(ws) } /** * 给地址加上前后 * @param str * @returns {string} */ function formatUrl(str) { let url; if (str.substring(0, 7) === "http://" || str.substring(0, 8) === "https://") { url = str.trim(); } else { url = "http://" + str.trim(); } if (url.substring(url.length - 1) != "/") { url += "/" } return url; } /** * 正则提取域名 * @param weburl * @returns {string|string} */ function getDomain(weburl) { let urlReg = /http(s)?:\/\/([^\/]+)/i; let domain = weburl.match(urlReg); return ((domain != null && domain.length > 0) ? domain[2] : ""); } /** * 右边是否包含 * @param string * @param find * @returns {boolean} */ function rightExists(string, find) { string += ""; find += ""; return (string.substring(string.length - find.length) === find); } /** ***************************************************************************************************/ /** ***************************************************************************************************/ /** ***************************************************************************************************/ const electronDir = path.resolve(__dirname, "public"); const nativeCachePath = path.resolve(__dirname, ".native"); const devloadCachePath = path.resolve(__dirname, ".devload"); const platform = ["build-mac", "build-mac-arm", "build-win"]; // 生成配置、编译应用 function step1(data, publish) { // config.js let systemInfo = { title: data.name, version: config.version, origin: "./", apiUrl: formatUrl(data.url) + "api/", } fs.writeFileSync(electronDir + "/config.js", "window.systemInformation = " + JSON.stringify(systemInfo), 'utf8'); fs.writeFileSync(nativeCachePath, formatUrl(data.url)); fs.writeFileSync(devloadCachePath, "", 'utf8'); // index.html let indexFile = path.resolve(electronDir, "index.html"); let indexString = fs.readFileSync(indexFile, 'utf8'); indexString = indexString.replace(`