Skip to content

Commit

Permalink
Fixes microsoft#279 adding helper that checks if Cordova is namespace…
Browse files Browse the repository at this point in the history
…d by Ionic CLI
  • Loading branch information
neilor committed May 24, 2017
1 parent cfc7d56 commit 5018a47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/debugger/extension.ts
Expand Up @@ -78,6 +78,12 @@ export function cordovaStartCommand(args: string[], cordovaRootPath: string): ch
let cliName = CordovaProjectHelper.isIonicProject(cordovaRootPath) ? 'ionic' : 'cordova';
let commandExtension = os.platform() === 'win32' ? '.cmd' : '';
let command = cliName + commandExtension;

if (CordovaProjectHelper.isIonicCordovaCLINamespacedProject(cordovaRootPath)) {
// add cordova namespace to Ionic projects that uses cli-plugin-cordova
args.unshift('cordova');
}

return child_process.spawn(command, args, { cwd: cordovaRootPath });
}

Expand Down
17 changes: 17 additions & 0 deletions src/utils/cordovaProjectHelper.ts
Expand Up @@ -302,6 +302,23 @@ export class CordovaProjectHelper {
return false;
}

/**
* Helper function to determine whether the project is an Ionic project using cli-plugin-cordova that add Cordova commands to an namespace
*/
public static isIonicCordovaCLINamespacedProject(projectRoot: string): boolean {
// First look if is an Ionic project, because cli-plugin-cordova didn't depend which Ionic version of project
if (CordovaProjectHelper.isIonicProject(projectRoot)) {
const packageJsonPath = path.join(projectRoot, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
return false;
}
const devDependencies = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')).devDependencies;

return !!(devDependencies && devDependencies['@ionic/cli-plugin-cordova']);
}
return false;
}

/**
* Helper function to determine whether the project has a tsconfig.json
* manifest and can be considered as a typescript project.
Expand Down

0 comments on commit 5018a47

Please sign in to comment.