@@ -25,7 +25,6 @@ import {
25
25
IErrors ,
26
26
IFileSystem ,
27
27
IProjectHelper ,
28
- IStringDictionary ,
29
28
IChildProcess ,
30
29
} from "../common/declarations" ;
31
30
import * as _ from "lodash" ;
@@ -188,7 +187,7 @@ export class ProjectService implements IProjectService {
188
187
189
188
await this . extractTemplate ( projectDir , templateData ) ;
190
189
191
- this . alterPackageJsonData ( projectDir , appId ) ;
190
+ this . alterPackageJsonData ( projectCreationSettings ) ;
192
191
this . $projectConfigService . writeDefaultConfig ( projectDir , appId ) ;
193
192
194
193
await this . ensureAppResourcesExist ( projectDir ) ;
@@ -256,30 +255,45 @@ export class ProjectService implements IProjectService {
256
255
}
257
256
258
257
@performanceLog ( )
259
- private alterPackageJsonData ( projectDir : string , appId : string ) : void {
258
+ private alterPackageJsonData (
259
+ projectCreationSettings : IProjectCreationSettings
260
+ ) : void {
261
+ const { projectDir, projectName } = projectCreationSettings ;
260
262
const projectFilePath = path . join (
261
263
projectDir ,
262
264
this . $staticConfig . PROJECT_FILE_NAME
263
265
) ;
264
266
265
267
let packageJsonData = this . $fs . readJson ( projectFilePath ) ;
266
268
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
270
288
} ;
271
289
272
- this . $fs . writeJson ( projectFilePath , packageJsonData ) ;
273
- }
290
+ packageJsonData = Object . assign ( packageJsonSchema , packageJsonData ) ;
274
291
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 ) ;
283
297
}
284
298
}
285
299
0 commit comments