Skip to content

Commit

Permalink
feat: simplify and split models/definition/filters files (#30)
Browse files Browse the repository at this point in the history
* feat: split universal editor files
* feat: reorganise to reduce the number of files again
* feat: rename files to partials
* feat: add husky pre-commit hook
* feat: run build:json when any model changes
* fix: glob pattern to blocks
* fix: rename file to follow partials pattern
* fix: def include, add columns filter
* fix: explicitly set the model id for default content
* fix: rename _component.json to _name.json
* fix: use name instead of label
* docs: update documentation
  • Loading branch information
buuhuu authored Aug 27, 2024
1 parent 4643b51 commit 986b77f
Show file tree
Hide file tree
Showing 21 changed files with 975 additions and 112 deletions.
1 change: 1 addition & 0 deletions .hlxignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ LICENSE
package.json
package-lock.json
test/*
_*
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node .husky/pre-commit.mjs
21 changes: 21 additions & 0 deletions .husky/pre-commit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { exec } from "node:child_process";

const run = (cmd) => new Promise((resolve, reject) => exec(
cmd,
(error, stdout, stderr) => {
if (error) reject();
if (stderr) reject(stderr);
resolve(stdout);
}
));

const changeset = await run('git diff --cached --name-only --diff-filter=ACMR');
const modifiedFiles = changeset.split('\n').filter(Boolean);

// check if there are any model files staged
const modifledPartials = modifiedFiles.filter((file) => file.match(/(^|\/)_.*.json/));
if (modifledPartials.length > 0) {
const output = await run('npm run build:json --silent');
console.log(output);
await run('git add .');
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ npm run lint
1. Install the [AEM CLI](https://github.com/adobe/helix-cli): `npm install -g @adobe/aem-cli`
1. Start AEM Proxy: `aem up` (opens your browser at `http://localhost:3000`)
1. Open the `{repo}` directory in your favorite IDE and start coding :)

## Prerequisites

- nodejs 18.3.x or newer
- AEM Cloud Service release 2024.8 or newer (>= `17465`)

## Resources

### Documentation
- [Getting Started Guide](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/edge-delivery/wysiwyg-authoring/edge-dev-getting-started)
- [Creating Blocks](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/edge-delivery/wysiwyg-authoring/create-block)
- [Content Modelling](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/edge-delivery/wysiwyg-authoring/content-modeling)
- [Working with Tabular Data / Spreadsheets](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/edge-delivery/wysiwyg-authoring/tabular-data)

### Presentations and Recordings
- [Getting started with AEM Authoring and Edge Delivery Services](https://experienceleague.adobe.com/en/docs/events/experience-manager-gems-recordings/gems2024/aem-authoring-and-edge-delivery)
63 changes: 63 additions & 0 deletions blocks/cards/_cards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"definitions": [
{
"title": "Cards",
"id": "cards",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"name": "Cards",
"filter": "cards"
}
}
}
}
},
{
"title": "Card",
"id": "card",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block/item",
"template": {
"name": "Card",
"model": "card"
}
}
}
}
}
],
"models": [
{
"id": "card",
"fields": [
{
"component": "reference",
"valueType": "string",
"name": "image",
"label": "Image",
"multi": false
},
{
"component": "richtext",
"name": "text",
"value": "",
"label": "Text",
"valueType": "string"
}
]
}
],
"filters": [
{
"id": "cards",
"components": [
"card"
]
}
]
}
57 changes: 57 additions & 0 deletions blocks/columns/_columns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"definitions": [
{
"title": "Columns",
"id": "columns",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/columns/v1/columns",
"template": {
"columns": "2",
"rows": "1"
}
}
}
}
}
],
"models": [
{
"id": "columns",
"fields": [
{
"component": "text",
"valueType": "number",
"name": "columns",
"value": "",
"label": "Columns"
},
{
"component": "text",
"valueType": "number",
"name": "rows",
"value": "",
"label": "Rows"
}
]
}
],
"filters": [
{
"id": "columns",
"components": [
"column"
]
},
{
"id": "column",
"components": [
"text",
"image",
"button",
"title"
]
}
]
}
32 changes: 32 additions & 0 deletions blocks/fragment/_fragment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"definitions": [
{
"title": "Fragment",
"id": "fragment",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"name": "Fragment",
"model": "fragment"
}
}
}
}
}
],
"models": [
{
"id": "fragment",
"fields": [
{
"component": "aem-content",
"name": "reference",
"label": "Reference"
}
]
}
],
"filters": []
}
48 changes: 48 additions & 0 deletions blocks/hero/_hero.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"definitions": [
{
"title": "Hero",
"id": "hero",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"name": "Hero",
"model": "hero"
}
}
}
}
}
],
"models": [
{
"id": "hero",
"fields": [
{
"component": "reference",
"valueType": "string",
"name": "image",
"label": "Image",
"multi": false
},
{
"component": "text",
"valueType": "string",
"name": "imageAlt",
"label": "Alt",
"value": ""
},
{
"component": "richtext",
"name": "text",
"value": "",
"label": "Text",
"valueType": "string"
}
]
}
],
"filters": []
}
62 changes: 34 additions & 28 deletions component-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"xwalk": {
"page": {
"resourceType": "core/franklin/components/title/v1/title",
"template": {}
"template": {
"model": "title"
}
}
}
}
Expand All @@ -47,7 +49,9 @@
"xwalk": {
"page": {
"resourceType": "core/franklin/components/button/v1/button",
"template": {}
"template": {
"model": "button"
}
}
}
}
Expand All @@ -65,7 +69,9 @@
"xwalk": {
"page": {
"resourceType": "core/franklin/components/section/v1/section",
"template": {}
"template": {
"model": "section"
}
}
}
}
Expand All @@ -77,75 +83,75 @@
"id": "blocks",
"components": [
{
"title": "Columns",
"id": "columns",
"title": "Cards",
"id": "cards",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/columns/v1/columns",
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"columns": "2",
"rows": "1"
"name": "Cards",
"filter": "cards"
}
}
}
}
},
{
"title": "Hero",
"id": "hero",
"title": "Card",
"id": "card",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"resourceType": "core/franklin/components/block/v1/block/item",
"template": {
"name": "Hero",
"model": "hero"
"name": "Card",
"model": "card"
}
}
}
}
},
{
"title": "Cards",
"id": "cards",
"title": "Columns",
"id": "columns",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"resourceType": "core/franklin/components/columns/v1/columns",
"template": {
"name": "Cards",
"filter": "cards"
"columns": "2",
"rows": "1"
}
}
}
}
},
{
"title": "Card",
"id": "card",
"title": "Fragment",
"id": "fragment",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block/item",
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"name": "Card",
"model": "card"
"name": "Fragment",
"model": "fragment"
}
}
}
}
},
{
"title": "Fragment",
"id": "fragment",
"title": "Hero",
"id": "hero",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/block/v1/block",
"template": {
"name": "Fragment",
"model": "fragment"
"name": "Hero",
"model": "hero"
}
}
}
Expand All @@ -154,4 +160,4 @@
]
}
]
}
}
Loading

0 comments on commit 986b77f

Please sign in to comment.