From 5bb01739d72039c719eb9bffd9fb3369cd54bdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E5=A4=A7=E5=BE=B7?= Date: Thu, 14 Dec 2023 16:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E6=96=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0webServer=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 2 ++ scripts/re-add.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 scripts/re-add.js diff --git a/plugin.xml b/plugin.xml index 9e25cf6..aa18fed 100644 --- a/plugin.xml +++ b/plugin.xml @@ -27,6 +27,8 @@ + + diff --git a/scripts/re-add.js b/scripts/re-add.js new file mode 100644 index 0000000..46bbcbb --- /dev/null +++ b/scripts/re-add.js @@ -0,0 +1,42 @@ +/** + * ~ Copyright (c) 2023 Beijing Shuto Technology Co,. Ltd. All rights reserved. + */ + +const path = require("path"); +const fs = require("fs"); +var child_process = require("child_process"); + +/** + * 读取文件内容,然后替换部分内容后写回 + * @param file + * @param callback + */ +function replaceContents(file, callback) { + fs.readFile(file, 'utf8', function (err, data) { + if (err) throw err; + data = callback(data); + fs.writeFile(file, data, 'utf8', writeErr => { + if (err) throw err; + console.log(file, 'replace success.'); + }); + }); +} + +/** + * 一些自定义操作 + * @param ctx + */ +module.exports = function (ctx) { + console.log('======================webServer pod re-add hook=========================='); + var rootDir = ctx.opts.projectRoot; + var project = path.join(rootDir, 'platforms/ios'); + if (fs.existsSync(project)) { + replaceContents(path.join(project, 'Podfile'), (content) => { + if (content.indexOf('GCDWebServer') < 0) { + content = content.replace("\nend", " pod 'GCDWebServer', :git => 'https://m.shuto.cn:8681/github/GCDWebServer.git'\nend") + } + return content; + }); + child_process.execSync("pod install", { cwd: project }); + } +};