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AU,aAAgB,QAEhC,KAAK,oCAGR,EAAM,KAAK,wBAGb,KAAK,UAAU,uBAAwB,EAC3C,EAEJ,QAAQ,IAAM","file":"/npm/swag-engine@0.1.24/lib/core.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/swag-engine@0.1.24/lib/core.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst define_1 = require(\"./define\");\nconst utils_1 = require(\"./utils\");\nconst diff_1 = require(\"./diff\");\nexports.diff = diff_1.diff;\nconst node_fetch_1 = require(\"node-fetch\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\nconst _ = require(\"lodash\");\nconst debug = require(\"./debugLog\");\nconst PROJECT_ROOT = process.cwd();\nfunction wait(ttl = 50) {\n    return new Promise(resolve => setTimeout(resolve, ttl));\n}\nclass Cmd {\n    constructor(rootPath, config) {\n        this.diffs = {\n            modDiffs: [],\n            boDiffs: []\n        };\n        this.log = debug.info;\n        this.rootPath = rootPath;\n        this.config = utils_1.getConfig(config);\n    }\n    syncNew() {\n        return node_fetch_1.default(this.config.originUrl)\n            .then(data => data.json())\n            .then((data) => {\n            this.newDataStructure = new define_1.DataStructure(data, this.config.usingOperationId);\n        });\n    }\n    diff() {\n        const modDiffs = diff_1.diff(this.dataStructure.mods, this.newDataStructure.mods, true);\n        utils_1.setDefinitionInfs(this.newDataStructure.definitions, this.newDataStructure.mods);\n        const boDiffs = diff_1.diff(this.dataStructure.definitions, this.newDataStructure.definitions, false);\n        this.diffs = { modDiffs, boDiffs };\n    }\n    save() {\n        console.log(this.getPath(this.config.lockPath), \"created\");\n        const content = this.serialize();\n        fs.writeFileSync(this.getPath(this.config.lockPath), content, \"utf8\");\n        this.dataStructure = define_1.DataStructure.getDataFromLock(JSON.parse(content));\n    }\n    serialize() {\n        return this.dataStructure.serialize();\n    }\n    ready() {\n        if (fs.existsSync(this.getPath()) &&\n            fs.existsSync(this.getPath(this.config.lockPath))) {\n            const fileData = fs.readFileSync(this.getPath(this.config.lockPath), \"utf8\");\n            const dataStructure = define_1.DataStructure.getDataFromLock(JSON.parse(fileData));\n            this.dataStructure = dataStructure;\n            return Promise.resolve();\n        }\n        else {\n            return node_fetch_1.default(this.config.originUrl)\n                .then(data => data.json())\n                .then((data) => {\n                this.dataStructure = new define_1.DataStructure(data, this.config.usingOperationId);\n                this.write();\n                this.save();\n            });\n        }\n    }\n    updateAll() {\n        this.dataStructure = this.newDataStructure;\n    }\n    updateMod(mod, onLog) {\n        this.dataStructure.updateMod(mod, onLog);\n        this.log = debug.bindInfo(onLog);\n    }\n    updateDef(def, onLog) {\n        this.dataStructure.updateDefinition(def, onLog);\n        this.log = debug.bindInfo(onLog);\n    }\n    getPath(specPath = \"\") {\n        if (!specPath) {\n            return path.join(this.rootPath || PROJECT_ROOT, this.config.outDir);\n        }\n        return path.join(this.rootPath || PROJECT_ROOT, this.config.outDir, specPath);\n    }\n    format(code) {\n        return __awaiter(this, void 0, void 0, function* () {\n            return utils_1.format(code, this.config.prettierConfig);\n        });\n    }\n    writeFile(filePath, code) {\n        return __awaiter(this, void 0, void 0, function* () {\n            const formattedCode = yield this.format(code);\n            fs.writeFileSync(this.getPath(filePath), formattedCode);\n        });\n    }\n    write() {\n        return __awaiter(this, void 0, void 0, function* () {\n            this.log(`${this.config.outDir}文件夹清空中`);\n            utils_1.clearPath(this.getPath());\n            yield wait();\n            this.log(`更新基类中`);\n            this.writeDefinetions();\n            yield wait();\n            this.log(`更新定义文件中`);\n            this.writeNamespace();\n            yield wait();\n            this.log(`更新接口文件中`);\n            this.writeInterfaces();\n        });\n    }\n    writeInterfaces() {\n        const mods = this.dataStructure.mods;\n        const template = utils_1.getTemplate(this.config.templatePath, this.rootPath);\n        try {\n            mods.forEach(mod => {\n                utils_1.clearPath(this.getPath(mod.name));\n                mod.interfaces.forEach(inter => {\n                    try {\n                        this.writeFile(mod.name + \"/\" + inter.name + \".ts\", template.implement(Object.assign({}, inter, { bodyParams: inter.bodyParams, paramsType: inter.paramsType, responseType: inter.responseType, initialValue: inter.response.initialValue || \"undefined\", method: inter.method.toUpperCase(), description: inter.summary })));\n                    }\n                    catch (e) {\n                        console.log(e, e.error, e.message, e.stack);\n                    }\n                });\n                this.writeFile(mod.name + \"/index.ts\", `\n\t\t\t\t\t${mod.interfaces\n                    .map(inter => `import * as ${inter.name} from './${inter.name}';`)\n                    .join(\"\\n\")}\n\n\t\t\t\t\texport {\n\t\t\t\t\t\t${mod.interfaces.map(inter => inter.name).join(\",\\n\")}\n\t\t\t\t\t};\n\t\t\t\t`);\n            });\n            this.writeFile(\"index.ts\", `\n\t\t\t\t${mods.map(mod => `import * as ${mod.name} from './${mod.name}';`).join(\"\\n\")}\n\n\t\t\t\t(window as any).API = {\n\t\t\t\t\t${mods.map(mod => mod.name).join(\",\\n\")}\n\t\t\t\t};\n\t\t\t`);\n        }\n        catch (e) {\n            console.log(e.stack);\n        }\n    }\n    writeNamespace() {\n        const mods = this.dataStructure.mods;\n        const definitions = this.dataStructure.definitions;\n        const template = utils_1.getTemplate(this.config.templatePath, this.rootPath);\n        try {\n            this.writeFile(\"api.d.ts\", `\n\t\tdeclare namespace defs {\n\t\t\t${definitions\n                .map(def => `\n\t\t\t\texport ${define_1.Property.toClass(def.name, def.properties)}\n\t\t\t`)\n                .join(\"\\n\")}\n\t\t}\n\n\t\t${template.commonHeader()}\n\n\t\tdeclare namespace API {\n\t\t\t${mods\n                .map(mod => `\n\t\t\t\t/**\n\t\t\t\t * ${mod.description}\n         * ${(mod.interfaces &&\n                mod.interfaces.length &&\n                mod.interfaces[0].samePath) ||\n                \"\"}\n\t\t\t\t */\n\t\t\t\texport namespace ${mod.name} {\n\t\t\t\t\t${mod.interfaces\n                .map(inter => `\n\t\t\t\t\t\t/**\n              * ${inter.summary}\n              * ${inter.path}\n\t\t\t\t\t\t\t*/\n\t\t\t\t\t\texport namespace ${inter.name} {\n\t\t\t\t\t\t\t${template.header(Object.assign({}, inter, { bodyParams: inter.bodyParams, paramsType: inter.paramsType, responseType: inter.responseType, description: inter.summary }))}\n\t\t\t\t\t\t}\n\t\t\t\t\t`)\n                .join(\"\\n\\n\")}\n\t\t\t\t}\n\t\t\t`)\n                .join(\"\\n\\n\")}\n\t\t}\n\t\t`);\n        }\n        catch (e) {\n            console.log(e.stack);\n        }\n    }\n    writeDefinetions() {\n        const indexPath = this.getPath(\"index.ts\");\n        utils_1.clearPath(this.getPath(\"definitions\"));\n        this.dataStructure.definitions.forEach(def => {\n            const { properties, name } = def;\n            const deps = _.uniq(_.compact(_.map(properties, property => property.dep))).filter(dep => {\n                return dep !== name;\n            });\n            try {\n                const code = `\n\t\t\t\t\t${deps\n                    .map(dep => {\n                    return `import ${dep} from './${dep}';`;\n                })\n                    .join(\"\\n\")}\n\n\t\t\t\t\texport default ${define_1.Property.toValueClass(name, properties, false)};\n\t\t\t\t`;\n                this.writeFile(`definitions/${name}.ts`, code);\n            }\n            catch (e) {\n                debug.error(e.stack);\n            }\n        });\n        const names = this.dataStructure.definitions.map(def => def.name);\n        const indexCode = `\n      ${names\n            .map(name => {\n            return `import ${name} from './${name}';`;\n        })\n            .join(\"\\n\")}\n\n      export {\n        ${names.join(\", \")}\n      };\n    `;\n        this.writeFile(\"definitions/index.ts\", indexCode);\n    }\n}\nexports.Cmd = Cmd;\n"]}