1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.createBuildSourceFile = createBuildSourceFile; 7exports.withBuildSourceFile = void 0; 8 9function _fs() { 10 const data = _interopRequireDefault(require("fs")); 11 12 _fs = function () { 13 return data; 14 }; 15 16 return data; 17} 18 19function _path() { 20 const data = _interopRequireDefault(require("path")); 21 22 _path = function () { 23 return data; 24 }; 25 26 return data; 27} 28 29function _iosPlugins() { 30 const data = require("../plugins/ios-plugins"); 31 32 _iosPlugins = function () { 33 return data; 34 }; 35 36 return data; 37} 38 39function _Xcodeproj() { 40 const data = require("./utils/Xcodeproj"); 41 42 _Xcodeproj = function () { 43 return data; 44 }; 45 46 return data; 47} 48 49function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 50 51/** 52 * Create a build source file and link it to Xcode. 53 * 54 * @param config 55 * @param props.filePath relative to the build source folder. ex: `ViewController.swift` would be created in `ios/myapp/ViewController.swift`. 56 * @param props.contents file contents to write. 57 * @param props.overwrite should the contents overwrite any existing file in the same location on disk. 58 * @returns 59 */ 60const withBuildSourceFile = (config, { 61 filePath, 62 contents, 63 overwrite 64}) => { 65 return (0, _iosPlugins().withXcodeProject)(config, config => { 66 const projectName = (0, _Xcodeproj().getProjectName)(config.modRequest.projectRoot); 67 config.modResults = createBuildSourceFile({ 68 project: config.modResults, 69 nativeProjectRoot: config.modRequest.platformProjectRoot, 70 fileContents: contents, 71 filePath: _path().default.join(projectName, filePath), 72 overwrite 73 }); 74 return config; 75 }); 76}; 77/** 78 * Add a source file to the Xcode project and write it to the file system. 79 * 80 * @param nativeProjectRoot absolute path to the native app root `user/app/ios` 81 * @param filePath path relative to the `nativeProjectRoot` for the file to create `user/app/ios/myapp/foobar.swift` 82 * @param fileContents string file contents to write to the `filePath` 83 * @param overwrite should write file even if one already exists 84 */ 85 86 87exports.withBuildSourceFile = withBuildSourceFile; 88 89function createBuildSourceFile({ 90 project, 91 nativeProjectRoot, 92 filePath, 93 fileContents, 94 overwrite 95}) { 96 const absoluteFilePath = _path().default.join(nativeProjectRoot, filePath); 97 98 if (overwrite || !_fs().default.existsSync(absoluteFilePath)) { 99 // Create the file 100 _fs().default.writeFileSync(absoluteFilePath, fileContents, 'utf8'); 101 } // `myapp` 102 103 104 const groupName = _path().default.dirname(filePath); // Ensure the file is linked with Xcode resource files 105 106 107 if (!project.hasFile(filePath)) { 108 project = (0, _Xcodeproj().addBuildSourceFileToGroup)({ 109 filepath: filePath, 110 groupName, 111 project 112 }); 113 } 114 115 return project; 116} 117//# sourceMappingURL=XcodeProjectFile.js.map