@@ -25,7 +25,6 @@ import {
2525 IErrors ,
2626 IFileSystem ,
2727 IProjectHelper ,
28- IStringDictionary ,
2928 IChildProcess ,
3029} from "../common/declarations" ;
3130import * as _ from "lodash" ;
@@ -188,7 +187,7 @@ export class ProjectService implements IProjectService {
188187
189188 await this . extractTemplate ( projectDir , templateData ) ;
190189
191- this . alterPackageJsonData ( projectDir , appId ) ;
190+ this . alterPackageJsonData ( projectCreationSettings ) ;
192191 this . $projectConfigService . writeDefaultConfig ( projectDir , appId ) ;
193192
194193 await this . ensureAppResourcesExist ( projectDir ) ;
@@ -256,30 +255,45 @@ export class ProjectService implements IProjectService {
256255 }
257256
258257 @performanceLog ( )
259- private alterPackageJsonData ( projectDir : string , appId : string ) : void {
258+ private alterPackageJsonData (
259+ projectCreationSettings : IProjectCreationSettings
260+ ) : void {
261+ const { projectDir, projectName } = projectCreationSettings ;
260262 const projectFilePath = path . join (
261263 projectDir ,
262264 this . $staticConfig . PROJECT_FILE_NAME
263265 ) ;
264266
265267 let packageJsonData = this . $fs . readJson ( projectFilePath ) ;
266268
267- packageJsonData = {
268- ...packageJsonData ,
269- ...this . packageJsonDefaultData ,
269+ // clean up keys from the template package.json that we don't care about.
270+ Object . keys ( packageJsonData ) . forEach ( ( key ) => {
271+ if (
272+ key . startsWith ( "_" ) ||
273+ constants . TemplatesV2PackageJsonKeysToRemove . includes ( key )
274+ ) {
275+ delete packageJsonData [ key ] ;
276+ }
277+ } ) ;
278+
279+ // this is used to ensure the order of keys is consistent, the blanks are filled in from the template
280+ const packageJsonSchema = {
281+ name : projectName ,
282+ main : "" ,
283+ version : "1.0.0" ,
284+ private : true ,
285+ dependencies : { } ,
286+ devDependencies : { } ,
287+ // anythign else would go below
270288 } ;
271289
272- this . $fs . writeJson ( projectFilePath , packageJsonData ) ;
273- }
290+ packageJsonData = Object . assign ( packageJsonSchema , packageJsonData ) ;
274291
275- private get packageJsonDefaultData ( ) : IStringDictionary {
276- return {
277- private : "true" ,
278- description : "NativeScript Application" ,
279- license : "SEE LICENSE IN <your-license-filename>" ,
280- readme : "NativeScript Application" ,
281- repository : "<fill-your-repository-here>" ,
282- } ;
292+ console . log ( {
293+ packageJsonData,
294+ } ) ;
295+
296+ this . $fs . writeJson ( projectFilePath , packageJsonData ) ;
283297 }
284298}
285299
0 commit comments