Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function _getProjectInfo () {
let baseRoutes = [];
let usernameRoutes = [];
let partials = [];
let bootstrapData = {user: {details: {}, appData: {}}, partials: {}};
forEachDeep(tree, function (value, key, parent, context) {
let fileNameWithoutExtension;
let currentFilePath;
if (value.name) {
fileNameWithoutExtension = value.name.replace(value.extension, ""); // e.g. "todos"
}
if (value.path) {
currentFilePath = path.join(__dirname, "../../", value.path); // e.g. "../../project-files/pages/todos.hbs"
}
if (value.extension === ".hbs") {
let _templateString = fs.readFileSync(currentFilePath, "utf8");
// check if we're in the /pages directory
if (currentFilePath.includes("/pages/")) {
// default to using inline named partials as opposed to partial files
let templateRenderFunc = RemakeStore.getNewItemRenderFunction({name: templateName});
let bootstrapData = getBootstrapData().partials[templateName] || {};
if (!templateRenderFunc && (!matchingPartial || !matchingPartial.templateString)) {
showConsoleError(`Error: Couldn't find a template or partial named "${templateName}"`);
return;
}
// use the user-defined partial files only if no render functions are found
if (!templateRenderFunc) {
templateRenderFunc = Handlebars.compile(matchingPartial.templateString);
}
// add a unique key to every plain object in the bootstrap data
forEachDeep(bootstrapData, function (value, key, parentValue, context) {
if (isPlainObject(value)) {
value.id = getUniqueId();
}
});
// construct referrer url, pathname, params, and query object from referrer url
let referrerUrl = req.get('Referrer'); // e.g. "http://exampleapp.org/jane/todo-list/123"
let referrerUrlParsed = new URL(referrerUrl);
let referrerUrlPath = referrerUrlParsed.pathname; // e.g. "/jane/todo-list/123"
let params = getParamsFromPathname(referrerUrlPath); // e.g. { username: 'jane', id: '123' }
let query = {};
for (let searchParamsPair of referrerUrlParsed.searchParams.entries()) {
query[searchParamsPair[0]] = searchParamsPair[1];
}
export async function preProcessData ({data, user, params, addUniqueIdsToData}) {
let currentItem;
let parentItem;
let someUniqueIdsAdded = false;
forEachDeep(data, function (value, key, parentValue, context) {
if (isPlainObject(value)) {
// generate unique ids for every object item
if (addUniqueIdsToData) {
if (!value.id) {
value.id = getUniqueId();
someUniqueIdsAdded = true;
}
}
// if an :id is specified in the route, get the data for it (currentItem and its parentItem)
if (params.id && value.id === params.id) {
currentItem = value;
// loop through all parent items (objects & arrays)