create-folder-structure
v3.0.5
Published
Declarative complex file/folder creator
Downloads
20
Readme
File/Folder Structure Creator
Declarative complex file/folder creator
yarn add --dev create-folder-structure
createFolderStructure
returns realpath
without any symbolic links (using fs.realpath
)
Create anonymous folder
import { createFolder } from 'create-folder-structure' const entryPath = await createFolder({ file7: 'file content7', ['folder6/folder7']: {}, })
Create anonymous file
import { createFile } from 'create-folder-structure' const entryPath = await createFile('file content')
import { createFile } from 'create-folder-structure' const entryPath = await createFile({ key1: 'value', key2: 1, })
Full API
Create folder
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ entryName: 'folder1', content: { ['file1.txt']: 'file content1', ['folder2/folder3/file2']: 'file content2', ['folder2/folder3/file3']: 'file content3', ['folder2/file4']: 'file content4', folder2: { folder5: { file5: 'file content5', file6: 'file content6', }, file7: 'file content7', }, folder4: { folder5: {}, }, ['folder6/folder7']: {}, }, })
Create anonymous folder
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ content: { file7: 'file content7', ['folder6/folder7']: {}, }, })
Create file
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ entryName: 'folder1', content: 'file content1', })
Create anonymous file
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ content: 'file content1', })
you can specify file with an json extension and give it a JSON value instead of a string value:
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ entryName: 'file.json', content: 1, })
import createFolderStructure from 'create-folder-structure' const { entryPath, cleanup } = await createFolderStructure({ entryName: 'dir1', content: { 'file.json': { a: 1, b: 2 }, }, })