Skip to content

feat: read process fields (#14) #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/DocsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
headingsAndContent,
findConstructorHeader,
consumeTypedKeysList,
findProcess,
} from './markdown-helpers';
import { WEBSITE_BASE_DOCS_URL, REPO_BASE_DOCS_URL } from './constants';
import { extendError } from './helpers';
Expand Down Expand Up @@ -146,6 +147,7 @@ export class DocsParser {
'HTMLElement documentation should not be considered a class',
);
}
const electronProcess = findProcess(tokens);
if (isClass) {
// Instance name will be taken either from an example in a method declaration or the camel
// case version of the class name
Expand All @@ -162,11 +164,7 @@ export class DocsParser {
parsed.push({
...container,
type: 'Class',
// FIXME: We should read the process correctly
process: {
main: true,
renderer: true,
},
process: electronProcess,
constructorMethod: constructorMethod
? {
signature: constructorMethod.signature,
Expand Down Expand Up @@ -197,11 +195,7 @@ export class DocsParser {
parsed.push({
...container,
type: 'Element',
// FIXME: We should read the process correctly
process: {
main: true,
renderer: true,
},
process: electronProcess,
// ## Methods
methods: parseMethodBlocks(findContentInsideHeader(tokens, 'Methods', 2)),
// ## Properties
Expand All @@ -213,11 +207,7 @@ export class DocsParser {
parsed.push({
...container,
type: 'Module',
// FIXME: We should read the process correctly
process: {
main: true,
renderer: true,
},
process: electronProcess,
// ## Methods
methods: parseMethodBlocks(findContentInsideHeader(tokens, 'Methods', 2)),
// ## Properties
Expand Down
19 changes: 7 additions & 12 deletions src/ParsedDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ export declare type BaseDocumentationContainer = {
websiteUrl: string;
repoUrl: string;
};
export declare type ProcessBlock = {
main: boolean;
renderer: boolean;
};
export declare type ModuleDocumentationContainer = {
type: 'Module';
process: {
main: boolean;
renderer: boolean;
};
process: ProcessBlock;
methods: MethodDocumentationBlock[];
events: EventDocumentationBlock[];
properties: PropertyDocumentationBlock[];
Expand All @@ -106,10 +107,7 @@ export declare type StructureDocumentationContainer = {
} & BaseDocumentationContainer;
export declare type ClassDocumentationContainer = {
type: 'Class';
process: {
main: boolean;
renderer: boolean;
};
process: ProcessBlock;
constructorMethod: Pick<MethodDocumentationBlock, 'signature' | 'parameters'> | null;
instanceName: string;
staticMethods: MethodDocumentationBlock[];
Expand All @@ -123,10 +121,7 @@ export declare type ClassDocumentationContainer = {
} & BaseDocumentationContainer;
export declare type ElementDocumentationContainer = {
type: 'Element';
process: {
main: boolean;
renderer: boolean;
};
process: ProcessBlock;
constructorMethod?: undefined;
methods: MethodDocumentationBlock[];
events: EventDocumentationBlock[];
Expand Down
47 changes: 47 additions & 0 deletions src/__tests__/markdown-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getTopLevelGenericType,
findFirstHeading,
consumeTypedKeysList,
findProcess,
} from '../markdown-helpers';
import { DocumentationTag } from '../ParsedDocumentation';

Expand Down Expand Up @@ -387,4 +388,50 @@ foo`),
);
});
});

describe('findProcess()', () => {
it('should be available in main processe only', () => {
var proc = findProcess(getTokens('Process: [Main](../glossary.md#main-process)'));
expect(proc.main).toEqual(true);
expect(proc.renderer).toEqual(false);
});

it('should be available in renderer processe only', () => {
var proc = findProcess(getTokens('Process: [Renderer](../glossary.md#renderer-process)'));
expect(proc.main).toEqual(false);
expect(proc.renderer).toEqual(true);
});

it('should be available in both processes', () => {
var proc = findProcess(
getTokens(
'Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)',
),
);
expect(proc.main).toEqual(true);
expect(proc.renderer).toEqual(true);
});

it('should be available in both processes', () => {
var proc = findProcess(
getTokens(
'Process: [Renderer](../glossary.md#renderer-process), [Main](../glossary.md#main-process)',
),
);
expect(proc.main).toEqual(true);
expect(proc.renderer).toEqual(true);
});

it('should be available in both processes', () => {
var proc = findProcess(getTokens(''));
expect(proc.main).toEqual(true);
expect(proc.renderer).toEqual(true);
});

it('should be available in both processes', () => {
var proc = findProcess([]);
expect(proc.main).toEqual(true);
expect(proc.renderer).toEqual(true);
});
});
});
17 changes: 17 additions & 0 deletions src/markdown-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MethodParameterDocumentation,
PossibleStringValue,
DocumentationTag,
ProcessBlock,
} from './ParsedDocumentation';

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

return unconsumedTypedKeyList(convertNestedListToTypedKeys(list));
};

export const findProcess = (tokens: Token[]): ProcessBlock => {
for (const tk of tokens) {
if (tk.type === 'inline' && tk.content.indexOf('Process') === 0) {
const ptks = tk.children.slice(2, tk.children.length - 1);
const procs: ProcessBlock = { main: false, renderer: false };
for (const ptk of ptks) {
if (ptk.type !== 'text') continue;
if (ptk.content === 'Main') procs.main = true;
if (ptk.content === 'Renderer') procs.renderer = true;
}
return procs;
}
}
return { main: true, renderer: true };
};