@docfy/ember 0.8.4 → 0.9.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/addon/components/docfy-demo/example.hbs +2 -2
- package/addon/components/docfy-demo.hbs +1 -1
- package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2-demo/demo1.md +25 -0
- package/dummy-docs/packages/ember/components/docfy-with-hyphenated-number-2.md +9 -0
- package/lib/get-config.d.ts +1 -1
- package/lib/get-config.js +90 -41
- package/lib/plugins/utils.js +3 -0
- package/package.json +4 -4
- package/src/get-config.ts +51 -32
- package/src/plugins/utils.ts +3 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<div class="docfy-demo__example" ...attributes>
|
|
1
|
+
<div class="docfy-demo__example not-prose" ...attributes>
|
|
2
2
|
{{yield}}
|
|
3
|
-
</div>
|
|
3
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 1
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Demo of DocfyLink component
|
|
6
|
+
|
|
7
|
+
[Link from a demo](../docfy-output.md)
|
|
8
|
+
|
|
9
|
+
```hbs template
|
|
10
|
+
<div data-test-id="demo-1">
|
|
11
|
+
This is my Demo:
|
|
12
|
+
|
|
13
|
+
<span class='hyphenated-demo'>Assertable DOM node</span>
|
|
14
|
+
<DocfyLink @to={{this.url}}>My Link</DocfyLink>
|
|
15
|
+
</div>
|
|
16
|
+
<div data-test-id="demo-1-js-data">{{this.url}}</div>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```js component
|
|
20
|
+
import Component from '@glimmer/component';
|
|
21
|
+
|
|
22
|
+
export default class MyDemo extends Component {
|
|
23
|
+
url = '/docs/ember/';
|
|
24
|
+
}
|
|
25
|
+
```
|
package/lib/get-config.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { RemarkHbsOptions } from 'remark-hbs';
|
|
|
3
3
|
interface EmberDocfyConfig extends DocfyConfig {
|
|
4
4
|
remarkHbsOptions?: RemarkHbsOptions;
|
|
5
5
|
}
|
|
6
|
-
export default function getDocfyConfig(root: string): EmberDocfyConfig
|
|
6
|
+
export default function getDocfyConfig(root: string): Promise<EmberDocfyConfig>;
|
|
7
7
|
export {};
|
package/lib/get-config.js
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
2
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
32
|
};
|
|
5
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
34
|
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const url_1 = require("url");
|
|
7
36
|
const remark_hbs_1 = __importDefault(require("remark-hbs"));
|
|
8
37
|
const replace_internal_links_with_docfy_link_1 = __importDefault(require("./plugins/replace-internal-links-with-docfy-link"));
|
|
9
38
|
const extract_demos_to_components_1 = __importDefault(require("./plugins/extract-demos-to-components"));
|
|
@@ -17,53 +46,73 @@ const DEFAULT_CONFIG = {
|
|
|
17
46
|
]
|
|
18
47
|
};
|
|
19
48
|
function getDocfyConfig(root) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const configPath = path_1.default.join(root, '.docfy-config.js');
|
|
52
|
+
let docfyConfig = {};
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
54
|
+
const pkg = require(path_1.default.join(root, 'package.json'));
|
|
55
|
+
try {
|
|
56
|
+
// Attempt to require (CJS)
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
58
|
+
docfyConfig = require(configPath);
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
60
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
61
|
+
catch (e) {
|
|
62
|
+
// Fallback to ESM if the error indicates ESM-only module
|
|
63
|
+
const isESMError = e.code === 'ERR_REQUIRE_ESM' ||
|
|
64
|
+
((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes('must use import to load ES Module')) ||
|
|
65
|
+
((_b = e.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot use import statement outside a module'));
|
|
66
|
+
if (isESMError || e.code === 'ERR_MODULE_NOT_FOUND') {
|
|
67
|
+
try {
|
|
68
|
+
const imported = yield Promise.resolve().then(() => __importStar(require((0, url_1.pathToFileURL)(configPath).href)));
|
|
69
|
+
docfyConfig = (_c = imported === null || imported === void 0 ? void 0 : imported.default) !== null && _c !== void 0 ? _c : imported;
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
}
|
|
72
|
+
catch (esmErr) {
|
|
73
|
+
const notFound = esmErr.code === 'ERR_MODULE_NOT_FOUND' ||
|
|
74
|
+
((_d = esmErr.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module'));
|
|
75
|
+
if (!notFound) {
|
|
76
|
+
throw esmErr;
|
|
77
|
+
}
|
|
78
|
+
docfyConfig = {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (typeof docfyConfig !== 'object' || docfyConfig == null) {
|
|
86
|
+
docfyConfig = {};
|
|
34
87
|
}
|
|
35
88
|
if (!Array.isArray(docfyConfig.sources)) {
|
|
36
|
-
console.warn('Docfy expected an array for sources in .docfy-config.js, received ', typeof docfyConfig.sources);
|
|
37
89
|
docfyConfig.sources = DEFAULT_CONFIG.sources;
|
|
38
90
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
docfyConfig.remarkPlugins.push([
|
|
59
|
-
remark_hbs_1.default,
|
|
60
|
-
docfyConfig.remarkHbsOptions || {}
|
|
61
|
-
]);
|
|
62
|
-
docfyConfig.sources.forEach((source) => {
|
|
63
|
-
if (typeof source.root === 'undefined') {
|
|
64
|
-
source.root = path_1.default.join(root, 'docs');
|
|
91
|
+
if (!Array.isArray(docfyConfig.plugins)) {
|
|
92
|
+
docfyConfig.plugins = [];
|
|
93
|
+
}
|
|
94
|
+
docfyConfig.plugins.unshift(replace_internal_links_with_docfy_link_1.default, preview_template_1.default, extract_demos_to_components_1.default);
|
|
95
|
+
if (!Array.isArray(docfyConfig.remarkPlugins)) {
|
|
96
|
+
docfyConfig.remarkPlugins = [];
|
|
97
|
+
}
|
|
98
|
+
docfyConfig.remarkPlugins.push([
|
|
99
|
+
remark_hbs_1.default,
|
|
100
|
+
docfyConfig.remarkHbsOptions || {}
|
|
101
|
+
]);
|
|
102
|
+
const repoUrl = ((_e = pkg.repository) === null || _e === void 0 ? void 0 : _e.url) || pkg.repository;
|
|
103
|
+
if (!docfyConfig.repository &&
|
|
104
|
+
typeof repoUrl === 'string' &&
|
|
105
|
+
repoUrl !== '') {
|
|
106
|
+
docfyConfig.repository = {
|
|
107
|
+
url: repoUrl
|
|
108
|
+
};
|
|
65
109
|
}
|
|
110
|
+
docfyConfig.sources.forEach((source) => {
|
|
111
|
+
if (typeof source.root === 'undefined') {
|
|
112
|
+
source.root = path_1.default.join(root, 'docs');
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return docfyConfig;
|
|
66
116
|
});
|
|
67
|
-
return docfyConfig;
|
|
68
117
|
}
|
|
69
118
|
exports.default = getDocfyConfig;
|
package/lib/plugins/utils.js
CHANGED
|
@@ -112,6 +112,9 @@ function generateDemoComponentName(identifier, seenNames, tentativeCount = 1) {
|
|
|
112
112
|
const pascalCase = dashCase
|
|
113
113
|
.replace(/(\w)(\w*)/g, function (_, g1, g2) {
|
|
114
114
|
return `${g1.toUpperCase()}${g2.toLowerCase()}`;
|
|
115
|
+
})
|
|
116
|
+
.replace(/-(\d+)/g, function (_, g1) {
|
|
117
|
+
return `_${g1}`;
|
|
115
118
|
})
|
|
116
119
|
.replace(/-/g, '');
|
|
117
120
|
if (seenNames.has(dashCase)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docfy/ember",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Ember integration with Docfy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test:ember-compatibility": "echo 'ember try:each TODO'"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@docfy/core": "^0.
|
|
33
|
+
"@docfy/core": "^0.9.0",
|
|
34
34
|
"broccoli-bridge": "^1.0.0",
|
|
35
35
|
"broccoli-file-creator": "^2.1.1",
|
|
36
36
|
"broccoli-funnel": "^3.0.8",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/helper-define-map": "^7.16.7",
|
|
55
|
-
"@docfy/plugin-with-prose": "^0.
|
|
55
|
+
"@docfy/plugin-with-prose": "^0.9.0",
|
|
56
56
|
"@ember/optional-features": "^2.0.0",
|
|
57
57
|
"@ember/test-helpers": "^2.6.0",
|
|
58
58
|
"@embroider/compat": "^1.0.0",
|
|
@@ -137,5 +137,5 @@
|
|
|
137
137
|
"prember"
|
|
138
138
|
]
|
|
139
139
|
},
|
|
140
|
-
"gitHead": "
|
|
140
|
+
"gitHead": "7084e3983d67d3d0d704a2aa13cd31341e6aaa4f"
|
|
141
141
|
}
|
package/src/get-config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
2
3
|
import { DocfyConfig } from '@docfy/core/lib/types';
|
|
3
4
|
import remarkHbs from 'remark-hbs';
|
|
4
5
|
import replaceInternalLinksWithDocfyLink from './plugins/replace-internal-links-with-docfy-link';
|
|
@@ -19,52 +20,58 @@ interface EmberDocfyConfig extends DocfyConfig {
|
|
|
19
20
|
remarkHbsOptions?: RemarkHbsOptions;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export default function getDocfyConfig(
|
|
23
|
+
export default async function getDocfyConfig(
|
|
24
|
+
root: string
|
|
25
|
+
): Promise<EmberDocfyConfig> {
|
|
23
26
|
const configPath = path.join(root, '.docfy-config.js');
|
|
24
|
-
let docfyConfig: EmberDocfyConfig =
|
|
27
|
+
let docfyConfig: Partial<EmberDocfyConfig> = {};
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
30
|
+
const pkg = require(path.join(root, 'package.json'));
|
|
27
31
|
|
|
28
32
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
32
59
|
throw e;
|
|
33
60
|
}
|
|
34
61
|
}
|
|
35
62
|
|
|
36
|
-
if (typeof docfyConfig
|
|
37
|
-
|
|
38
|
-
docfyConfig.sources = DEFAULT_CONFIG.sources;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!Array.isArray(docfyConfig.sources)) {
|
|
42
|
-
console.warn(
|
|
43
|
-
'Docfy expected an array for sources in .docfy-config.js, received ',
|
|
44
|
-
typeof docfyConfig.sources
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
docfyConfig.sources = DEFAULT_CONFIG.sources;
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
docfyConfig = DEFAULT_CONFIG;
|
|
63
|
+
if (typeof docfyConfig !== 'object' || docfyConfig == null) {
|
|
64
|
+
docfyConfig = {};
|
|
51
65
|
}
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
!docfyConfig.repository &&
|
|
57
|
-
typeof repoUrl === 'string' &&
|
|
58
|
-
repoUrl !== ''
|
|
59
|
-
) {
|
|
60
|
-
docfyConfig.repository = {
|
|
61
|
-
url: repoUrl
|
|
62
|
-
};
|
|
67
|
+
if (!Array.isArray(docfyConfig.sources)) {
|
|
68
|
+
docfyConfig.sources = DEFAULT_CONFIG.sources;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
if (!Array.isArray(docfyConfig.plugins)) {
|
|
66
72
|
docfyConfig.plugins = [];
|
|
67
73
|
}
|
|
74
|
+
|
|
68
75
|
docfyConfig.plugins.unshift(
|
|
69
76
|
replaceInternalLinksWithDocfyLink,
|
|
70
77
|
previewTemplate,
|
|
@@ -80,11 +87,23 @@ export default function getDocfyConfig(root: string): EmberDocfyConfig {
|
|
|
80
87
|
docfyConfig.remarkHbsOptions || {}
|
|
81
88
|
]);
|
|
82
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
|
+
|
|
83
102
|
docfyConfig.sources.forEach((source) => {
|
|
84
103
|
if (typeof source.root === 'undefined') {
|
|
85
104
|
source.root = path.join(root, 'docs');
|
|
86
105
|
}
|
|
87
106
|
});
|
|
88
107
|
|
|
89
|
-
return docfyConfig;
|
|
108
|
+
return docfyConfig as EmberDocfyConfig;
|
|
90
109
|
}
|
package/src/plugins/utils.ts
CHANGED
|
@@ -153,6 +153,9 @@ export function generateDemoComponentName(
|
|
|
153
153
|
.replace(/(\w)(\w*)/g, function (_, g1, g2) {
|
|
154
154
|
return `${g1.toUpperCase()}${g2.toLowerCase()}`;
|
|
155
155
|
})
|
|
156
|
+
.replace(/-(\d+)/g, function (_, g1) {
|
|
157
|
+
return `_${g1}`;
|
|
158
|
+
})
|
|
156
159
|
.replace(/-/g, '');
|
|
157
160
|
|
|
158
161
|
if (seenNames.has(dashCase)) {
|