-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from sasjs/issue-203
feat: add utils for sasjs fs command
- Loading branch information
Showing
32 changed files
with
878 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getAbsolutePath } from '../getAbsolutePath' | ||
import path from 'path' | ||
|
||
describe('getAbsolutePath', () => { | ||
it('should return absolute path in normalized form', () => { | ||
expect(getAbsolutePath('~/..', '')).toBeTruthy() | ||
}) | ||
|
||
it('should return joined path when provided path is not absolute path', () => { | ||
expect(getAbsolutePath('utils', 'sasjs')).toEqual( | ||
path.join('sasjs', 'utils') | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import path from 'path' | ||
import { isFolder, listFilesInFolder, listSubFoldersInFolder } from '../file' | ||
import { | ||
getInitialCode, | ||
getCompiledMacrosCode, | ||
generateCodeForFileCreation | ||
} from './internal/helper' | ||
|
||
export const generateCompileProgram = async (folderPath: string) => { | ||
const compiledMacrosCode = await getCompiledMacrosCode(['mf_mkdir.sas']) | ||
|
||
const initialProgramContent = getInitialCode() | ||
|
||
const folderCreationCode = await fileAndDirectoryCreationCode(folderPath) | ||
|
||
return compiledMacrosCode + initialProgramContent + folderCreationCode | ||
} | ||
|
||
const fileAndDirectoryCreationCode = async ( | ||
resourcePath: string, | ||
pathRelativeTo: string = resourcePath, | ||
resultCode: string = '' | ||
) => { | ||
if (!(await isFolder(resourcePath))) { | ||
resultCode += await generateCodeForFileCreation( | ||
resourcePath, | ||
pathRelativeTo | ||
) | ||
return resultCode | ||
} | ||
|
||
const files = await listFilesInFolder(resourcePath) | ||
for (const file of files) { | ||
resultCode = await fileAndDirectoryCreationCode( | ||
path.join(resourcePath, file), | ||
pathRelativeTo, | ||
resultCode | ||
) | ||
} | ||
|
||
const subFolders = await listSubFoldersInFolder(resourcePath) | ||
for (const folder of subFolders) { | ||
const folderPath = path.join(resourcePath, folder) | ||
|
||
resultCode = `${resultCode} | ||
%mf_mkdir(&fsTarget${folderPath.replace(pathRelativeTo, '')}) | ||
` | ||
|
||
resultCode = await fileAndDirectoryCreationCode( | ||
folderPath, | ||
pathRelativeTo, | ||
resultCode | ||
) | ||
} | ||
|
||
return resultCode | ||
} |
Oops, something went wrong.