@docfy/ember 0.9.0 → 0.10.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
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
7
|
-
const plugin_1 = __importDefault(require("@docfy/core/lib/plugin"));
|
|
8
|
-
const unist_util_find_1 = __importDefault(require("unist-util-find"));
|
|
9
|
-
const mdast_util_to_string_1 = __importDefault(require("mdast-util-to-string"));
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
/*
|
|
13
|
-
* Create the heading for the examples section of the page.
|
|
14
|
-
*
|
|
15
|
-
* It uses the remark stack to make sure any plugins that manage headings can be
|
|
16
|
-
* executed.
|
|
17
|
-
*
|
|
18
|
-
* This is necessary for apps using remark-autolink-headings, for example.
|
|
19
|
-
*/
|
|
20
|
-
function createHeading(ctx) {
|
|
21
|
-
const heading = ctx.remark.runSync(ctx.remark.parse('## Examples')).children[0];
|
|
22
|
-
heading.depth = 2;
|
|
23
|
-
return heading;
|
|
24
|
-
}
|
|
25
|
-
const isTextMarker = (node) => node.type === 'paragraph' &&
|
|
26
|
-
node.children.length === 1 &&
|
|
27
|
-
node.children[0].type === 'text';
|
|
28
|
-
const demoMarkerRegex = /^\[\[demo:(.+?)\]\]$/;
|
|
29
|
-
const demoMarker = (node) => isTextMarker(node) && demoMarkerRegex.test(node.children[0].value);
|
|
30
|
-
const demosAllMarkerRegex = /^\[\[demos-all\]\]$/;
|
|
31
|
-
const demosAllMarker = (node) => isTextMarker(node) &&
|
|
32
|
-
demosAllMarkerRegex.test(node.children[0].value);
|
|
33
|
-
/*
|
|
34
|
-
* Insert Demo nodes into the page.
|
|
35
|
-
*/
|
|
36
|
-
function insertDemoNodesIntoPage(page, toInsert) {
|
|
37
|
-
if (Array.isArray(page.ast.children)) {
|
|
38
|
-
const secondHeading = (0, unist_util_find_1.default)(page.ast, (node) => node.type === 'heading' && node.depth !== 1);
|
|
39
|
-
if (secondHeading) {
|
|
40
|
-
const index = page.ast.children.findIndex((el) => el === secondHeading);
|
|
41
|
-
page.ast.children.splice(index, 0, ...toInsert);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
page.ast.children.push(...toInsert);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function replaceDemoMarkers(page, demos) {
|
|
49
|
-
if (Array.isArray(page.ast.children)) {
|
|
50
|
-
const markers = [];
|
|
51
|
-
const allMarkers = [];
|
|
52
|
-
(0, unist_util_visit_1.default)(page.ast, 'paragraph', (node) => {
|
|
53
|
-
if (demoMarker(node))
|
|
54
|
-
markers.push(node);
|
|
55
|
-
if (demosAllMarker(node))
|
|
56
|
-
allMarkers.push(node);
|
|
57
|
-
});
|
|
58
|
-
markers.forEach((marker) => {
|
|
59
|
-
const child = marker.children[0];
|
|
60
|
-
const matches = child.value.match(demoMarkerRegex);
|
|
61
|
-
if (!matches)
|
|
62
|
-
return;
|
|
63
|
-
// TODO: This is an inner loop and can cause perf issues if someone
|
|
64
|
-
// out there has many demos on a single page. It would be better to
|
|
65
|
-
// create a demo component hash that can be looked up by demo name.
|
|
66
|
-
const demoName = matches[1];
|
|
67
|
-
const demo = demos.find((d) => d.name.dashCase.endsWith(demoName));
|
|
68
|
-
if (!demo) {
|
|
69
|
-
console.warn(`Found demo marker "${demoName}" with no matching demo component in ${page.source}`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
marker.type = 'div';
|
|
73
|
-
marker.children.splice(0, 1, ...(0, utils_1.createDemoNodes)(demo));
|
|
74
|
-
});
|
|
75
|
-
allMarkers.forEach((marker) => {
|
|
76
|
-
const demoNodes = demos
|
|
77
|
-
.map((component) => (0, utils_1.createDemoNodes)(component))
|
|
78
|
-
.flat();
|
|
79
|
-
marker.type = 'div';
|
|
80
|
-
marker.children.splice(0, 1, ...demoNodes);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.default = (0, plugin_1.default)({
|
|
85
|
-
runWithMdast(ctx) {
|
|
86
|
-
const seenNames = new Set();
|
|
87
|
-
ctx.pages.forEach((page) => {
|
|
88
|
-
if (page.demos) {
|
|
89
|
-
const demoComponents = [];
|
|
90
|
-
page.demos.forEach((demo) => {
|
|
91
|
-
const chunks = [];
|
|
92
|
-
(0, unist_util_visit_1.default)(demo.ast, 'code', (node) => {
|
|
93
|
-
if (['component', 'template', 'styles'].includes(node.meta || '')) {
|
|
94
|
-
chunks.push({
|
|
95
|
-
snippet: node,
|
|
96
|
-
code: node.value.replace(/\\{{/g, '{{'),
|
|
97
|
-
ext: (0, utils_1.getExt)(node.lang || (node.meta === 'template' ? 'hbs' : 'js')),
|
|
98
|
-
type: node.meta
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
// 1. exclude extension
|
|
103
|
-
// 2. remove /index.md because of web conventions
|
|
104
|
-
const baseName = page.source.replace('/index.md', '').split('.')[0];
|
|
105
|
-
const componentName = (0, utils_1.generateDemoComponentName)(`docfy-demo-${baseName}-${path_1.default.basename(demo.source).split('.')[0]}`, seenNames);
|
|
106
|
-
const demoTitle = (0, unist_util_find_1.default)(demo.ast, (node) => node.type === 'heading' && node.depth === 1);
|
|
107
|
-
if (demoTitle) {
|
|
108
|
-
demoTitle.depth = 3;
|
|
109
|
-
demoTitle.data = Object.assign(Object.assign({}, (demoTitle.data || {})), { id: componentName.dashCase, docfyDelete: true // mark the heading to be deleted by @docfy/core TOC plugin
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
demoComponents.push({
|
|
113
|
-
name: componentName,
|
|
114
|
-
chunks,
|
|
115
|
-
description: {
|
|
116
|
-
title: demoTitle ? (0, mdast_util_to_string_1.default)(demoTitle) : undefined,
|
|
117
|
-
ast: demo.ast,
|
|
118
|
-
editUrl: demo.meta.editUrl
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
// Delete used code blocks
|
|
122
|
-
chunks.forEach(({ snippet }) => {
|
|
123
|
-
(0, utils_1.deleteNode)(demo.ast.children, snippet);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
if (page.meta.frontmatter.manualDemoInsertion) {
|
|
127
|
-
// Manual demo insertion inserts demos into markdown files
|
|
128
|
-
// wherever there is a demo marker ([[demo:name]] or [[demos-all]])
|
|
129
|
-
replaceDemoMarkers(page, demoComponents);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
// Automatic demo insertion creates an Example block after
|
|
133
|
-
// the first heading.
|
|
134
|
-
const toInsert = [createHeading(ctx)];
|
|
135
|
-
demoComponents.forEach((component) => {
|
|
136
|
-
toInsert.push(...(0, utils_1.createDemoNodes)(component));
|
|
137
|
-
});
|
|
138
|
-
insertDemoNodesIntoPage(page, toInsert);
|
|
139
|
-
}
|
|
140
|
-
if ((0, utils_1.isDemoComponents)(page.pluginData.demoComponents)) {
|
|
141
|
-
page.pluginData.demoComponents.push(...demoComponents);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
page.pluginData.demoComponents = demoComponents;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
7
|
-
const plugin_1 = __importDefault(require("@docfy/core/lib/plugin"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
exports.default = (0, plugin_1.default)({
|
|
11
|
-
runWithMdast(ctx) {
|
|
12
|
-
const seenNames = new Set();
|
|
13
|
-
ctx.pages.forEach((page) => {
|
|
14
|
-
const demoComponents = [];
|
|
15
|
-
(0, unist_util_visit_1.default)(page.ast, 'code', (node) => {
|
|
16
|
-
if (['preview-template', 'preview'].includes(node.meta || '')) {
|
|
17
|
-
demoComponents.push({
|
|
18
|
-
name: (0, utils_1.generateDemoComponentName)(`docfy-demo-preview-${path_1.default.basename(page.meta.url)}`, seenNames),
|
|
19
|
-
chunks: [
|
|
20
|
-
{
|
|
21
|
-
snippet: node,
|
|
22
|
-
code: node.value.replace(/\\{{/g, '{{'),
|
|
23
|
-
ext: (0, utils_1.getExt)(node.lang || 'hbs'),
|
|
24
|
-
type: node.meta
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
demoComponents.forEach((demoComponent) => {
|
|
31
|
-
(0, utils_1.replaceNode)(page.ast.children, demoComponent.chunks[0].snippet, ...(0, utils_1.createDemoNodes)(demoComponent));
|
|
32
|
-
});
|
|
33
|
-
if ((0, utils_1.isDemoComponents)(page.pluginData.demoComponents)) {
|
|
34
|
-
page.pluginData.demoComponents.push(...demoComponents);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
page.pluginData.demoComponents = demoComponents;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@docfy/core/lib/types").Plugin<import("@docfy/core/lib/types").PluginOptions | null | undefined>;
|
|
2
|
-
/**
|
|
3
|
-
* This function finds all the links starting with an `/` and replace them with
|
|
4
|
-
* the `DocfyLink` component.
|
|
5
|
-
*/
|
|
6
|
-
export default _default;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const plugin_1 = __importDefault(require("@docfy/core/lib/plugin"));
|
|
7
|
-
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
8
|
-
const unist_builder_1 = __importDefault(require("unist-builder"));
|
|
9
|
-
function visitor(page) {
|
|
10
|
-
(0, unist_util_visit_1.default)(page.ast, 'link', (node, index, parent) => {
|
|
11
|
-
if (node.url[0] === '/') {
|
|
12
|
-
const data = node.data || (node.data = {});
|
|
13
|
-
const props = (data.hProperties || (data.hProperties = {}));
|
|
14
|
-
const urlParts = node.url.split('#');
|
|
15
|
-
const attributes = Object.keys(props)
|
|
16
|
-
.map((key) => {
|
|
17
|
-
return `${key}=${String(props[key])}`;
|
|
18
|
-
})
|
|
19
|
-
.join(' ');
|
|
20
|
-
const toInsert = [
|
|
21
|
-
(0, unist_builder_1.default)('html', `<DocfyLink @to="${urlParts[0]}" ${urlParts[1] ? `@anchor="${urlParts[1]}"` : ''} ${attributes}>`),
|
|
22
|
-
...node.children,
|
|
23
|
-
(0, unist_builder_1.default)('html', `</DocfyLink>`)
|
|
24
|
-
];
|
|
25
|
-
parent === null || parent === void 0 ? void 0 : parent.children.splice(index, 1, ...toInsert);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* This function finds all the links starting with an `/` and replace them with
|
|
31
|
-
* the `DocfyLink` component.
|
|
32
|
-
*/
|
|
33
|
-
exports.default = (0, plugin_1.default)({
|
|
34
|
-
runWithMdast(ctx) {
|
|
35
|
-
ctx.pages.forEach((page) => {
|
|
36
|
-
visitor(page);
|
|
37
|
-
if (Array.isArray(page.demos)) {
|
|
38
|
-
page.demos.forEach((demo) => {
|
|
39
|
-
visitor(demo);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
package/lib/plugins/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Node } from 'unist';
|
|
2
|
-
interface Literal {
|
|
3
|
-
value: string;
|
|
4
|
-
}
|
|
5
|
-
export interface CodeNode extends Node, Literal {
|
|
6
|
-
type: 'code';
|
|
7
|
-
lang?: string;
|
|
8
|
-
meta?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface DemoComponent {
|
|
11
|
-
name: DemoComponentName;
|
|
12
|
-
chunks: DemoComponentChunk[];
|
|
13
|
-
description?: {
|
|
14
|
-
title?: string;
|
|
15
|
-
ast: Node;
|
|
16
|
-
editUrl?: string;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export interface DemoComponentName {
|
|
20
|
-
dashCase: string;
|
|
21
|
-
pascalCase: string;
|
|
22
|
-
}
|
|
23
|
-
export interface DemoComponentChunk {
|
|
24
|
-
type: string;
|
|
25
|
-
code: string;
|
|
26
|
-
ext: string;
|
|
27
|
-
snippet: Node;
|
|
28
|
-
}
|
|
29
|
-
export {};
|
package/lib/plugins/types.js
DELETED
package/lib/plugins/utils.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Node } from 'unist';
|
|
2
|
-
import { DemoComponent, DemoComponentName } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates all the Nodes necessary to render a Demo Component.
|
|
5
|
-
*
|
|
6
|
-
* It will render something like the follwing:
|
|
7
|
-
* ```hbs
|
|
8
|
-
* <DocfyDemo as |demo|>
|
|
9
|
-
* <demo.Example>
|
|
10
|
-
* <ComponentName />
|
|
11
|
-
* </demo.Example>
|
|
12
|
-
* <demo.Description @title="Heading depth 1" @editUrl="url">
|
|
13
|
-
* Demo markdown content
|
|
14
|
-
* </demo.Description>
|
|
15
|
-
* <demo.Snippets as |Snippet|>
|
|
16
|
-
* <Snippet @name="component">
|
|
17
|
-
* Code Snippet (with any highlight applied from remark)
|
|
18
|
-
* </Snippet>
|
|
19
|
-
* </demo.Snippets>
|
|
20
|
-
* </DocfyDemo>
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function createDemoNodes(component: DemoComponent): Node[];
|
|
24
|
-
export declare function getExt(lang: string): string;
|
|
25
|
-
export declare function deleteNode(nodes: unknown, nodeToDelete: Node | undefined): void;
|
|
26
|
-
export declare function replaceNode(nodes: unknown, nodeToDelete: Node, ...newNodes: Node[]): void;
|
|
27
|
-
export declare function generateDemoComponentName(identifier: string, seenNames: Set<string>, tentativeCount?: number): DemoComponentName;
|
|
28
|
-
/**
|
|
29
|
-
* Checks if a property is of type DemoComponent[]
|
|
30
|
-
*/
|
|
31
|
-
export declare function isDemoComponents(components: unknown): components is DemoComponent[];
|
package/lib/plugins/utils.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isDemoComponents = exports.generateDemoComponentName = exports.replaceNode = exports.deleteNode = exports.getExt = exports.createDemoNodes = void 0;
|
|
7
|
-
const unist_builder_1 = __importDefault(require("unist-builder"));
|
|
8
|
-
/**
|
|
9
|
-
* Creates all the Nodes necessary to render a Demo Component.
|
|
10
|
-
*
|
|
11
|
-
* It will render something like the follwing:
|
|
12
|
-
* ```hbs
|
|
13
|
-
* <DocfyDemo as |demo|>
|
|
14
|
-
* <demo.Example>
|
|
15
|
-
* <ComponentName />
|
|
16
|
-
* </demo.Example>
|
|
17
|
-
* <demo.Description @title="Heading depth 1" @editUrl="url">
|
|
18
|
-
* Demo markdown content
|
|
19
|
-
* </demo.Description>
|
|
20
|
-
* <demo.Snippets as |Snippet|>
|
|
21
|
-
* <Snippet @name="component">
|
|
22
|
-
* Code Snippet (with any highlight applied from remark)
|
|
23
|
-
* </Snippet>
|
|
24
|
-
* </demo.Snippets>
|
|
25
|
-
* </DocfyDemo>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
function createDemoNodes(component) {
|
|
29
|
-
const nodes = [
|
|
30
|
-
(0, unist_builder_1.default)('html', `<DocfyDemo @id="${component.name.dashCase}" as |demo|>`)
|
|
31
|
-
];
|
|
32
|
-
if (component.description) {
|
|
33
|
-
nodes.push((0, unist_builder_1.default)('html', `<demo.Description
|
|
34
|
-
${component.description.title
|
|
35
|
-
? `@title="${component.description.title}" `
|
|
36
|
-
: ''}${component.description.editUrl
|
|
37
|
-
? `@editUrl="${component.description.editUrl}"`
|
|
38
|
-
: ''}>`), component.description.ast, (0, unist_builder_1.default)('html', '</demo.Description>'));
|
|
39
|
-
}
|
|
40
|
-
nodes.push((0, unist_builder_1.default)('html', '<demo.Example>'), (0, unist_builder_1.default)('html', `<${component.name.pascalCase} />`), (0, unist_builder_1.default)('html', '</demo.Example>'));
|
|
41
|
-
if (component.chunks.length > 1) {
|
|
42
|
-
nodes.push((0, unist_builder_1.default)('html', '<demo.Snippets as |Snippet|>'));
|
|
43
|
-
component.chunks.forEach((chunk) => {
|
|
44
|
-
nodes.push((0, unist_builder_1.default)('html', `<Snippet @name="${chunk.type}">`), chunk.snippet, (0, unist_builder_1.default)('html', '</Snippet>'));
|
|
45
|
-
});
|
|
46
|
-
nodes.push((0, unist_builder_1.default)('html', '</demo.Snippets>'));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
component.chunks.forEach((chunk) => {
|
|
50
|
-
nodes.push((0, unist_builder_1.default)('html', `<demo.Snippet @name="${chunk.type}">`), chunk.snippet, (0, unist_builder_1.default)('html', '</demo.Snippet>'));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
nodes.push((0, unist_builder_1.default)('html', '</DocfyDemo>'));
|
|
54
|
-
return nodes;
|
|
55
|
-
}
|
|
56
|
-
exports.createDemoNodes = createDemoNodes;
|
|
57
|
-
const MAP_LANG_TO_EXT = {
|
|
58
|
-
javascript: 'js',
|
|
59
|
-
typescript: 'ts',
|
|
60
|
-
handlebars: 'hbs',
|
|
61
|
-
'html.hbs': 'hbs',
|
|
62
|
-
'html.handlebars': 'hbs'
|
|
63
|
-
};
|
|
64
|
-
/*
|
|
65
|
-
* It returns the file extension from a lang string.
|
|
66
|
-
*/
|
|
67
|
-
function getExt(lang) {
|
|
68
|
-
lang = lang.toLowerCase();
|
|
69
|
-
return MAP_LANG_TO_EXT[lang] || lang;
|
|
70
|
-
}
|
|
71
|
-
exports.getExt = getExt;
|
|
72
|
-
/*
|
|
73
|
-
* Delete a node from a list of nodes
|
|
74
|
-
*/
|
|
75
|
-
function deleteNode(nodes, nodeToDelete) {
|
|
76
|
-
if (!nodeToDelete) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (Array.isArray(nodes)) {
|
|
80
|
-
const index = nodes.findIndex((item) => item === nodeToDelete);
|
|
81
|
-
if (index !== -1) {
|
|
82
|
-
nodes.splice(index, 1);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.deleteNode = deleteNode;
|
|
87
|
-
/*
|
|
88
|
-
* Replace a node from a list of nodes
|
|
89
|
-
*/
|
|
90
|
-
function replaceNode(nodes, nodeToDelete, ...newNodes) {
|
|
91
|
-
if (Array.isArray(nodes)) {
|
|
92
|
-
const index = nodes.findIndex((item) => item === nodeToDelete);
|
|
93
|
-
if (index !== -1) {
|
|
94
|
-
nodes.splice(index, 1, ...newNodes);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.replaceNode = replaceNode;
|
|
99
|
-
/*
|
|
100
|
-
* Generate the component name from the source path of the demo
|
|
101
|
-
*
|
|
102
|
-
* It returns both dash case and pastal case.
|
|
103
|
-
* The dash-case can be used for the file name and the PascalCase for the
|
|
104
|
-
* rendering of the component.
|
|
105
|
-
*/
|
|
106
|
-
function generateDemoComponentName(identifier, seenNames, tentativeCount = 1) {
|
|
107
|
-
const dashCase = identifier
|
|
108
|
-
.split('.')[0]
|
|
109
|
-
.toLowerCase()
|
|
110
|
-
.replace(/\/|\\/g, '-')
|
|
111
|
-
.replace(/[^a-zA-Z0-9|-]/g, '');
|
|
112
|
-
const pascalCase = dashCase
|
|
113
|
-
.replace(/(\w)(\w*)/g, function (_, g1, g2) {
|
|
114
|
-
return `${g1.toUpperCase()}${g2.toLowerCase()}`;
|
|
115
|
-
})
|
|
116
|
-
.replace(/-(\d+)/g, function (_, g1) {
|
|
117
|
-
return `_${g1}`;
|
|
118
|
-
})
|
|
119
|
-
.replace(/-/g, '');
|
|
120
|
-
if (seenNames.has(dashCase)) {
|
|
121
|
-
return generateDemoComponentName(`${dashCase}${tentativeCount}`, seenNames, tentativeCount + 1);
|
|
122
|
-
}
|
|
123
|
-
seenNames.add(dashCase);
|
|
124
|
-
return {
|
|
125
|
-
dashCase,
|
|
126
|
-
pascalCase
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
exports.generateDemoComponentName = generateDemoComponentName;
|
|
130
|
-
/**
|
|
131
|
-
* Checks if a property is of type DemoComponent[]
|
|
132
|
-
*/
|
|
133
|
-
function isDemoComponents(components) {
|
|
134
|
-
if (Array.isArray(components) &&
|
|
135
|
-
typeof components[0] == 'object' &&
|
|
136
|
-
{}.hasOwnProperty.call(components[0], 'name') &&
|
|
137
|
-
{}.hasOwnProperty.call(components[0], 'chunks')) {
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
exports.isDemoComponents = isDemoComponents;
|
package/output.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The actual output.js file is generated at build time. This is only to
|
|
3
|
-
* provide typing.
|
|
4
|
-
*/
|
|
5
|
-
import { NestedPageMetadata } from '@docfy/core/lib/types';
|
|
6
|
-
|
|
7
|
-
interface Output {
|
|
8
|
-
nested: NestedPageMetadata;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare const output: Output;
|
|
12
|
-
|
|
13
|
-
export default output;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export default function docfyOutputTemplate(modulePrefix: string): string {
|
|
2
|
-
return `;
|
|
3
|
-
define('@docfy/ember/output', [
|
|
4
|
-
'exports',
|
|
5
|
-
'${modulePrefix}/docfy-output'
|
|
6
|
-
], function (_exports, _docfyOutput) {
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(_exports, '__esModule', {
|
|
10
|
-
value: true
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(_exports, 'default', {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _docfyOutput.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
`;
|
|
20
|
-
}
|
package/src/get-config.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { pathToFileURL } from 'url';
|
|
3
|
-
import { DocfyConfig } from '@docfy/core/lib/types';
|
|
4
|
-
import remarkHbs from 'remark-hbs';
|
|
5
|
-
import replaceInternalLinksWithDocfyLink from './plugins/replace-internal-links-with-docfy-link';
|
|
6
|
-
import extractDemosToComponents from './plugins/extract-demos-to-components';
|
|
7
|
-
import previewTemplate from './plugins/preview-template';
|
|
8
|
-
import type { RemarkHbsOptions } from 'remark-hbs';
|
|
9
|
-
|
|
10
|
-
const DEFAULT_CONFIG: DocfyConfig = {
|
|
11
|
-
sources: [
|
|
12
|
-
{
|
|
13
|
-
pattern: '**/*.md',
|
|
14
|
-
urlPrefix: 'docs'
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
interface EmberDocfyConfig extends DocfyConfig {
|
|
20
|
-
remarkHbsOptions?: RemarkHbsOptions;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default async function getDocfyConfig(
|
|
24
|
-
root: string
|
|
25
|
-
): Promise<EmberDocfyConfig> {
|
|
26
|
-
const configPath = path.join(root, '.docfy-config.js');
|
|
27
|
-
let docfyConfig: Partial<EmberDocfyConfig> = {};
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
30
|
-
const pkg = require(path.join(root, 'package.json'));
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
// Attempt to require (CJS)
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
35
|
-
docfyConfig = require(configPath);
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
} catch (e: any) {
|
|
38
|
-
// Fallback to ESM if the error indicates ESM-only module
|
|
39
|
-
const isESMError =
|
|
40
|
-
e.code === 'ERR_REQUIRE_ESM' ||
|
|
41
|
-
e.message?.includes('must use import to load ES Module') ||
|
|
42
|
-
e.message?.includes('Cannot use import statement outside a module');
|
|
43
|
-
|
|
44
|
-
if (isESMError || e.code === 'ERR_MODULE_NOT_FOUND') {
|
|
45
|
-
try {
|
|
46
|
-
const imported = await import(pathToFileURL(configPath).href);
|
|
47
|
-
docfyConfig = imported?.default ?? imported;
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
} catch (esmErr: any) {
|
|
50
|
-
const notFound =
|
|
51
|
-
esmErr.code === 'ERR_MODULE_NOT_FOUND' ||
|
|
52
|
-
esmErr.message?.includes('Cannot find module');
|
|
53
|
-
if (!notFound) {
|
|
54
|
-
throw esmErr;
|
|
55
|
-
}
|
|
56
|
-
docfyConfig = {};
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
throw e;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (typeof docfyConfig !== 'object' || docfyConfig == null) {
|
|
64
|
-
docfyConfig = {};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!Array.isArray(docfyConfig.sources)) {
|
|
68
|
-
docfyConfig.sources = DEFAULT_CONFIG.sources;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!Array.isArray(docfyConfig.plugins)) {
|
|
72
|
-
docfyConfig.plugins = [];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
docfyConfig.plugins.unshift(
|
|
76
|
-
replaceInternalLinksWithDocfyLink,
|
|
77
|
-
previewTemplate,
|
|
78
|
-
extractDemosToComponents
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
if (!Array.isArray(docfyConfig.remarkPlugins)) {
|
|
82
|
-
docfyConfig.remarkPlugins = [];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
docfyConfig.remarkPlugins.push([
|
|
86
|
-
remarkHbs,
|
|
87
|
-
docfyConfig.remarkHbsOptions || {}
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
const repoUrl = pkg.repository?.url || pkg.repository;
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
!docfyConfig.repository &&
|
|
94
|
-
typeof repoUrl === 'string' &&
|
|
95
|
-
repoUrl !== ''
|
|
96
|
-
) {
|
|
97
|
-
docfyConfig.repository = {
|
|
98
|
-
url: repoUrl
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
docfyConfig.sources.forEach((source) => {
|
|
103
|
-
if (typeof source.root === 'undefined') {
|
|
104
|
-
source.root = path.join(root, 'docs');
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return docfyConfig as EmberDocfyConfig;
|
|
109
|
-
}
|