Skip to content

Commit 796488e

Browse files
committed
Move shopify dev renderer into own folder, begin to componentize
1 parent cdadaf2 commit 796488e

File tree

8 files changed

+706
-589
lines changed

8 files changed

+706
-589
lines changed

scripts/typedoc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {renderForShopifyDev} from './typedoc';
1+
export {renderForShopifyDev} from './shopify-dev-renderer';
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import {resolve} from 'path';
2+
import * as fs from 'fs';
3+
4+
import type {
5+
Paths,
6+
InterfaceType,
7+
} from '../types';
8+
9+
import {createDependencyGraph} from '../utilities/dependency-graph';
10+
import {renderYamlFrontMatter, findUuid, dedupe, propsTable} from './shared';
11+
import type {Node} from './shared';
12+
13+
const additionalPropsTables: string[] = [];
14+
15+
export async function extensionPoints(paths: Paths) {
16+
const extensionsIndex = resolve(`${paths.inputRoot}/src/index.ts`);
17+
18+
const graph = await createDependencyGraph(extensionsIndex);
19+
20+
const allInterfaces: InterfaceType[] = [];
21+
22+
for (const value of graph.values()) {
23+
const localValues = [...value.locals.values()];
24+
allInterfaces.push(
25+
...(localValues.filter(
26+
({kind}) => kind === 'InterfaceType',
27+
) as InterfaceType[]),
28+
);
29+
}
30+
31+
const nodes: Node[] = [];
32+
33+
graph.forEach((value) => {
34+
value.locals.forEach((value: any, key) => {
35+
if (value.kind !== 'Imported') {
36+
if (value.name == null) {
37+
value.name = key;
38+
}
39+
nodes.push({value, module: undefined});
40+
}
41+
});
42+
});
43+
44+
const interfaceEntryPoints = ['ExtensionPoints'];
45+
46+
const interfaces = allInterfaces.filter(({name}) =>
47+
interfaceEntryPoints.includes(name),
48+
);
49+
50+
const apiFile = resolve(`${paths.outputRoot}/extension-points/api.md`);
51+
const folder = resolve(`${paths.outputRoot}/extension-points`);
52+
53+
if (!fs.existsSync(folder)) {
54+
fs.mkdirSync(folder);
55+
}
56+
57+
let markdown = renderYamlFrontMatter({
58+
gid: findUuid(apiFile),
59+
url: `${paths.shopifyDevUrl}/extension-points/api`,
60+
title: 'Extension points API',
61+
hidden: true,
62+
});
63+
64+
interfaces.forEach(({name, docs, properties}) => {
65+
markdown += propsTable(name, docs, properties, nodes, extensionsIndex, additionalPropsTables);
66+
});
67+
68+
markdown += dedupe(additionalPropsTables).reverse().join('');
69+
70+
fs.writeFile(apiFile, markdown, function (err) {
71+
if (err) throw err;
72+
});
73+
74+
additionalPropsTables.length = 0;
75+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {resolve} from 'path';
2+
import * as fs from 'fs';
3+
4+
import type {Paths} from '../types';
5+
6+
import {renderYamlFrontMatter, findUuid} from './shared';
7+
8+
export function gettingStarted(paths: Paths) {
9+
const outputRoot = resolve(paths.outputRoot);
10+
const extensionPointsDocsPath = resolve(
11+
`${paths.outputRoot}/extension-points`,
12+
);
13+
14+
if (!fs.existsSync(outputRoot)) {
15+
fs.mkdirSync(outputRoot);
16+
}
17+
18+
if (!fs.existsSync(extensionPointsDocsPath)) {
19+
fs.mkdirSync(extensionPointsDocsPath);
20+
}
21+
22+
const indexFile = resolve(`${extensionPointsDocsPath}/index.md`);
23+
24+
let markdown = renderYamlFrontMatter({
25+
gid: findUuid(indexFile),
26+
url: `${paths.shopifyDevUrl}/extension-points/index`,
27+
title: 'Checkout extensions API reference',
28+
description:
29+
'API reference for Checkout extension points. Learn about global objects, rendering, components, and how you’ll interact with them.',
30+
hidden: true,
31+
});
32+
33+
const docsInputPath = resolve(`${paths.inputRoot}/documentation`);
34+
35+
const files = ['extension-points.md', 'globals.md', 'rendering.md'];
36+
37+
if (fs.existsSync(docsInputPath)) {
38+
files.forEach((file) => {
39+
markdown += `${fs.readFileSync(`${docsInputPath}/${file}`, 'utf8')}\n`;
40+
});
41+
}
42+
43+
// Demote each heading
44+
markdown = markdown.replace(/# /g, '## ');
45+
// Replace github links to in-page anchors
46+
markdown = markdown.replace(/\.\/([\w-]+)\.md/g, '#$1');
47+
// Add a link to the extension points API
48+
markdown = markdown.replace(
49+
' `Checkout::Feature::Render`',
50+
` [\`Checkout::Feature::Render\`](${paths.shopifyDevUrl}/extension-points/api)`,
51+
);
52+
markdown = markdown.replace(
53+
'#components',
54+
`${paths.shopifyDevUrl}/components`,
55+
);
56+
57+
fs.writeFile(indexFile, markdown, function (err) {
58+
if (err) throw err;
59+
});
60+
61+
return markdown;
62+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Paths} from '../types';
2+
3+
import {gettingStarted} from './getting-started';
4+
import {extensionPoints, components} from './typedoc';
5+
6+
export function renderForShopifyDev(paths: Paths) {
7+
extensionPoints(paths);
8+
components(paths);
9+
gettingStarted(paths);
10+
}

0 commit comments

Comments
 (0)