This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

59 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const ios_plugins_1 = require("../plugins/ios-plugins");
const Xcodeproj_1 = require("./utils/Xcodeproj");
/**
* Create a build source file and link it to Xcode.
*
* @param config
* @param props.filePath relative to the build source folder. ex: `ViewController.swift` would be created in `ios/myapp/ViewController.swift`.
* @param props.contents file contents to write.
* @param props.overwrite should the contents overwrite any existing file in the same location on disk.
* @returns
*/
exports.withBuildSourceFile = (config, { filePath, contents, overwrite }) => {
return ios_plugins_1.withXcodeProject(config, config => {
const projectName = Xcodeproj_1.getProjectName(config.modRequest.projectRoot);
config.modResults = createBuildSourceFile({
project: config.modResults,
nativeProjectRoot: config.modRequest.platformProjectRoot,
fileContents: contents,
filePath: path_1.default.join(projectName, filePath),
overwrite,
});
return config;
});
};
/**
* Add a source file to the Xcode project and write it to the file system.
*
* @param nativeProjectRoot absolute path to the native app root `user/app/ios`
* @param filePath path relative to the `nativeProjectRoot` for the file to create `user/app/ios/myapp/foobar.swift`
* @param fileContents string file contents to write to the `filePath`
* @param overwrite should write file even if one already exists
*/
function createBuildSourceFile({ project, nativeProjectRoot, filePath, fileContents, overwrite, }) {
const absoluteFilePath = path_1.default.join(nativeProjectRoot, filePath);
if (overwrite || !fs_extra_1.default.existsSync(absoluteFilePath)) {
// Create the file
fs_extra_1.default.writeFileSync(absoluteFilePath, fileContents, 'utf8');
}
// `myapp`
const groupName = path_1.default.dirname(filePath);
// Ensure the file is linked with Xcode resource files
if (!project.hasFile(filePath)) {
project = Xcodeproj_1.addBuildSourceFileToGroup({
filepath: filePath,
groupName,
project,
});
}
return project;
}
exports.createBuildSourceFile = createBuildSourceFile;
//# sourceMappingURL=XcodeProjectFile.js.map