corvid-local-site
Advanced tools
Comparing version 0.1.52 to 0.1.53
{ | ||
"name": "corvid-local-site", | ||
"version": "0.1.52", | ||
"version": "0.1.53", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
const fs = require("fs-extra"); | ||
const get_ = require("lodash/get"); | ||
const set_ = require("lodash/set"); | ||
const mapValues_ = require("lodash/mapValues"); | ||
@@ -16,2 +17,3 @@ const merge_ = require("lodash/merge"); | ||
const { prettyStringify, tryToPrettifyJsonString } = require("./prettify"); | ||
const { localFileSystemLayout } = require("./versions.json"); | ||
@@ -57,3 +59,3 @@ const removeFileExtension = filename => filename.replace(/\.[^/.]+$/, ""); | ||
documentPart = mapKeys_( | ||
mapValues_(folder, JSON.parse), | ||
mapValues_(folder, content => unwrap(JSON.parse(content))), | ||
getFilenameFromKey | ||
@@ -71,2 +73,6 @@ ); | ||
const getMenus = partial_(getDocumentPartByKey, "menus"); | ||
const getMetadata = async () => { | ||
const content = await fs.readFile(fullPath(sitePaths.metadata()), "utf8"); | ||
return JSON.parse(content); | ||
}; | ||
@@ -79,16 +85,25 @@ const getSiteDocument = async () => { | ||
routers: await getRouters(), | ||
menus: await getMenus() | ||
menus: await getMenus(), | ||
documentSchemaVersion: (await getMetadata()).documentSchemaVersion | ||
}; | ||
}; | ||
const payloadToFile = pathGetter => payload => | ||
const payloadToFile = pathGetter => (payload, wrapper) => | ||
Object.keys(payload).map(keyName => { | ||
return { | ||
path: pathGetter(keyName), | ||
content: payload[keyName] | ||
content: wrapper(payload[keyName]) | ||
}; | ||
}); | ||
const wrapWithVersion = (documentSchemaVersion, content) => ({ | ||
content, | ||
documentSchemaVersion | ||
}); | ||
const unwrap = wrapped => { | ||
return wrapped.content; | ||
}; | ||
const payloadConvertors = { | ||
pages: pagePayload => { | ||
pages: (pagePayload, wrapper) => { | ||
return Object.values(pagePayload).map(page => { | ||
@@ -98,3 +113,3 @@ const isPopup = get_(page, "isPopup"); | ||
path: isPopup ? sitePaths.lightboxes(page) : sitePaths.pages(page), | ||
content: page | ||
content: wrapper(page) | ||
}; | ||
@@ -106,10 +121,24 @@ }); | ||
routers: payloadToFile(sitePaths.routers), | ||
menus: payloadToFile(sitePaths.menus) | ||
menus: payloadToFile(sitePaths.menus), | ||
documentSchemaVersion: documentSchemaVersion => ({ | ||
path: sitePaths.metadata(), | ||
content: { | ||
documentSchemaVersion, | ||
localFileSystemLayout | ||
} | ||
}) | ||
}; | ||
const siteDocumentToFiles = siteDocument => | ||
flatten_( | ||
const siteDocumentToFiles = siteDocument => { | ||
const documentSchemaVersion = siteDocument.documentSchemaVersion; | ||
if (!siteDocument.documentSchemaVersion) { | ||
set_(siteDocument, "documentSchemaVersion", ""); | ||
} | ||
return flatten_( | ||
Object.keys(siteDocument).map(paylodKey => { | ||
if (payloadConvertors.hasOwnProperty(paylodKey)) { | ||
return payloadConvertors[paylodKey](siteDocument[paylodKey]); | ||
return payloadConvertors[paylodKey]( | ||
siteDocument[paylodKey], | ||
partial_(wrapWithVersion, documentSchemaVersion) | ||
); | ||
} else { | ||
@@ -119,3 +148,3 @@ const message = getMessage("ReadWrite_Unknown_PropertyLog", { | ||
}); | ||
logger.warning(message); | ||
logger.warn(message); | ||
return []; | ||
@@ -125,2 +154,3 @@ } | ||
); | ||
}; | ||
@@ -127,0 +157,0 @@ const deleteFolder = async folderPath => { |
@@ -59,2 +59,4 @@ const path = require("path"); | ||
const metadata = () => ".metadata.json"; | ||
const pages = (page = null, extention = fileExtention) => | ||
@@ -183,3 +185,4 @@ path.posix.join( | ||
matchLocalPageCodePath, | ||
masterPageCode | ||
masterPageCode, | ||
metadata | ||
}; |
@@ -16,3 +16,3 @@ const flatten_ = require("lodash/flatten"); | ||
const pageFileName = page => | ||
[sanitize(removeSpaces(page.title)), page.pageId, wixFileExtension].join("."); | ||
[sanitize(removeSpaces(page.title)), page.pageId].join("."); | ||
@@ -38,3 +38,9 @@ const pageCodeFileName = page => | ||
const PATH_LIGHTBOXES = `${PATH_FRONTEND}/lightboxes`; | ||
const documentSchemaVersion = "1.0"; | ||
const wrapWithVersion = content => ({ | ||
content, | ||
documentSchemaVersion | ||
}); | ||
const wixFilePath = (filename, parentPath = "") => | ||
@@ -45,3 +51,3 @@ `${parentPath}/${filename}.${wixFileExtension}`; | ||
path: wixFilePath(name, parentPath), | ||
content: prettyStringify(content) | ||
content: prettyStringify(wrapWithVersion(content)) | ||
}); | ||
@@ -66,6 +72,3 @@ | ||
const page = page => ({ | ||
path: `${PATH_PAGES}/${pageFileName(page)}`, | ||
content: prettyStringify(page) | ||
}); | ||
const page = page => wixFile(PATH_PAGES, pageFileName(page), page); | ||
@@ -82,6 +85,4 @@ const pageCode = (page, code) => ({ | ||
const lightbox = lightbox => ({ | ||
path: `${PATH_LIGHTBOXES}/${lightboxFileName(lightbox)}`, | ||
content: prettyStringify(lightbox) | ||
}); | ||
const lightbox = lightbox => | ||
wixFile(PATH_LIGHTBOXES, lightboxFileName(lightbox), lightbox); | ||
@@ -126,2 +127,10 @@ const lighboxCode = (lightbox, code) => ({ | ||
const metadata = () => ({ | ||
path: ".metadata.json", | ||
content: prettyStringify({ | ||
documentSchemaVersion: "1.0", | ||
localFileSystemLayout: "1.0" | ||
}) | ||
}); | ||
// builders | ||
@@ -158,2 +167,4 @@ | ||
); | ||
const file = metadata(); | ||
set_(localSite, file.path.split("/"), file.content); | ||
@@ -160,0 +171,0 @@ return localSite; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47296
22
1153