Skip to content

Commit 62d543e

Browse files
committed
Use npm to fetch tns-core-modules package. Create tns_modules from tns-core-modules package.
1 parent 5895849 commit 62d543e

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $injector.require("androidProjectService", "./services/android-project-service")
1111
$injector.require("iOSProjectService", "./services/ios-project-service");
1212

1313
$injector.require("projectTemplatesService", "./services/project-templates-service");
14+
$injector.require("tnsModulesService", "./services/tns-modules-service");
1415

1516
$injector.require("platformsData", "./platforms-data");
1617
$injector.require("platformService", "./services/platform-service");

lib/declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ interface IOptions extends ICommonOptions {
7878
keyStoreAliasPassword: string;
7979
sdk: string;
8080
ignoreScripts: boolean;
81+
tnsModulesVersion: string;
8182
}
8283

8384
interface IProjectFilesManager {

lib/definitions/project.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
interface ITNSModulesService {
2+
tnsModulesInstallationPath(projectRoot: string): IFuture<string>;
3+
NPM_TNS_CORE_MODULES_NAME: string;
4+
}
5+
16
interface IProjectService {
27
createProject(projectName: string): IFuture<void>;
38
}

lib/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
2727
keyStoreAlias: { type: OptionType.String },
2828
keyStoreAliasPassword: { type: OptionType.String },
2929
sdk: { type: OptionType.String },
30-
ignoreScripts: {type: OptionType.Boolean }
30+
ignoreScripts: {type: OptionType.Boolean },
31+
tnsModulesVersion: {type: OptionType.String }
3132
},
3233
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
3334
$errors, $staticConfig);

lib/services/project-service.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class ProjectService implements IProjectService {
1717
private $projectHelper: IProjectHelper,
1818
private $projectNameValidator: IProjectNameValidator,
1919
private $projectTemplatesService: IProjectTemplatesService,
20-
private $options: IOptions) { }
20+
private $options: IOptions,
21+
private $tnsModulesService: ITNSModulesService) { }
2122

2223
public createProject(projectName: string): IFuture<void> {
2324
return(() => {
@@ -75,21 +76,23 @@ export class ProjectService implements IProjectService {
7576
this.$logger.trace("Copying NativeScript hello world application into %s", appDirectory);
7677
appPath = defaultTemplatePath;
7778
}
79+
80+
// Download tns-core-modules via npm and get destination file path
81+
var tnsModulesResourcePath = this.$tnsModulesService.tnsModulesInstallationPath(tnsModulesVersion).wait();
7882

7983
try {
80-
this.createProjectCore(projectDir, appPath, projectId).wait();
84+
this.createProjectCore(projectDir, appPath, tnsModulesResourcePath, projectId).wait();
8185
} catch (err) {
8286
this.$fs.deleteDirectory(projectDir).wait();
8387
throw err;
8488
}
8589

86-
8790
this.$logger.out("Project %s was successfully created", projectName);
8891

8992
}).future<void>()();
9093
}
9194

92-
private createProjectCore(projectDir: string, appSourcePath: string, projectId: string): IFuture<void> {
95+
private createProjectCore(projectDir: string, appSourcePath: string, tnsModulesPath: string, projectId: string): IFuture<void> {
9396
return (() => {
9497
this.$fs.ensureDirectoryExists(projectDir).wait();
9598

@@ -101,16 +104,25 @@ export class ProjectService implements IProjectService {
101104
} else {
102105
shell.cp('-R', path.join(appSourcePath, "*"), appDestinationPath);
103106
}
104-
this.createBasicProjectStructure(projectDir, projectId).wait();
107+
108+
// Copy tns-core-modules package to node_modules destination directory
109+
var nodeModulesDestination = path.join(appDestinationPath, constants.NODE_MODULES_FOLDER_NAME);
110+
this.$fs.ensureDirectoryExists(nodeModulesDestination).wait();
111+
shell.cp('-Rf', path.join(tnsModulesPath, '*'), nodeModulesDestination);
112+
113+
var tnsModulesVersion = this.$fs.readJson(path.join(nodeModulesDestination, constants.PACKAGE_JSON_FILE_NAME)).wait().version;
114+
115+
this.createBasicProjectStructure(projectDir, projectId, tnsModulesVersion).wait();
105116
}).future<void>()();
106117
}
107118

108-
private createBasicProjectStructure(projectDir: string, projectId: string): IFuture<void> {
119+
private createBasicProjectStructure(projectDir: string, projectId: string, tnsModulesVersion: string): IFuture<void> {
109120
return (() => {
110121
this.$fs.createDirectory(path.join(projectDir, "platforms")).wait();
111122

112123
this.$projectDataService.initialize(projectDir);
113124
this.$projectDataService.setValue("id", projectId).wait();
125+
this.$projectDataService.setValue(this.$tnsModulesService.NPM_TNS_CORE_MODULES_NAME, { version: tnsModulesVersion }).wait();
114126
}).future<void>()();
115127
}
116128

lib/services/tns-modules-service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import util = require("util");
5+
import path = require("path");
6+
import shell = require("shelljs");
7+
import npm = require("npm");
8+
var helpers = require("../common/helpers");
9+
import Future = require("fibers/future");
10+
11+
export class TNSModulesService implements ITNSModulesService {
12+
private static NPM_TNS_CORE_MODULES_NAME = "tns-core-modules";
13+
14+
public constructor(private $npmInstallationManager: INpmInstallationManager) { }
15+
16+
public tnsModulesInstallationPath(version: string): IFuture<string> {
17+
return this.$npmInstallationManager.install(TNSModulesService.NPM_TNS_CORE_MODULES_NAME, version);
18+
}
19+
20+
public get NPM_TNS_CORE_MODULES_NAME(): string {
21+
return TNSModulesService.NPM_TNS_CORE_MODULES_NAME;
22+
}
23+
}
24+
$injector.register("tnsModulesService", TNSModulesService);

0 commit comments

Comments
 (0)