From e51bfffccb7f1f95cbd2a2653690f344c7536b84 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Sun, 16 May 2021 15:32:39 +0100 Subject: [PATCH] Publish file content --- .../file-explorer/src/lib/file-explorer.tsx | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index 188c805084..d450022a66 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -378,8 +378,8 @@ export const FileExplorer = (props: FileExplorerProps) => { }) } - const publishToGist = () => { - modal('Create a public gist', `Are you sure you want to anonymously publish all your files in the ${name} workspace as a public gist on github.com?`, 'OK', toGist, 'Cancel', () => {}) + const publishToGist = (path?: string, type?: string) => { + modal('Create a public gist', `Are you sure you want to anonymously publish all your files in the ${name} workspace as a public gist on github.com?`, 'OK', () => toGist(path, type), 'Cancel', () => {}) } const toGist = (path?: string, type?: string) => { @@ -875,18 +875,36 @@ export const FileExplorer = (props: FileExplorerProps) => { export default FileExplorer async function packageFiles (filesProvider, directory, callback) { + const isFile = filesProvider.isFile(directory) const ret = {} - try { - await filesProvider.copyFolderToJson(directory, ({ path, content }) => { - if (/^\s+$/.test(content) || !content.length) { - content = '// this line is added to create a gist. Empty file is not allowed.' - } - path = path.replace(/\//g, '...') - ret[path] = { content } - }) - callback(null, ret) - } catch (e) { - return callback(e) + + if (isFile) { + try { + filesProvider.get(directory, (error, content) => { + if (error) throw new Error('An error ocurred while getting file content. ' + directory) + if (/^\s+$/.test(content) || !content.length) { + content = '// this line is added to create a gist. Empty file is not allowed.' + } + directory = directory.replace(/\//g, '...') + ret[directory] = { content } + callback(null, ret) + }) + } catch (e) { + return callback(e) + } + } else { + try { + await filesProvider.copyFolderToJson(directory, ({ path, content }) => { + if (/^\s+$/.test(content) || !content.length) { + content = '// this line is added to create a gist. Empty file is not allowed.' + } + path = path.replace(/\//g, '...') + ret[path] = { content } + }) + callback(null, ret) + } catch (e) { + return callback(e) + } } }