Add block.json file support + fields config.
This commit is contained in:
@@ -21,6 +21,20 @@ module.exports = class extends Generator {
|
||||
return !!str;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "group",
|
||||
message: "Company/Organization Name",
|
||||
validate: (str) => {
|
||||
const matches = str.match(/\d+/g);
|
||||
|
||||
if (matches != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!str;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "list",
|
||||
name: "baseView",
|
||||
@@ -45,9 +59,11 @@ module.exports = class extends Generator {
|
||||
|
||||
writing() {
|
||||
const title = capitalize(this.data.name);
|
||||
const group = capitalize(this.data.group);
|
||||
const data = Object.assign(this.data, {
|
||||
title,
|
||||
blockFilename: title.toLowerCase().replace(/ /ig, '-'),
|
||||
blockGroupName: group.toLowerCase().replace(/ /ig, '-'),
|
||||
blockClassName: title.toLowerCase().replace(/ /ig, '_'),
|
||||
});
|
||||
|
||||
@@ -85,6 +101,12 @@ module.exports = class extends Generator {
|
||||
data
|
||||
);
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('block.json'),
|
||||
this.destinationPath(path.join(pathDist, 'block.json')),
|
||||
data
|
||||
);
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('package.json'),
|
||||
this.destinationPath(path.join(pathDist, 'package.json')),
|
||||
@@ -123,7 +145,8 @@ module.exports = class extends Generator {
|
||||
}
|
||||
};
|
||||
|
||||
function capitalize(str) {
|
||||
// TODO: Same function is located in "/helpers.js" file. Find a way to remove cjs files.
|
||||
export function capitalize(str) {
|
||||
if (typeof str !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "<%= blockGroupName %>/<%= blockFilename %>",
|
||||
"version": "1.0.0",
|
||||
"title": "<%= title %>",
|
||||
"categories": [],
|
||||
"icon": "shortcode",
|
||||
"preview_image": "",
|
||||
"field_groups": [
|
||||
{
|
||||
"name": "content",
|
||||
"label": "Content",
|
||||
"fields": {
|
||||
"title": {
|
||||
"type": "text",
|
||||
"label": "Title"
|
||||
},
|
||||
"content": {
|
||||
"type": "wysiwyg",
|
||||
"label": "Content"
|
||||
},
|
||||
"cta": {
|
||||
"type": "link",
|
||||
"label": "CTA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "styling",
|
||||
"label": "Styling",
|
||||
"fields": {
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user