Skip to content

Commit f768c15

Browse files
committed
Improve implementation by moving new functionality to stratigically better places.
1 parent 6215768 commit f768c15

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface INodePackageManager {
66
cache(packageName: string, version: string, cache?: any): IFuture<IDependencyData>;
77
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
88
view(packageName: string, propertyName: string): IFuture<any>;
9+
executeNpmCommand(npmCommandName: string, currentWorkingDirectory: string): IFuture<void>;
910
}
1011

1112
interface INpmInstallationManager {

lib/node-package-manager.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import Future = require("fibers/future");
55
import npm = require("npm");
66

77
export class NodePackageManager implements INodePackageManager {
8-
constructor(private $logger: ILogger,
8+
constructor(private $childProcess: IChildProcess,
9+
private $logger: ILogger,
910
private $errors: IErrors,
1011
private $fs: IFileSystem,
1112
private $lockfile: ILockFile,
@@ -53,6 +54,12 @@ export class NodePackageManager implements INodePackageManager {
5354
public view(packageName: string, propertyName: string): IFuture<any> {
5455
return this.loadAndExecute("view", [[packageName, propertyName], [false]]);
5556
}
57+
58+
public executeNpmCommand(npmCommandName: string, currentWorkingDirectory: string): IFuture<void> {
59+
return (() => {
60+
this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory }).wait();
61+
}).future<void>()();
62+
}
5663

5764
private loadAndExecute(commandName: string, args: any[], opts?: { config?: any, subCommandName?: string }): IFuture<any> {
5865
return (() => {

lib/services/platform-service.ts

-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ export class PlatformService implements IPlatformService {
178178
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
179179
let tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, PlatformService.TNS_MODULES_FOLDER_NAME);
180180
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, this.$projectData.projectDir, platform, lastModifiedTime).wait();
181-
shell.cp("-Rf", path.join(tnsModulesDestinationPath, constants.TNS_CORE_MODULES_NAME, "*"), tnsModulesDestinationPath);
182-
this.$fs.deleteDirectory(constants.TNS_CORE_MODULES_NAME).wait();
183181

184182
// Process platform specific files
185183
let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);

lib/services/project-service.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export class ProjectService implements IProjectService {
1818
private $projectHelper: IProjectHelper,
1919
private $projectNameValidator: IProjectNameValidator,
2020
private $projectTemplatesService: IProjectTemplatesService,
21-
private $options: IOptions,
22-
private $childProcess: IChildProcess) { }
21+
private $options: IOptions) { }
2322

2423
public createProject(projectName: string): IFuture<void> {
2524
return(() => {
@@ -113,9 +112,7 @@ export class ProjectService implements IProjectService {
113112

114113
this.$projectDataService.initialize(projectDir);
115114
this.$projectDataService.setValue("id", projectId).wait();
116-
//Start child process because --save --save-exact option is necessary when installing tns-core-modules
117-
//in order to create "dependencies" key in package.json.
118-
this.$childProcess.exec("npm install " + constants.TNS_CORE_MODULES_NAME + " --save --save-exact", { cwd: projectDir }).wait();
115+
this.$npm.executeNpmCommand("npm install " + constants.TNS_CORE_MODULES_NAME + " --save --save-exact", projectDir).wait();
119116
}).future<void>()();
120117
}
121118

lib/tools/broccoli/node-modules-dest-copy.ts

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export class DestCopy implements IBroccoliPlugin {
7575
if(isPlugin) {
7676
this.$pluginsService.prepare(dependency).wait();
7777
}
78+
79+
if (dependency.name == constants.TNS_CORE_MODULES_NAME) {
80+
shelljs.cp("-Rf", path.join(this.outputRoot, constants.TNS_CORE_MODULES_NAME, "*"), this.outputRoot);
81+
this.$fs.deleteDirectory(path.join(this.outputRoot, constants.TNS_CORE_MODULES_NAME)).wait();
82+
}
7883
});
7984
}
8085

test/project-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
import yok = require('../lib/common/yok');
5+
import ChildProcessLib = require("../lib/common/child-process");
56
import stubs = require('./stubs');
67

78
import ProjectServiceLib = require("../lib/services/project-service");
@@ -99,7 +100,7 @@ class ProjectIntegrationTest {
99100

100101
private createTestInjector(): void {
101102
this.testInjector = new yok.Yok();
102-
103+
this.testInjector.register("childProcess", ChildProcessLib.ChildProcess);
103104
this.testInjector.register("errors", stubs.ErrorsStub);
104105
this.testInjector.register('logger', stubs.LoggerStub);
105106
this.testInjector.register("projectService", ProjectServiceLib.ProjectService);
@@ -171,6 +172,8 @@ function createTestInjector() {
171172
testInjector.register("httpClient", HttpClientLib.HttpClient);
172173
testInjector.register("config", {});
173174
testInjector.register("lockfile", stubs.LockFile);
175+
176+
testInjector.register("childProcess", ChildProcessLib.ChildProcess);
174177

175178
testInjector.register('projectData', ProjectDataLib.ProjectData);
176179
testInjector.register("options", optionsLib.Options);

0 commit comments

Comments
 (0)