diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 1b5d33e4b..180346f5d 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -73,7 +73,7 @@ class Api { constructor (platform, platformRootDir, events) { // 'platform' property is required as per PlatformApi spec this.platform = platform || 'ios'; - this.root = platformRootDir || path.resolve(__dirname, '..'); + this.root = platformRootDir; setupEvents(events); diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 0dedbebe2..0e00aa9a1 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -85,9 +85,9 @@ function getDefaultSimulatorTarget () { } /** @returns {Promise} */ -module.exports.run = buildOpts => { +module.exports.run = function (buildOpts) { + const projectPath = this.root; let emulatorTarget = ''; - const projectPath = path.join(__dirname, '..', '..'); let projectName = ''; buildOpts = buildOpts || {}; @@ -192,7 +192,7 @@ module.exports.run = buildOpts => { writeCodeSignStyle('Automatic'); } - return fs.writeFile(path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8'); + return fs.writeFile(path.join(projectPath, 'cordova/build-extras.xcconfig'), extraConfig, 'utf-8'); }).then(() => { const configuration = buildOpts.release ? 'Release' : 'Debug'; diff --git a/bin/templates/scripts/cordova/lib/clean.js b/bin/templates/scripts/cordova/lib/clean.js index 821c7ea79..38748559e 100644 --- a/bin/templates/scripts/cordova/lib/clean.js +++ b/bin/templates/scripts/cordova/lib/clean.js @@ -22,9 +22,8 @@ const fs = require('fs-extra'); const execa = require('execa'); const { CordovaError } = require('cordova-common'); -const projectPath = path.join(__dirname, '..', '..'); - -module.exports.run = () => { +module.exports.run = function () { + const projectPath = this.root; const projectName = fs.readdirSync(projectPath).filter(name => path.extname(name) === '.xcodeproj'); if (!projectName) { diff --git a/bin/templates/scripts/cordova/lib/run.js b/bin/templates/scripts/cordova/lib/run.js index 6ae7427d4..678bd130b 100644 --- a/bin/templates/scripts/cordova/lib/run.js +++ b/bin/templates/scripts/cordova/lib/run.js @@ -24,11 +24,10 @@ const { CordovaError, events } = require('cordova-common'); const check_reqs = require('./check_reqs'); const fs = require('fs-extra'); -const cordovaPath = path.join(__dirname, '..'); -const projectPath = path.join(__dirname, '..', '..'); - /** @returns {Promise} */ -module.exports.run = runOptions => { +module.exports.run = function (runOptions) { + const projectPath = this.root; + // Validate args if (runOptions.device && runOptions.emulator) { return Promise.reject(new CordovaError('Only one of "device"/"emulator" options should be specified')); @@ -185,7 +184,8 @@ async function deployToSim (appPath, target) { } function startSim (appPath, target) { - const logPath = path.join(cordovaPath, 'console.log'); + const projectPath = path.join(path.dirname(appPath), '../..'); + const logPath = path.join(projectPath, 'cordova/console.log'); const deviceTypeId = `com.apple.CoreSimulator.SimDeviceType.${target}`; const subprocess = execa( diff --git a/tests/spec/create.spec.js b/tests/spec/create.spec.js index c8da4acce..63a08156e 100644 --- a/tests/spec/create.spec.js +++ b/tests/spec/create.spec.js @@ -66,7 +66,7 @@ function verifyProjectBundleIdentifier (tmpDir, projectName, expectedBundleIdent function verifyBuild (tmpDir) { const Api = require(path.join(tmpDir, 'cordova/Api.js')); - return expectAsync(new Api().build({ emulator: true })) + return expectAsync(new Api('ios', tmpDir).build({ emulator: true })) .toBeResolved(); }