diff --git a/Tools/nib2cib/Converter.j b/Tools/nib2cib/Converter.j index eeed7d66c..e1dc57897 100644 --- a/Tools/nib2cib/Converter.j +++ b/Tools/nib2cib/Converter.j @@ -34,25 +34,23 @@ @global java -var path = require("path"); -var fs = require("fs"); -var os = require("os"); -var child_process = require("child_process"); -var utilsFile = ObjectiveJ.utils.file; +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { execSync, spawnSync } = require('child_process'); +const child_process = require("child_process"); +const utilsFile = ObjectiveJ.utils.file; -/* var FILE = require("file"), - OS = require("os"), */ +var SharedConverter = nil; -var SharedConverter = nil; +NibFormatUndetermined = 0; +NibFormatMac = 1; +NibFormatIPhone = 2; -NibFormatUndetermined = 0; -NibFormatMac = 1; -NibFormatIPhone = 2; +ConverterModeLegacy = 0; +ConverterModeNew = 1; -ConverterModeLegacy = 0; -ConverterModeNew = 1; - -ConverterConversionException = @"ConverterConversionException"; +ConverterConversionException = @"ConverterConversionException"; @implementation Converter : CPObject { @@ -89,7 +87,7 @@ ConverterConversionException = @"ConverterConversionException"; // Some .xibs are iPhone nibs, check the actual contents in this case. if (path.extname(inputPath) !== ".nib" && fs.lstatSync(inputPath).isFile() && fs.readFileSync(inputPath, { encoding: "utf8" }).indexOf(" tag targets deployment version 10.10 + var xibContent = fs.readFileSync(aFilePath, { encoding: 'utf8' }); + + // Perform the in-memory modification of the deployment tag + // + // Remove existing tag, if present + // xib's with Xcode 14 or later do not have a element at all. + // It is simpler to ensure no element is present, + // then add what we want. + // + // Add a new element as the first child of the element. + // This is the placement expected when Xcode adds the element. + // Target version 10.10 as the deployment version. + if (xibContent.includes('/g, ''); + } + // Where will the element be inserted in the string? + var deploymentTag = '\n '; + var insertPosition = xibContent.indexOf("") + "".length; + + // Slice the string representing the source xib and insert the new element. + var updatedXIBContent = xibContent.slice(0, insertPosition) + deploymentTag + xibContent.slice(insertPosition); - try { - child_process.execSync("/usr/bin/ibtool" + " '" + aFilePath + "' " + "--compile" + " '" + temporaryNibFilePath + "'", {stdio: 'inherit'}); - } catch(err) { - [CPException raise:ConverterConversionException reason:@"Could not compile file: " + aFilePath]; + fs.writeFileSync(temporaryXibFilePath, updatedXIBContent, 'utf8'); + try + { + child_process.execSync("/usr/bin/ibtool" + " '" + temporaryXibFilePath + "' " + "--compile" + " '" + temporaryNibFilePath + "'", {stdio: 'inherit'}); + } + catch(err) + { + [CPException raise:ConverterConversionException reason:@"Could not compile file: " + temporaryXibFilePath]; } } else @@ -169,30 +198,19 @@ ConverterConversionException = @"ConverterConversionException"; // Convert from binary plist to XML plist var temporaryPlistFilePath = path.join(tmpdir, path.basename(aFilePath) + ".tmp.plist"); - try { + try + { child_process.execSync("/usr/bin/plutil" + " " + "-convert" + " " + "xml1" + " '" + (temporaryNibFilePathInDirectoryFile || temporaryNibFilePath) + "' " + "-o" + " '" + temporaryPlistFilePath + "'", {stdio: 'inherit'}); - } catch(err) { + } + catch(err) + { [CPException raise:ConverterConversionException reason:@"Could not convert to xml plist for file: " + aFilePath]; } -/* try - { - var p = OS.popen(["/usr/bin/plutil", "-convert", "xml1", temporaryNibFilePath, "-o", temporaryPlistFilePath]); - if (p.wait() === 1) - [CPException raise:ConverterConversionException reason:@"Could not convert to xml plist for file: " + aFilePath]; - } - finally - { - p.stdin.close(); - p.stdout.close(); - p.stderr.close(); - } */ - if (!isReadable(temporaryPlistFilePath)) [CPException raise:ConverterConversionException reason:@"Unable to convert nib file."]; var plistContents = fs.readFileSync(temporaryPlistFilePath, { encoding: "utf8" }); - //var plistContents = FILE.read(temporaryPlistFilePath, { charset: "UTF-8" }); // Minor NS keyed archive to CP keyed archive conversion. // Use Java directly because rhino's string.replace is *so slow*. 4 seconds vs. 1 millisecond.