@@ -187,7 +187,7 @@ module.exports = async (api, options, rootOptions) => {
187
187
// render App_Resources folder
188
188
api . render ( async ( ) => {
189
189
// eslint-disable-next-line prettier/prettier
190
- await renderDirectory (
190
+ await renderDirectoryStructure (
191
191
api ,
192
192
options ,
193
193
rootOptions ,
@@ -202,7 +202,7 @@ module.exports = async (api, options, rootOptions) => {
202
202
if ( ! options . isNativeOnly ) {
203
203
api . render ( async ( ) => {
204
204
// render src directory
205
- await renderDirectory (
205
+ await renderDirectoryStructure (
206
206
api ,
207
207
options ,
208
208
rootOptions ,
@@ -222,7 +222,7 @@ module.exports = async (api, options, rootOptions) => {
222
222
// Is Native Only
223
223
api . render ( async ( ) => {
224
224
// render app directory
225
- await renderDirectory (
225
+ await renderDirectoryStructure (
226
226
api ,
227
227
options ,
228
228
rootOptions ,
@@ -247,6 +247,11 @@ module.exports = async (api, options, rootOptions) => {
247
247
// create nsconfig.json in ./ or ./ns-example
248
248
nsconfigSetup ( genConfig . dirPathPrefix , api . resolve ( 'nsconfig.json' ) , genConfig . nativeAppPathModifier , genConfig . appResourcesPathModifier ) ;
249
249
250
+ // copy over .vue with native.vue files
251
+ if ( options . isNativeOnly ) {
252
+ nativeOnlyRenameFiles ( genConfig . dirPathPrefix + genConfig . nativeAppPathModifier . slice ( 0 , - 1 ) ) ;
253
+ }
254
+
250
255
if ( api . hasPlugin ( 'typescript' ) ) {
251
256
if ( fs . existsSync ( api . resolve ( 'tslint.json' ) ) ) {
252
257
require ( '../lib/tslint' ) ( { } , api , true ) ;
@@ -581,6 +586,53 @@ const nsconfigSetup = (module.exports.nsconfigSetup = async (dirPathPrefix, nsco
581
586
}
582
587
} ) ;
583
588
589
+ // can be used to strip out template tags in native only project
590
+ // currently unused in preference for EJS templating
591
+ // eslint-disable-next-line no-unused-vars
592
+ const stripTemplateTags = ( module . exports . stripTemplateTags = async ( srcPathPrefix ) => {
593
+ try {
594
+ const files = await getAllFilesInDirStructure ( srcPathPrefix , '' ) ;
595
+
596
+ for ( const file of files ) {
597
+ if ( file . slice ( - 4 ) == '.vue' ) {
598
+ const options = {
599
+ files : path . join ( srcPathPrefix , file ) ,
600
+ from : [
601
+ new RegExp ( `^((<template)(.+\\bweb\\b))([\\s\\S]*?>)[\\s\\S]*?(<\\/template>)` , `gim` ) ,
602
+ new RegExp ( `^((<template)(.+\\bnative\\b))([\\s\\S]*?>)` , `gim` )
603
+ ] ,
604
+ to : [ '' , '<template>' ]
605
+ } ;
606
+
607
+ await replaceInFile ( options ) ;
608
+ }
609
+ }
610
+ } catch ( err ) {
611
+ throw err ;
612
+ }
613
+ } ) ;
614
+
615
+ const nativeOnlyRenameFiles = ( module . exports . nativeOnlyRenameFiles = async ( srcPathPrefix ) => {
616
+ try {
617
+ const _files = await getAllFilesInDirStructure ( srcPathPrefix , '' ) ;
618
+ const files = new Array ( ) ;
619
+ const match = '.native.vue' ;
620
+
621
+ for ( const file of _files ) {
622
+ if ( file . slice ( - 11 ) == match ) {
623
+ files . push ( path . join ( srcPathPrefix , file ) ) ;
624
+ }
625
+ }
626
+
627
+ for ( const file of files ) {
628
+ const oldFile = file . replace ( match , '.vue' ) ;
629
+ fs . moveSync ( file , oldFile , { overwrite : true } ) ;
630
+ }
631
+ } catch ( err ) {
632
+ throw err ;
633
+ }
634
+ } ) ;
635
+
584
636
// setup tslintSetup
585
637
const nativeOnlyPackageJsonSetup = ( module . exports . nativeOnlyPackageJsonSetup = async ( filePath ) => {
586
638
let fileContents = '' ;
@@ -719,17 +771,6 @@ const tsconfigSetup = (module.exports.tsconfigSetup = async (options, dirPathPre
719
771
}
720
772
} ) ;
721
773
722
- // extract callsite file location using error stack
723
- const extractCallDir = ( module . exports . extractCallDir = ( ) => {
724
- try {
725
- const obj = { } ;
726
- Error . captureStackTrace ( obj ) ;
727
- return path . dirname ( obj . stack . split ( '\n' ) [ 3 ] . match ( / \s \( ( .* ) : \d + : \d + \) $ / ) [ 1 ] ) ;
728
- } catch ( err ) {
729
- throw err ;
730
- }
731
- } ) ;
732
-
733
774
// Use the generator's render function to render individual files passed in from an array.
734
775
// Will iterate through the array and then construct and object that is passed to render()
735
776
const renderFilesIndividually = ( module . exports . renderFilesIndividually = async (
@@ -766,16 +807,22 @@ const renderFilesIndividually = (module.exports.renderFilesIndividually = async
766
807
// function lacks a simple directory in and directory out option. So, we have to get the contents
767
808
// of the passed in directory and then render each file individually to where we want it via
768
809
// the render function's isObject(source) option that we use in our renderFilesIndividually function.
769
- const renderDirectory = ( module . exports . renderDirectory = async ( api , options , rootOptions , jsOrTs , commonRenderOptions , srcPathPrefix , destPathPrefix ) => {
810
+
811
+ // eslint-disable-next-line prettier/prettier
812
+ // eslint-disable-next-line max-len
813
+ const renderDirectoryStructure = ( module . exports . renderDirectoryStructure = async (
814
+ api ,
815
+ options ,
816
+ rootOptions ,
817
+ jsOrTs ,
818
+ commonRenderOptions ,
819
+ srcPathPrefix ,
820
+ destPathPrefix
821
+ ) => {
770
822
try {
771
- const baseDir = await extractCallDir ( ) ;
772
- const source = path . resolve ( baseDir , srcPathPrefix ) ;
773
823
const files = new Array ( ) ;
774
-
775
- const globby = require ( 'globby' ) ;
776
- const _files = await globby ( [ '**/*' ] , {
777
- cwd : source
778
- } ) ;
824
+ const baseDir = await extractCallDir ( )
825
+ const _files = await getAllFilesInDirStructure ( srcPathPrefix , baseDir ) ;
779
826
780
827
for ( const rawPath of _files ) {
781
828
// // // let filename = path.basename(rawPath);
@@ -820,13 +867,48 @@ const renderDirectory = (module.exports.renderDirectory = async (api, options, r
820
867
files . push ( rawPath ) ;
821
868
}
822
869
}
823
-
824
870
renderFilesIndividually ( api , options , jsOrTs , files , commonRenderOptions , srcPathPrefix , destPathPrefix ) ;
825
871
} catch ( err ) {
826
872
throw err ;
827
873
}
828
874
} ) ;
829
875
876
+ // extract callsite file location using error stack
877
+ const extractCallDir = ( module . exports . extractCallDir = ( ) => {
878
+ try {
879
+ const obj = { } ;
880
+ Error . captureStackTrace ( obj ) ;
881
+ return path . dirname ( obj . stack . split ( '\n' ) [ 3 ] . match ( / \s \( ( .* ) : \d + : \d + \) $ / ) [ 1 ] ) ;
882
+ } catch ( err ) {
883
+ throw err ;
884
+ }
885
+ } ) ;
886
+
887
+ // utility function used to get all the files in a directory structure. is recursive in nature due to globby
888
+ const getAllFilesInDirStructure = ( module . exports . replaceInFile = async ( srcPathPrefix , baseDir ) => {
889
+ try {
890
+ const source = path . resolve ( baseDir , srcPathPrefix ) ;
891
+ const globby = require ( 'globby' ) ;
892
+ const _files = await globby ( [ '**/*' ] , {
893
+ cwd : source
894
+ } ) ;
895
+
896
+ return _files ;
897
+ } catch ( error ) {
898
+ console . log ( error ) ;
899
+ }
900
+ } ) ;
901
+
902
+ // utility function used to remove sections of strings from files
903
+ const replaceInFile = ( module . exports . replaceInFile = async ( options ) => {
904
+ try {
905
+ //const changes =
906
+ await replace ( options ) ;
907
+ } catch ( error ) {
908
+ console . error ( 'Error occurred:' , error ) ;
909
+ }
910
+ } ) ;
911
+
830
912
// utility function used to remove items from an array that match 'item'
831
913
const removeFromArray = ( module . exports . removeFromArray = async ( array , item ) => {
832
914
const index = array . indexOf ( item ) ;
0 commit comments