UNPKG

webextensions-api-mock

Version:
42 lines (41 loc) 1.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const webextensions_schema_1 = __importDefault(require("webextensions-schema")); const prettier_1 = __importDefault(require("prettier")); const namespaces_1 = require("./generator/namespaces"); class Update { constructor() { this.prettierOptions = {}; this.generatedDir = path_1.default.join(__dirname, 'generated'); } async run() { const schema = await webextensions_schema_1.default(); console.log(`[webextensions-api-mock] updating to ${schema.tag()}`); const options = await prettier_1.default.resolveConfig('.'); if (options) { this.prettierOptions = options; } this.namespaces = schema.namespaces(); await Promise.all([this.updateSchema(), this.updateTypes()]); return this.namespaces; } async updateSchema() { await fs_1.promises.writeFile(path_1.default.join(this.generatedDir, 'schema.json'), prettier_1.default.format(JSON.stringify(this.namespaces), { ...this.prettierOptions, parser: 'json', })); } async updateTypes() { const types = new namespaces_1.NamespacesGenerator(this.namespaces).out(); await fs_1.promises.writeFile(path_1.default.join(this.generatedDir, 'types.d.ts'), prettier_1.default.format(types, { ...this.prettierOptions, parser: 'typescript', })); } } exports.Update = Update;