Skip to content

Commit

Permalink
refactor: do not infer project root from script location (apache#1202)
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
  • Loading branch information
erisu and raphinesse authored Nov 22, 2021
1 parent 1dbf072 commit 457bfa0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ function getDefaultSimulatorTarget () {
}

/** @returns {Promise<void>} */
module.exports.run = buildOpts => {
module.exports.run = function (buildOpts) {
const projectPath = this.root;
let emulatorTarget = '';
const projectPath = path.join(__dirname, '..', '..');
let projectName = '';

buildOpts = buildOpts || {};
Expand Down Expand Up @@ -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';

Expand Down
5 changes: 2 additions & 3 deletions bin/templates/scripts/cordova/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions bin/templates/scripts/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>} */
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'));
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 457bfa0

Please sign in to comment.