8000 Fix android custom platform template installation. (#2504) · NativeScript/nativescript-cli@39f4010 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 39f4010

Browse files
authored
Fix android custom platform template installation. (#2504)
1 parent 7a481be commit 39f4010

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/node-package-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export class NodePackageManager implements INodePackageManager {
2323
config = config || {};
2424
config["ignore-scripts"] = true;
2525
}
26+
let packageJsonPath = path.join(pathToSave, "package.json");
2627

27-
let jsonContentBefore = this.$fs.readJson(path.join(pathToSave, "package.json"));
28+
let jsonContentBefore = this.$fs.readJson(packageJsonPath);
2829
let dependenciesBefore = _.keys(jsonContentBefore.dependencies).concat(_.keys(jsonContentBefore.devDependencies));
2930

3031
let flags = this.getFlagsString(config, true);

lib/services/platform-service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ export class PlatformService implements IPlatformService {
134134
}
135135
this.$projectDataService.setValue(platformData.frameworkPackageName, frameworkPackageNameData);
136136

137+
if (pathToTemplate) {
138+
let installedTemplateName = path.basename(pathToTemplate);
139+
if (coreModuleName !== installedTemplateName) {
140+
this.$npm.uninstall(installedTemplateName, { save: true }).wait();
141+
}
142+
}
143+
137144
return coreModuleName;
138145

139146
}).future<string>()();
@@ -149,7 +156,6 @@ export class PlatformService implements IPlatformService {
149156
}
150157

151158
if (selectedTemplate) {
152-
let tempDir = temp.mkdirSync("platform-template");
153159
try {
154160
/*
155161
* Output of npm.install is array of arrays. For example:
@@ -160,8 +166,8 @@ export class PlatformService implements IPlatformService {
160166
* '..\\..\\..\\android-platform-template' ] ]
161167
* Project successfully created.
162168
*/
163-
let pathToTemplate = this.$npm.install(selectedTemplate, tempDir).wait()[0];
164-
return { selectedTemplate, pathToTemplate };
169+
let templateName = this.$npm.install(selectedTemplate, this.$projectData.projectDir, { save: true }).wait()[0];
170+
return { selectedTemplate, pathToTemplate: path.join(this.$projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME, templateName) };
165171
} catch (err) {
166172
this.$logger.trace("Error while trying to install specified template: ", err);
167173
this.$errors.failWithoutHelp(`Unable to install platform template ${selectedTemplate}. Make sure the specified value is valid.`);
@@ -348,7 +354,7 @@ export class PlatformService implements IPlatformService {
348354
}
349355
let platformData = this.$platformsData.getPlatformData(platform);
350356
let forDevice = !buildConfig || buildConfig.buildForDevice;
351-
let outputPath = forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
357+
let outputPath = forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
352358
if (!this.$fs.exists(outputPath)) {
353359
return true;
354360
}
@@ -484,7 +490,7 @@ export class PlatformService implements IPlatformService {
484490
this.$devicesService.initialize({ platform: platform, deviceId: this.$options.device }).wait();
485491
let found: Mobile.IDeviceInfo[] = [];
486492
if (this.$devicesService.hasDevices) {
487-
found = this.$devicesService.getDevices().filter((device:Mobile.IDeviceInfo) => device.identifier === this.$options.device);
493+
found = this.$devicesService.getDevices().filter((device: Mobile.IDeviceInfo) => device.identifier === this.$options.device);
488494
}
489495
if (found.length === 0) {
490496
this.$errors.fail("Cannot find device with name: %s", this.$options.device);
@@ -514,7 +520,7 @@ export class PlatformService implements IPlatformService {
514520
let deviceFilePath = this.getDeviceBuildInfoFilePath(device);
515521
try {
516522
return JSON.parse(this.readFile(device, deviceFilePath).wait());
517-
} catch(e) {
523+
} catch (e) {
518524
return null;
519525
};
520526
}).future<IBuildInfo>()();
@@ -527,7 +533,7 @@ export class PlatformService implements IPlatformService {
527533
try {
528534
let buildInfoTime = this.$fs.readJson(buildInfoFile);
529535
return buildInfoTime;
530-
} catch(e) {
536+
} catch (e) {
531537
return null;
532538
}
533539
}

0 commit comments

Comments
 (0)
0