添加重新添加webServer的脚本

This commit is contained in:
范大德 2023-12-14 16:56:34 +08:00
parent 2d41148067
commit 5bb01739d7
2 changed files with 44 additions and 0 deletions

View File

@ -27,6 +27,8 @@
</platform> </platform>
<platform name="ios"> <platform name="ios">
<hook type="after_platform_add" src="scripts/re-add.js" />
<hook type="after_plugin_add" src="scripts/re-add.js" />
<config-file target="config.xml" parent="/*"> <config-file target="config.xml" parent="/*">
<feature name="Webserver"> <feature name="Webserver">
<param name="ios-package" value="Webserver" /> <param name="ios-package" value="Webserver" />

42
scripts/re-add.js Normal file
View File

@ -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 });
}
};