Skip to content

Commit d2e86df

Browse files
tongMarshallOfSound
authored andcommittedDec 1, 2019
feat: read process fields (#14) (#17)
* read process fields (#14) * improve reading process fields * improve read process fields. * add ProcessBlock type * add markdown-helper.findProcess * add markdown-helper.findProcess tests
1 parent 0c9cfa1 commit d2e86df

File tree

4 files changed

+76
-27
lines changed

4 files changed

+76
-27
lines changed
 

‎src/DocsParser.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
headingsAndContent,
2424
findConstructorHeader,
2525
consumeTypedKeysList,
26+
findProcess,
2627
} from './markdown-helpers';
2728
import { WEBSITE_BASE_DOCS_URL, REPO_BASE_DOCS_URL } from './constants';
2829
import { extendError } from './helpers';
@@ -146,6 +147,7 @@ export class DocsParser {
146147
'HTMLElement documentation should not be considered a class',
147148
);
148149
}
150+
const electronProcess = findProcess(tokens);
149151
if (isClass) {
150152
// Instance name will be taken either from an example in a method declaration or the camel
151153
// case version of the class name
@@ -162,11 +164,7 @@ export class DocsParser {
162164
parsed.push({
163165
...container,
164166
type: 'Class',
165-
// FIXME: We should read the process correctly
166-
process: {
167-
main: true,
168-
renderer: true,
169-
},
167+
process: electronProcess,
170168
constructorMethod: constructorMethod
171169
? {
172170
signature: constructorMethod.signature,
@@ -197,11 +195,7 @@ export class DocsParser {
197195
parsed.push({
198196
...container,
199197
type: 'Element',
200-
// FIXME: We should read the process correctly
201-
process: {
202-
main: true,
203-
renderer: true,
204-
},
198+
process: electronProcess,
205199
// ## Methods
206200
methods: parseMethodBlocks(findContentInsideHeader(tokens, 'Methods', 2)),
207201
// ## Properties
@@ -213,11 +207,7 @@ export class DocsParser {
213207
parsed.push({
214208
...container,
215209
type: 'Module',
216-
// FIXME: We should read the process correctly
217-
process: {
218-
main: true,
219-
renderer: true,
220-
},
210+
process: electronProcess,
221211
// ## Methods
222212
methods: parseMethodBlocks(findContentInsideHeader(tokens, 'Methods', 2)),
223213
// ## Properties

‎src/ParsedDocumentation.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ export declare type BaseDocumentationContainer = {
7575
websiteUrl: string;
7676
repoUrl: string;
7777
};
78+
export declare type ProcessBlock = {
79+
main: boolean;
80+
renderer: boolean;
81+
};
7882
export declare type ModuleDocumentationContainer = {
7983
type: 'Module';
80-
process: {
81-
main: boolean;
82-
renderer: boolean;
83-
};
84+
process: ProcessBlock;
8485
methods: MethodDocumentationBlock[];
8586
events: EventDocumentationBlock[];
8687
properties: PropertyDocumentationBlock[];
@@ -106,10 +107,7 @@ export declare type StructureDocumentationContainer = {
106107
} & BaseDocumentationContainer;
107108
export declare type ClassDocumentationContainer = {
108109
type: 'Class';
109-
process: {
110-
main: boolean;
111-
renderer: boolean;
112-
};
110+
process: ProcessBlock;
113111
constructorMethod: Pick<MethodDocumentationBlock, 'signature' | 'parameters'> | null;
114112
instanceName: string;
115113
staticMethods: MethodDocumentationBlock[];
@@ -123,10 +121,7 @@ export declare type ClassDocumentationContainer = {
123121
} & BaseDocumentationContainer;
124122
export declare type ElementDocumentationContainer = {
125123
type: 'Element';
126-
process: {
127-
main: boolean;
128-
renderer: boolean;
129-
};
124+
process: ProcessBlock;
130125
constructorMethod?: undefined;
131126
methods: MethodDocumentationBlock[];
132127
events: EventDocumentationBlock[];

‎src/__tests__/markdown-helpers.spec.ts

+47
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getTopLevelGenericType,
1212
findFirstHeading,
1313
consumeTypedKeysList,
14+
findProcess,
1415
} from '../markdown-helpers';
1516
import { DocumentationTag } from '../ParsedDocumentation';
1617

@@ -387,4 +388,50 @@ foo`),
387388
);
388389
});
389390
});
391+
392+
describe('findProcess()', () => {
393+
it('should be available in main processe only', () => {
394+
var proc = findProcess(getTokens('Process: [Main](../glossary.md#main-process)'));
395+
expect(proc.main).toEqual(true);
396+
expect(proc.renderer).toEqual(false);
397+
});
398+
399+
it('should be available in renderer processe only', () => {
400+
var proc = findProcess(getTokens('Process: [Renderer](../glossary.md#renderer-process)'));
401+
expect(proc.main).toEqual(false);
402+
expect(proc.renderer).toEqual(true);
403+
});
404+
405+
it('should be available in both processes', () => {
406+
var proc = findProcess(
407+
getTokens(
408+
'Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)',
409+
),
410+
);
411+
expect(proc.main).toEqual(true);
412+
expect(proc.renderer).toEqual(true);
413+
});
414+
415+
it('should be available in both processes', () => {
416+
var proc = findProcess(
417+
getTokens(
418+
'Process: [Renderer](../glossary.md#renderer-process), [Main](../glossary.md#main-process)',
419+
),
420+
);
421+
expect(proc.main).toEqual(true);
422+
expect(proc.renderer).toEqual(true);
423+
});
424+
425+
it('should be available in both processes', () => {
426+
var proc = findProcess(getTokens(''));
427+
expect(proc.main).toEqual(true);
428+
expect(proc.renderer).toEqual(true);
429+
});
430+
431+
it('should be available in both processes', () => {
432+
var proc = findProcess([]);
433+
expect(proc.main).toEqual(true);
434+
expect(proc.renderer).toEqual(true);
435+
});
436+
});
390437
});

‎src/markdown-helpers.ts

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
MethodParameterDocumentation,
77
PossibleStringValue,
88
DocumentationTag,
9+
ProcessBlock,
910
} from './ParsedDocumentation';
1011

1112
const tagMap = {
@@ -716,3 +717,19 @@ export const convertListToTypedKeys = (listTokens: Token[]): TypedKeyList => {
716717

717718
return unconsumedTypedKeyList(convertNestedListToTypedKeys(list));
718719
};
720+
721+
export const findProcess = (tokens: Token[]): ProcessBlock => {
722+
for (const tk of tokens) {
723+
if (tk.type === 'inline' && tk.content.indexOf('Process') === 0) {
724+
const ptks = tk.children.slice(2, tk.children.length - 1);
725+
const procs: ProcessBlock = { main: false, renderer: false };
726+
for (const ptk of ptks) {
727+
if (ptk.type !== 'text') continue;
728+
if (ptk.content === 'Main') procs.main = true;
729+
if (ptk.content === 'Renderer') procs.renderer = true;
730+
}
731+
return procs;
732+
}
733+
}
734+
return { main: true, renderer: true };
735+
};

0 commit comments

Comments
 (0)
Please sign in to comment.