@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.
Files changed (166) hide show
  1. package/README.md +8 -5
  2. package/addon-main.cjs +4 -0
  3. package/declarations/components/docfy-demo.d.ts +44 -0
  4. package/declarations/components/docfy-demo.d.ts.map +1 -0
  5. package/declarations/components/docfy-link.d.ts +23 -0
  6. package/declarations/components/docfy-link.d.ts.map +1 -0
  7. package/declarations/components/docfy-output.d.ts +24 -0
  8. package/declarations/components/docfy-output.d.ts.map +1 -0
  9. package/declarations/components/docfy-previous-and-next-page.d.ts +23 -0
  10. package/declarations/components/docfy-previous-and-next-page.d.ts.map +1 -0
  11. package/declarations/index.d.ts +7 -0
  12. package/declarations/index.d.ts.map +1 -0
  13. package/declarations/routing.d.ts +3 -0
  14. package/declarations/routing.d.ts.map +1 -0
  15. package/{services → declarations/services}/docfy.d.ts +4 -8
  16. package/declarations/services/docfy.d.ts.map +1 -0
  17. package/declarations/template-registry.d.ts +11 -0
  18. package/declarations/template-registry.d.ts.map +1 -0
  19. package/dist/_app_/components/docfy-demo.js +1 -0
  20. package/dist/_app_/components/docfy-link.js +1 -0
  21. package/dist/_app_/components/docfy-output.js +1 -0
  22. package/dist/_app_/components/docfy-previous-and-next-page.js +1 -0
  23. package/dist/_app_/services/docfy.js +1 -0
  24. package/dist/components/docfy-demo.js +121 -0
  25. package/dist/components/docfy-demo.js.map +1 -0
  26. package/dist/components/docfy-link.js +58 -0
  27. package/dist/components/docfy-link.js.map +1 -0
  28. package/dist/components/docfy-output.js +43 -0
  29. package/dist/components/docfy-output.js.map +1 -0
  30. package/dist/components/docfy-previous-and-next-page.js +27 -0
  31. package/dist/components/docfy-previous-and-next-page.js.map +1 -0
  32. package/dist/index.js +8 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/output.d.ts +2 -0
  35. package/dist/output.d.ts.map +1 -0
  36. package/dist/output.js +17 -0
  37. package/dist/output.js.map +1 -0
  38. package/dist/routing.js +29 -0
  39. package/dist/routing.js.map +1 -0
  40. package/dist/services/docfy.js +87 -0
  41. package/dist/services/docfy.js.map +1 -0
  42. package/dist/template-registry.js +2 -0
  43. package/dist/template-registry.js.map +1 -0
  44. package/package.json +91 -124
  45. package/-private/find-previous-or-next-page.d.ts +0 -2
  46. package/-private/flat-nested.d.ts +0 -2
  47. package/.docfy-config.js +0 -40
  48. package/addon/-private/find-previous-or-next-page.ts +0 -22
  49. package/addon/-private/flat-nested.ts +0 -18
  50. package/addon/components/docfy-demo/description.hbs +0 -26
  51. package/addon/components/docfy-demo/description.ts +0 -3
  52. package/addon/components/docfy-demo/example.hbs +0 -3
  53. package/addon/components/docfy-demo/example.ts +0 -3
  54. package/addon/components/docfy-demo/snippet.hbs +0 -8
  55. package/addon/components/docfy-demo/snippet.ts +0 -35
  56. package/addon/components/docfy-demo/snippets.hbs +0 -25
  57. package/addon/components/docfy-demo/snippets.ts +0 -27
  58. package/addon/components/docfy-demo.hbs +0 -10
  59. package/addon/components/docfy-demo.ts +0 -7
  60. package/addon/components/docfy-link.hbs +0 -8
  61. package/addon/components/docfy-link.ts +0 -54
  62. package/addon/components/docfy-output.hbs +0 -1
  63. package/addon/components/docfy-output.ts +0 -37
  64. package/addon/components/docfy-previous-and-next-page.hbs +0 -1
  65. package/addon/components/docfy-previous-and-next-page.ts +0 -20
  66. package/addon/helpers/docfy-eq.ts +0 -7
  67. package/addon/index.ts +0 -31
  68. package/addon/output.d.ts +0 -13
  69. package/addon/services/docfy.ts +0 -101
  70. package/app/components/docfy-demo/description.js +0 -1
  71. package/app/components/docfy-demo/example.js +0 -1
  72. package/app/components/docfy-demo/snippet.js +0 -1
  73. package/app/components/docfy-demo/snippets.js +0 -1
  74. package/app/components/docfy-demo.js +0 -1
  75. package/app/components/docfy-link.js +0 -1
  76. package/app/components/docfy-output.js +0 -1
  77. package/app/components/docfy-previous-and-next-page.js +0 -1
  78. package/app/helpers/docfy-eq.js +0 -1
  79. package/app/services/docfy.js +0 -1
  80. package/components/docfy-demo/description.d.ts +0 -3
  81. package/components/docfy-demo/example.d.ts +0 -3
  82. package/components/docfy-demo/snippet.d.ts +0 -13
  83. package/components/docfy-demo/snippets.d.ts +0 -11
  84. package/components/docfy-demo.d.ts +0 -7
  85. package/components/docfy-link.d.ts +0 -15
  86. package/components/docfy-output.d.ts +0 -16
  87. package/components/docfy-previous-and-next-page.d.ts +0 -12
  88. package/config/environment.js +0 -5
  89. package/docs/components/docfy-demo.md +0 -67
  90. package/docs/components/docfy-link-demo/anchor.md +0 -9
  91. package/docs/components/docfy-link-demo/simple.md +0 -7
  92. package/docs/components/docfy-link.md +0 -31
  93. package/docs/components/docfy-output-demo/edit-page.md +0 -54
  94. package/docs/components/docfy-output-demo/flat.md +0 -23
  95. package/docs/components/docfy-output-demo/on-this-page.md +0 -30
  96. package/docs/components/docfy-output-demo/sidebar.md +0 -45
  97. package/docs/components/docfy-output-demo/top-nav.md +0 -35
  98. package/docs/components/docfy-output.md +0 -34
  99. package/docs/components/docfy-previous-and-next-page-demo/scope.md +0 -26
  100. package/docs/components/docfy-previous-and-next-page-demo/simple.md +0 -24
  101. package/docs/components/docfy-previous-and-next-page.md +0 -21
  102. package/docs/configuration.md +0 -57
  103. package/docs/index.md +0 -165
  104. package/docs/writing-demos-demo/demo1.md +0 -18
  105. package/docs/writing-demos.md +0 -109
  106. package/dummy-docs/README.md +0 -140
  107. package/dummy-docs/github-icon.png +0 -0
  108. package/dummy-docs/installation.md +0 -14
  109. package/dummy-docs/introduction.md +0 -30
  110. package/dummy-docs/overview.md +0 -19
  111. package/dummy-docs/packages/core/helpers/genereate-flat-output.md +0 -10
  112. package/dummy-docs/packages/core/helpers/genereate-nested-output.md +0 -12
  113. package/dummy-docs/packages/core/overview.md +0 -19
  114. package/dummy-docs/packages/ember/components/docfy-link-demo/demo1.md +0 -26
  115. package/dummy-docs/packages/ember/components/docfy-link-demo/demo2.md +0 -20
  116. package/dummy-docs/packages/ember/components/docfy-link.md +0 -19
  117. package/dummy-docs/packages/ember/components/docfy-output.md +0 -32
  118. package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2-demo/demo1.md +0 -25
  119. package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2.md +0 -9
  120. package/dummy-docs/packages/ember/demo/my-ember-demo.md +0 -3
  121. package/dummy-docs/packages/ember/index.md +0 -23
  122. package/dummy-docs/packages/ember/installation.md +0 -14
  123. package/dummy-docs/packages/ember/plugins/manual-demo-insertion-demo/tomster.md +0 -15
  124. package/dummy-docs/packages/ember/plugins/manual-demo-insertion-demo/zoey.md +0 -9
  125. package/dummy-docs/packages/ember/plugins/manual-demo-insertion.md +0 -31
  126. package/dummy-docs/packages/ember/preview.md +0 -20
  127. package/ember-cli-addon.js +0 -3
  128. package/helpers/docfy-eq.d.ts +0 -7
  129. package/index.d.ts +0 -3
  130. package/lib/docfy-output-template.d.ts +0 -1
  131. package/lib/docfy-output-template.js +0 -23
  132. package/lib/get-config.d.ts +0 -7
  133. package/lib/get-config.js +0 -118
  134. package/lib/index.d.ts +0 -1
  135. package/lib/index.js +0 -177
  136. package/lib/plugins/extract-demos-to-components.d.ts +0 -2
  137. package/lib/plugins/extract-demos-to-components.js +0 -149
  138. package/lib/plugins/preview-template.d.ts +0 -2
  139. package/lib/plugins/preview-template.js +0 -41
  140. package/lib/plugins/replace-internal-links-with-docfy-link.d.ts +0 -6
  141. package/lib/plugins/replace-internal-links-with-docfy-link.js +0 -44
  142. package/lib/plugins/types.d.ts +0 -29
  143. package/lib/plugins/types.js +0 -2
  144. package/lib/plugins/utils.d.ts +0 -31
  145. package/lib/plugins/utils.js +0 -142
  146. package/output.d.ts +0 -13
  147. package/src/docfy-output-template.ts +0 -20
  148. package/src/get-config.ts +0 -109
  149. package/src/index.ts +0 -229
  150. package/src/plugins/extract-demos-to-components.ts +0 -196
  151. package/src/plugins/preview-template.ts +0 -54
  152. package/src/plugins/replace-internal-links-with-docfy-link.ts +0 -61
  153. package/src/plugins/types.ts +0 -33
  154. package/src/plugins/utils.ts +0 -191
  155. package/src/tsconfig.json +0 -14
  156. package/src/types/broccoli-bridge.d.ts +0 -11
  157. package/src/types/broccoli-file-creator.d.ts +0 -11
  158. package/src/types/broccoli-funnel.d.ts +0 -19
  159. package/src/types/broccoli-merge-trees.d.ts +0 -13
  160. package/src/types/broccoli-source.d.ts +0 -9
  161. package/src/types/mdast-util-to-string.d.ts +0 -5
  162. package/src/types/unist-util-find.d.ts +0 -8
  163. package/tsconfig.json +0 -42
  164. package/types/dummy/index.d.ts +0 -0
  165. package/types/ember-get-config/index.d.ts +0 -9
  166. 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,2 +0,0 @@
1
- declare const _default: import("@docfy/core/lib/types").Plugin<import("@docfy/core/lib/types").PluginOptions | null | undefined>;
2
- export default _default;
@@ -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
- });
@@ -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 {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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[];
@@ -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
- }