Skip to content

Commit

Permalink
Script to generate table in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Jan 2, 2018
1 parent 72414b0 commit f385e7d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions webpage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"homepage": "https://michelebertoli.github.io/css-in-js/",
"dependencies": {
"markdown-table": "^1.1.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-helmet": "^5.2.0"
Expand Down
51 changes: 51 additions & 0 deletions webpage/scripts/generate_readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node

const table = require("markdown-table");
const fs = require("fs");
const data = require("../src/data.json");

const headers = [
"Package",
"Version",
"Automatic Vendor Prefixing",
"Pseudo Classes",
"Media Queries",
"Styles As Object Literals",
"Extract CSS File"
];

const link = obj => `[${obj.text}](${obj.href})`;
const links = objs => objs.map(link).join(" + ");
const version = obj => obj;
const symbol = obj => (obj === true ? "✓" : "");

const row = obj =>
headers.map(header => {
if (header === "Package") {
return links(obj[header]);
} else if (header === "Version") {
return version(obj[header]);
} else {
return symbol(obj[header]);
}
});

const rows = data.rows.map(row);
rows.unshift(headers);

let text = fs.readFileSync("../README.md", "utf8");

if (text.indexOf("<!-- autogenerated table start -->") === -1) {
console.log(
`Error! Please, place tags around the table \n<!-- autogenerated table start --> table <!-- autogenerated table end -->`
);
process.exit(1);
}

text = text.replace(
/<!-- autogenerated table start -->[\s\S]*?<!-- autogenerated table end -->/,
`<!-- autogenerated table start -->\n${table(
rows
)}\n<!-- autogenerated table end -->`
);
fs.writeFileSync("../README.md", text, "utf8");
6 changes: 3 additions & 3 deletions webpage/src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const join = (array, separator) =>

const symbol = value => {
if (value === true) {
return '✓';
return "✓";
} else if (value === false) {
return '';
return "";
} else {
return '?';
return "?";
}
};

Expand Down
3 changes: 2 additions & 1 deletion webpage/src/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@
"Package": [
{
"text": "react-fela",
"href": "https://github.com/rofrischmann/fela/tree/master/packages/react-fela"
"href":
"https://github.com/rofrischmann/fela/tree/master/packages/react-fela"
}
],
"Version": "2.1.0",
Expand Down
4 changes: 4 additions & 0 deletions webpage/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4331,6 +4331,10 @@ map-obj@^1.0.0, map-obj@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"

markdown-table@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-1.1.1.tgz#4b3dd3a133d1518b8ef0dbc709bf2a1b4824bc8c"

marked@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.6.tgz#b2c6c618fccece4ef86c4fc6cb8a7cbf5aeda8d7"
Expand Down

0 comments on commit f385e7d

Please sign in to comment.