cordova-plugin-webserver/scripts/re-add.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-12-14 16:56:34 +08:00
/**
* ~ 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) {
2023-12-15 01:48:52 +08:00
var data = fs.readFileSync(file, 'utf8');
data = callback(data);
fs.writeFileSync(file,data,'utf8');
2023-12-14 16:56:34 +08:00
}
/**
* 一些自定义操作
* @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) {
2023-12-14 17:02:16 +08:00
content = content.replace("\nend", "\n pod 'GCDWebServer', :git => 'https://m.shuto.cn:8681/github/GCDWebServer.git'\nend")
2023-12-14 16:56:34 +08:00
}
return content;
});
child_process.execSync("pod install", { cwd: project });
}
};