@@ -187,7 +187,7 @@ module.exports = async (api, options, rootOptions) => {
187187 // render App_Resources folder
188188 api . render ( async ( ) => {
189189 // eslint-disable-next-line prettier/prettier
190- await renderDirectory (
190+ await renderDirectoryStructure (
191191 api ,
192192 options ,
193193 rootOptions ,
@@ -202,7 +202,7 @@ module.exports = async (api, options, rootOptions) => {
202202 if ( ! options . isNativeOnly ) {
203203 api . render ( async ( ) => {
204204 // render src directory
205- await renderDirectory (
205+ await renderDirectoryStructure (
206206 api ,
207207 options ,
208208 rootOptions ,
@@ -222,7 +222,7 @@ module.exports = async (api, options, rootOptions) => {
222222 // Is Native Only
223223 api . render ( async ( ) => {
224224 // render app directory
225- await renderDirectory (
225+ await renderDirectoryStructure (
226226 api ,
227227 options ,
228228 rootOptions ,
@@ -247,6 +247,11 @@ module.exports = async (api, options, rootOptions) => {
247247 // create nsconfig.json in ./ or ./ns-example
248248 nsconfigSetup ( genConfig . dirPathPrefix , api . resolve ( 'nsconfig.json' ) , genConfig . nativeAppPathModifier , genConfig . appResourcesPathModifier ) ;
249249
250+ // copy over .vue with native.vue files
251+ if ( options . isNativeOnly ) {
252+ nativeOnlyRenameFiles ( genConfig . dirPathPrefix + genConfig . nativeAppPathModifier . slice ( 0 , - 1 ) ) ;
253+ }
254+
250255 if ( api . hasPlugin ( 'typescript' ) ) {
251256 if ( fs . existsSync ( api . resolve ( 'tslint.json' ) ) ) {
252257 require ( '../lib/tslint' ) ( { } , api , true ) ;
@@ -581,6 +586,53 @@ const nsconfigSetup = (module.exports.nsconfigSetup = async (dirPathPrefix, nsco
581586 }
582587} ) ;
583588
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+
584636// setup tslintSetup
585637const nativeOnlyPackageJsonSetup = ( module . exports . nativeOnlyPackageJsonSetup = async ( filePath ) => {
586638 let fileContents = '' ;
@@ -719,17 +771,6 @@ const tsconfigSetup = (module.exports.tsconfigSetup = async (options, dirPathPre
719771 }
720772} ) ;
721773
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-
733774// Use the generator's render function to render individual files passed in from an array.
734775// Will iterate through the array and then construct and object that is passed to render()
735776const renderFilesIndividually = ( module . exports . renderFilesIndividually = async (
@@ -766,16 +807,22 @@ const renderFilesIndividually = (module.exports.renderFilesIndividually = async
766807// function lacks a simple directory in and directory out option. So, we have to get the contents
767808// of the passed in directory and then render each file individually to where we want it via
768809// 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+ ) => {
770822 try {
771- const baseDir = await extractCallDir ( ) ;
772- const source = path . resolve ( baseDir , srcPathPrefix ) ;
773823 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 ) ;
779826
780827 for ( const rawPath of _files ) {
781828 // // // let filename = path.basename(rawPath);
@@ -820,13 +867,48 @@ const renderDirectory = (module.exports.renderDirectory = async (api, options, r
820867 files . push ( rawPath ) ;
821868 }
822869 }
823-
824870 renderFilesIndividually ( api , options , jsOrTs , files , commonRenderOptions , srcPathPrefix , destPathPrefix ) ;
825871 } catch ( err ) {
826872 throw err ;
827873 }
828874} ) ;
829875
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+
830912// utility function used to remove items from an array that match 'item'
831913const removeFromArray = ( module . exports . removeFromArray = async ( array , item ) => {
832914 const index = array . indexOf ( item ) ;
0 commit comments