Skip to content

Commit 6215768

Browse files
committed
Refactor implementation. Delete unnecessary newly added code fragments.
1 parent adbfe03 commit 6215768

File tree

7 files changed

+15
-52
lines changed

7 files changed

+15
-52
lines changed

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export var APP_RESOURCES_FOLDER_NAME = "App_Resources";
55
export var PROJECT_FRAMEWORK_FOLDER_NAME = "framework";
66
export var NATIVESCRIPT_KEY_NAME = "nativescript";
77
export var NODE_MODULES_FOLDER_NAME = "node_modules";
8+
export var TNS_CORE_MODULES_NAME = "tns-core-modules";
89
export var PACKAGE_JSON_FILE_NAME = "package.json";
910
export var NODE_MODULE_CACHE_PATH_KEY_NAME = "node-modules-cache-path";
1011
export var DEFAULT_APP_IDENTIFIER_PREFIX = "org.nativescript";

lib/declarations.ts

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

8483
interface IProjectFilesManager {

lib/definitions/project.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
interface ITNSModulesService {
2-
tnsModulesInstallationPath(projectRoot: string): IFuture<string>;
3-
npmTnsCoreModulesName: string;
4-
}
51

62
interface IProjectService {
73
createProject(projectName: string): IFuture<void>;

lib/options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ 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 },
31-
tnsModulesVersion: {type: OptionType.String }
30+
ignoreScripts: {type: OptionType.Boolean }
3231
},
3332
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
3433
$errors, $staticConfig);

lib/services/platform-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ 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-
181+
shell.cp("-Rf", path.join(tnsModulesDestinationPath, constants.TNS_CORE_MODULES_NAME, "*"), tnsModulesDestinationPath);
182+
this.$fs.deleteDirectory(constants.TNS_CORE_MODULES_NAME).wait();
183+
182184
// Process platform specific files
183185
let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
184186
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];

lib/services/project-service.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import util = require("util");
1010

1111
export class ProjectService implements IProjectService {
1212

13-
constructor(private $errors: IErrors,
13+
constructor(private $npm: INodePackageManager,
14+
private $errors: IErrors,
1415
private $fs: IFileSystem,
1516
private $logger: ILogger,
1617
private $projectDataService: IProjectDataService,
1718
private $projectHelper: IProjectHelper,
1819
private $projectNameValidator: IProjectNameValidator,
1920
private $projectTemplatesService: IProjectTemplatesService,
2021
private $options: IOptions,
21-
private $tnsModulesService: ITNSModulesService) { }
22+
private $childProcess: IChildProcess) { }
2223

2324
public createProject(projectName: string): IFuture<void> {
2425
return(() => {
@@ -77,21 +78,8 @@ export class ProjectService implements IProjectService {
7778
appPath = defaultTemplatePath;
7879
}
7980

80-
var tnsModulesVersion: string = null;
81-
// Optional parameter has a higher priority than defined version in package.json
82-
if (this.$options.tnsModulesVersion) {
83-
tnsModulesVersion = this.$options.tnsModulesVersion;
84-
}
85-
else {
86-
let coreModulesName = this.$tnsModulesService.npmTnsCoreModulesName;
87-
tnsModulesVersion = this.$fs.readJson(path.join(appPath, constants.PACKAGE_JSON_FILE_NAME)).wait()[coreModulesName]["version"];
88-
}
89-
90-
// Download tns-core-modules via npm and get destination file path
91-
var tnsModulesResourcePath = this.$tnsModulesService.tnsModulesInstallationPath(tnsModulesVersion).wait();
92-
9381
try {
94-
this.createProjectCore(projectDir, appPath, tnsModulesResourcePath, projectId).wait();
82+
this.createProjectCore(projectDir, appPath, projectId).wait();
9583
} catch (err) {
9684
this.$fs.deleteDirectory(projectDir).wait();
9785
throw err;
@@ -102,7 +90,7 @@ export class ProjectService implements IProjectService {
10290
}).future<void>()();
10391
}
10492

105-
private createProjectCore(projectDir: string, appSourcePath: string, tnsModulesPath: string, projectId: string): IFuture<void> {
93+
private createProjectCore(projectDir: string, appSourcePath: string, projectId: string): IFuture<void> {
10694
return (() => {
10795
this.$fs.ensureDirectoryExists(projectDir).wait();
10896

@@ -114,25 +102,20 @@ export class ProjectService implements IProjectService {
114102
} else {
115103
shell.cp('-R', path.join(appSourcePath, "*"), appDestinationPath);
116104
}
117-
118-
// Copy tns-core-modules package to node_modules destination directory
119-
let nodeModulesDestination = path.join(appDestinationPath, constants.NODE_MODULES_FOLDER_NAME);
120-
this.$fs.ensureDirectoryExists(nodeModulesDestination).wait();
121-
shell.cp('-Rf', path.join(tnsModulesPath, '*'), nodeModulesDestination);
122-
123-
let tnsModulesVersion = this.$fs.readJson(path.join(nodeModulesDestination, constants.PACKAGE_JSON_FILE_NAME)).wait().version;
124105

125-
this.createBasicProjectStructure(projectDir, projectId, tnsModulesVersion).wait();
106+
this.createBasicProjectStructure(projectDir, projectId).wait();
126107
}).future<void>()();
127108
}
128109

129-
private createBasicProjectStructure(projectDir: string, projectId: string, tnsModulesVersion: string): IFuture<void> {
110+
private createBasicProjectStructure(projectDir: string, projectId: string): IFuture<void> {
130111
return (() => {
131112
this.$fs.createDirectory(path.join(projectDir, "platforms")).wait();
132113

133114
this.$projectDataService.initialize(projectDir);
134115
this.$projectDataService.setValue("id", projectId).wait();
135-
this.$projectDataService.setValue(this.$tnsModulesService.npmTnsCoreModulesName, { version: tnsModulesVersion }).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();
136119
}).future<void>()();
137120
}
138121

lib/services/tns-modules-service.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)