|
1 |
| -const { readdirSync, readFileSync } = require('fs'); |
| 1 | +const { readdirSync } = require('fs'); |
2 | 2 | const cmp = require('semver-compare');
|
3 | 3 | const semver = require('semver');
|
4 | 4 |
|
5 | 5 | function partialUrlEncode(input) {
|
6 |
| - return input.replace('/', '%2F'); |
| 6 | + return input.replace(/\//g, '%2F'); |
7 | 7 | }
|
8 | 8 |
|
| 9 | +const singularData = { |
| 10 | + classes: 'class', |
| 11 | + namespaces: 'namespace', |
| 12 | + modules: 'module', |
| 13 | +}; |
| 14 | + |
9 | 15 | module.exports = function () {
|
10 | 16 | const projects = readdirSync('ember-api-docs-data/json-docs');
|
11 | 17 |
|
@@ -72,36 +78,42 @@ module.exports = function () {
|
72 | 78 | `/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}`
|
73 | 79 | );
|
74 | 80 |
|
75 |
| - // TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it |
76 |
| - urls.push( |
77 |
| - `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( |
78 |
| - cleanId |
79 |
| - )}/methods` |
80 |
| - ); |
81 |
| - urls.push( |
82 |
| - `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( |
83 |
| - cleanId |
84 |
| - )}/properties` |
85 |
| - ); |
86 |
| - urls.push( |
87 |
| - `/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}/events` |
88 |
| - ); |
| 81 | + const fileName = revIndex.meta[singularData[entity]][id]; |
| 82 | + let entityData; |
89 | 83 |
|
90 |
| - if (entity === 'modules') { |
91 |
| - const moduleKey = id; |
| 84 | + if (fileName !== undefined) { |
| 85 | + // rare cases when very strange things make it through this far |
| 86 | + // e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed. |
| 87 | + // 🤷♀️ |
| 88 | + entityData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/${entity}/${fileName}.json`); |
| 89 | + } |
92 | 90 |
|
93 |
| - const fileName = revIndex.meta.module[moduleKey]; |
| 91 | + if (entityData.data.attributes.methods?.length) { |
| 92 | + urls.push( |
| 93 | + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( |
| 94 | + cleanId |
| 95 | + )}/methods` |
| 96 | + ); |
| 97 | + } |
94 | 98 |
|
95 |
| - if (fileName === undefined) { |
96 |
| - // rare cases when very strange things make it through this far |
97 |
| - // e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed. |
98 |
| - // 🤷♀️ |
99 |
| - return; |
100 |
| - } |
| 99 | + if (entityData.data.attributes.properties?.length) { |
| 100 | + urls.push( |
| 101 | + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( |
| 102 | + cleanId |
| 103 | + )}/properties` |
| 104 | + ); |
| 105 | + } |
101 | 106 |
|
102 |
| - const moduleData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/modules/${fileName}.json`); |
| 107 | + if (entityData.data.attributes.events?.length) { |
| 108 | + urls.push( |
| 109 | + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( |
| 110 | + cleanId |
| 111 | + )}/events` |
| 112 | + ); |
| 113 | + } |
103 | 114 |
|
104 |
| - const staticFunctions = moduleData.data.attributes.staticfunctions; |
| 115 | + if (entity === 'modules' && entityData) { |
| 116 | + const staticFunctions = entityData.data.attributes.staticfunctions; |
105 | 117 |
|
106 | 118 | Object.keys(staticFunctions).forEach((k) => {
|
107 | 119 | const listOfFunctions = staticFunctions[k];
|
|
0 commit comments