|
| 1 | +diff --git a/dist/index.d.ts b/dist/index.d.ts |
| 2 | +index 9b2c8c403b6a5dcf28ef118cddac08e65340ef70..a35824411fc454dd2864035100a19920c1eaf097 100644 |
| 3 | +--- a/dist/index.d.ts |
| 4 | ++++ b/dist/index.d.ts |
| 5 | +@@ -20,6 +20,21 @@ interface SafariXcodeOptions { |
| 6 | + * If not provided, the generated Xcode project will need to have the development team set manually |
| 7 | + */ |
| 8 | + developmentTeam?: string; |
| 9 | ++ /** |
| 10 | ++ * Output path for the Xcode project |
| 11 | ++ * Defaults to '.output/{projectName}/' directory |
| 12 | ++ */ |
| 13 | ++ outputPath?: string; |
| 14 | ++ /** |
| 15 | ++ * Project type |
| 16 | ++ * Defaults to "both" (MacOS and iOS) |
| 17 | ++ */ |
| 18 | ++ projectType?: 'macos' | 'ios' | 'both'; |
| 19 | ++ /** |
| 20 | ++ * Open the Xcode project after creation |
| 21 | ++ * Defaults to false |
| 22 | ++ */ |
| 23 | ++ openProject?: boolean; |
| 24 | + } |
| 25 | + declare const _default: wxt.WxtModule<SafariXcodeOptions>; |
| 26 | + |
| 27 | +diff --git a/dist/index.js b/dist/index.js |
| 28 | +index 22b72c5c99e6b72c77b7487e4b82127395f44c4b..1ab00ce7b921fb780f6699a5620bb09764132365 100644 |
| 29 | +--- a/dist/index.js |
| 30 | ++++ b/dist/index.js |
| 31 | +@@ -1,5 +1,6 @@ |
| 32 | + // src/index.ts |
| 33 | + import "wxt"; |
| 34 | ++import fs2 from "fs/promises"; |
| 35 | + import { defineWxtModule } from "wxt/modules"; |
| 36 | + import { $ } from "zx"; |
| 37 | + |
| 38 | +@@ -10,7 +11,7 @@ import fs from "fs/promises"; |
| 39 | + async function updateProjectConfig(options) { |
| 40 | + const projectConfigPath = path.resolve( |
| 41 | + options.rootPath, |
| 42 | +- `.output/${options.projectName}/${options.projectName}.xcodeproj/project.pbxproj` |
| 43 | ++ `${options.outputPath}/${options.projectName}.xcodeproj/project.pbxproj` |
| 44 | + ); |
| 45 | + const packageJsonModule = await import(path.resolve(options.rootPath, "package.json"), { |
| 46 | + with: { type: "json" } |
| 47 | +@@ -49,7 +50,7 @@ async function updateProjectConfig(options) { |
| 48 | + await fs.writeFile(projectConfigPath, newContent); |
| 49 | + } |
| 50 | + async function updateInfoPlist(options) { |
| 51 | +- const projectPath = path.resolve(options.rootPath, ".output", options.projectName); |
| 52 | ++ const projectPath = path.resolve(options.rootPath, options.outputPath); |
| 53 | + const files = await globby("**/*.plist", { |
| 54 | + cwd: projectPath |
| 55 | + }); |
| 56 | +@@ -78,28 +79,47 @@ var index_default = defineWxtModule({ |
| 57 | + return; |
| 58 | + } |
| 59 | + const { appCategory, bundleIdentifier, developmentTeam } = options ?? {}; |
| 60 | +- const projectName = options?.projectName ?? wxt.config.manifest.name; |
| 61 | ++ const projectName = options?.projectName ?? wxt.config.manifest.name ?? await fs2.readFile(`${wxt.config.root}/package.json`, "utf-8").then((data) => JSON.parse(data).name); |
| 62 | + if (!projectName || !appCategory || !bundleIdentifier) { |
| 63 | + wxt.logger.warn( |
| 64 | + "Safari Xcode module is not configured properly. Please provide projectName, appCategory and bundleIdentifier." |
| 65 | + ); |
| 66 | + return; |
| 67 | + } |
| 68 | ++ const inputPath = `.output/safari-mv${wxt.config.manifestVersion}`; |
| 69 | ++ const outputPath = options?.outputPath ?? `.output/${projectName}/`; |
| 70 | ++ const projectType = options?.projectType ?? "both"; |
| 71 | ++ const openProject = options?.openProject ?? false; |
| 72 | + wxt.hook("build:done", async (wxt2) => { |
| 73 | +- wxt2.logger.info("Converting Safari extension to Xcode project..."); |
| 74 | ++ wxt2.logger.info(`Converting ${highlight("Safari extension")} to ${highlight("Xcode project")}...`); |
| 75 | ++ if (process.platform !== "darwin") { |
| 76 | ++ const error = new Error("Safari Xcode conversion requires macOS."); |
| 77 | ++ wxt2.logger.error("Safari Xcode conversion is only supported on macOS.", error); |
| 78 | ++ throw error; |
| 79 | ++ } |
| 80 | + try { |
| 81 | +- wxt2.logger.info("Running safari-web-extension-converter..."); |
| 82 | +- await $`xcrun safari-web-extension-converter --bundle-identifier ${bundleIdentifier} --force --project-location .output .output/safari-mv3`; |
| 83 | +- wxt2.logger.info("Updating Xcode project config..."); |
| 84 | ++ wxt2.logger.info(`Running ${highlight("safari-web-extension-converter")}...`); |
| 85 | ++ const options2 = [ |
| 86 | ++ `--bundle-identifier "${bundleIdentifier}"`, |
| 87 | ++ `--project-location "${outputPath}"`, |
| 88 | ++ "--force" |
| 89 | ++ ]; |
| 90 | ++ if (!openProject) options2.push("--no-open"); |
| 91 | ++ if (projectType === "ios") options2.push("--ios-only"); |
| 92 | ++ if (projectType === "macos") options2.push("--macos-only"); |
| 93 | ++ await $`xcrun safari-web-extension-converter ${options2.join(" ")} ${inputPath}`; |
| 94 | ++ wxt2.logger.info(`Updating ${highlight("Xcode project config")}...`); |
| 95 | + await updateProjectConfig({ |
| 96 | + projectName, |
| 97 | ++ outputPath, |
| 98 | + appCategory, |
| 99 | + developmentTeam, |
| 100 | + rootPath: wxt2.config.root |
| 101 | + }); |
| 102 | +- wxt2.logger.info("Updating Info.plist files..."); |
| 103 | ++ wxt2.logger.info(`Updating ${highlight("Info.plist files")}...`); |
| 104 | + await updateInfoPlist({ |
| 105 | + projectName, |
| 106 | ++ outputPath, |
| 107 | + appCategory, |
| 108 | + developmentTeam, |
| 109 | + rootPath: wxt2.config.root |
| 110 | +@@ -112,6 +132,9 @@ var index_default = defineWxtModule({ |
| 111 | + }); |
| 112 | + } |
| 113 | + }); |
| 114 | ++function highlight(text) { |
| 115 | ++ return `\x1B[36m${text}\x1B[0m`; |
| 116 | ++} |
| 117 | + export { |
| 118 | + index_default as default |
| 119 | + }; |
0 commit comments