@@ -12,12 +12,12 @@ module.exports = (api, options, rootOptions) => {
12
12
console . log ( 'usingTS - ' , api . hasPlugin ( 'typescript' ) )
13
13
console . log ( 'usingBabel - ' , api . hasPlugin ( 'babel' ) )
14
14
15
- const existingDirPath = './example/' ;
16
- const jsOrTs = api . hasPlugin ( 'typescript' ) ? 'ts' : 'js'
15
+ const existingDirPath = './ns- example/' ;
16
+ const jsOrTs = api . hasPlugin ( 'typescript' ) ? '. ts' : '. js'
17
17
18
18
const srcfiles = [
19
- 'router.' + jsOrTs ,
20
- 'main.' + jsOrTs ,
19
+ 'router.js' ,
20
+ 'main.js' ,
21
21
'App.vue' ,
22
22
'views/About.vue' ,
23
23
'views/Home.vue' ,
@@ -27,7 +27,7 @@ module.exports = (api, options, rootOptions) => {
27
27
28
28
const appfiles = [
29
29
'package.json' ,
30
- 'main.' + jsOrTs ,
30
+ 'main.js' ,
31
31
'App.native.vue' ,
32
32
'App.ios.vue' ,
33
33
'App.android.vue' ,
@@ -97,9 +97,19 @@ module.exports = (api, options, rootOptions) => {
97
97
'nativescript-vue-template-compiler' : '^2.0.2' ,
98
98
'nativescript-worker-loader' : '~0.9.1' ,
99
99
'replace-in-file' : '^3.4.2' ,
100
+ 'tns-platform-declarations' : '^5.0.2' ,
100
101
}
101
102
} )
102
103
104
+ if ( api . hasPlugin ( 'typescript' ) ) {
105
+ // api.extendPackage({
106
+ // dependencies: {
107
+ // },
108
+ // devDependencies: {
109
+ // }
110
+ // })
111
+ }
112
+
103
113
// if the project is using babel, then load appropriate packages
104
114
if ( api . hasPlugin ( 'babel' ) ) {
105
115
api . extendPackage ( {
@@ -144,8 +154,8 @@ module.exports = (api, options, rootOptions) => {
144
154
// New Project and not using Nativescript-Vue-Web
145
155
if ( ! options . isNVW && ! options . isNativeOnly ) {
146
156
147
- renderFilesIndividually ( api , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , './src/' ) ;
148
- renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './app/' ) ;
157
+ renderFilesIndividually ( api , jsOrTs , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , './src/' ) ;
158
+ renderFilesIndividually ( api , jsOrTs , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './app/' ) ;
149
159
150
160
vueRouterSetup ( api , './' , jsOrTs ) ;
151
161
vuexSetup ( api , './' , jsOrTs ) ;
@@ -158,7 +168,7 @@ module.exports = (api, options, rootOptions) => {
158
168
159
169
// New Project & Native Only -- should never be able to use Nativescript-Vue-Web
160
170
if ( ! options . isNVW && options . isNativeOnly ) {
161
- renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './app/' ) ;
171
+ renderFilesIndividually ( api , jsOrTs , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './app/' ) ;
162
172
}
163
173
164
174
if ( options . isNativeOnly && options . isNVW ) {
@@ -179,8 +189,8 @@ module.exports = (api, options, rootOptions) => {
179
189
180
190
// Existing Project and not using Nativescript-Vue-Web
181
191
if ( ! options . isNVW && ! options . isNativeOnly ) {
182
- renderFilesIndividually ( api , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , existingDirPath + 'src/' ) ;
183
- renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , existingDirPath + 'app/' ) ;
192
+ renderFilesIndividually ( api , jsOrTs , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , existingDirPath + 'src/' ) ;
193
+ renderFilesIndividually ( api , jsOrTs , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , existingDirPath + 'app/' ) ;
184
194
185
195
vueRouterSetup ( api , existingDirPath , jsOrTs ) ;
186
196
vuexSetup ( api , existingDirPath , jsOrTs ) ;
@@ -193,7 +203,7 @@ module.exports = (api, options, rootOptions) => {
193
203
194
204
// Existing Project & Native Only -- should never be able to use Nativescript-Vue-Web
195
205
if ( ! options . isNVW && options . isNativeOnly ) {
196
- renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , existingDirPath + 'app/' ) ;
206
+ renderFilesIndividually ( api , jsOrTs , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , existingDirPath + 'app/' ) ;
197
207
}
198
208
199
209
if ( options . isNVW && options . isNativeOnly ) {
@@ -217,11 +227,11 @@ module.exports = (api, options, rootOptions) => {
217
227
218
228
if ( options . isNewProject ) {
219
229
writeEnvFiles ( './' )
220
- nsconfigSetup ( api . resolve ( 'nsconfig.json' ) ) ;
230
+ nsconfigSetup ( './' , api . resolve ( 'nsconfig.json' ) ) ;
221
231
222
- if ( hasPlugin ( 'typescript' ) ) {
223
- tsconfigSetup ( api . resolve ( 'tsconfig.json' ) ) ;
224
- tslintSetup ( api . resolve ( 'tslint.json' ) ) ;
232
+ if ( api . hasPlugin ( 'typescript' ) ) {
233
+ tsconfigSetup ( api , './' , api . resolve ( 'tsconfig.json' ) ) ;
234
+ tslintSetup ( './' , api . resolve ( 'tslint.json' ) ) ;
225
235
}
226
236
227
237
// for new projects that are native only, move files/dirs and delete others
@@ -255,12 +265,11 @@ module.exports = (api, options, rootOptions) => {
255
265
256
266
} else {
257
267
writeEnvFiles ( existingDirPath )
258
- nsconfigSetup ( api . resolve ( existingDirPath + 'nsconfig.json' ) ) ;
268
+ nsconfigSetup ( existingDirPath , api . resolve ( 'nsconfig.json' ) ) ;
259
269
260
- if ( hasPlugin ( 'typescript' ) ) {
261
- tsconfigSetup ( api . resolve ( existingDirPath + 'tsconfig.json' ) ) ;
262
- tslintSetup ( api . resolve ( existingDirPath + 'tslint.json' ) ) ;
263
-
270
+ if ( api . hasPlugin ( 'typescript' ) ) {
271
+ tsconfigSetup ( api , existingDirPath , api . resolve ( 'tsconfig.json' ) ) ;
272
+ tslintSetup ( existingDirPath , api . resolve ( 'tslint.json' ) ) ;
264
273
}
265
274
266
275
@@ -401,7 +410,7 @@ const gitignoreAdditions = module.exports.gitignoreAdditions = async (api) => {
401
410
}
402
411
403
412
// setup nsconfig.json file
404
- const nsconfigSetup = module . exports . nsconfigSetup = async ( nsconfigPath ) => {
413
+ const nsconfigSetup = module . exports . nsconfigSetup = async ( existingDirPath , nsconfigPath ) => {
405
414
let nsconfigContent = '' ;
406
415
407
416
try {
@@ -414,7 +423,7 @@ const nsconfigSetup = module.exports.nsconfigSetup = async (nsconfigPath) => {
414
423
nsconfigContent . appPath = 'app' ;
415
424
nsconfigContent . appResourcesPath = 'app/App_Resources'
416
425
417
- fs . writeFileSync ( nsconfigPath , JSON . stringify ( nsconfigContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
426
+ fs . writeFileSync ( existingDirPath + 'nsconfig.json' , JSON . stringify ( nsconfigContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
418
427
if ( err ) console . error ( err )
419
428
} ) ;
420
429
@@ -426,32 +435,29 @@ const nsconfigSetup = module.exports.nsconfigSetup = async (nsconfigPath) => {
426
435
}
427
436
428
437
// setup tsconfigSetup
429
- const tsconfigSetup = module . exports . tsconfigSetup = async ( tsconfigPath ) => {
430
- let tsconfigContent = '' ;
438
+ const tsconfigSetup = module . exports . tsconfigSetup = async ( api , existingDirPath , tsconfigPath ) => {
439
+ let tsconfigContent = { } ;
431
440
432
441
try {
442
+
433
443
if ( fs . existsSync ( tsconfigPath ) ) {
434
- tsconfigContent = JSON . parse ( fs . readFileSync ( tsconfigPath , { encoding : 'utf8' } ) ) ;
444
+ tsconfigContent = JSON . parse ( fs . readFileSync ( tsconfigPath , 'utf8' ) ) ;
435
445
} else {
436
446
tsconfigContent = { } ;
437
447
}
438
448
439
- delete tsconfigContent . paths [ '@/*' ] ;
440
- tsconfigContent . paths [ '~/*' ] = "src/*" ;
441
- tsconfigContent . paths [ 'src/*' ] = "src/*" ;
442
- tsconfigContent . paths [ 'assets/*' ] = "src/assets/*" ;
443
- tsconfigContent . paths [ 'fonts/*' ] = "src/fonts/*" ;
444
- tsconfigContent . paths [ 'root/*' ] = "/*" ;
445
- tsconfigContent . paths [ 'components/*' ] = "/src/components*" ;
446
-
447
- tsconfigContent . include . push [ 'app/**/*.ts' ] ;
448
- tsconfigContent . include . push [ 'app/**/*.tsx' ] ;
449
- tsconfigContent . include . push [ 'app/**/*.vue' ] ;
449
+ delete tsconfigContent . compilerOptions . paths [ '@/*' ] ;
450
+ tsconfigContent . compilerOptions . paths [ '~/*' ] = [ "src/*" ] ;
451
+ tsconfigContent . compilerOptions . paths [ 'src/*' ] = [ "src/*" ] ;
452
+ tsconfigContent . compilerOptions . paths [ 'assets/*' ] = [ "src/assets/*" ] ;
453
+ tsconfigContent . compilerOptions . paths [ 'fonts/*' ] = [ "src/fonts/*" ] ;
454
+ tsconfigContent . compilerOptions . paths [ 'root/*' ] = [ "/*" ] ;
455
+ tsconfigContent . compilerOptions . paths [ 'components/*' ] = [ "/src/components*" ] ;
450
456
451
- tsconfigContent . exclude . push [ 'platforms' ] ;
452
- tsconfigContent . exclude . push [ ' hooks'] ;
457
+ tsconfigContent . include = tsconfigContent . include . concat ( [ 'app/**/*.ts' , 'app/**/*.tsx' , 'app/**/*.vue' ] ) ;
458
+ tsconfigContent . exclude = tsconfigContent . exclude . concat ( [ 'platforms' , ' hooks'] )
453
459
454
- fs . writeFileSync ( tsconfigPath , JSON . stringify ( tsconfigContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
460
+ fs . writeFileSync ( existingDirPath + 'tsconfig.json' , JSON . stringify ( tsconfigContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
455
461
if ( err ) console . error ( err )
456
462
} ) ;
457
463
@@ -463,7 +469,7 @@ const tsconfigSetup = module.exports.tsconfigSetup = async (tsconfigPath) => {
463
469
}
464
470
465
471
// setup tslintSetup
466
- const tslintSetup = module . exports . tslintSetup = async ( tslintPath ) => {
472
+ const tslintSetup = module . exports . tslintSetup = async ( existingDirPath , tslintPath ) => {
467
473
let tslintContent = '' ;
468
474
469
475
try {
@@ -473,14 +479,10 @@ const tslintSetup = module.exports.tslintSetup = async (tslintPath) => {
473
479
return ;
474
480
}
475
481
476
- tslintContent . linterOptions . exclude . push [ 'platforms/**' ] ;
477
- tslintContent . linterOptions . exclude . push [ ' hooks/**' ] ;
482
+ tslintContent . linterOptions . exclude = tslintContent . linterOptions . exclude . concat ( [ 'platforms/**' , 'hooks/**' ] )
483
+ tslintContent . exclude = tslintContent . exclude . concat ( [ 'platforms' , ' hooks' ] )
478
484
479
- tslintContent . exclude . push [ 'platforms' ] ;
480
- tslintContent . exclude . push [ 'hooks' ] ;
481
-
482
-
483
- fs . writeFileSync ( tslintPath , JSON . stringify ( tslintContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
485
+ fs . writeFileSync ( existingDirPath + 'tslint.json' , JSON . stringify ( tslintContent , null , 2 ) , { encoding : 'utf8' } , ( err ) => {
484
486
if ( err ) console . error ( err )
485
487
} ) ;
486
488
@@ -514,13 +516,19 @@ const extractCallDir = module.exports.extractCallDir = () => {
514
516
515
517
}
516
518
517
- const renderFilesIndividually = module . exports . renderFilesIndividually = async ( api , files , commonRenderOptions , srcPathPrepend , destPathPrepend ) => {
519
+ const renderFilesIndividually = module . exports . renderFilesIndividually = async ( api , jsOrTs , files , commonRenderOptions , srcPathPrepend , destPathPrepend ) => {
518
520
try {
519
521
const obj = { }
520
- for ( let file of files )
521
- obj [ destPathPrepend + file ] = srcPathPrepend + file ;
522
+ for ( let file of files ) {
523
+ let newFile = file ;
524
+ if ( file . slice ( - 3 ) === '.js' || file . slice ( - 3 ) === '.ts' )
525
+ newFile = file . substring ( 0 , file . length - 3 ) + jsOrTs ;
526
+
527
+ obj [ destPathPrepend + newFile ] = srcPathPrepend + file ;
528
+ }
522
529
523
530
api . render ( obj , commonRenderOptions ) ;
531
+
524
532
} catch ( err ) {
525
533
throw err
526
534
}
0 commit comments