@@ -11,6 +11,32 @@ module.exports = (api, options, rootOptions) => {
11
11
12
12
const newline = process . platform === 'win32' ? '\r\n' : '\n' ;
13
13
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
+ ]
14
40
15
41
// New Project & Native Only -- should never be able to use Nativescript-Vue-Web
16
42
if ( options . isNativeOnly && options . isNVW ) {
@@ -96,9 +122,9 @@ module.exports = (api, options, rootOptions) => {
96
122
delete pkg . scripts [ 'build' ]
97
123
98
124
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
102
128
}
103
129
104
130
} )
@@ -113,20 +139,12 @@ module.exports = (api, options, rootOptions) => {
113
139
114
140
// New Project and not using Nativescript-Vue-Web
115
141
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 , './' ) ;
130
148
}
131
149
132
150
// New Project and is using Nativescript-Vue-Web
@@ -136,7 +154,7 @@ module.exports = (api, options, rootOptions) => {
136
154
137
155
// New Project & Native Only -- should never be able to use Nativescript-Vue-Web
138
156
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/' ) ;
140
158
}
141
159
142
160
if ( options . isNativeOnly && options . isNVW ) {
@@ -156,7 +174,11 @@ module.exports = (api, options, rootOptions) => {
156
174
157
175
// Existing Project and not using Nativescript-Vue-Web
158
176
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/' ) ;
160
182
}
161
183
162
184
// Existing Project and is using Nativescript-Vue-Web
@@ -166,7 +188,7 @@ module.exports = (api, options, rootOptions) => {
166
188
167
189
// Existing Project & Native Only -- should never be able to use Nativescript-Vue-Web
168
190
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/' ) ;
170
192
}
171
193
172
194
if ( options . isNVW && options . isNativeOnly ) {
@@ -297,6 +319,22 @@ module.exports = (api, options, rootOptions) => {
297
319
}
298
320
299
321
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
+
300
338
const applyBabelConfig = module . exports . applyBabelConfig = async ( api , filePath ) => {
301
339
302
340
try {
@@ -315,11 +353,9 @@ const applyBabelConfig = module.exports.applyBabelConfig = async (api, filePath)
315
353
}
316
354
317
355
const copyDirs = module . exports . copyDirs = async ( srcPath , destPath ) => {
318
-
319
356
const baseDir = extractCallDir ( )
320
357
const source = path . resolve ( baseDir , srcPath )
321
358
await fs . copy ( source , destPath )
322
-
323
359
}
324
360
325
361
// extract callsite file location using error stack
@@ -328,3 +364,11 @@ const extractCallDir = module.exports.extractCallDir = () => {
328
364
Error . captureStackTrace ( obj )
329
365
return path . dirname ( obj . stack . split ( '\n' ) [ 3 ] . match ( / \s \( ( .* ) : \d + : \d + \) $ / ) [ 1 ] )
330
366
}
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