From 72b69658622ce48ea6b004b5c1457cff14154f01 Mon Sep 17 00:00:00 2001 From: Mitko-Kerezov Date: Mon, 8 Feb 2016 14:11:12 +0200 Subject: [PATCH] Use spawn wherever possible Wherever possible use `spawn` instead of `exec`. This minifies the chance of something going wrong wherever there are spaces, quotation marks and whatnots in the project's name. Addresses https://github.com/NativeScript/nativescript-cli/issues/1455 --- lib/services/ios-project-service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index aea0609113..c3208b333b 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -268,7 +268,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ let project = this.createPbxProj(); let frameworkName = path.basename(frameworkPath, path.extname(frameworkPath)); let frameworkBinaryPath = path.join(frameworkPath, frameworkName); - let isDynamic = _.contains(this.$childProcess.exec(`otool -Vh ${frameworkBinaryPath}`).wait(), " DYLIB "); + let isDynamic = _.contains(this.$childProcess.spawnFromEvent("otool", ["-Vh", frameworkBinaryPath], "close").wait().stdout, " DYLIB "); let frameworkAddOptions: xcode.Options = { customFramework: true }; @@ -577,7 +577,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.$errors.failWithoutHelp("The bundle at %s does not contain an Info.plist file.", libraryPath); } - let packageType = this.$childProcess.exec(`/usr/libexec/PlistBuddy -c "Print :CFBundlePackageType" "${infoPlistPath}"`).wait().trim(); + let packageType = this.$childProcess.spawnFromEvent("/usr/libexec/PlistBuddy", ["-c", "Print :CFBundlePackageType", infoPlistPath], "close").wait().stdout.trim(); if (packageType !== "FMWK") { this.$errors.failWithoutHelp("The bundle at %s does not appear to be a dynamic framework.", libraryPath); } @@ -762,7 +762,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.$fs.writeFile(projectFile, "").wait(); } - let mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${projectFile}').merge(Xcodeproj::Config.new('${pluginFile}')).save_as(Pathname.new('${projectFile}'))`; + let escapedProjectFile = projectFile.replace(/'/g, "\\'"), + escapedPluginFile = pluginFile.replace(/'/g, "\\'"), + mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${escapedProjectFile}').merge(Xcodeproj::Config.new('${escapedPluginFile}')).save_as(Pathname.new('${escapedProjectFile}'))`; this.$childProcess.exec(`ruby -e "${mergeScript}"`).wait(); }).future()(); }