11const crud = require ( '@cocreate/crud-client' )
22const Config = require ( '@cocreate/config' )
33const fs = require ( 'fs' ) ;
4+ const realpathAsync = fs . promises . realpath ;
5+
46const path = require ( 'path' ) ;
57const mimeTypes = {
68 ".aac" : "audio/aac" ,
@@ -168,8 +170,6 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
168170 let files = fs . readdirSync ( entryPath ) ;
169171
170172 for ( let file of files ) {
171- if ( fs . lstatSync ( `${ entryPath } /${ file } ` ) . isSymbolicLink ( ) )
172- continue
173173 let skip = false
174174 for ( let i = 0 ; i < exclude . length ; i ++ ) {
175175 if ( file . includes ( exclude ) ) {
@@ -179,7 +179,14 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
179179 }
180180 if ( skip ) continue
181181
182- let isDirectory = fs . existsSync ( `${ entryPath } /${ file } ` ) && fs . lstatSync ( `${ entryPath } /${ file } ` ) . isDirectory ( ) ;
182+ let isDirectory
183+ let isSymlink = fs . lstatSync ( `${ entryPath } /${ file } ` ) . isSymbolicLink ( )
184+ if ( isSymlink ) {
185+ let symlinkPath = await realpathAsync ( `${ entryPath } /${ file } ` )
186+ isDirectory = fs . existsSync ( symlinkPath ) && fs . lstatSync ( symlinkPath ) . isDirectory ( )
187+ } else
188+ isDirectory = fs . existsSync ( `${ entryPath } /${ file } ` ) && fs . lstatSync ( `${ entryPath } /${ file } ` ) . isDirectory ( )
189+
183190 let name = file
184191 let source = ''
185192
@@ -229,7 +236,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
229236 if ( isDirectory )
230237 mimeType = "text/directory"
231238 else
232- source = getSource ( `${ entryPath } /${ file } ` , mimeType )
239+ source = await getSource ( `${ entryPath } /${ file } ` , mimeType , isSymlink )
233240
234241 let values = {
235242 '{{name}}' : name || '' ,
@@ -303,13 +310,17 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
303310 }
304311
305312
306- function getSource ( path , mimeType ) {
313+ async function getSource ( path , mimeType , isSymlink ) {
307314 let readType = 'utf8'
308315 if ( mimeType === 'image/svg+xml' ) {
309316 readType = 'utf8' ;
310317 } else if ( / ^ ( i m a g e | a u d i o | v i d e o ) \/ [ - + . \w ] + / . test ( mimeType ) ) {
311318 readType = 'base64' ;
312319 }
320+
321+ if ( isSymlink )
322+ path = await realpathAsync ( path )
323+
313324 let binary = fs . readFileSync ( path ) ;
314325 let content = new Buffer . from ( binary ) . toString ( readType ) ;
315326
0 commit comments