Skip to content

Commit a70b704

Browse files
committed
Merge pull request #1116 from NativeScript/sd/tsc
`tns install <module>` command should do npm install "nativescript-dev-<module>"
2 parents 14a995a + b979f8d commit a70b704

File tree

9 files changed

+66
-21
lines changed

9 files changed

+66
-21
lines changed

Gruntfile.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = function(grunt) {
5757
}
5858
},
5959
},
60-
60+
6161
tslint: {
6262
build: {
6363
files: {
@@ -68,7 +68,7 @@ module.exports = function(grunt) {
6868
}
6969
}
7070
},
71-
71+
7272
watch: {
7373
devall: {
7474
files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts"],
@@ -80,6 +80,16 @@ module.exports = function(grunt) {
8080
atBegin: true,
8181
interrupt: true
8282
}
83+
},
84+
ts: {
85+
files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts"],
86+
tasks: [
87+
'ts:devall'
88+
],
89+
options: {
90+
atBegin: true,
91+
interrupt: true
92+
}
8393
}
8494
},
8595

@@ -106,7 +116,7 @@ module.exports = function(grunt) {
106116
npm_test: {
107117
command: "npm test"
108118
}
109-
119+
110120
},
111121

112122
copy: {

docs/man_pages/project/configuration/install.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ install
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns install [--path]`
6+
Install all dependencies | `$ tns install [--path]`
7+
Install a selected npm module | `$ tns install <Module>`
8+
Enable TypeScript support | `$ tns install typescript`
79

8-
Installs all platforms and dependencies described in the `package.json` file in the current directory.
10+
Installs all dependencies described in a valid `package.json` or installs a selected NativeScript development module as a dev dependency.
911

10-
<% if(isHtml) { %>
11-
The `package.json` file must be a valid `package.json` describing the configuration of a NativeScript project. If missing or corrupted, you can recreate the file by running `$ tns init` in the directory of a NativeScript project.
12+
<% if(isHtml) { %>
13+
The `package.json` file must be a valid `package.json` describing the configuration of a NativeScript project. If missing or corrupted, you can recreate the file by running `$ tns init` in the directory of a NativeScript project.
1214
<% } %>
1315

1416
### Options
1517
* `--path` - Specifies the directory which contains the `package.json` file, if different from the current directory.
1618

17-
<% if(isHtml) { %>
19+
### Arguments
20+
* `<Module>` - Specifies a NativeScript development module by path to a local directory containing a valid npm module or by name in the npm registry.<% if(isHtml) { %> When a `<Module>` is specified, this command adds the module as a dev dependency in your `package.json`.
21+
22+
> **TIP:** When installing a module from the npm registry, you can specify it by full name or suffix. NativeScript development modules are published in the npm registry with the following name format: `nativescript-dev-<suffix>`.
23+
1824
### Related Commands
1925

2026
Command | Description
@@ -24,4 +30,4 @@ Command | Description
2430
[platform update](platform-update.html) | Updates the NativeScript runtime for the specified platform.
2531
[platform](platform.html) | Lists all platforms that the project currently targets.
2632
[prepare](prepare.html) | Copies common and relevant platform-specific content from the app directory to the subdirectory for the selected target platform in the platforms directory.
27-
<% } %>
33+
<% } %>

lib/commands/install.ts

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
///<reference path="../.d.ts"/>
22
"use strict";
33

4+
import * as path from 'path';
5+
46
export class InstallCommand implements ICommand {
57
constructor(private $platformsData: IPlatformsData,
68
private $platformService: IPlatformService,
79
private $projectData: IProjectData,
810
private $projectDataService: IProjectDataService,
911
private $pluginsService: IPluginsService,
10-
private $logger: ILogger) { }
12+
private $logger: ILogger,
13+
private $fs: IFileSystem,
14+
private $stringParameter: ICommandParameter,
15+
private $npm: INodePackageManager) { }
1116

1217
public enableHooks = false;
1318

14-
public allowedParameters: ICommandParameter[] = [];
19+
public allowedParameters: ICommandParameter[] = [this.$stringParameter];
1520

1621
public execute(args: string[]): IFuture<void> {
22+
return args[0] ? this.installModule(args[0]) : this.installProjectDependencies();
23+
}
24+
25+
private installProjectDependencies(): IFuture<void> {
1726
return (() => {
1827
let error: string = "";
1928

@@ -23,19 +32,33 @@ export class InstallCommand implements ICommand {
2332
_.each(this.$platformsData.platformsNames, platform => {
2433
let platformData = this.$platformsData.getPlatformData(platform);
2534
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
26-
if(frameworkPackageData && frameworkPackageData.version) {
35+
if (frameworkPackageData && frameworkPackageData.version) {
2736
try {
2837
this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`]).wait();
29-
} catch(err) {
38+
} catch (err) {
3039
error += err;
3140
}
3241
}
3342
});
3443

35-
if(error) {
44+
if (error) {
3645
this.$logger.error(error);
3746
}
47+
}).future<void>()();
48+
}
49+
50+
private installModule(moduleName: string): IFuture<void> {
51+
return (() => {
52+
let projectDir = this.$projectData.projectDir;
53+
process.env['TNS_PROJECT_DIR'] = projectDir;
54+
process.env['TNS_HOOKS_DIR'] = path.join(projectDir, 'hooks');
55+
56+
let devPrefix = 'nativescript-dev-';
57+
if (!this.$fs.exists(moduleName).wait() && moduleName.indexOf(devPrefix) !== 0) {
58+
moduleName = devPrefix + moduleName;
59+
}
3860

61+
this.$npm.install(moduleName, projectDir, { 'save-dev': true }).wait();
3962
}).future<void>()();
4063
}
4164
}

lib/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase imple
3737
this.RESOURCE_DIR_PATH = path.join(this.RESOURCE_DIR_PATH, "../../resources");
3838
}
3939

40+
public get disableHooks() {
41+
return true;
42+
}
43+
4044
public get SYS_REQUIREMENTS_LINK(): string {
4145
let linkToSysRequirements: string;
4246
switch(process.platform) {

lib/services/platform-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class PlatformService implements IPlatformService {
1919
private $projectData: IProjectData,
2020
private $projectDataService: IProjectDataService,
2121
private $prompter: IPrompter,
22+
private $hooksService: IHooksService,
2223
private $commandsService: ICommandsService,
2324
private $options: IOptions,
2425
private $broccoliBuilder: IBroccoliBuilder,
@@ -147,6 +148,7 @@ export class PlatformService implements IPlatformService {
147148
}).future<string[]>()();
148149
}
149150

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

test/platform-commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function createTestInjector() {
120120
}
121121
});
122122
testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager);
123+
testInjector.register("hooksService", stubs.HooksServiceStub);
123124

124125
return testInjector;
125126
}

test/platform-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function createTestInjector() {
5252
}
5353
});
5454
testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager);
55+
testInjector.register("hooksService", stubs.HooksServiceStub);
5556

5657
return testInjector;
5758
}

test/stubs.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,11 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
383383
}
384384

385385
export class HooksServiceStub implements IHooksService {
386-
initialize(commandName: string): void {
387-
}
388-
executeBeforeHooks(): IFuture<void> {
389-
return (() => { }).future<void>()();
386+
executeBeforeHooks(commandName: string): IFuture<void> {
387+
return Future.fromResult();
390388
}
391-
executeAfterHooks(): IFuture<void> {
392-
return (() => { }).future<void>()();
389+
executeAfterHooks(commandName: string): IFuture<void> {
390+
return Future.fromResult();
393391
}
394392
}
395393

0 commit comments

Comments
 (0)