@@ -12,12 +12,12 @@ module.exports = (api, options, rootOptions) => {
1212 console . log ( 'usingTS - ' , api . hasPlugin ( 'typescript' ) )
1313 console . log ( 'usingBabel - ' , api . hasPlugin ( 'babel' ) )
1414
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'
1717
1818 const srcfiles = [
19- 'router.' + jsOrTs ,
20- 'main.' + jsOrTs ,
19+ 'router.js' ,
20+ 'main.js' ,
2121 'App.vue' ,
2222 'views/About.vue' ,
2323 'views/Home.vue' ,
@@ -27,7 +27,7 @@ module.exports = (api, options, rootOptions) => {
2727
2828 const appfiles = [
2929 'package.json' ,
30- 'main.' + jsOrTs ,
30+ 'main.js' ,
3131 'App.native.vue' ,
3232 'App.ios.vue' ,
3333 'App.android.vue' ,
@@ -97,9 +97,19 @@ module.exports = (api, options, rootOptions) => {
9797 'nativescript-vue-template-compiler' : '^2.0.2' ,
9898 'nativescript-worker-loader' : '~0.9.1' ,
9999 'replace-in-file' : '^3.4.2' ,
100+ 'tns-platform-declarations' : '^5.0.2' ,
100101 }
101102 } )
102103
104+ if ( api . hasPlugin ( 'typescript' ) ) {
105+ // api.extendPackage({
106+ // dependencies: {
107+ // },
108+ // devDependencies: {
109+ // }
110+ // })
111+ }
112+
103113 // if the project is using babel, then load appropriate packages
104114 if ( api . hasPlugin ( 'babel' ) ) {
105115 api . extendPackage ( {
@@ -144,8 +154,8 @@ module.exports = (api, options, rootOptions) => {
144154 // New Project and not using Nativescript-Vue-Web
145155 if ( ! options . isNVW && ! options . isNativeOnly ) {
146156
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/' ) ;
149159
150160 vueRouterSetup ( api , './' , jsOrTs ) ;
151161 vuexSetup ( api , './' , jsOrTs ) ;
@@ -158,7 +168,7 @@ module.exports = (api, options, rootOptions) => {
158168
159169 // New Project & Native Only -- should never be able to use Nativescript-Vue-Web
160170 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/' ) ;
162172 }
163173
164174 if ( options . isNativeOnly && options . isNVW ) {
@@ -179,8 +189,8 @@ module.exports = (api, options, rootOptions) => {
179189
180190 // Existing Project and not using Nativescript-Vue-Web
181191 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/' ) ;
184194
185195 vueRouterSetup ( api , existingDirPath , jsOrTs ) ;
186196 vuexSetup ( api , existingDirPath , jsOrTs ) ;
@@ -193,7 +203,7 @@ module.exports = (api, options, rootOptions) => {
193203
194204 // Existing Project & Native Only -- should never be able to use Nativescript-Vue-Web
195205 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/' ) ;
197207 }
198208
199209 if ( options . isNVW && options . isNativeOnly ) {
@@ -217,11 +227,11 @@ module.exports = (api, options, rootOptions) => {
217227
218228 if ( options . isNewProject ) {
219229 writeEnvFiles ( './' )
220- nsconfigSetup ( api . resolve ( 'nsconfig.json' ) ) ;
230+ nsconfigSetup ( './' , api . resolve ( 'nsconfig.json' ) ) ;
221231
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' ) ) ;
225235 }
226236
227237 // for new projects that are native only, move files/dirs and delete others
@@ -255,12 +265,11 @@ module.exports = (api, options, rootOptions) => {
255265
256266 } else {
257267 writeEnvFiles ( existingDirPath )
258- nsconfigSetup ( api . resolve ( existingDirPath + 'nsconfig.json' ) ) ;
268+ nsconfigSetup ( existingDirPath , api . resolve ( 'nsconfig.json' ) ) ;
259269
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' ) ) ;
264273 }
265274
266275
@@ -401,7 +410,7 @@ const gitignoreAdditions = module.exports.gitignoreAdditions = async (api) => {
401410}
402411
403412// setup nsconfig.json file
404- const nsconfigSetup = module . exports . nsconfigSetup = async ( nsconfigPath ) => {
413+ const nsconfigSetup = module . exports . nsconfigSetup = async ( existingDirPath , nsconfigPath ) => {
405414 let nsconfigContent = '' ;
406415
407416 try {
@@ -414,7 +423,7 @@ const nsconfigSetup = module.exports.nsconfigSetup = async (nsconfigPath) => {
414423 nsconfigContent . appPath = 'app' ;
415424 nsconfigContent . appResourcesPath = 'app/App_Resources'
416425
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 ) => {
418427 if ( err ) console . error ( err )
419428 } ) ;
420429
@@ -426,32 +435,29 @@ const nsconfigSetup = module.exports.nsconfigSetup = async (nsconfigPath) => {
426435}
427436
428437// 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 = { } ;
431440
432441 try {
442+
433443 if ( fs . existsSync ( tsconfigPath ) ) {
434- tsconfigContent = JSON . parse ( fs . readFileSync ( tsconfigPath , { encoding : 'utf8' } ) ) ;
444+ tsconfigContent = JSON . parse ( fs . readFileSync ( tsconfigPath , 'utf8' ) ) ;
435445 } else {
436446 tsconfigContent = { } ;
437447 }
438448
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*" ] ;
450456
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'] )
453459
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 ) => {
455461 if ( err ) console . error ( err )
456462 } ) ;
457463
@@ -463,7 +469,7 @@ const tsconfigSetup = module.exports.tsconfigSetup = async (tsconfigPath) => {
463469}
464470
465471// setup tslintSetup
466- const tslintSetup = module . exports . tslintSetup = async ( tslintPath ) => {
472+ const tslintSetup = module . exports . tslintSetup = async ( existingDirPath , tslintPath ) => {
467473 let tslintContent = '' ;
468474
469475 try {
@@ -473,14 +479,10 @@ const tslintSetup = module.exports.tslintSetup = async (tslintPath) => {
473479 return ;
474480 }
475481
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' ] )
478484
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 ) => {
484486 if ( err ) console . error ( err )
485487 } ) ;
486488
@@ -514,13 +516,19 @@ const extractCallDir = module.exports.extractCallDir = () => {
514516
515517}
516518
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 ) => {
518520 try {
519521 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+ }
522529
523530 api . render ( obj , commonRenderOptions ) ;
531+
524532 } catch ( err ) {
525533 throw err
526534 }
0 commit comments