@pictogrammers/element-esbuild 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/element-build.ts +21 -5
- package/bin/element-start.ts +13 -156
- package/default/playground.html +1 -3
- package/package.json +1 -1
- package/scripts/createPlaygroundIndex.ts +186 -0
package/bin/element-build.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { build } from 'esbuild';
|
|
|
6
6
|
import { htmlDependentsPlugin } from '../scripts/htmlDependentsPlugin.ts';
|
|
7
7
|
import { rebuildNotifyPlugin } from '../scripts/rebuildNotifyPlugin.ts';
|
|
8
8
|
import { fileExists } from '../scripts/fileExists.ts';
|
|
9
|
-
import { copyFile } from 'node:fs/promises';
|
|
9
|
+
import { copyFile, writeFile } from 'node:fs/promises';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import { playgroundPlugin } from '../scripts/playgroundPlugin.ts';
|
|
12
|
+
import { createPlaygroundIndex } from '../scripts/createPlaygroundIndex.ts';
|
|
12
13
|
|
|
13
14
|
const plugins = [htmlDependentsPlugin, rebuildNotifyPlugin];
|
|
14
15
|
const entryPoints: string[] = [];
|
|
@@ -16,6 +17,7 @@ const entryPoints: string[] = [];
|
|
|
16
17
|
const green = (text: string) => `\x1b[32m${text}\x1b[0m`;
|
|
17
18
|
const red = (text: string) => `\x1b[31m${text}\x1b[0m`;
|
|
18
19
|
|
|
20
|
+
const playgroundFile = 'playground.html';
|
|
19
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
22
|
const __dirname = dirname(__filename);
|
|
21
23
|
const defaultDir = join(__dirname, '..', 'default');
|
|
@@ -38,6 +40,10 @@ if (!(await fileExists(configFile))) {
|
|
|
38
40
|
const config = await import(fullConfigPath.href);
|
|
39
41
|
const {
|
|
40
42
|
namespace,
|
|
43
|
+
title,
|
|
44
|
+
repo,
|
|
45
|
+
repoComponent,
|
|
46
|
+
navigation,
|
|
41
47
|
} = config.default;
|
|
42
48
|
|
|
43
49
|
if (namespace) {
|
|
@@ -49,7 +55,20 @@ if (namespace) {
|
|
|
49
55
|
plugins.push(
|
|
50
56
|
playgroundPlugin({
|
|
51
57
|
after: async (namespaces: any[]) => {
|
|
52
|
-
|
|
58
|
+
const indexContent = await createPlaygroundIndex({
|
|
59
|
+
mode: 'production',
|
|
60
|
+
rootDir,
|
|
61
|
+
srcDir,
|
|
62
|
+
indexFile,
|
|
63
|
+
defaultDir,
|
|
64
|
+
playgroundFile,
|
|
65
|
+
title,
|
|
66
|
+
repo,
|
|
67
|
+
repoComponent,
|
|
68
|
+
navigation,
|
|
69
|
+
namespaces,
|
|
70
|
+
});
|
|
71
|
+
await writeFile(join(rootDir, buildDir, indexFile), indexContent);
|
|
53
72
|
}
|
|
54
73
|
})
|
|
55
74
|
);
|
|
@@ -70,9 +89,6 @@ build({
|
|
|
70
89
|
},
|
|
71
90
|
plugins,
|
|
72
91
|
}).then(async () => {
|
|
73
|
-
if (await fileExists(join(rootDir, distDir, indexFile))) {
|
|
74
|
-
await copyFile(join(rootDir, distDir, indexFile), join(rootDir, buildDir, indexFile));
|
|
75
|
-
}
|
|
76
92
|
// Handle favicon.svg
|
|
77
93
|
const faviconSvg = 'favicon.svg';
|
|
78
94
|
if (await fileExists(join(rootDir, srcDir, faviconSvg))) {
|
package/bin/element-start.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { folderExists } from '../scripts/folderExists.ts';
|
|
|
11
11
|
import { playgroundPlugin } from '../scripts/playgroundPlugin.ts';
|
|
12
12
|
import { htmlDependentsPlugin } from '../scripts/htmlDependentsPlugin.ts';
|
|
13
13
|
import { rebuildNotifyPlugin } from '../scripts/rebuildNotifyPlugin.ts';
|
|
14
|
+
import { createPlaygroundIndex } from '../scripts/createPlaygroundIndex.ts';
|
|
14
15
|
|
|
15
16
|
const plugins = [htmlDependentsPlugin, rebuildNotifyPlugin];
|
|
16
17
|
|
|
@@ -93,162 +94,18 @@ if (namespace) {
|
|
|
93
94
|
plugins.push(
|
|
94
95
|
playgroundPlugin({
|
|
95
96
|
after: async (namespaces: any[]) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`<h1>${title ?? 'Default'}</h1>`
|
|
109
|
-
);
|
|
110
|
-
const navItems = structuredClone(navigation ?? []);
|
|
111
|
-
for (let navItem of navItems) {
|
|
112
|
-
navItem.items = [];
|
|
113
|
-
}
|
|
114
|
-
let defaultItem;
|
|
115
|
-
if (navItems.length === 0) {
|
|
116
|
-
defaultItem = { label: 'Components', items: [] };
|
|
117
|
-
navItems.push(defaultItem);
|
|
118
|
-
} else {
|
|
119
|
-
defaultItem = navItems.find((x: any) => !x.extends && !x.components && !x.namespaces);
|
|
120
|
-
if (!defaultItem) {
|
|
121
|
-
defaultItem = { label: 'Other', items: [] };
|
|
122
|
-
navItems.push(defaultItem);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const componentMap = new Map();
|
|
126
|
-
// Loop and organize into lists
|
|
127
|
-
namespaces.forEach(({ components }: any) => {
|
|
128
|
-
components.forEach(({ component, namespace, tag, readme, examples, className, classExtends }: any) => {
|
|
129
|
-
// Front end data
|
|
130
|
-
componentMap.set(className, {
|
|
131
|
-
className, // MyComponent
|
|
132
|
-
classExtends, // MyModal
|
|
133
|
-
component, // component
|
|
134
|
-
namespace, // my
|
|
135
|
-
tag, // my-component
|
|
136
|
-
readme, // # My Component
|
|
137
|
-
examples: examples.map((example: any) => example.className)
|
|
138
|
-
});
|
|
139
|
-
examples.forEach((example: any) => {
|
|
140
|
-
componentMap.set(example.className, {
|
|
141
|
-
className: example.className, // XMyComponentBasic
|
|
142
|
-
classExtends: example.classExtends, // HtmlElement
|
|
143
|
-
component: example.component, // myComponentBasic
|
|
144
|
-
namespace: example.namespace, // x
|
|
145
|
-
tag: example.tag, // x-my-component-basic
|
|
146
|
-
example: example.example, // Basic
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
// Quick insert any direct includes
|
|
150
|
-
for (let navItem of navItems) {
|
|
151
|
-
if (navItem.include && navItem.include.includes(className)) {
|
|
152
|
-
navItem.items.push({
|
|
153
|
-
namespace,
|
|
154
|
-
component,
|
|
155
|
-
className,
|
|
156
|
-
tag,
|
|
157
|
-
});
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// Move on to any other nav groups
|
|
162
|
-
for (let navItem of navItems) {
|
|
163
|
-
// skip default nav group
|
|
164
|
-
if (navItem === defaultItem) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
// ignore if excluded
|
|
168
|
-
if (navItem.exclude && navItem.exclude.includes(className)) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
// ignore if not in namespace
|
|
172
|
-
if (navItem.namespaces && !navItem.namespaces.includes(namespace)) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
// ignore if not extending the required class
|
|
176
|
-
if (navItem.extends && !navItem.extends.includes(classExtends)) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
navItem.items.push({
|
|
180
|
-
namespace,
|
|
181
|
-
component,
|
|
182
|
-
className,
|
|
183
|
-
tag,
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
defaultItem.items.push({
|
|
188
|
-
namespace,
|
|
189
|
-
component,
|
|
190
|
-
examples,
|
|
191
|
-
className,
|
|
192
|
-
tag,
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
// Replace left nav
|
|
197
|
-
indexContent = indexContent.replace(/([ ]*)<!-- \[Navigation\] -->/, (match: any, indent: any) => {
|
|
198
|
-
return navItems.map(({ label, items }: any) => {
|
|
199
|
-
return [
|
|
200
|
-
indent,
|
|
201
|
-
`<div>${label}</div>`,
|
|
202
|
-
'<ul>',
|
|
203
|
-
items.map(({component, namespace, tag, className}: any) => {
|
|
204
|
-
return [
|
|
205
|
-
`<li data-tag="${tag}" data-class-name="${className}" data-component="${component}"><a href="#${tag}">${component}</a></li>`
|
|
206
|
-
].join(`\n${indent}`);
|
|
207
|
-
}).join(`\n${indent}`),
|
|
208
|
-
'</ul>'
|
|
209
|
-
].join(`\n${indent}`)
|
|
210
|
-
}).join(`\n${indent}`);
|
|
211
|
-
});
|
|
212
|
-
// Repo
|
|
213
|
-
if (repo) {
|
|
214
|
-
const github = 'M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z';
|
|
215
|
-
const generic = 'M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z';
|
|
216
|
-
const repoIcon = repo.includes('github.com') ? github : generic;
|
|
217
|
-
indexContent = indexContent.replace(/([ ]*)<!-- \[Repo\] -->/, (match: any, indent: any) => {
|
|
218
|
-
return [
|
|
219
|
-
indent,
|
|
220
|
-
`<a href="${repo}">`,
|
|
221
|
-
' <svg viewBox="0 0 24 24">',
|
|
222
|
-
` <path fill="currentColor" d="${repoIcon}" />`,
|
|
223
|
-
' </svg>',
|
|
224
|
-
' <span>View Repo</span>',
|
|
225
|
-
'</a>'
|
|
226
|
-
].join(`\n${indent}`)
|
|
227
|
-
});
|
|
228
|
-
indexContent = indexContent.replace(/const repo = '';/, (match: any) => {
|
|
229
|
-
return `const repo = '${repo}';`;
|
|
230
|
-
});
|
|
231
|
-
indexContent = indexContent.replace(/const repoComponent = '';/, (match: any) => {
|
|
232
|
-
return `const repoComponent = '${repoComponent.replace(/\$repo/g, repo)}';`;
|
|
233
|
-
});
|
|
234
|
-
indexContent = indexContent.replace(/const repoIcon = '';/, (match: any) => {
|
|
235
|
-
return `const repoIcon = '${repoIcon}';`;
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
// Components
|
|
239
|
-
const classNames = [...componentMap.keys()];
|
|
240
|
-
indexContent = indexContent.replace(/([ ]*)const componentMap = new Map\(\);/, (match: any, indent: any) => {
|
|
241
|
-
return [
|
|
242
|
-
`${indent}const componentMap = new Map();`,
|
|
243
|
-
...classNames.map((className: any) => {
|
|
244
|
-
const data = componentMap.get(className);
|
|
245
|
-
return `componentMap.set('${className}', ${JSON.stringify(data)});`;
|
|
246
|
-
})
|
|
247
|
-
].join(`${indent}\n`)
|
|
248
|
-
});
|
|
249
|
-
// Components
|
|
250
|
-
indexContent = indexContent.replace(/([ ]*)const navigation = \[\];/, (match: any, indent: any) => {
|
|
251
|
-
return`${indent}const navigation = ${JSON.stringify(navItems, null, ' ')};`;
|
|
97
|
+
const indexContent = await createPlaygroundIndex({
|
|
98
|
+
mode: 'dev',
|
|
99
|
+
rootDir,
|
|
100
|
+
srcDir,
|
|
101
|
+
indexFile,
|
|
102
|
+
defaultDir,
|
|
103
|
+
playgroundFile,
|
|
104
|
+
title,
|
|
105
|
+
repo,
|
|
106
|
+
repoComponent,
|
|
107
|
+
navigation,
|
|
108
|
+
namespaces,
|
|
252
109
|
});
|
|
253
110
|
await writeFile(join(rootDir, distDir, indexFile), indexContent);
|
|
254
111
|
}
|
package/default/playground.html
CHANGED
|
@@ -338,9 +338,7 @@
|
|
|
338
338
|
|
|
339
339
|
<body>
|
|
340
340
|
<template id="templateInfo">
|
|
341
|
-
|
|
342
|
-
<code>npm start c-button</code>.
|
|
343
|
-
</p>
|
|
341
|
+
<!-- [info] -->
|
|
344
342
|
</template>
|
|
345
343
|
<template id="templateComponent">
|
|
346
344
|
<h2>
|
package/package.json
CHANGED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { fileExists } from "./fileExists.ts";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
export async function createPlaygroundIndex({
|
|
6
|
+
mode,
|
|
7
|
+
rootDir,
|
|
8
|
+
srcDir,
|
|
9
|
+
indexFile,
|
|
10
|
+
defaultDir,
|
|
11
|
+
playgroundFile,
|
|
12
|
+
title,
|
|
13
|
+
repo,
|
|
14
|
+
repoComponent,
|
|
15
|
+
navigation,
|
|
16
|
+
namespaces,
|
|
17
|
+
}: any) {
|
|
18
|
+
let indexContent = '';
|
|
19
|
+
if (await fileExists(join(rootDir, srcDir, indexFile))) {
|
|
20
|
+
indexContent = await readFile(join(rootDir, srcDir, indexFile), 'utf8');
|
|
21
|
+
} else {
|
|
22
|
+
console.log(defaultDir, playgroundFile);
|
|
23
|
+
indexContent = await readFile(join(defaultDir, playgroundFile), 'utf8');
|
|
24
|
+
}
|
|
25
|
+
indexContent = indexContent.replace(
|
|
26
|
+
'<title>Default</title>',
|
|
27
|
+
`<title>${title ?? 'Default'}</title>`
|
|
28
|
+
);
|
|
29
|
+
indexContent = indexContent.replace(
|
|
30
|
+
'<h1>Default</h1>',
|
|
31
|
+
`<h1>${title ?? 'Default'}</h1>`
|
|
32
|
+
);
|
|
33
|
+
const navItems = structuredClone(navigation ?? []);
|
|
34
|
+
for (let navItem of navItems) {
|
|
35
|
+
navItem.items = [];
|
|
36
|
+
}
|
|
37
|
+
let defaultItem;
|
|
38
|
+
if (navItems.length === 0) {
|
|
39
|
+
defaultItem = { label: 'Components', items: [] };
|
|
40
|
+
navItems.push(defaultItem);
|
|
41
|
+
} else {
|
|
42
|
+
defaultItem = navItems.find((x: any) => !x.extends && !x.components && !x.namespaces);
|
|
43
|
+
if (!defaultItem) {
|
|
44
|
+
defaultItem = { label: 'Other', items: [] };
|
|
45
|
+
navItems.push(defaultItem);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const componentMap = new Map();
|
|
49
|
+
// Loop and organize into lists
|
|
50
|
+
namespaces.forEach(({ components }: any) => {
|
|
51
|
+
components.forEach(({ component, namespace, tag, readme, examples, className, classExtends }: any) => {
|
|
52
|
+
// Front end data
|
|
53
|
+
componentMap.set(className, {
|
|
54
|
+
className, // MyComponent
|
|
55
|
+
classExtends, // MyModal
|
|
56
|
+
component, // component
|
|
57
|
+
namespace, // my
|
|
58
|
+
tag, // my-component
|
|
59
|
+
readme, // # My Component
|
|
60
|
+
examples: examples.map((example: any) => example.className),
|
|
61
|
+
});
|
|
62
|
+
examples.forEach((example: any) => {
|
|
63
|
+
componentMap.set(example.className, {
|
|
64
|
+
className: example.className, // XMyComponentBasic
|
|
65
|
+
classExtends: example.classExtends, // HtmlElement
|
|
66
|
+
component: example.component, // myComponentBasic
|
|
67
|
+
namespace: example.namespace, // x
|
|
68
|
+
tag: example.tag, // x-my-component-basic
|
|
69
|
+
example: example.example, // Basic
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
// Quick insert any direct includes
|
|
73
|
+
for (let navItem of navItems) {
|
|
74
|
+
if (navItem.include && navItem.include.includes(className)) {
|
|
75
|
+
navItem.items.push({
|
|
76
|
+
namespace,
|
|
77
|
+
component,
|
|
78
|
+
className,
|
|
79
|
+
tag,
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Move on to any other nav groups
|
|
85
|
+
for (let navItem of navItems) {
|
|
86
|
+
// skip default nav group
|
|
87
|
+
if (navItem === defaultItem) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// ignore if excluded
|
|
91
|
+
if (navItem.exclude && navItem.exclude.includes(className)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// ignore if not in namespace
|
|
95
|
+
if (navItem.namespaces && !navItem.namespaces.includes(namespace)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// ignore if not extending the required class
|
|
99
|
+
if (navItem.extends && !navItem.extends.includes(classExtends)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
navItem.items.push({
|
|
103
|
+
namespace,
|
|
104
|
+
component,
|
|
105
|
+
className,
|
|
106
|
+
tag,
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
defaultItem.items.push({
|
|
111
|
+
namespace,
|
|
112
|
+
component,
|
|
113
|
+
examples,
|
|
114
|
+
className,
|
|
115
|
+
tag,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
// Replace left nav
|
|
120
|
+
indexContent = indexContent.replace(/([ ]*)<!-- \[Navigation\] -->/, (match: any, indent: any) => {
|
|
121
|
+
return navItems.map(({ label, items }: any) => {
|
|
122
|
+
return [
|
|
123
|
+
indent,
|
|
124
|
+
`<div>${label}</div>`,
|
|
125
|
+
'<ul>',
|
|
126
|
+
items.map(({ component, namespace, tag, className }: any) => {
|
|
127
|
+
return [
|
|
128
|
+
`<li data-tag="${tag}" data-class-name="${className}" data-component="${component}"><a href="#${tag}">${component}</a></li>`
|
|
129
|
+
].join(`\n${indent}`);
|
|
130
|
+
}).join(`\n${indent}`),
|
|
131
|
+
'</ul>'
|
|
132
|
+
].join(`\n${indent}`)
|
|
133
|
+
}).join(`\n${indent}`);
|
|
134
|
+
});
|
|
135
|
+
// Repo
|
|
136
|
+
if (repo) {
|
|
137
|
+
const github = 'M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z';
|
|
138
|
+
const generic = 'M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z';
|
|
139
|
+
const repoIcon = repo.includes('github.com') ? github : generic;
|
|
140
|
+
indexContent = indexContent.replace(/([ ]*)<!-- \[Repo\] -->/, (match: any, indent: any) => {
|
|
141
|
+
return [
|
|
142
|
+
indent,
|
|
143
|
+
`<a href="${repo}">`,
|
|
144
|
+
' <svg viewBox="0 0 24 24">',
|
|
145
|
+
` <path fill="currentColor" d="${repoIcon}" />`,
|
|
146
|
+
' </svg>',
|
|
147
|
+
' <span>View Repo</span>',
|
|
148
|
+
'</a>'
|
|
149
|
+
].join(`\n${indent}`)
|
|
150
|
+
});
|
|
151
|
+
indexContent = indexContent.replace(/const repo = '';/, (match: any) => {
|
|
152
|
+
return `const repo = '${repo}';`;
|
|
153
|
+
});
|
|
154
|
+
indexContent = indexContent.replace(/const repoComponent = '';/, (match: any) => {
|
|
155
|
+
return `const repoComponent = '${repoComponent.replace(/\$repo/g, repo)}';`;
|
|
156
|
+
});
|
|
157
|
+
indexContent = indexContent.replace(/const repoIcon = '';/, (match: any) => {
|
|
158
|
+
return `const repoIcon = '${repoIcon}';`;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// info message
|
|
162
|
+
if (mode === 'dev') {
|
|
163
|
+
indexContent = indexContent.replace(/([ ]*)<!-- \[info\] -->/, (match: any, indent: any) => {
|
|
164
|
+
return [
|
|
165
|
+
indent,
|
|
166
|
+
'<p>This page is generated from <code>npm start</code>. To render only specific components use <code>npm start c-button</code>.</p>'
|
|
167
|
+
].join(`\n${indent}`)
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Components
|
|
171
|
+
const classNames = [...componentMap.keys()];
|
|
172
|
+
indexContent = indexContent.replace(/([ ]*)const componentMap = new Map\(\);/, (match: any, indent: any) => {
|
|
173
|
+
return [
|
|
174
|
+
`${indent}const componentMap = new Map();`,
|
|
175
|
+
...classNames.map((className: any) => {
|
|
176
|
+
const data = componentMap.get(className);
|
|
177
|
+
return `componentMap.set('${className}', ${JSON.stringify(data)});`;
|
|
178
|
+
})
|
|
179
|
+
].join(`${indent}\n`)
|
|
180
|
+
});
|
|
181
|
+
// Components
|
|
182
|
+
indexContent = indexContent.replace(/([ ]*)const navigation = \[\];/, (match: any, indent: any) => {
|
|
183
|
+
return `${indent}const navigation = ${JSON.stringify(navItems, null, ' ')};`;
|
|
184
|
+
});
|
|
185
|
+
return indexContent;
|
|
186
|
+
}
|