Skip to content
Closed
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
16 changes: 10 additions & 6 deletions base/base_footer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
declare module 'electron' {
export = Electron;
}

interface NodeRequireFunction {
(moduleName: 'electron'): typeof Electron;
Expand All @@ -13,11 +10,18 @@ interface File {
path: string;
}

interface Document {
createElement(tagName: 'webview'): Electron.WebviewTag;
}

}

declare module 'electron' {
export = Electron;
}

declare module 'original-fs' {
import * as fs from 'fs';
export = fs;
}

interface Document {
createElement(tagName: 'webview'): Electron.WebviewTag;
}
3 changes: 3 additions & 0 deletions base/base_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
// Definitions: https://github.com/electron/electron-typescript-definitions

/// <reference types="node" />
import events = require('events');

type GlobalEvent = Event;

declare global {
15 changes: 7 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ParsedDocumentationResult } from '@electron/docs-parser';
import { DynamicParamInterfaces } from './dynamic-param-interfaces';

// takes the predefined header and footer and wraps them around the generated files
const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string) => {
const wrapWithHeaderAndFooter = (outputLines: string[], nodeJSOverride: string[], electronVersion: string) => {
const newOutputLines: string[] = [];
utils.extendArray(
newOutputLines,
Expand All @@ -19,7 +19,7 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string)
.split(/\r?\n/),
);

newOutputLines.push('declare namespace Electron {');
newOutputLines.push('namespace Electron {');
utils.extendArray(
newOutputLines,
fs
Expand All @@ -30,6 +30,7 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string)

outputLines.slice(1).forEach(l => newOutputLines.push(`${_.trimEnd(` ${l}`)}`));
utils.extendArray(newOutputLines, ['}', '']);
utils.extendArray(newOutputLines, nodeJSOverride);

utils.extendArray(
newOutputLines,
Expand All @@ -41,8 +42,8 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string)
return newOutputLines;
};

const appendNodeJSOverride = (outputLines: string[]) => {
utils.extendArray(outputLines, ['', 'declare namespace NodeJS {']);
const createNodeJSOverride = () => {
let outputLines = ['', 'namespace NodeJS {', ' interface ReadableStream {}'];

const processAPI = getModuleDeclarations().Process;
processAPI.push('}');
Expand All @@ -61,7 +62,7 @@ const appendNodeJSOverride = (outputLines: string[]) => {

utils.extendArray(outputLines, ['}']);

return outputLines.join('\n');
return outputLines;
};

interface GenerateOptions {
Expand Down Expand Up @@ -102,7 +103,5 @@ export async function generateDefinitions({ electronApi: API }: GenerateOptions)

DynamicParamInterfaces.flushParamInterfaces(API, addToOutput);

const electronOutput = wrapWithHeaderAndFooter(outputLines, API[0].version);

return appendNodeJSOverride(electronOutput);
return wrapWithHeaderAndFooter(outputLines, createNodeJSOverride(), API[0].version).join('\n');
}
2 changes: 1 addition & 1 deletion src/module-declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const generateModuleDeclaration = (
`${isClass ? 'class' : 'interface'} ${_.upperFirst(
module.name,
)} extends ${module.extends ||
(module.name === 'remote' ? 'MainInterface' : 'NodeJS.EventEmitter')} {`,
(module.name === 'remote' ? 'MainInterface' : 'events.EventEmitter')} {`,
);
moduleAPI.push('', `// Docs: ${module.websiteUrl}`, '');
} else {
Expand Down