@@ -11,6 +11,32 @@ module.exports = (api, options, rootOptions) => {
1111
1212 const newline = process . platform === 'win32' ? '\r\n' : '\n' ;
1313
14+ const srcfiles = [
15+ 'router.js' ,
16+ 'main.js' ,
17+ 'App.vue' ,
18+ 'views/About.vue' ,
19+ 'views/Home.vue' ,
20+ 'components/HelloWorld.vue' ,
21+ 'assets/logo.png'
22+ ]
23+
24+ const appfiles = [
25+ 'package.json' ,
26+ 'main.js' ,
27+ 'App.native.vue' ,
28+ 'App.ios.vue' ,
29+ 'App.android.vue' ,
30+ 'views/About.native.vue' ,
31+ 'views/About.ios.vue' ,
32+ 'views/About.android.vue' ,
33+ 'views/Home.native.vue' ,
34+ 'views/Home.ios.vue' ,
35+ 'views/Home.android.vue' ,
36+ 'components/HelloWorld.native.vue' ,
37+ 'components/HelloWorld.ios.vue' ,
38+ 'components/HelloWorld.android.vue' ,
39+ ]
1440
1541 // New Project & Native Only -- should never be able to use Nativescript-Vue-Web
1642 if ( options . isNativeOnly && options . isNVW ) {
@@ -96,9 +122,9 @@ module.exports = (api, options, rootOptions) => {
96122 delete pkg . scripts [ 'build' ]
97123
98124 if ( options . isNativeOnly ) {
99- delete pkg . dependencies [ 'vue' ]
100- delete pkg . devDependencies [ 'vue-template-compiler' ]
101- delete pkg . browserslist
125+ // delete pkg.dependencies['vue']
126+ // delete pkg.devDependencies['vue-template-compiler']
127+ // delete pkg.browserslist
102128 }
103129
104130 } )
@@ -113,20 +139,12 @@ module.exports = (api, options, rootOptions) => {
113139
114140 // New Project and not using Nativescript-Vue-Web
115141 if ( ! options . isNVW && ! options . isNativeOnly ) {
116- api . render ( './templates/simple/without-nvw/new' , commonRenderOptions )
117-
118- if ( api . hasPlugin ( 'vue-router' ) ) {
119- api . injectImports ( 'src/main.js' , `import router from '~/router'` )
120- api . injectRootOptions ( 'src/main.js' , `router` )
121- }
122-
123- if ( api . hasPlugin ( 'vuex' ) ) {
124- api . injectImports ( 'src/main.js' , `import store from '~/store'` )
125- api . injectRootOptions ( 'src/main.js' , `store` )
126- api . injectImports ( 'app/main.js' , `import store from 'src/store'` )
127- api . injectRootOptions ( 'app/main.js' , `store` )
128-
129- }
142+
143+ renderFilesIndividually ( api , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , './src/' ) ;
144+ renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './app/' ) ;
145+
146+ setupVueRouter ( api , './' ) ;
147+ setupVuex ( api , './' ) ;
130148 }
131149
132150 // New Project and is using Nativescript-Vue-Web
@@ -136,7 +154,7 @@ module.exports = (api, options, rootOptions) => {
136154
137155 // New Project & Native Only -- should never be able to use Nativescript-Vue-Web
138156 if ( ! options . isNVW && options . isNativeOnly ) {
139- api . render ( './templates/simple/native-only/new ' , commonRenderOptions ) ;
157+ renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/ ' , './app/' ) ;
140158 }
141159
142160 if ( options . isNativeOnly && options . isNVW ) {
@@ -156,7 +174,11 @@ module.exports = (api, options, rootOptions) => {
156174
157175 // Existing Project and not using Nativescript-Vue-Web
158176 if ( ! options . isNVW && ! options . isNativeOnly ) {
159- api . render ( './templates/simple/without-nvw/existing' , commonRenderOptions )
177+ renderFilesIndividually ( api , srcfiles , commonRenderOptions , './templates/simple/without-nvw/src/' , './example/src/' ) ;
178+ renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/' , './example/app/' ) ;
179+
180+ setupVueRouter ( api , './example/' ) ;
181+ setupVuex ( api , './example/' ) ;
160182 }
161183
162184 // Existing Project and is using Nativescript-Vue-Web
@@ -166,7 +188,7 @@ module.exports = (api, options, rootOptions) => {
166188
167189 // Existing Project & Native Only -- should never be able to use Nativescript-Vue-Web
168190 if ( ! options . isNVW && options . isNativeOnly ) {
169- api . render ( './templates/simple/native-only/existing ' , commonRenderOptions )
191+ renderFilesIndividually ( api , appfiles , commonRenderOptions , './templates/simple/without-nvw/app/ ' , './example/app/' ) ;
170192 }
171193
172194 if ( options . isNVW && options . isNativeOnly ) {
@@ -297,6 +319,22 @@ module.exports = (api, options, rootOptions) => {
297319}
298320
299321
322+ const setupVueRouter = module . exports . setupVueRouter = async ( api , filePathPrepend ) => {
323+ if ( api . hasPlugin ( 'vue-router' ) ) {
324+ api . injectImports ( filePathPrepend + 'src/main.js' , `import router from '~/router'` )
325+ api . injectRootOptions ( filePathPrepend + 'src/main.js' , `router` )
326+ }
327+ }
328+
329+ const setupVuex = module . exports . setupVuex = async ( api , filePathPrepend ) => {
330+ if ( api . hasPlugin ( 'vuex' ) ) {
331+ api . injectImports ( filePathPrepend + 'src/main.js' , `import store from '~/store'` )
332+ api . injectRootOptions ( filePathPrepend + 'src/main.js' , `store` )
333+ api . injectImports ( filePathPrepend + 'app/main.js' , `import store from 'src/store'` )
334+ api . injectRootOptions ( filePathPrepend + 'app/main.js' , `store` )
335+ }
336+ }
337+
300338const applyBabelConfig = module . exports . applyBabelConfig = async ( api , filePath ) => {
301339
302340 try {
@@ -315,11 +353,9 @@ const applyBabelConfig = module.exports.applyBabelConfig = async (api, filePath)
315353}
316354
317355const copyDirs = module . exports . copyDirs = async ( srcPath , destPath ) => {
318-
319356 const baseDir = extractCallDir ( )
320357 const source = path . resolve ( baseDir , srcPath )
321358 await fs . copy ( source , destPath )
322-
323359}
324360
325361 // extract callsite file location using error stack
@@ -328,3 +364,11 @@ const extractCallDir = module.exports.extractCallDir = () => {
328364 Error . captureStackTrace ( obj )
329365 return path . dirname ( obj . stack . split ( '\n' ) [ 3 ] . match ( / \s \( ( .* ) : \d + : \d + \) $ / ) [ 1 ] )
330366}
367+
368+ const renderFilesIndividually = module . exports . renderFilesIndividually = async ( api , files , commonRenderOptions , srcPathPrepend , destPathPrepend ) => {
369+ const obj = { }
370+ for ( let file of files )
371+ obj [ destPathPrepend + file ] = srcPathPrepend + file ;
372+
373+ api . render ( obj , commonRenderOptions ) ;
374+ }
0 commit comments