2020-05-29 14:08:26 -04:00
|
|
|
export const createFile = (path, content = '') => ({
|
|
|
|
id: path,
|
|
|
|
path,
|
|
|
|
content,
|
|
|
|
raw: content,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createNewFile = (path, content) =>
|
|
|
|
Object.assign(createFile(path, content), {
|
|
|
|
tempFile: true,
|
|
|
|
raw: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createDeletedFile = (path, content) =>
|
|
|
|
Object.assign(createFile(path, content), {
|
|
|
|
deleted: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createUpdatedFile = (path, oldContent, content) =>
|
|
|
|
Object.assign(createFile(path, content), {
|
|
|
|
raw: oldContent,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createMovedFile = (path, prevPath, content) =>
|
|
|
|
Object.assign(createNewFile(path, content), {
|
|
|
|
prevPath,
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
export const createEntries = (path) =>
|
2020-05-29 14:08:26 -04:00
|
|
|
path.split('/').reduce((acc, part, idx, parts) => {
|
|
|
|
const parentPath = parts.slice(0, idx).join('/');
|
|
|
|
const fullPath = parentPath ? `${parentPath}/${part}` : part;
|
|
|
|
|
|
|
|
return Object.assign(acc, { [fullPath]: { ...createFile(fullPath), parentPath } });
|
|
|
|
}, {});
|