diff --git a/api/scripts/copySASjsCore.ts b/api/scripts/copySASjsCore.ts index 94b08c0..6dcb02e 100644 --- a/api/scripts/copySASjsCore.ts +++ b/api/scripts/copySASjsCore.ts @@ -1,7 +1,14 @@ import path from 'path' -import { asyncForEach, copy, createFolder, deleteFolder } from '@sasjs/utils' +import { + asyncForEach, + copy, + createFile, + createFolder, + deleteFolder, + listFilesInFolder +} from '@sasjs/utils' -import { apiRoot, sasJSCoreMacros } from '../src/utils' +import { apiRoot, sasJSCoreMacros, sasJSCoreMacrosInfo } from '../src/utils' const macroCorePath = path.join(apiRoot, 'node_modules', '@sasjs', 'core') @@ -16,6 +23,10 @@ export const copySASjsCore = async () => { await copy(coreSubFolderPath, sasJSCoreMacros) }) + + const fileNames = await listFilesInFolder(sasJSCoreMacros) + + await createFile(sasJSCoreMacrosInfo, fileNames.join('\n')) } copySASjsCore() diff --git a/api/src/app.ts b/api/src/app.ts index 9fdf244..0416d3e 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -56,8 +56,6 @@ export default setProcessVariables().then(async () => { // index.html needs to be injected with some js script. app.use(express.static(getWebBuildFolderPath())) - console.log('sasJSCoreMacros', sasJSCoreMacros) - app.use(onError) await connectDB() diff --git a/api/src/utils/copySASjsCore.ts b/api/src/utils/copySASjsCore.ts index 9a5e07c..3bce118 100644 --- a/api/src/utils/copySASjsCore.ts +++ b/api/src/utils/copySASjsCore.ts @@ -1,10 +1,32 @@ -import { copy, createFolder } from '@sasjs/utils' +import path from 'path' +import { + asyncForEach, + createFile, + createFolder, + deleteFolder, + readFile +} from '@sasjs/utils' -import { getTmpMacrosPath, sasJSCoreMacros } from '.' +import { getTmpMacrosPath, sasJSCoreMacros, sasJSCoreMacrosInfo } from '.' export const copySASjsCore = async () => { - await createFolder(sasJSCoreMacros) + console.log('Copying Macros from container to drive(tmp).') const macrosDrivePath = getTmpMacrosPath() - await copy(sasJSCoreMacros, macrosDrivePath) + + await deleteFolder(macrosDrivePath) + await createFolder(macrosDrivePath) + + const macros = await readFile(sasJSCoreMacrosInfo) + + await asyncForEach(macros.split('\n'), async (macroName) => { + const macroFileSourcePath = path.join(sasJSCoreMacros, macroName) + const macroContent = await readFile(macroFileSourcePath) + + const macroFileDestPath = path.join(macrosDrivePath, macroName) + + await createFile(macroFileDestPath, macroContent) + }) + + console.log('Macros Drive Path:', macrosDrivePath) } diff --git a/api/src/utils/file.ts b/api/src/utils/file.ts index 42bb12c..8013ce1 100644 --- a/api/src/utils/file.ts +++ b/api/src/utils/file.ts @@ -9,6 +9,7 @@ export const sysInitCompiledPath = path.join( ) export const sasJSCoreMacros = path.join(apiRoot, 'sasjscore') +export const sasJSCoreMacrosInfo = path.join(apiRoot, 'sasjscore', '.macrolist') export const getWebBuildFolderPath = () => path.join(codebaseRoot, 'web', 'build')