@docfy/ember 0.9.0 → 0.9.1-beta.0
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/README.md +8 -5
- package/addon-main.cjs +4 -0
- package/declarations/components/docfy-demo.d.ts +44 -0
- package/declarations/components/docfy-demo.d.ts.map +1 -0
- package/declarations/components/docfy-link.d.ts +23 -0
- package/declarations/components/docfy-link.d.ts.map +1 -0
- package/declarations/components/docfy-output.d.ts +24 -0
- package/declarations/components/docfy-output.d.ts.map +1 -0
- package/declarations/components/docfy-previous-and-next-page.d.ts +23 -0
- package/declarations/components/docfy-previous-and-next-page.d.ts.map +1 -0
- package/declarations/index.d.ts +7 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/routing.d.ts +3 -0
- package/declarations/routing.d.ts.map +1 -0
- package/{services → declarations/services}/docfy.d.ts +4 -8
- package/declarations/services/docfy.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +11 -0
- package/declarations/template-registry.d.ts.map +1 -0
- package/dist/_app_/components/docfy-demo.js +1 -0
- package/dist/_app_/components/docfy-link.js +1 -0
- package/dist/_app_/components/docfy-output.js +1 -0
- package/dist/_app_/components/docfy-previous-and-next-page.js +1 -0
- package/dist/_app_/services/docfy.js +1 -0
- package/dist/components/docfy-demo.js +121 -0
- package/dist/components/docfy-demo.js.map +1 -0
- package/dist/components/docfy-link.js +58 -0
- package/dist/components/docfy-link.js.map +1 -0
- package/dist/components/docfy-output.js +43 -0
- package/dist/components/docfy-output.js.map +1 -0
- package/dist/components/docfy-previous-and-next-page.js +27 -0
- package/dist/components/docfy-previous-and-next-page.js.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +2 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +17 -0
- package/dist/output.js.map +1 -0
- package/dist/routing.js +29 -0
- package/dist/routing.js.map +1 -0
- package/dist/services/docfy.js +87 -0
- package/dist/services/docfy.js.map +1 -0
- package/dist/template-registry.js +2 -0
- package/dist/template-registry.js.map +1 -0
- package/package.json +91 -124
- package/-private/find-previous-or-next-page.d.ts +0 -2
- package/-private/flat-nested.d.ts +0 -2
- package/.docfy-config.js +0 -40
- package/addon/-private/find-previous-or-next-page.ts +0 -22
- package/addon/-private/flat-nested.ts +0 -18
- package/addon/components/docfy-demo/description.hbs +0 -26
- package/addon/components/docfy-demo/description.ts +0 -3
- package/addon/components/docfy-demo/example.hbs +0 -3
- package/addon/components/docfy-demo/example.ts +0 -3
- package/addon/components/docfy-demo/snippet.hbs +0 -8
- package/addon/components/docfy-demo/snippet.ts +0 -35
- package/addon/components/docfy-demo/snippets.hbs +0 -25
- package/addon/components/docfy-demo/snippets.ts +0 -27
- package/addon/components/docfy-demo.hbs +0 -10
- package/addon/components/docfy-demo.ts +0 -7
- package/addon/components/docfy-link.hbs +0 -8
- package/addon/components/docfy-link.ts +0 -54
- package/addon/components/docfy-output.hbs +0 -1
- package/addon/components/docfy-output.ts +0 -37
- package/addon/components/docfy-previous-and-next-page.hbs +0 -1
- package/addon/components/docfy-previous-and-next-page.ts +0 -20
- package/addon/helpers/docfy-eq.ts +0 -7
- package/addon/index.ts +0 -31
- package/addon/output.d.ts +0 -13
- package/addon/services/docfy.ts +0 -101
- package/app/components/docfy-demo/description.js +0 -1
- package/app/components/docfy-demo/example.js +0 -1
- package/app/components/docfy-demo/snippet.js +0 -1
- package/app/components/docfy-demo/snippets.js +0 -1
- package/app/components/docfy-demo.js +0 -1
- package/app/components/docfy-link.js +0 -1
- package/app/components/docfy-output.js +0 -1
- package/app/components/docfy-previous-and-next-page.js +0 -1
- package/app/helpers/docfy-eq.js +0 -1
- package/app/services/docfy.js +0 -1
- package/components/docfy-demo/description.d.ts +0 -3
- package/components/docfy-demo/example.d.ts +0 -3
- package/components/docfy-demo/snippet.d.ts +0 -13
- package/components/docfy-demo/snippets.d.ts +0 -11
- package/components/docfy-demo.d.ts +0 -7
- package/components/docfy-link.d.ts +0 -15
- package/components/docfy-output.d.ts +0 -16
- package/components/docfy-previous-and-next-page.d.ts +0 -12
- package/config/environment.js +0 -5
- package/docs/components/docfy-demo.md +0 -67
- package/docs/components/docfy-link-demo/anchor.md +0 -9
- package/docs/components/docfy-link-demo/simple.md +0 -7
- package/docs/components/docfy-link.md +0 -31
- package/docs/components/docfy-output-demo/edit-page.md +0 -54
- package/docs/components/docfy-output-demo/flat.md +0 -23
- package/docs/components/docfy-output-demo/on-this-page.md +0 -30
- package/docs/components/docfy-output-demo/sidebar.md +0 -45
- package/docs/components/docfy-output-demo/top-nav.md +0 -35
- package/docs/components/docfy-output.md +0 -34
- package/docs/components/docfy-previous-and-next-page-demo/scope.md +0 -26
- package/docs/components/docfy-previous-and-next-page-demo/simple.md +0 -24
- package/docs/components/docfy-previous-and-next-page.md +0 -21
- package/docs/configuration.md +0 -57
- package/docs/index.md +0 -165
- package/docs/writing-demos-demo/demo1.md +0 -18
- package/docs/writing-demos.md +0 -109
- package/dummy-docs/README.md +0 -140
- package/dummy-docs/github-icon.png +0 -0
- package/dummy-docs/installation.md +0 -14
- package/dummy-docs/introduction.md +0 -30
- package/dummy-docs/overview.md +0 -19
- package/dummy-docs/packages/core/helpers/genereate-flat-output.md +0 -10
- package/dummy-docs/packages/core/helpers/genereate-nested-output.md +0 -12
- package/dummy-docs/packages/core/overview.md +0 -19
- package/dummy-docs/packages/ember/components/docfy-link-demo/demo1.md +0 -26
- package/dummy-docs/packages/ember/components/docfy-link-demo/demo2.md +0 -20
- package/dummy-docs/packages/ember/components/docfy-link.md +0 -19
- package/dummy-docs/packages/ember/components/docfy-output.md +0 -32
- package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2-demo/demo1.md +0 -25
- package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2.md +0 -9
- package/dummy-docs/packages/ember/demo/my-ember-demo.md +0 -3
- package/dummy-docs/packages/ember/index.md +0 -23
- package/dummy-docs/packages/ember/installation.md +0 -14
- package/dummy-docs/packages/ember/plugins/manual-demo-insertion-demo/tomster.md +0 -15
- package/dummy-docs/packages/ember/plugins/manual-demo-insertion-demo/zoey.md +0 -9
- package/dummy-docs/packages/ember/plugins/manual-demo-insertion.md +0 -31
- package/dummy-docs/packages/ember/preview.md +0 -20
- package/ember-cli-addon.js +0 -3
- package/helpers/docfy-eq.d.ts +0 -7
- package/index.d.ts +0 -3
- package/lib/docfy-output-template.d.ts +0 -1
- package/lib/docfy-output-template.js +0 -23
- package/lib/get-config.d.ts +0 -7
- package/lib/get-config.js +0 -118
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -177
- package/lib/plugins/extract-demos-to-components.d.ts +0 -2
- package/lib/plugins/extract-demos-to-components.js +0 -149
- package/lib/plugins/preview-template.d.ts +0 -2
- package/lib/plugins/preview-template.js +0 -41
- package/lib/plugins/replace-internal-links-with-docfy-link.d.ts +0 -6
- package/lib/plugins/replace-internal-links-with-docfy-link.js +0 -44
- package/lib/plugins/types.d.ts +0 -29
- package/lib/plugins/types.js +0 -2
- package/lib/plugins/utils.d.ts +0 -31
- package/lib/plugins/utils.js +0 -142
- package/output.d.ts +0 -13
- package/src/docfy-output-template.ts +0 -20
- package/src/get-config.ts +0 -109
- package/src/index.ts +0 -229
- package/src/plugins/extract-demos-to-components.ts +0 -196
- package/src/plugins/preview-template.ts +0 -54
- package/src/plugins/replace-internal-links-with-docfy-link.ts +0 -61
- package/src/plugins/types.ts +0 -33
- package/src/plugins/utils.ts +0 -191
- package/src/tsconfig.json +0 -14
- package/src/types/broccoli-bridge.d.ts +0 -11
- package/src/types/broccoli-file-creator.d.ts +0 -11
- package/src/types/broccoli-funnel.d.ts +0 -19
- package/src/types/broccoli-merge-trees.d.ts +0 -13
- package/src/types/broccoli-source.d.ts +0 -9
- package/src/types/mdast-util-to-string.d.ts +0 -5
- package/src/types/unist-util-find.d.ts +0 -8
- package/tsconfig.json +0 -42
- package/types/dummy/index.d.ts +0 -0
- package/types/ember-get-config/index.d.ts +0 -9
- package/types/global.d.ts +0 -6
package/src/index.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import BroccoliBridge from 'broccoli-bridge';
|
|
4
|
-
import Funnel from 'broccoli-funnel';
|
|
5
|
-
import MergeTrees from 'broccoli-merge-trees';
|
|
6
|
-
import Plugin from 'broccoli-plugin';
|
|
7
|
-
import WriteFile from 'broccoli-file-creator';
|
|
8
|
-
import { Node, InputNode } from 'broccoli-node-api';
|
|
9
|
-
import { UnwatchedDir } from 'broccoli-source';
|
|
10
|
-
import Docfy from '@docfy/core';
|
|
11
|
-
import { DocfyConfig, SourceConfig } from '@docfy/core/lib/types';
|
|
12
|
-
import { DemoComponentChunk } from './plugins/types';
|
|
13
|
-
import docfyOutputTemplate from './docfy-output-template';
|
|
14
|
-
import getDocfyConfig from './get-config';
|
|
15
|
-
import { isDemoComponents } from './plugins/utils';
|
|
16
|
-
import cacheKeyForTree from 'calculate-cache-key-for-tree';
|
|
17
|
-
import debugFactory from 'debug';
|
|
18
|
-
const debug = debugFactory('@docfy/ember');
|
|
19
|
-
|
|
20
|
-
const templateOnlyComponent = `
|
|
21
|
-
import Component from '@glimmer/component';
|
|
22
|
-
export default class extends Component {}
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
function ensureDirectoryExistence(filePath: string): void {
|
|
26
|
-
const dirname = path.dirname(filePath);
|
|
27
|
-
if (fs.existsSync(dirname)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
ensureDirectoryExistence(dirname);
|
|
31
|
-
fs.mkdirSync(dirname);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function hasBackingJS(chunks: DemoComponentChunk[]): boolean {
|
|
35
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
36
|
-
const chunk = chunks[i];
|
|
37
|
-
|
|
38
|
-
if (['js', 'ts', 'gts', 'gjs'].includes(chunk.ext)) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line
|
|
46
|
-
function isDeepAddonInstance(addon: any): boolean {
|
|
47
|
-
return addon.parent !== addon.project;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class DocfyBroccoli extends Plugin {
|
|
51
|
-
config: DocfyConfig;
|
|
52
|
-
|
|
53
|
-
constructor(inputNodes: InputNode[], options = {}) {
|
|
54
|
-
super(inputNodes, options);
|
|
55
|
-
this.config = options as DocfyConfig;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async build(): Promise<void> {
|
|
59
|
-
debug('Output Path: ', this.outputPath);
|
|
60
|
-
debug('Config: ', this.config);
|
|
61
|
-
const docfy = new Docfy(this.config);
|
|
62
|
-
const result = await docfy.run(this.config.sources as SourceConfig[]);
|
|
63
|
-
const snippets = {
|
|
64
|
-
components: {}
|
|
65
|
-
};
|
|
66
|
-
result.content.forEach((page) => {
|
|
67
|
-
const parts = [this.outputPath, 'templates', page.meta.url];
|
|
68
|
-
|
|
69
|
-
if (page.meta.url[page.meta.url.length - 1] === '/') {
|
|
70
|
-
parts.push('index');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const fileName = `${path.join(...parts)}.hbs`;
|
|
74
|
-
|
|
75
|
-
// console.log(fileName, "RENDERED AS", page.rendered);
|
|
76
|
-
ensureDirectoryExistence(fileName);
|
|
77
|
-
fs.writeFileSync(fileName, page.rendered);
|
|
78
|
-
|
|
79
|
-
const demoComponents = page.pluginData.demoComponents;
|
|
80
|
-
if (isDemoComponents(demoComponents)) {
|
|
81
|
-
demoComponents.forEach((component) => {
|
|
82
|
-
component.chunks.forEach((chunk) => {
|
|
83
|
-
const chunkPath = path.join(
|
|
84
|
-
this.outputPath,
|
|
85
|
-
'components',
|
|
86
|
-
`${component.name.dashCase}.${chunk.ext}`
|
|
87
|
-
);
|
|
88
|
-
ensureDirectoryExistence(chunkPath);
|
|
89
|
-
|
|
90
|
-
snippets.components[`${component.name.dashCase}`] = {
|
|
91
|
-
...(snippets.components[`${component.name.dashCase}`] || {}),
|
|
92
|
-
[chunk.ext]: chunk.code
|
|
93
|
-
};
|
|
94
|
-
fs.writeFileSync(chunkPath, chunk.code);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (!hasBackingJS(component.chunks)) {
|
|
98
|
-
const chunkPath = path.join(
|
|
99
|
-
this.outputPath,
|
|
100
|
-
'components',
|
|
101
|
-
`${component.name.dashCase}.js`
|
|
102
|
-
);
|
|
103
|
-
ensureDirectoryExistence(chunkPath);
|
|
104
|
-
snippets.components[`${component.name.dashCase}`] = {
|
|
105
|
-
...(snippets.components[`${component.name.dashCase}`] || {}),
|
|
106
|
-
js: templateOnlyComponent
|
|
107
|
-
};
|
|
108
|
-
fs.writeFileSync(chunkPath, templateOnlyComponent);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
fs.writeFileSync(
|
|
115
|
-
path.join(this.outputPath, 'docfy-output.js'),
|
|
116
|
-
`export default ${JSON.stringify({ nested: result.nestedPageMetadata })};`
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const urlsJsonFile = path.join(
|
|
120
|
-
this.outputPath,
|
|
121
|
-
'public',
|
|
122
|
-
'docfy-urls.json'
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
ensureDirectoryExistence(urlsJsonFile);
|
|
126
|
-
fs.writeFileSync(
|
|
127
|
-
urlsJsonFile,
|
|
128
|
-
JSON.stringify(result.content.map((page) => page.meta.url))
|
|
129
|
-
);
|
|
130
|
-
const snippetsJsonFile = path.join(
|
|
131
|
-
this.outputPath,
|
|
132
|
-
'public',
|
|
133
|
-
'docfy-snippets.json'
|
|
134
|
-
);
|
|
135
|
-
ensureDirectoryExistence(snippetsJsonFile);
|
|
136
|
-
fs.writeFileSync(snippetsJsonFile, JSON.stringify(snippets));
|
|
137
|
-
result.staticAssets.forEach((asset) => {
|
|
138
|
-
const dest = path.join(this.outputPath, 'public', asset.toPath);
|
|
139
|
-
ensureDirectoryExistence(dest);
|
|
140
|
-
fs.copyFileSync(asset.fromPath, dest);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
module.exports = {
|
|
146
|
-
name: require('../package').name, // eslint-disable-line
|
|
147
|
-
|
|
148
|
-
docfyConfig: undefined,
|
|
149
|
-
|
|
150
|
-
included(...args: unknown[]): void {
|
|
151
|
-
if (!isDeepAddonInstance(this)) {
|
|
152
|
-
this.docfyConfig = getDocfyConfig(this.project.root);
|
|
153
|
-
this.bridge = new BroccoliBridge();
|
|
154
|
-
}
|
|
155
|
-
this._super.included.apply(this, args);
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
// Re-enables caching of this addon, due to opting out
|
|
159
|
-
// of the caching implicitly by specifying treeFor* methods
|
|
160
|
-
cacheKeyForTree(treeType: string): string {
|
|
161
|
-
switch (treeType) {
|
|
162
|
-
case 'app':
|
|
163
|
-
case 'addon': {
|
|
164
|
-
return cacheKeyForTree(treeType, this, [this.docfyConfig]);
|
|
165
|
-
}
|
|
166
|
-
default:
|
|
167
|
-
return cacheKeyForTree(treeType, this);
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
treeForApp(tree: Node): Node {
|
|
172
|
-
const trees: Node[] = [this._super.treeForApp.call(this, tree)];
|
|
173
|
-
if (isDeepAddonInstance(this)) {
|
|
174
|
-
return trees[0];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const inputs: InputNode[] = [new UnwatchedDir(this.project.root)];
|
|
178
|
-
|
|
179
|
-
(this.docfyConfig as DocfyConfig).sources.forEach((item) => {
|
|
180
|
-
if (item.root && item.root !== this.project.root) {
|
|
181
|
-
inputs.push(item.root);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const docfyTree = new DocfyBroccoli(inputs, this.docfyConfig);
|
|
186
|
-
trees.push(docfyTree);
|
|
187
|
-
|
|
188
|
-
(this.bridge as BroccoliBridge).fulfill('docfy-tree', docfyTree);
|
|
189
|
-
|
|
190
|
-
return new MergeTrees(trees, { overwrite: true });
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
treeForAddon(tree: Node): Node {
|
|
194
|
-
const trees: Node[] = [this._super.treeForAddon.call(this, tree)];
|
|
195
|
-
if (isDeepAddonInstance(this)) {
|
|
196
|
-
return trees[0];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const EmberApp = require('ember-cli/lib/broccoli/ember-app'); // eslint-disable-line
|
|
200
|
-
const modulePrefix = this.project.config(EmberApp.env()).modulePrefix;
|
|
201
|
-
|
|
202
|
-
trees.push(new WriteFile('output.js', docfyOutputTemplate(modulePrefix)));
|
|
203
|
-
|
|
204
|
-
return new MergeTrees(trees);
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
treeForPublic(): Node | undefined {
|
|
208
|
-
if (isDeepAddonInstance(this)) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return new Funnel(
|
|
213
|
-
(this.bridge as BroccoliBridge).placeholderFor('docfy-tree'),
|
|
214
|
-
{
|
|
215
|
-
srcDir: 'public',
|
|
216
|
-
destDir: './'
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
urlsForPrember(distDir: string): string[] {
|
|
222
|
-
try {
|
|
223
|
-
return require(path.join(distDir, 'docfy-urls.json')); // eslint-disable-line
|
|
224
|
-
} catch {
|
|
225
|
-
// empty
|
|
226
|
-
}
|
|
227
|
-
return [];
|
|
228
|
-
}
|
|
229
|
-
};
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import visit from 'unist-util-visit';
|
|
2
|
-
import { Context, PageContent } from '@docfy/core/lib/types';
|
|
3
|
-
import plugin from '@docfy/core/lib/plugin';
|
|
4
|
-
import { Node, Parent } from 'unist';
|
|
5
|
-
import findNode from 'unist-util-find';
|
|
6
|
-
import toString from 'mdast-util-to-string';
|
|
7
|
-
import { DemoComponent, DemoComponentChunk, CodeNode } from './types';
|
|
8
|
-
import {
|
|
9
|
-
generateDemoComponentName,
|
|
10
|
-
getExt,
|
|
11
|
-
createDemoNodes,
|
|
12
|
-
deleteNode,
|
|
13
|
-
isDemoComponents
|
|
14
|
-
} from './utils';
|
|
15
|
-
import path from 'path';
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
* Create the heading for the examples section of the page.
|
|
19
|
-
*
|
|
20
|
-
* It uses the remark stack to make sure any plugins that manage headings can be
|
|
21
|
-
* executed.
|
|
22
|
-
*
|
|
23
|
-
* This is necessary for apps using remark-autolink-headings, for example.
|
|
24
|
-
*/
|
|
25
|
-
function createHeading(ctx: Context): Node {
|
|
26
|
-
const heading = (
|
|
27
|
-
ctx.remark.runSync(ctx.remark.parse('## Examples')).children as Node[]
|
|
28
|
-
)[0];
|
|
29
|
-
heading.depth = 2;
|
|
30
|
-
return heading;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const isTextMarker = (node: Parent): boolean =>
|
|
34
|
-
node.type === 'paragraph' &&
|
|
35
|
-
node.children.length === 1 &&
|
|
36
|
-
node.children[0].type === 'text';
|
|
37
|
-
|
|
38
|
-
const demoMarkerRegex = /^\[\[demo:(.+?)\]\]$/;
|
|
39
|
-
const demoMarker = (node: Parent): boolean =>
|
|
40
|
-
isTextMarker(node) && demoMarkerRegex.test(node.children[0].value as string);
|
|
41
|
-
|
|
42
|
-
const demosAllMarkerRegex = /^\[\[demos-all\]\]$/;
|
|
43
|
-
const demosAllMarker = (node: Parent): boolean =>
|
|
44
|
-
isTextMarker(node) &&
|
|
45
|
-
demosAllMarkerRegex.test(node.children[0].value as string);
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* Insert Demo nodes into the page.
|
|
49
|
-
*/
|
|
50
|
-
function insertDemoNodesIntoPage(page: PageContent, toInsert: Node[]): void {
|
|
51
|
-
if (Array.isArray(page.ast.children)) {
|
|
52
|
-
const secondHeading = findNode(
|
|
53
|
-
page.ast,
|
|
54
|
-
(node: Node) => node.type === 'heading' && node.depth !== 1
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
if (secondHeading) {
|
|
58
|
-
const index = page.ast.children.findIndex((el) => el === secondHeading);
|
|
59
|
-
page.ast.children.splice(index, 0, ...toInsert);
|
|
60
|
-
} else {
|
|
61
|
-
page.ast.children.push(...toInsert);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function replaceDemoMarkers(page: PageContent, demos: DemoComponent[]): void {
|
|
67
|
-
if (Array.isArray(page.ast.children)) {
|
|
68
|
-
const markers: Parent[] = [];
|
|
69
|
-
const allMarkers: Parent[] = [];
|
|
70
|
-
|
|
71
|
-
visit(page.ast, 'paragraph', (node: Parent) => {
|
|
72
|
-
if (demoMarker(node)) markers.push(node);
|
|
73
|
-
if (demosAllMarker(node)) allMarkers.push(node);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
markers.forEach((marker) => {
|
|
77
|
-
const child = marker.children[0];
|
|
78
|
-
const matches = (child.value as string).match(demoMarkerRegex);
|
|
79
|
-
if (!matches) return;
|
|
80
|
-
|
|
81
|
-
// TODO: This is an inner loop and can cause perf issues if someone
|
|
82
|
-
// out there has many demos on a single page. It would be better to
|
|
83
|
-
// create a demo component hash that can be looked up by demo name.
|
|
84
|
-
const demoName = matches[1];
|
|
85
|
-
const demo = demos.find((d) => d.name.dashCase.endsWith(demoName));
|
|
86
|
-
|
|
87
|
-
if (!demo) {
|
|
88
|
-
console.warn(
|
|
89
|
-
`Found demo marker "${demoName}" with no matching demo component in ${page.source}`
|
|
90
|
-
);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
marker.type = 'div';
|
|
95
|
-
marker.children.splice(0, 1, ...createDemoNodes(demo));
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
allMarkers.forEach((marker) => {
|
|
99
|
-
const demoNodes = demos
|
|
100
|
-
.map((component) => createDemoNodes(component))
|
|
101
|
-
.flat();
|
|
102
|
-
|
|
103
|
-
marker.type = 'div';
|
|
104
|
-
marker.children.splice(0, 1, ...demoNodes);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export default plugin({
|
|
110
|
-
runWithMdast(ctx: Context): void {
|
|
111
|
-
const seenNames: Set<string> = new Set();
|
|
112
|
-
|
|
113
|
-
ctx.pages.forEach((page) => {
|
|
114
|
-
if (page.demos) {
|
|
115
|
-
const demoComponents: DemoComponent[] = [];
|
|
116
|
-
|
|
117
|
-
page.demos.forEach((demo) => {
|
|
118
|
-
const chunks: DemoComponentChunk[] = [];
|
|
119
|
-
|
|
120
|
-
visit(demo.ast, 'code', (node: CodeNode) => {
|
|
121
|
-
if (['component', 'template', 'styles'].includes(node.meta || '')) {
|
|
122
|
-
chunks.push({
|
|
123
|
-
snippet: node,
|
|
124
|
-
code: node.value.replace(/\\{{/g, '{{'), // un-escape hbs
|
|
125
|
-
ext: getExt(
|
|
126
|
-
node.lang || (node.meta === 'template' ? 'hbs' : 'js')
|
|
127
|
-
),
|
|
128
|
-
type: node.meta as string
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// 1. exclude extension
|
|
134
|
-
// 2. remove /index.md because of web conventions
|
|
135
|
-
const baseName = page.source.replace('/index.md', '').split('.')[0];
|
|
136
|
-
|
|
137
|
-
const componentName = generateDemoComponentName(
|
|
138
|
-
`docfy-demo-${baseName}-${
|
|
139
|
-
path.basename(demo.source).split('.')[0]
|
|
140
|
-
}`,
|
|
141
|
-
seenNames
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const demoTitle = findNode(
|
|
145
|
-
demo.ast,
|
|
146
|
-
(node: Node) => node.type === 'heading' && node.depth === 1
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (demoTitle) {
|
|
150
|
-
demoTitle.depth = 3;
|
|
151
|
-
demoTitle.data = {
|
|
152
|
-
...(demoTitle.data || {}),
|
|
153
|
-
id: componentName.dashCase,
|
|
154
|
-
docfyDelete: true // mark the heading to be deleted by @docfy/core TOC plugin
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
demoComponents.push({
|
|
159
|
-
name: componentName,
|
|
160
|
-
chunks,
|
|
161
|
-
description: {
|
|
162
|
-
title: demoTitle ? toString(demoTitle) : undefined,
|
|
163
|
-
ast: demo.ast,
|
|
164
|
-
editUrl: demo.meta.editUrl
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Delete used code blocks
|
|
169
|
-
chunks.forEach(({ snippet }) => {
|
|
170
|
-
deleteNode(demo.ast.children, snippet);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
if (page.meta.frontmatter.manualDemoInsertion) {
|
|
175
|
-
// Manual demo insertion inserts demos into markdown files
|
|
176
|
-
// wherever there is a demo marker ([[demo:name]] or [[demos-all]])
|
|
177
|
-
replaceDemoMarkers(page, demoComponents);
|
|
178
|
-
} else {
|
|
179
|
-
// Automatic demo insertion creates an Example block after
|
|
180
|
-
// the first heading.
|
|
181
|
-
const toInsert: Node[] = [createHeading(ctx)];
|
|
182
|
-
demoComponents.forEach((component) => {
|
|
183
|
-
toInsert.push(...createDemoNodes(component));
|
|
184
|
-
});
|
|
185
|
-
insertDemoNodesIntoPage(page, toInsert);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (isDemoComponents(page.pluginData.demoComponents)) {
|
|
189
|
-
page.pluginData.demoComponents.push(...demoComponents);
|
|
190
|
-
} else {
|
|
191
|
-
page.pluginData.demoComponents = demoComponents;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import visit from 'unist-util-visit';
|
|
2
|
-
import plugin from '@docfy/core/lib/plugin';
|
|
3
|
-
import { DemoComponent, CodeNode } from './types';
|
|
4
|
-
import {
|
|
5
|
-
generateDemoComponentName,
|
|
6
|
-
getExt,
|
|
7
|
-
createDemoNodes,
|
|
8
|
-
isDemoComponents,
|
|
9
|
-
replaceNode
|
|
10
|
-
} from './utils';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
|
|
13
|
-
export default plugin({
|
|
14
|
-
runWithMdast(ctx): void {
|
|
15
|
-
const seenNames: Set<string> = new Set();
|
|
16
|
-
|
|
17
|
-
ctx.pages.forEach((page) => {
|
|
18
|
-
const demoComponents: DemoComponent[] = [];
|
|
19
|
-
|
|
20
|
-
visit(page.ast, 'code', (node: CodeNode) => {
|
|
21
|
-
if (['preview-template', 'preview'].includes(node.meta || '')) {
|
|
22
|
-
demoComponents.push({
|
|
23
|
-
name: generateDemoComponentName(
|
|
24
|
-
`docfy-demo-preview-${path.basename(page.meta.url)}`,
|
|
25
|
-
seenNames
|
|
26
|
-
),
|
|
27
|
-
chunks: [
|
|
28
|
-
{
|
|
29
|
-
snippet: node,
|
|
30
|
-
code: node.value.replace(/\\{{/g, '{{'), // un-escape hbs
|
|
31
|
-
ext: getExt(node.lang || 'hbs'),
|
|
32
|
-
type: node.meta as string
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
demoComponents.forEach((demoComponent) => {
|
|
40
|
-
replaceNode(
|
|
41
|
-
page.ast.children,
|
|
42
|
-
demoComponent.chunks[0].snippet,
|
|
43
|
-
...createDemoNodes(demoComponent)
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (isDemoComponents(page.pluginData.demoComponents)) {
|
|
48
|
-
page.pluginData.demoComponents.push(...demoComponents);
|
|
49
|
-
} else {
|
|
50
|
-
page.pluginData.demoComponents = demoComponents;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import plugin from '@docfy/core/lib/plugin';
|
|
2
|
-
import visit from 'unist-util-visit';
|
|
3
|
-
import { PageContent } from '@docfy/core/lib/types';
|
|
4
|
-
import { Node } from 'unist';
|
|
5
|
-
import u from 'unist-builder';
|
|
6
|
-
|
|
7
|
-
interface LinkNode extends Node {
|
|
8
|
-
title: string | null;
|
|
9
|
-
url: string;
|
|
10
|
-
children: Node[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function visitor(page: PageContent): void {
|
|
14
|
-
visit(page.ast, 'link', (node: LinkNode, index, parent) => {
|
|
15
|
-
if (node.url[0] === '/') {
|
|
16
|
-
const data = node.data || (node.data = {});
|
|
17
|
-
const props = (data.hProperties || (data.hProperties = {})) as Record<
|
|
18
|
-
string,
|
|
19
|
-
unknown
|
|
20
|
-
>;
|
|
21
|
-
|
|
22
|
-
const urlParts = node.url.split('#');
|
|
23
|
-
const attributes = Object.keys(props)
|
|
24
|
-
.map((key) => {
|
|
25
|
-
return `${key}=${String(props[key])}`;
|
|
26
|
-
})
|
|
27
|
-
.join(' ');
|
|
28
|
-
|
|
29
|
-
const toInsert: Node[] = [
|
|
30
|
-
u(
|
|
31
|
-
'html',
|
|
32
|
-
`<DocfyLink @to="${urlParts[0]}" ${
|
|
33
|
-
urlParts[1] ? `@anchor="${urlParts[1]}"` : ''
|
|
34
|
-
} ${attributes}>`
|
|
35
|
-
),
|
|
36
|
-
...node.children,
|
|
37
|
-
u('html', `</DocfyLink>`)
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
parent?.children.splice(index, 1, ...toInsert);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* This function finds all the links starting with an `/` and replace them with
|
|
47
|
-
* the `DocfyLink` component.
|
|
48
|
-
*/
|
|
49
|
-
export default plugin({
|
|
50
|
-
runWithMdast(ctx): void {
|
|
51
|
-
ctx.pages.forEach((page) => {
|
|
52
|
-
visitor(page);
|
|
53
|
-
|
|
54
|
-
if (Array.isArray(page.demos)) {
|
|
55
|
-
page.demos.forEach((demo) => {
|
|
56
|
-
visitor(demo);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
});
|
package/src/plugins/types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Node } from 'unist';
|
|
2
|
-
|
|
3
|
-
interface Literal {
|
|
4
|
-
value: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface CodeNode extends Node, Literal {
|
|
8
|
-
type: 'code';
|
|
9
|
-
lang?: string;
|
|
10
|
-
meta?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface DemoComponent {
|
|
14
|
-
name: DemoComponentName;
|
|
15
|
-
chunks: DemoComponentChunk[];
|
|
16
|
-
description?: {
|
|
17
|
-
title?: string;
|
|
18
|
-
ast: Node;
|
|
19
|
-
editUrl?: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface DemoComponentName {
|
|
24
|
-
dashCase: string;
|
|
25
|
-
pascalCase: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DemoComponentChunk {
|
|
29
|
-
type: string;
|
|
30
|
-
code: string;
|
|
31
|
-
ext: string;
|
|
32
|
-
snippet: Node;
|
|
33
|
-
}
|