Skip to content

Commit 488a2a3

Browse files
authored
move to separate function
1 parent 7da8299 commit 488a2a3

3 files changed

Lines changed: 51 additions & 84 deletions

File tree

src/generators/legacy-json-all/index.mjs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -85,47 +85,7 @@ export default {
8585
if (output) {
8686
await writeFile(
8787
join(output, 'all.json'),
88-
JSON.stringify(
89-
generatedValue,
90-
[
91-
// TODO: remove this array once all the additional keys have been introduced downstream
92-
'added',
93-
'changes',
94-
'classes',
95-
'classMethods',
96-
'commit',
97-
'ctors',
98-
'default',
99-
'deprecated',
100-
'desc',
101-
'description',
102-
'displayName',
103-
'events',
104-
'examples',
105-
'globals',
106-
'introduced_in',
107-
'meta',
108-
'methods',
109-
'miscs',
110-
'name',
111-
'napiVersion',
112-
'options',
113-
'params',
114-
'pr-url',
115-
'properties',
116-
'removed',
117-
'return',
118-
'shortDesc',
119-
'signatures',
120-
'source',
121-
'stability',
122-
'stabilityText',
123-
'textRaw',
124-
'type',
125-
'version',
126-
],
127-
2,
128-
)
88+
legacyToJSON(generatedValue)
12989
);
13090
}
13191

src/generators/legacy-json/index.mjs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,7 @@ export default {
7878
for (const section of chunkResult) {
7979
const out = join(output, `${section.api}.json`);
8080

81-
await writeFile(out, JSON.stringify(section, [
82-
// TODO: remove this array once all the additional keys have been introduced downstream
83-
'added',
84-
'changes',
85-
'classes',
86-
'classMethods',
87-
'commit',
88-
'ctors',
89-
'default',
90-
'deprecated',
91-
'desc',
92-
'description',
93-
'displayName',
94-
'events',
95-
'examples',
96-
'globals',
97-
'introduced_in',
98-
'meta',
99-
'methods',
100-
'miscs',
101-
...(section.api === 'index' ? [] : ['modules']),
102-
'name',
103-
'napiVersion',
104-
'options',
105-
'params',
106-
'pr-url',
107-
'properties',
108-
'removed',
109-
'return',
110-
'shortDesc',
111-
'signatures',
112-
'source',
113-
'stability',
114-
'stabilityText',
115-
'textRaw',
116-
'type',
117-
'version',
118-
], 2));
81+
await writeFile(out, legacyToJSON(section));
11982
}
12083
}
12184

src/utils/generators.mjs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { DOC_API_BASE_URL_VERSION } from '../constants.mjs';
1010
*
1111
* @param {Array<ApiDocMetadataEntry>} nodes The API metadata Nodes to be grouped
1212
*/
13-
export const groupNodesByModule = nodes => {
13+
export const groupNodesByModule = (nodes) => {
1414
/** @type {Map<string, Array<ApiDocMetadataEntry>>} */
1515
const groupedNodes = new Map();
1616

@@ -30,7 +30,7 @@ export const groupNodesByModule = nodes => {
3030
*
3131
* @param {import('semver').SemVer} version The version to be parsed
3232
*/
33-
export const getVersionFromSemVer = version =>
33+
export const getVersionFromSemVer = (version) =>
3434
version.minor === 0
3535
? `${version.major}.x`
3636
: `${version.major}.${version.minor}.x`;
@@ -54,7 +54,7 @@ export const getVersionURL = (version, api) =>
5454
* @param {string|import('semver').SemVer} version SemVer compatible version (maybe)
5555
* @returns {import('semver').SemVer} SemVer compatible version
5656
*/
57-
export const coerceSemVer = version => {
57+
export const coerceSemVer = (version) => {
5858
const coercedVersion = coerce(version);
5959

6060
if (coercedVersion === null) {
@@ -77,7 +77,7 @@ export const getCompatibleVersions = (introduced, releases) => {
7777
const coercedMajor = major(coerceSemVer(introduced));
7878
// All Node.js versions that support the current API; If there's no "introduced_at" field,
7979
// we simply show all versions, as we cannot pinpoint the exact version
80-
return releases.filter(release => release.version.major >= coercedMajor);
80+
return releases.filter((release) => release.version.major >= coercedMajor);
8181
};
8282

8383
/**
@@ -108,4 +108,48 @@ export const sortChanges = (changes, key = 'version') => {
108108
* @param {Object} source - The source object
109109
*/
110110
export const leftHandAssign = (target, source) =>
111-
Object.keys(source).forEach(k => k in target || (target[k] = source[k]));
111+
Object.keys(source).forEach((k) => k in target || (target[k] = source[k]));
112+
113+
export const legacyToJSON = (section) =>
114+
JSON.stringify(
115+
section,
116+
[
117+
// TODO: remove this array once all the additional keys have been introduced downstream
118+
'added',
119+
'changes',
120+
'classes',
121+
'classMethods',
122+
'commit',
123+
'ctors',
124+
'default',
125+
'deprecated',
126+
'desc',
127+
'description',
128+
'displayName',
129+
'events',
130+
'examples',
131+
'globals',
132+
'introduced_in',
133+
'meta',
134+
'methods',
135+
'miscs',
136+
...(section.api === 'index' ? [] : ['modules']),
137+
'name',
138+
'napiVersion',
139+
'options',
140+
'params',
141+
'pr-url',
142+
'properties',
143+
'removed',
144+
'return',
145+
'shortDesc',
146+
'signatures',
147+
'source',
148+
'stability',
149+
'stabilityText',
150+
'textRaw',
151+
'type',
152+
'version',
153+
],
154+
2
155+
);

0 commit comments

Comments
 (0)