Skip to content

Commit

Permalink
updated individual READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmaguitar committed Oct 28, 2023
1 parent 6b85168 commit 032d0f8
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 39 deletions.
22 changes: 11 additions & 11 deletions README.md

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions bin/README.md

This file was deleted.

26 changes: 13 additions & 13 deletions bin/createGutenbergExample/generateExamplesTableMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const toMarkdownTable = require("markdown-table");
const { info, error } = require("../log");

const rootPath = process.cwd();
const readmePath = join(rootPath, "README.md");
const readmePathRoot = join(rootPath, "README.md");
const examplesJsonPath = join(rootPath, "data/examples.json");
const tagsJsonPath = join(rootPath, "data/tags.json");

Expand All @@ -18,16 +18,10 @@ const {
const startMarker = "<!-- @TABLE EXAMPLES BEGIN -->";
const endMarker = "<!-- @TABLE EXAMPLES END -->";

module.exports = ({ slug: slugLastAdded }) => {
module.exports = ({ slug: slugReadme, readmePath = readmePathRoot }) => {

const examplesJson = JSON.parse(fs.readFileSync(examplesJsonPath, "utf8"));
const tagsJson = JSON.parse(fs.readFileSync(tagsJsonPath, "utf8"));

const readmePathDisplay = readmePath.split("/gutenberg-examples-2023/")[1];
let messageUpdate = `Updating ${readmePathDisplay}`
if (slugLastAdded) messageUpdate += ` with example ${slugLastAdded}`
info(messageUpdate)

const markdownContent = fs.readFileSync(readmePath, "utf8");

const regex = new RegExp(
Expand All @@ -43,22 +37,28 @@ module.exports = ({ slug: slugLastAdded }) => {
(acc, { slug, name }) => ({ ...acc, [slug]: name }),
{}
);
let processedExamplesJson = examplesJson;
if (slugReadme) {
processedExamplesJson = examplesJson.filter(({ slug }) => slug === slugReadme);
}

const markdownTableRows = examplesJson.map(({ slug, description, tags }) => {
const urlAssetIconWp = `https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/trunk/assets/icon-wp.svg`;
const urlRepo = `https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk`
const markdownTableRows = processedExamplesJson.map(({ slug, description, tags }) => {
const id = slug.split("-").pop();
let playgroundUrl = PLAYGROUND_URL_WITH_PLUGIN.replaceAll(SLUG_EXAMPLE_MARKER,slug);
if (tags.includes('gutenberg-plugin')) playgroundUrl = PLAYGROUND_URL_WITH_PLUGIN_AND_GUTENBERG.replaceAll(SLUG_EXAMPLE_MARKER,slug);
const urlZip = URL_EXAMPLE_ZIP.replaceAll(SLUG_EXAMPLE_MARKER,slug);

return [
`![](https://placehold.co/15x15/${id}/${id})`,
`[${id}](./plugins/${slug})`,
`[${id}](${urlRepo}/plugins/${slug})`,
description,
tags
.map((tagSlug) => `[\`${processedTags[tagSlug]}\`](#${tagSlug})`)
.map((tagSlug) => `[\`${processedTags[tagSlug]}\`](${urlRepo}#${tagSlug})`)
.join(", "),
`<a href="${urlZip}" target="_blank">📦</a>`,
`<a href="${playgroundUrl}" target="_blank"><img src="./assets/icon-wp.svg"></a>`
`<a href="${playgroundUrl}" target="_blank"><img src="${urlAssetIconWp}"></a>`
];
});
const markdownTable = toMarkdownTable([
Expand All @@ -73,7 +73,7 @@ module.exports = ({ slug: slugLastAdded }) => {

try {
fs.writeFileSync(readmePath, markdownContentWithUpdatedTable);
info(`${readmePathDisplay} was updated!`);
info(`README.md was updated!`);
} catch (err) {
error(`An error has ocurred when saving the file ${readmePath}`);
error(err);
Expand Down
5 changes: 4 additions & 1 deletion bin/createGutenbergExample/initCreateExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const generateExamplesTableMarkdown = require("./generateExamplesTableMarkdown")
module.exports = async (promptObject) => {
const { name, id, slug, keywords, description, source } = promptObject;
const rootPath = process.cwd();
const readmePath = join(rootPath, "README.md");
const pluginsFolderPath = join(rootPath, "plugins");
const sourceFolderPath = join(pluginsFolderPath, source);
const exampleFolderPath = join(pluginsFolderPath, slug);
Expand Down Expand Up @@ -108,7 +109,9 @@ module.exports = async (promptObject) => {

const exampleObject = { slug, tags: keywords.slice(1), description };
addExamplesJson({ exampleObject });
generateExamplesTableMarkdown({ slug,});
const readmePathDisplay = readmePath.split("/gutenberg-examples-2023/")[1];
info(`Updating ${readmePathDisplay} with example ${slug}`);
generateExamplesTableMarkdown();

info(`Installing dependencies...`);
execa.sync("pnpm i", { shell: true, all: true, cwd: rootPath });
Expand Down
15 changes: 14 additions & 1 deletion bin/updateTableMarkdown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
const { join } = require("path");
const fs = require('fs');

const generateExamplesTableMarkdown = require("./createGutenbergExample/generateExamplesTableMarkdown.js");
const slug = process.argv[2];
generateExamplesTableMarkdown({slug});
const rootPath = process.cwd();
let readmePath;

if (slug) {
const pluginPath = join(rootPath, "plugins", slug);
if (!fs.existsSync(pluginPath)) throw `plugin path doesn't exist: ${pluginPath}`;
readmePath = join(pluginPath, "README.md");
console.log({slug, readmePath})
}

generateExamplesTableMarkdown({slug, readmePath});
8 changes: 7 additions & 1 deletion plugins/basic-block-translations-3df23d/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Basic Block Translation 3df23d

Basic block that shows how to use translations in a block.
<!-- Please, do not remove these @TABLE EXAMPLES BEGIN and @TABLE EXAMPLES END comments or modify the table inside. This table is automatically generated from the data at data/examples.json and data/tags.json -->
<!-- @TABLE EXAMPLES BEGIN -->
| | ID | Short description | Tags | Download .zip | Live Demo |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://placehold.co/15x15/3df23d/3df23d) | [3df23d](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk/plugins/basic-block-translations-3df23d) | Basic Block with Translations | [`STATIC RENDERING`](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk#static-rendering) | <a href="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/basic-block-translations-3df23d.zip" target="_blank">📦</a> | <a href="https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/plugins.php%22,%22steps%22:%5B%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22mkdir%22,%22path%22:%22/downloads%22%7D,%7B%22step%22:%22writeFile%22,%22path%22:%22/downloads/plugin.zip%22,%22data%22:%7B%22resource%22:%22url%22,%22url%22:%22https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/basic-block-translations-3df23d.zip%22,%22caption%22:%22Downloading%20plugin...%22%7D%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22vfs%22,%22path%22:%22/downloads/plugin.zip%22%7D%7D%5D%7D" target="_blank"><img src="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/trunk/assets/icon-wp.svg"></a> |
<!-- @TABLE EXAMPLES END -->

Basic block that shows how to use translations in a block.

## Start Guide

Expand Down
8 changes: 8 additions & 0 deletions plugins/block-dynamic-rendering-64756b/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Block Dynamic Rendering 64756b

<!-- Please, do not remove these @TABLE EXAMPLES BEGIN and @TABLE EXAMPLES END comments or modify the table inside. This table is automatically generated from the data at data/examples.json and data/tags.json -->
<!-- @TABLE EXAMPLES BEGIN -->
| | ID | Short description | Tags | Download .zip | Live Demo |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://placehold.co/15x15/64756b/64756b) | [64756b](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk/plugins/block-dynamic-rendering-64756b) | Basic Block with Dynamic Rendering | [`DYNAMIC RENDERING`](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk#dynamic-rendering), [`CREATE BLOCK`](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk#create-block) | <a href="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/block-dynamic-rendering-64756b.zip" target="_blank">📦</a> | <a href="https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/plugins.php%22,%22steps%22:%5B%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22mkdir%22,%22path%22:%22/downloads%22%7D,%7B%22step%22:%22writeFile%22,%22path%22:%22/downloads/plugin.zip%22,%22data%22:%7B%22resource%22:%22url%22,%22url%22:%22https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/block-dynamic-rendering-64756b.zip%22,%22caption%22:%22Downloading%20plugin...%22%7D%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22vfs%22,%22path%22:%22/downloads/plugin.zip%22%7D%7D%5D%7D" target="_blank"><img src="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/trunk/assets/icon-wp.svg"></a> |
<!-- @TABLE EXAMPLES END -->

Basic block that shows how to use of dynamic rendering in a block.


## Start Guide

#### 1. Install dependencies
Expand Down
8 changes: 8 additions & 0 deletions plugins/block-static-rendering-b16608/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Block Static Rendering b16608

<!-- Please, do not remove these @TABLE EXAMPLES BEGIN and @TABLE EXAMPLES END comments or modify the table inside. This table is automatically generated from the data at data/examples.json and data/tags.json -->
<!-- @TABLE EXAMPLES BEGIN -->
| | ID | Short description | Tags | Download .zip | Live Demo |
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ![](https://placehold.co/15x15/b16608/b16608) | [b16608](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk/plugins/block-static-rendering-b16608) | Block with Static Rendering | [`STATIC RENDERING`](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk#static-rendering), [`CREATE BLOCK`](https://github.com/wordpress-juanmaguitar/gutenberg-examples-2023/tree/trunk#create-block) | <a href="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/block-static-rendering-b16608.zip" target="_blank">📦</a> | <a href="https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/plugins.php%22,%22steps%22:%5B%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22mkdir%22,%22path%22:%22/downloads%22%7D,%7B%22step%22:%22writeFile%22,%22path%22:%22/downloads/plugin.zip%22,%22data%22:%7B%22resource%22:%22url%22,%22url%22:%22https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/deploy/zips/block-static-rendering-b16608.zip%22,%22caption%22:%22Downloading%20plugin...%22%7D%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22vfs%22,%22path%22:%22/downloads/plugin.zip%22%7D%7D%5D%7D" target="_blank"><img src="https://raw.githubusercontent.com/wordpress-juanmaguitar/gutenberg-examples-2023/trunk/assets/icon-wp.svg"></a> |
<!-- @TABLE EXAMPLES END -->

Basic block that shows how to use of static rendering in a block.


## Start Guide

#### 1. Install dependencies
Expand Down
Loading

0 comments on commit 032d0f8

Please sign in to comment.