From a96d0cf75320d9fb1f62795785e6ed50a7e29a2d Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 25 Aug 2021 13:57:48 -0700 Subject: [PATCH] chore: remove unused index.js file --- index.js | 74 -------------------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 index.js diff --git a/index.js b/index.js deleted file mode 100644 index d77dcd1..0000000 --- a/index.js +++ /dev/null @@ -1,74 +0,0 @@ -require('colors') -const _ = require('lodash') -const fs = require('fs') -const path = require('path') - -const utils = require('./lib/utils') -const paramInterfaces = require('./lib/dynamic-param-interfaces') -const generatePrimaryInterfaces = require('./lib/primary-interfaces') -const moduleDeclaration = require('./lib/module-declaration') -const remapOptionals = require('./lib/remap-optionals') - -Array.prototype.includes = Array.prototype.includes || function (thing) { // eslint-disable-line - return this.indexOf(thing) !== -1 -} - -// takes the predefined header and footer and wraps them around the generated files -const wrapWithHeaderAndFooter = (outputLines, electronVersion) => { - const newOutputLines = [] - utils.extendArray(newOutputLines, fs.readFileSync(path.resolve(__dirname, 'base/base_header.ts'), 'utf8').replace('<>', electronVersion).split(/\r?\n/)) - - newOutputLines.push('declare namespace Electron {') - utils.extendArray(newOutputLines, fs.readFileSync(path.resolve(__dirname, 'base/base_inner.ts'), 'utf8').replace('<>', electronVersion).split(/\r?\n/)) - - outputLines.slice(1).forEach((l) => newOutputLines.push(`${_.trimEnd(` ${l}`)}`)) - utils.extendArray(newOutputLines, ['}', '']) - - utils.extendArray(newOutputLines, fs.readFileSync(path.resolve(__dirname, 'base/base_footer.ts'), 'utf8').replace('<>', electronVersion).split(/\r?\n/)) - return newOutputLines -} - -const appendNodeJSOverride = (outputLines) => { - utils.extendArray(outputLines, ['', 'declare namespace NodeJS {']) - - const processAPI = moduleDeclaration.getModuleDeclarations().Process - processAPI.push('}') - utils.extendArray(outputLines, (processAPI.map((l, index) => l.length ? ((index === 0 || index === processAPI.length - 1) ? ` ${l}` : ` ${l}`) : ''))) - utils.extendArray(outputLines, [' interface ProcessVersions {', ' electron: string;', ' chrome: string;', ' }']) - - utils.extendArray(outputLines, ['}']) - - return outputLines -} - -module.exports = (API) => { - const outputLines = [] - - // adds lines to output with given indentation level - const addToOutput = (lines, indentation) => { - indentation = indentation || '' - utils.extendArray(outputLines, lines.map((l, i) => (i === 0 || i >= lines.length - 1) ? l : `${l}${indentation}`).concat(['\n'])) - } - - remapOptionals(API) - generatePrimaryInterfaces(API, addToOutput) - - // generate module declaration for every class, module, structure, element, etc - API.sort((m1, m2) => m1.name.localeCompare(m2.name)).forEach((module, index) => { - moduleDeclaration.generateModuleDeclaration(module, index, API) - }) - - // fetch everything that's been made and pop it into the actual API - Object.keys(moduleDeclaration.getModuleDeclarations()).forEach((moduleKey) => { - if (moduleKey === 'Process') return - const moduleAPI = moduleDeclaration.getModuleDeclarations()[moduleKey] - moduleAPI.push('}') - addToOutput(moduleAPI.map((l, index) => (index === 0 || index === moduleAPI.length - 1) ? l : ` ${l}`)) - }) - - paramInterfaces.flushParamInterfaces(API, addToOutput) - - const electronOutput = wrapWithHeaderAndFooter(outputLines, API[0].version) - - return appendNodeJSOverride(electronOutput) -}