Skip to content

Commit be52cbc

Browse files
authored
refactor: migrate from astro to svelte + vite to improve performance (#131)
* add highlighter * add playground url * add markdown support and notification center * fix multiple md files * add meta description with framework list * fix: framework id loop index * store frameworkIdsSelected in locale storage * add generateFrameworkContent vite plugin * add missing snippet case * add content generate cache * add angular component highlighter * improve content generator organization * add format and linter * add git hooks * add default frameworks
1 parent 4526ef2 commit be52cbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4410
-3839
lines changed

.eslintrc.esm.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import FRAMEWORKS from "./src/frameworks.mjs";
1+
import FRAMEWORKS from "./frameworks.mjs";
22

33
/**
44
* @type {import("eslint").Linter.Config}

.github/workflows/node.js.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
node-version: [14.x, 16.x]
21+
node-version: [16.x, 18.x]
2222
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2323

2424
steps:

.gitignore

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
110
node_modules
2-
new-section
3-
.eslintcache
4-
yarn.lock
5-
package-lock.json
611
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
719
.DS_Store
8-
.history
9-
.chrome
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
src/generatedContent

.gitpod.yml

-2
This file was deleted.

.husky/.gitignore

-1
This file was deleted.

.husky/pre-commit

-4
This file was deleted.

.npmrc

-2
This file was deleted.

.vscode/settings.json

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
{
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
3-
"eslint.probe": ["javascript", "javascriptreact", "vue"],
4-
"editor.formatOnSave": false,
53
// Runs Prettier, then ESLint
64
"editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
75
"[svelte]": {
86
"editor.defaultFormatter": "svelte.svelte-vscode"
9-
},
10-
"cSpell.words": [
11-
"alpinejs",
12-
"astro",
13-
"astrojs",
14-
"matschik",
15-
"mdast",
16-
"pnpm",
17-
"qwik",
18-
"shiki",
19-
"webp"
20-
]
7+
}
218
}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This site is built with [Astro](https://docs.astro.build). Site content is writt
77
1. Fork the project and create a new branch
88
2. Add the new framework SVG logo in `public/framework`
99
3. Install the ESLint plugin associated to the framework
10-
4. In `src/frameworks.mjs`, add a new entry with SVG link and ESLint configuration
10+
4. In `frameworks.mjs`, add a new entry with SVG link and ESLint configuration
1111

1212
## Improve website
1313

LICENSE

-21
This file was deleted.

README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[![Open in Gitpod][gitpod-src]][gitpod-href]
2-
31
![Component Party 🎉](.github/banner.webp)
42

53
> Web component JS frameworks quick overview by their syntax and features
@@ -383,7 +381,7 @@ This project requires Node.js to be `v14.0.0` or higher, because we use new Java
383381
1. Fork the project and create a new branch
384382
2. Add the new framework SVG logo in `public/framework`
385383
3. Install the ESLint plugin associated to the framework
386-
4. In `src/frameworks.mjs`, add a new entry with SVG link and ESLint configuration
384+
4. In `frameworks.mjs`, add a new entry with SVG link and ESLint configuration
387385

388386
## 🧑‍💻 Contributors
389387

@@ -393,8 +391,3 @@ This project exists thanks to all the people who contribute. \[[Contribute](CONT
393391
## ⚖️ License
394392

395393
MIT. Made with 💖
396-
397-
<!-- variables -->
398-
399-
[gitpod-src]: https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod
400-
[gitpod-href]: https://gitpod.io/#https://github.com/matschik/component-party

astro.config.mjs

-16
This file was deleted.

build/generateContentVitePlugin.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import fs from "fs";
2+
import generateContent from "./lib/generateContent.js";
3+
import { createFsCache } from "micache";
4+
import { hashElement } from "folder-hash";
5+
6+
const contentDirFsCache = await createFsCache("pluginGenerateFrameworkContent");
7+
8+
export default function pluginGenerateFrameworkContent() {
9+
const name = "generateFrameworkContent";
10+
11+
function logInfo(...args) {
12+
console.info(`[${name}]`, ...args);
13+
}
14+
15+
async function build() {
16+
logInfo("Generating framework content files...");
17+
const contentDirHash =
18+
(await hashElement("content")).hash + (await hashElement("build")).hash;
19+
const contentDirLastHash = await contentDirFsCache.get("contentDirHash");
20+
if (contentDirHash !== contentDirLastHash) {
21+
await generateContent();
22+
await contentDirFsCache.set("contentDirHash", contentDirHash);
23+
logInfo(`done`);
24+
} else {
25+
logInfo(`done with cache`);
26+
}
27+
}
28+
29+
let fsContentWatcher;
30+
if (process.env.NODE_ENV === "development") {
31+
fsContentWatcher = fs.watch("content", { recursive: true }, build);
32+
}
33+
34+
return {
35+
name,
36+
async buildStart() {
37+
await build();
38+
},
39+
buildEnd() {
40+
fsContentWatcher && fsContentWatcher.close();
41+
},
42+
};
43+
}

build/lib/angularHighlighter.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export function mustUseAngularHighlighter(fileContent) {
2+
return (
3+
fileContent.includes("@angular/core") && fileContent.includes("template")
4+
);
5+
}
6+
7+
export function highlightAngularComponent(highlighter, fileContent, fileExt) {
8+
const templateCode = getAngularTemplateCode(fileContent);
9+
10+
let codeHighlighted = "";
11+
if (templateCode) {
12+
const componentWithEmptyTemplate =
13+
removeAngularTemplateContent(fileContent);
14+
const templateCodeHighlighted = highlighter(templateCode, {
15+
lang: "html",
16+
});
17+
18+
const componentWithoutTemplateHighlighted = highlighter(
19+
componentWithEmptyTemplate,
20+
{
21+
lang: fileExt,
22+
}
23+
);
24+
25+
codeHighlighted = componentWithoutTemplateHighlighted.replace(
26+
"template",
27+
"template: `" + removeCodeWrapper(templateCodeHighlighted) + "`,"
28+
);
29+
} else {
30+
codeHighlighted = highlighter(fileContent, {
31+
lang: fileExt,
32+
});
33+
}
34+
35+
return codeHighlighted;
36+
}
37+
38+
function getAngularTemplateCode(fileContent) {
39+
// regex to grab what is inside angular component template inside backticks
40+
const regex = /template:\s*`([\s\S]*?)`/gm;
41+
42+
// grab the template string
43+
const template = regex.exec(fileContent);
44+
45+
if (template) return template[1];
46+
47+
return "";
48+
}
49+
50+
function removeAngularTemplateContent(fileContent) {
51+
const componentWithoutContentInsideTemplate = fileContent.replace(
52+
/template:\s*`([\s\S]*?)([^*])`,?/gm,
53+
"template"
54+
);
55+
56+
return componentWithoutContentInsideTemplate;
57+
}
58+
59+
function removeCodeWrapper(html) {
60+
const regexForWrapper = /<pre([\s\S]*?)><code>([\s\S]*?)<\/code><\/pre>/gm;
61+
const code = regexForWrapper.exec(html);
62+
return code[2];
63+
}

0 commit comments

Comments
 (0)