Skip to content

Commit

Permalink
fix(start): run diez using package manager wrappers
Browse files Browse the repository at this point in the history
This will increase compatibility across different OS since we delegate
the handling of paths to the package manager.
  • Loading branch information
roperzh committed Feb 7, 2020
1 parent 80ddf66 commit edcf09b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/cli/cli-core/src/package-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {spawn, SpawnOptions, spawnSync} from 'child_process';
import {execSync, ExecSyncOptions, spawn, SpawnOptions, spawnSync} from 'child_process';
import {PackageManagerCommands, PackageManagers} from './api';
import {canRunCommand} from './utils';

Expand Down Expand Up @@ -48,10 +48,12 @@ const commands: PackageManagerCommands = {
[PackageManagers.Npm]: {
addDependency: 'install',
installAllDependencies: 'install',
execBinary: 'npx',
},
[PackageManagers.Yarn]: {
addDependency: 'add',
installAllDependencies: 'install',
execBinary: 'yarn',
},
};

Expand All @@ -76,8 +78,8 @@ export class PackageManager {
/**
* Installs all the dependencies listed in package.json.
*/
installAllDependencies (options?: SpawnOptions) {
return this.exec([this.commands.installAllDependencies], options);
installAllDependencies (options?: ExecSyncOptions) {
return execSync(`${this.binary} ${this.commands.installAllDependencies}`, options);
}

/**
Expand All @@ -96,6 +98,10 @@ export class PackageManager {
});
});
}

execBinary (command: string, options?: ExecSyncOptions) {
execSync(`${this.commands.execBinary} ${command}`, options);
}
}

let packageManager: PackageManager;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/start/src/index.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ export = async (_: {}, target: Target) => {
const guideUrl = guideUrls[target];
switch (target) {
case Target.Android:
execSync(`${diez} compile -t android`, {stdio: 'inherit'});
packageManager.execBinary('diez compile -t android', {stdio: 'inherit'});
Log.comment('Starting the Diez hot server...');
hotProcess = fork(diez, ['hot', '-t', 'android'], {stdio: 'inherit'});
break;
case Target.Ios:
execSync(`${diez} compile -t ios --cocoapods`, {stdio: 'inherit'});
packageManager.execBinary('diez compile -t ios --cocoapods', {stdio: 'inherit'});
Log.comment('Installing CocoaPods dependencies in example codebase...');
execSync('pod install', {cwd: targetRoot, stdio: 'inherit'});
Log.comment('Starting the Diez hot server...');
hotProcess = fork(diez, ['hot', '-t', 'ios'], {stdio: 'inherit'});
break;
case Target.Web:
execSync(`${diez} compile -t web`, {stdio: 'inherit'});
packageManager.execBinary('diez compile -t web', {stdio: 'inherit'});
Log.comment('Installing Node dependencies in example codebase...');
await packageManager.installAllDependencies({cwd: targetRoot, stdio: 'inherit'});
Log.comment('Starting the Diez hot server...');
Expand Down

0 comments on commit edcf09b

Please sign in to comment.