From ed4b4bf3e63d47bdccccfa041469988d8e0a8147 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 2 Aug 2018 18:43:47 +0300 Subject: [PATCH] fix: remove keys from package.json after project is created Remove confusing keys from project's package.json when Template v2 is used. Remove `name` and `version` as the users may decide we will use the values to set project name and version of the application. --- lib/constants.ts | 1 + lib/services/project-service.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/constants.ts b/lib/constants.ts index 000205df55..d2a96c0d06 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -54,6 +54,7 @@ export class LiveSyncTrackActionNames { } export const PackageJsonKeysToKeep: Array = ["name", "main", "android", "version", "pluginsData"]; +export const TemplatesV2PackageJsonKeysToRemove: Array = ["name", "version", "displayName", "templateType", "author", "keywords", "homepage", "bugs"]; export class SaveOptions { static PRODUCTION = "save"; diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index acea014f6d..8e5addb6b0 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as shelljs from "shelljs"; import { format } from "util"; import { exported } from "../common/decorators"; -import { Hooks } from "../constants"; +import { Hooks, TemplatesV2PackageJsonKeysToRemove } from "../constants"; export class ProjectService implements IProjectService { @@ -212,7 +212,7 @@ export class ProjectService implements IProjectService { const packageJsonData = this.$fs.readJson(projectFilePath); // Remove the metadata keys from the package.json - let updatedPackageJsonData = _.omitBy(packageJsonData, (value: any, key: string) => _.startsWith(key, "_")); + let updatedPackageJsonData = _.omitBy(packageJsonData, (value: any, key: string) => _.startsWith(key, "_") || TemplatesV2PackageJsonKeysToRemove.indexOf(key) !== -1); updatedPackageJsonData = _.merge(updatedPackageJsonData, this.packageJsonDefaultData); if (updatedPackageJsonData.nativescript && updatedPackageJsonData.nativescript.templateVersion) {