Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Table Generator #22

Merged
merged 7 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/markdown-table-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Generate README markdown table"

on:
pull_request:
branches:
- main
types:
- closed
jobs:
readme-generator:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Prepare repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}

- name: Prepare Node.js
uses: actions/setup-node@v2
with:
node-version: "16"

- name: Prepare function
run: |
cd .github/workflows/markdown-table-workflow
npm install

- name: Run function
run: cd .github/workflows/markdown-table-workflow && node index.js

- name: Push changes
run: |
git config user.name github-actions
git config user.email [email protected]
git add README.md
git commit -m "Auto: README table generation" || true
git push || true
1 change: 1 addition & 0 deletions .github/workflows/markdown-table-workflow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
71 changes: 71 additions & 0 deletions .github/workflows/markdown-table-workflow/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as fs from "fs";
import * as path from "path";
import {markdownTable} from 'markdown-table';

const verboseRuntimes = {
cpp: "C++",
dart: "Dart",
deno: "Deno",
dotnet: ".NET",
java: "Java",
kotlin: "Kotlin",
node: "Node.js",
php: "PHP",
python: "Python",
ruby: "Ruby",
swift: "Swift"
};

const folderDenylist = [ '.github', '.git' ];

const runtimes = fs.readdirSync(path.join('.', '../../../'), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
.filter((folder) => !folderDenylist.includes(folder))
.sort();

const templates = [];

for(const runtime of runtimes) {
const folders = fs.readdirSync(path.join('.', `../../../${runtime}`), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
templates.push(...folders);
}

const uniqueTemplates = [...new Set(templates)];

const rows = uniqueTemplates.map((template) => {
const languagesSupport = runtimes.map((runtime) => {
return fs.existsSync(path.join('.', `../../../${runtime}/${template}`)) ? `[✅](/${runtime}/${template})` : '';
})

return [template, ...languagesSupport];
});

const table = markdownTable([
['Template', ...runtimes.map((r) => verboseRuntimes[r] ? verboseRuntimes[r] : r)],
...rows.sort((a, b) => {
const aCount = a.filter((column) => column !== '');
const bCount = b.filter((column) => column !== '');

return aCount > bCount ? -1 : 1;
})
]);


const readmePath = path.join('.', "../../../README.md");
const readme = fs.readFileSync(readmePath).toString();
let newReadme = '';

if(readme.includes('<!-- TABLE:START -->') && readme.includes('<!-- TABLE:END -->')) {
newReadme += readme.split('<!-- TABLE:START -->')[0];
newReadme += '<!-- TABLE:START -->\n';

newReadme += table;

newReadme += '\n<!-- TABLE:END -->';
newReadme += readme.split('<!-- TABLE:END -->')[1];
}

fs.writeFileSync(readmePath, newReadme);
25 changes: 25 additions & 0 deletions .github/workflows/markdown-table-workflow/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .github/workflows/markdown-table-workflow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "markdown-table-workflow",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"markdown-table": "^3.0.3"
}
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# templates-for-node
Repository to hold all the function starter templates for Node.js
# Templates

Repository to hold all the starter templates for Appwrite Functions.

<!-- TABLE:START -->
<!-- TABLE:END -->