Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ interface IPluginsService {
getAllInstalledPlugins(): IFuture<IPluginData[]>;
ensureAllDependenciesAreInstalled(): IFuture<void>;
afterPrepareAllPlugins(): IFuture<void>;
/**
* Installs all devDependencies of the project.
* In case all of them are already installed, no operation will be executed.
* In case any of them is missing, all of them will be installed.
* @return {IFuture<void>}
*/
installDevDependencies(): IFuture<void>;
}

interface IPluginData extends INodeModuleData {
Expand Down Expand Up @@ -53,6 +60,7 @@ interface IPluginVariablesService {
* @return {IFuture<string>} returns the changed plugin configuration file content.
*/
getPluginVariablePropertyName(pluginData: IPluginData): string;

}

interface IPluginVariableData {
Expand Down
11 changes: 10 additions & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ export class PlatformService implements IPlatformService {
}).future<string[]>()();
}

@helpers.hook('prepare')
public preparePlatform(platform: string): IFuture<void> {
return (() => {
this.validatePlatform(platform);

//Install dev-dependencies here, so before-prepare hooks will be executed correctly.
this.$pluginsService.installDevDependencies().wait();

this.preparePlatformCore(platform).wait();
}).future<void>()();
}

@helpers.hook('prepare')
private preparePlatformCore(platform: string): IFuture<void> {
return (() => {
platform = platform.toLowerCase();
this.ensurePlatformInstalled(platform).wait();

Expand Down
16 changes: 16 additions & 0 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ export class PluginsService implements IPluginsService {
return this.executeForAllInstalledPlatforms(action);
}

public installDevDependencies(): IFuture<void> {
return (() => {
let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : [];
let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
let devDependencies = _.keys(packageJsonContent.devDependencies);
if(devDependencies.length && (this.$options.force || _.difference(devDependencies, installedDependencies).length)) {
let command = `npm install ${devDependencies.join(" ")}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use npm install --development?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, I want only devDependencies to be installed, while npm i --development is installing everything including devDependencies.

if(this.$options.ignoreScripts) {
command += "--ignore-scripts";
}
this.$logger.trace(`Command for installing devDependencies is: '${command}'.`);
this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait();
}
}).future<void>()();
}

private get nodeModulesPath(): string {
return path.join(this.$projectData.projectDir, "node_modules");
}
Expand Down
3 changes: 2 additions & 1 deletion test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function createTestInjector() {
},
ensureAllDependenciesAreInstalled: () => {
return Future.fromResult();
}
},
installDevDependencies: () => Future.fromResult()
});
testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager);
testInjector.register("hooksService", stubs.HooksServiceStub);
Expand Down