You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
import {getBlockConfigs, getBlockName, getBlockVariations, handlebarLayoutsPath, verifyVersion} from "../helpers.js";
|
|
import path from "path";
|
|
import {REGISTRY_URL} from "@axe-web/create-block/env.js";
|
|
|
|
export async function index(req, res, next) {
|
|
|
|
const blockName = req.query.block;
|
|
const block = getBlockName(blockName);
|
|
|
|
const blockDir = path.join('blocks', '@' + block.project, block.name);
|
|
const dataFiles = await getBlockVariations(blockDir);
|
|
|
|
const data = await getBlockConfigs(Object.assign({}, block, {dataFiles}));
|
|
|
|
if (data.error && data.errorMessage) {
|
|
// TODO: Throw Error.
|
|
}
|
|
|
|
data.helpers = {
|
|
include_partial: (filesPath) => handlebarLayoutsPath('.', filesPath),
|
|
}
|
|
|
|
// TODO: Make sure we sync block before we start working on it.
|
|
try {
|
|
const verifiedVersion = await verifyVersion(blockName, blockDir, REGISTRY_URL);
|
|
if (!verifiedVersion && !req.query['ignoreVersionSync']) {
|
|
return res.render('sync', data);
|
|
}
|
|
} catch (err) {
|
|
const errorMessage = "Can't verify block version.";
|
|
console.log(errorMessage, err);
|
|
return next(new Error(errorMessage));
|
|
}
|
|
|
|
data.blockName = blockName;
|
|
data.baseView = 'alignfull';
|
|
data.port = `/view/${data.baseView}`;
|
|
|
|
let previewFrameUrl = ``; // This variable is used in `*.hbs` and it will be updated once BrowserSync is ready.
|
|
data.previewFrameUrl = `${previewFrameUrl}${data.port}`;
|
|
data.previewFrameUrlNewWindow = `${previewFrameUrl}${data.port}`;
|
|
data.shareUrl = '';
|
|
|
|
data.viewMode = process.env.VIEW_MODE ?? false;
|
|
|
|
res.render('index', data);
|
|
}
|
|
|