anl 1.4.8 → 1.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="3.0.1",t={title:"Swagger Generator",description:"This is an online swagger codegen server. You can find out more at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).",license:{name:"Apache 2.0",url:"http://www.apache.org/licenses/LICENSE-2.0.html"},version:"3.0.68"},r=[{url:"/api"}],n=[{name:"clients"},{name:"servers"},{name:"documentation"},{name:"config"}],o={"/generate":{get:{tags:["clients","servers","documentation","config"],summary:"Generates and download code. GenerationRequest input provided as JSON available at URL specified in parameter codegenOptionsURL.",operationId:"generateFromURL",parameters:[{name:"codegenOptionsURL",in:"query",required:!0,schema:{type:"string"}}],responses:{200:{description:"successful operation",content:{"application/octet-stream":{schema:{type:"string",format:"binary"}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"},post:{tags:["clients","servers","documentation","config"],summary:"Generates and download code. GenerationRequest input provided as request body.",operationId:"generate",requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/GenerationRequest"}}}},responses:{200:{description:"successful operation",content:{"application/octet-stream":{schema:{type:"string",format:"binary"}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/clients":{get:{tags:["clients","documentation"],summary:"Deprecated, use '/{type}/{version}' instead. List generator languages of type 'client' or 'documentation' for given codegen version (defaults to V3)",operationId:"clientLanguages",parameters:[{$ref:"#/components/parameters/version"},{name:"clientOnly",in:"query",description:"flag to only return languages of type `client`",schema:{type:"boolean",default:!1}}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"array",items:{type:"string"}}}}}},deprecated:!0,"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/servers":{get:{tags:["servers"],summary:"Deprecated, use '/{type}/{version}' instead. List generator languages of type 'server' for given codegen version (defaults to V3)",operationId:"serverLanguages",parameters:[{$ref:"#/components/parameters/version"}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"array",items:{type:"string"}}}}}},deprecated:!0,"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/documentation":{get:{tags:["documentation"],summary:"Deprecated, use '/{type}/{version}' instead. List generator languages of type 'documentation' for given codegen version (defaults to V3)",operationId:"documentationLanguages",parameters:[{$ref:"#/components/parameters/version"}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"array",items:{type:"string"}}}}}},deprecated:!0,"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/{type}/{version}":{get:{tags:["clients","servers","documentation","config"],summary:"List generator languages of the given type and version",operationId:"languages",parameters:[{$ref:"#/components/parameters/type"},{name:"version",in:"path",description:"generator version used by codegen engine",required:!0,schema:{type:"string",enum:["V2","V3"]}}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"array",items:{type:"string"}}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/types":{get:{tags:["clients","servers","documentation","config"],summary:"List generator languages of version defined in 'version parameter (defaults to V3) and type included in 'types' parameter; all languages",operationId:"languagesMulti",parameters:[{$ref:"#/components/parameters/types"},{$ref:"#/components/parameters/version"}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"array",items:{type:"string"}}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/options":{get:{tags:["clients","servers","documentation","config"],summary:"Returns options for a given language and version (defaults to V3)",operationId:"listOptions",parameters:[{name:"language",in:"query",description:"language",schema:{type:"string"}},{$ref:"#/components/parameters/version"}],responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"object",additionalProperties:{$ref:"#/components/schemas/CliOption"}}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/model":{post:{tags:["clients","servers","documentation","config"],summary:'Generates the intermediate model ("bundle") and returns it as a JSON. body.',operationId:"generateBundle",requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/GenerationRequest"}}}},responses:{200:{description:"successful operation",content:{"application/json":{schema:{type:"object"}}}}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}},"/render":{post:{tags:["documentation"],summary:"render a template using the provided data",operationId:"renderTemplate",requestBody:{content:{"application/json":{schema:{$ref:"#/components/schemas/RenderRequest"}}}},responses:{200:{description:"successful operation"}},"x-swagger-router-controller":"io.swagger.v3.generator.online.GeneratorController"}}},i={schemas:{GenerationRequest:{required:["lang"],type:"object",properties:{lang:{title:"language",type:"string",description:"language to generate (required)",example:"java"},spec:{type:"object",description:"spec in json format. . Alternative to `specURL`"},specURL:{type:"string",description:"URL of the spec in json format. Alternative to `spec`"},type:{type:"string",description:"type of the spec",enum:["CLIENT","SERVER","DOCUMENTATION","CONFIG"]},codegenVersion:{type:"string",description:"codegen version to use",enum:["V2","V3"]},options:{$ref:"#/components/schemas/Options"}},"x-swagger-router-model":"io.swagger.codegen.v3.service.GenerationRequest"},AuthorizationValue:{title:"authorization",type:"object",properties:{value:{type:"string",description:"Authorization value"},keyName:{type:"string",description:"Authorization key"},type:{type:"string",description:"Authorization type",enum:["query","header"]}},description:"adds authorization headers when fetching the open api definitions remotely. Pass in an authorizationValue object","x-swagger-router-model":"io.swagger.v3.parser.core.models.AuthorizationValue"},Options:{type:"object",properties:{auth:{title:"authorization",type:"string",description:"adds authorization headers when fetching the open api definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values"},authorizationValue:{$ref:"#/components/schemas/AuthorizationValue"},apiPackage:{title:"api package",type:"string",description:"package for generated api classes"},templateVersion:{title:"Template Version",type:"string",description:"template version for generation"},modelPackage:{title:"model package",type:"string",description:"package for generated models"},modelNamePrefix:{title:"model name prefix",type:"string",description:"Prefix that will be prepended to all model names. Default is the empty string."},modelNameSuffix:{title:"model name suffix",type:"string",description:"PrefixSuffix that will be appended to all model names. Default is the empty string."},systemProperties:{title:"System Properties",type:"object",additionalProperties:{type:"string"},description:"sets specified system properties in key/value format"},instantiationTypes:{title:"instantiation types",type:"object",additionalProperties:{type:"string"},description:"sets instantiation type mappings in key/value format. For example (in Java): array=ArrayList,map=HashMap. In other words array types will get instantiated as ArrayList in generated code."},typeMappings:{title:"type mappings",type:"object",additionalProperties:{type:"string"},description:"sets mappings between swagger spec types and generated code types in key/value format. For example: array=List,map=Map,string=String."},additionalProperties:{title:"additional properties",type:"object",additionalProperties:{type:"object"},description:"sets additional properties that can be referenced by the mustache templates in key/value format."},languageSpecificPrimitives:{title:"language specific primitives",type:"array",description:"specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double. You can also have multiple occurrences of this option.",items:{type:"string"}},importMappings:{title:"import mappings",type:"object",additionalProperties:{type:"string"},description:"specifies mappings between a given class and the import that should be used for that class in key/value format."},invokerPackage:{title:"invoker package",type:"string",description:"root package for generated code"},groupId:{title:"group id",type:"string",description:"groupId in generated pom.xml"},artifactId:{title:"artifact id",type:"string",description:"artifactId in generated pom.xml"},artifactVersion:{title:"artifact version",type:"string",description:"artifact version generated in pom.xml"},library:{title:"library",type:"string",description:"library template (sub-template)"},gitUserId:{title:"git user id",type:"string",description:"Git user ID, e.g. swagger-api."},gitRepoId:{title:"git repo id",type:"string",description:"Git repo ID, e.g. swagger-codegen."},releaseNote:{title:"release note",type:"string",description:"Release note, default to 'Minor update'."},httpUserAgent:{title:"http user agent",type:"string",description:"HTTP user agent, e.g. codegen_csharp_api_client, default to 'Swagger-Codegen/{packageVersion}}/{language}'"},reservedWordsMappings:{title:"reserved words mappings",type:"object",additionalProperties:{type:"string"},description:"pecifies how a reserved name should be escaped to. Otherwise, the default _<name> is used. For example id=identifier."},ignoreFileOverride:{title:"ignore file override location",type:"string",description:"Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation."},removeOperationIdPrefix:{title:"remove prefix of the operationId",type:"boolean",description:"Remove prefix of operationId, e.g. config_getId => getId"},skipOverride:{type:"boolean"}},"x-swagger-router-model":"io.swagger.codegen.v3.service.Options"},CliOption:{type:"object",properties:{optionName:{type:"string"},description:{type:"string"},type:{type:"string",description:"Data type is based on the types supported by the JSON-Schema"},enum:{type:"object",additionalProperties:{type:"string"}},default:{type:"string"}}},RenderRequest:{required:["context","template"],type:"object",properties:{template:{title:"template",type:"string",description:"template as string",example:"{{!mustache}}"},context:{title:"context",type:"string",description:"context as string",example:"{}"}},"x-swagger-router-model":"io.swagger.codegen.v3.service.RenderRequest"},RenderResponse:{required:["value"],type:"object",properties:{value:{type:"string"}},"x-swagger-router-model":"io.swagger.codegen.v3.service.RenderResponse"}},parameters:{version:{name:"version",in:"query",description:"generator version used by codegen engine",schema:{type:"string",enum:["V2","V3"]}},type:{name:"type",in:"path",description:"generator type",required:!0,schema:{type:"string",enum:["client","server","documentation","config"]}},types:{name:"types",in:"query",description:"comma-separated list of generator types",required:!0,style:"form",explode:!1,schema:{type:"array",items:{type:"string",enum:["client","server","documentation","config"]}}}}},s={openapi:e,info:t,servers:r,tags:n,paths:o,components:i};exports.components=i,exports.default=s,exports.info=t,exports.openapi=e,exports.paths=o,exports.servers=r,exports.tags=n;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.4.8",i="FE command line tool",s="bin/an-cli.js",l={dev:"rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",build:"rimraf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",pub:"bash publish.sh",ts:"tsc ./src/int.ts --noEmit --watch",blink:"npm run build && npm link"},p={anl:"bin/an-cli.js"},t="Gleason <bianliuzhu@gmail.com>",r={"@commitlint/cli":"^17.4.3","@commitlint/config-conventional":"^17.4.3","@rollup/plugin-commonjs":"^21.0.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@rollup/plugin-typescript":"^8.3.0","@types/inquirer":"^9.0.3","@types/shelljs":"^0.8.11","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","cross-env":"^7.0.3",eslint:"^8.7.0",husky:"^8.0.3","openapi-types":"^12.1.3",prettier:"^3.3.2",rimraf:"^5.0.7",rollup:"^2.64.0","rollup-plugin-cleandir":"^2.0.0","rollup-plugin-copy":"^3.5.0","rollup-plugin-terser":"^7.0.2",typescript:"^4.5.4"},o={"app-root-path":"^3.1.0",cac:"^6.7.12",chalk:"4.*","clear-console":"^1.1.0",commander:"^10.0.0",figures:"^6.1.0",inquirer:"^10.1.8","log-symbols":"^5.1.0",ora:"5.*","progress-estimator":"^0.3.0",shelljs:"^0.8.5"},n=["typescript","cli","typescript 脚手架","ts 脚手架","ts-cli","脚手架"],c=["package.json","README.md","lib","template"],u={type:"git",url:"https://github.com/bianliuzhu/an-cli.git"},a="commonjs",m={name:"anl",version:e,description:i,main:s,scripts:l,bin:p,author:t,license:"ISC",devDependencies:r,dependencies:o,keywords:n,files:c,repository:u,type:a};exports.author=t,exports.bin=p,exports.default=m,exports.dependencies=o,exports.description=i,exports.devDependencies=r,exports.files=c,exports.keywords=n,exports.license="ISC",exports.main=s,exports.name="anl",exports.repository=u,exports.scripts=l,exports.type=a,exports.version=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.4.10",i="FE command line tool",s="bin/an-cli.js",l={dev:"rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",build:"rimraf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",pub:"bash publish.sh",ts:"tsc ./src/int.ts --noEmit --watch",blink:"npm run build && npm link"},p={anl:"bin/an-cli.js"},t="Gleason <bianliuzhu@gmail.com>",r={"@commitlint/cli":"^17.4.3","@commitlint/config-conventional":"^17.4.3","@rollup/plugin-commonjs":"^21.0.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@rollup/plugin-typescript":"^8.3.0","@types/inquirer":"^9.0.3","@types/shelljs":"^0.8.11","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","cross-env":"^7.0.3",eslint:"^8.7.0",husky:"^8.0.3","openapi-types":"^12.1.3",prettier:"^3.3.2",rimraf:"^5.0.7",rollup:"^2.64.0","rollup-plugin-cleandir":"^2.0.0","rollup-plugin-copy":"^3.5.0","rollup-plugin-terser":"^7.0.2",typescript:"^4.5.4"},o={"app-root-path":"^3.1.0",cac:"^6.7.12",chalk:"4.*","clear-console":"^1.1.0",commander:"^10.0.0",figures:"^6.1.0",inquirer:"^10.1.8","log-symbols":"^5.1.0",ora:"5.*","progress-estimator":"^0.3.0",shelljs:"^0.8.5"},n=["typescript","cli","typescript 脚手架","ts 脚手架","ts-cli","脚手架"],c=["package.json","README.md","lib","template"],u={type:"git",url:"https://github.com/bianliuzhu/an-cli.git"},a="commonjs",m={name:"anl",version:e,description:i,main:s,scripts:l,bin:p,author:t,license:"ISC",devDependencies:r,dependencies:o,keywords:n,files:c,repository:u,type:a};exports.author=t,exports.bin=p,exports.default=m,exports.dependencies=o,exports.description=i,exports.devDependencies=r,exports.files=c,exports.keywords=n,exports.license="ISC",exports.main=s,exports.name="anl",exports.repository=u,exports.scripts=l,exports.type=a,exports.version=e;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const t="\t";var n;!function(e){e.GET="get",e.PUT="put",e.POST="post",e.DELETE="delete",e.OPTIONS="options",e.HEAD="head",e.PATCH="patch",e.TRACE="trace"}(n||(n={}));const r={typeMapping:new Map([["integer","number"],["string","string"],["boolean","boolean"],["binary","File"]]),errorHandling:{throwOnError:!1,logErrors:!0}};class s{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",requestPath:"",summary:"",apiName:"",typeName:""};Map=new Map;config;errors=[];schemaCache=new Map;referenceCache=new Map;templates={exportConst:e=>`export const ${e}`,typeDefinition:(e,t)=>`type ${e} = ${t}`,interfaceDefinition:e=>`interface ${e}`};constructor(e,t){this.pathsObject=e,this.config={...r,...t,typeMapping:new Map([...r.typeMapping||[],...t.typeMapping||[]])}}handleError(t){if(this.errors.push(t),this.config.errorHandling?.logErrors&&e.log.error(`${t.type}: ${t.message}${t.path?` at ${t.path}`:""}`),this.config.errorHandling?.throwOnError)throw new Error(`${t.type}: ${t.message}`)}getIndentation(){return this.config.formatting?.indentation||t}formatCode(e){const t=this.getIndentation(),n=this.config.formatting?.lineEnding||"\n";return e.split("\n").map((e=>`${t}${e}`)).join(n)}typeNameToFileName(e){return e=(e=(e=e.replace(/_/g,"-")).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()).replace(/-+/g,"-")}handleComplexType(e){try{return e.oneOf?e.oneOf.map((e=>this.schemaParse(e))).join(" | "):e.allOf?e.allOf.map((e=>this.schemaParse(e))).join(" & "):e.anyOf?e.anyOf.map((e=>this.schemaParse(e))).join(" | "):e.enum?"number"===e.type||"integer"===e.type?e.enum.join(" | "):e.enum.map((e=>`'${e}'`)).join(" | "):"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to handle complex type",details:e}),"unknown"}}propertiesParse(e){if(!e)return[];const n=[];for(const r in e){const s=e[r],a=this.schemaParse(s);let i="";i=Array.isArray(a)?`${t}${t}${r}: {${a.join("\n")}};`:`${t}${t}${r}: ${a};`,n.push(i)}return n}nonArraySchemaObjectParse(e){if(!e)return"unknown";if("binary"===e.format||"string"===e.type&&"binary"===e.format)return"File";switch(e.type){case"boolean":return"boolean";case"integer":case"number":return"number";case"object":return this.propertiesParse(e.properties);case"string":return"binary"===e.format?"File":"string";default:return"unknown"}}arraySchemaObjectParse(e){if("array"!==e.type)return"";const{items:t}=e,n="$ref"in t?t:null,r=t;if(n){return`Array<${this.referenceObjectParse(n)}>`}if(r){const e=this.schemaParse(t);return Array.isArray(e)?`Array<{${e.join("\n")}}>`:`Array<${e}>`}return""}referenceObjectParse(e){try{const t=e.$ref,n=this.referenceCache.get(t);if(n)return n;let r=t;t.startsWith("#/components/schemas/")?r=t.replace("#/components/schemas/",""):t.startsWith("#/definitions/")&&(r=t.replace("#/definitions/",""));const s=this.typeNameToFileName(r),a=/enum/gi.test(r)?`import('${this.config.importEnumPath}/${s}').${r}`:`import('../models/${s}').${r}`;return this.referenceCache.set(t,a),a}catch(e){return this.handleError({type:"REFERENCE",message:"Failed to parse reference object",details:e}),"unknown"}}schemaParse(e){try{if(!e)return"unknown";if("oneOf"in e||"allOf"in e||"anyOf"in e||"enum"in e)return this.handleComplexType(e);if("$ref"in e)return this.referenceObjectParse(e);const t=e,n=t.type,r=!0===t.nullable?" | null":"";if(e.format&&this.config.typeMapping?.has(e.format))return this.config.typeMapping.get(e.format)+r;if(n&&this.config.typeMapping?.has(n))return this.config.typeMapping.get(n)+r;if("array"===n&&t.items){const e=this.schemaParse(t.items);if(Array.isArray(e)){const t=this.config.formatting?.lineEnding,n=this.config.formatting?.indentation;return`Array<{${t}${e.join("\n")}${t}${n}${n}}>`}return"Array<any>"}if("object"===n){if(t.properties){const e=this.propertiesParse(t.properties);return e.length?e:["unknown"]}if(!0===t.additionalProperties)return"Record<string, unknown>"+r;if("object"==typeof t.additionalProperties){return`Record<string, ${this.schemaParse(t.additionalProperties)}>`+r}}return"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),"unknown"}}responseObjectParse(e){try{const t=e.content;if(!t)return"";const n=["application/json","text/json","text/plain","*/*"];let r;for(const e of n)if(t[e]?.schema){r=t[e].schema;break}return r?this.schemaParse(r):""}catch(e){return this.handleError({type:"RESPONSE",message:"Failed to parse response object",details:e}),""}}responseHandle(e){const t=e[200];if(!t)return;const n="content"in t?t:null,r="$ref"in t?t:null;if(null===n&&null===r&&(this.contentBody.response="type Response = unknown",this.contentBody._response="unknown"),r){const e=this.referenceObjectParse(r);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(n){const e=this.responseObjectParse(n);if(Array.isArray(e)){if(1===e.length&&"unknown"===e[0])this.contentBody.response=`type Response = ${e.join("\n")};`;else{const t=this.config.formatting?.lineEnding,n=this.config.formatting?.indentation;this.contentBody.response=`interface Response {${t}${e.join("\n")}${t}${n}};`}this.contentBody._response=`${e.join("\n")}`}else this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`}}requestBodyObjectParse(e){const n=Object.values(e.content),{schema:r}=n[0]||{schema:null};if(r){const e=r?.type,n="$ref"in r?r:null,s="array"===e?r:null,a=e&&this.nonArrayType.includes(e)?r:null;if(n){const e=this.referenceObjectParse(n);return`${t}type Body = ${e}`}if(s){const e=this.arraySchemaObjectParse(s);return`${t}type Body = ${e}`}if(a){const e=this.nonArraySchemaObjectParse(a);return Array.isArray(e)?0===e.length?[`${t}type Body = ${a.type};`]:[`${t}interface Body {`,...e.map((e=>e.replace(/: string;/,": File;"))),"}"]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return"{}";const n="$ref"in e?e:null,r="content"in e?e:null;if(n){const e=this.referenceObjectParse(n);return`${t}type Body = ${e}`}return r&&"[object Object]"===String(e)&&0!==Reflect.ownKeys(e).length?this.requestBodyObjectParse(r):"{}"}requestParametersParse(n){const r=[],s=[];n?.map((n=>{const a="$ref"in n?n:null,i="name"in n?n:null;if(a){const t=this.referenceObjectParse(a);return e.log.warning(`${this.pathKey} ${t} item 是 ReferenceObject 类型 ----未处理---`),t}if(i){if("path"===i.in){const e=this.schemaParse(i.schema);r.push(`${t}${t}type ${i.name} = ${e};`),this.contentBody.payload._path?"string"==typeof e?this.contentBody.payload._path[i.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._path={[i.name]:e}:console.log("Unexpected v2value type:",e)}if("query"===i.in){const e=this.schemaParse(i.schema);s.push(`${t}${t}${i.name}: ${e};`),this.contentBody.payload._query?"string"==typeof e?this.contentBody.payload._query[i.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._query={[i.name]:e}:console.log("Unexpected v2value type:",e)}}})),0!==r.length&&(r.unshift(`${t}namespace Path {`),r.push(`${t}}`)),0!==s.length&&(s.unshift(`${t}interface Query {`),s.push(`${t}}`)),this.contentBody.payload.path=r,this.contentBody.payload.query=s}requestHandle(e){if(e.parameters&&this.requestParametersParse(e.parameters),e.requestBody){const t=this.requestBodyParse(e.requestBody);if(Array.isArray(t))this.contentBody.payload.body=t;else if(t){const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}apiRequestItemHandle(e){const{payload:t,requestPath:n,_response:r,method:s,typeName:a,apiName:i}=e,{_path:o,_query:p,body:c}=t,h=c.some((e=>e.includes("File:")||e.includes(": File"))),l=e=>{const t=[];for(const n in e)t.push(`${n}: ${a}.Path.${n}`);return t.length>1?t.join(","):t.join("")},y=o?l(o):"",u=p?`params: ${a}.Query`:"",d=c.length>0?`params: ${a}.Body`:"",m={};y&&(m.apiParamsPath=y),u&&(m.apiParamsQuery=u),d&&(m.apiParamsBody=d);const f=Object.keys(m).length>=2,g=h?`,${this.config.dataLevel}`:"",$=h?", { headers: { 'Content-Type': 'multipart/form-data' } }":"";return[`export const ${i} = `,"(",o?l(o):"",""+(f?",":""),p?`params: ${a}.Query`:"",c.length>0?`params: ${a}.Body`:"",")"," => ",`${s}${r?`<${a}.Response>`:""}`,"(`"+n+"`"+(u||d?", params":"")+g+$+");"].join("")}parsePathItemObject(e,t){if(e)for(const n in e){const r=e[n];if(r){const e=n.toUpperCase(),s=t+"|"+e,{apiName:a,typeName:i,fileName:o,path:p}=this.convertEndpointString(s);this.contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:o,method:e,typeName:i,requestPath:p,apiName:a,summary:r.summary},this.requestHandle(r),this.responseHandle(r.responses),this.Map.has(s)||this.Map.set(s,JSON.parse(JSON.stringify(this.contentBody)))}}}convertEndpointString(e){let t=e;e.startsWith("/")||(t="/"+e);const[n,r]=t.split("|"),s=`${n.replace("/api/","").split("/").map((e=>e.includes("{")?`$${e.slice(1,-1)}`:e.charAt(0).toUpperCase()+e.slice(1))).join("")}_${r}`;return{apiName:s.charAt(0).toLowerCase()+s.slice(1),fileName:(n.slice(1).replace(/\//g,"-").replace("api-","")+"-"+r).toLowerCase(),typeName:s.charAt(0).toUpperCase()+s.slice(1),path:n.replace(/(\/api)|(api)/g,"").replace(/\{\w+\}/g,(e=>`$${e}`))}}parseData(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];t&&this.parsePathItemObject(t,e)}e(this.Map)}catch(e){this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),t(e)}}))}async writeFile(){const n=[],r=[],s=this.config.saveTypeFolderPath,a=[],i=(n,i)=>new Promise(((o,p)=>{try{const{payload:c,response:h,fileName:l,summary:y,typeName:u}=i,[,d]=n.split("|");!a.includes(d)&&a.push(d);const m=[`declare namespace ${u} {`,...c.path,...c.query,...c.body,`${t}${h}`,"}"];y&&r.push(["/**","\n",` * ${y}`,"\n"," */"].join(""));const f=this.apiRequestItemHandle(i);r.push(f,"\n"),e.writeFileRecursive(`${s}/connectors/${l}.d.ts`,m.join("\n")).then((()=>o(1))).catch((e=>{this.handleError({type:"FILE_WRITE",message:"Failed to write type definition file",path:l,details:e}),p(e)}))}catch(e){this.handleError({type:"PATH",message:"Failed to process path item",path:n,details:e}),p(e)}}));for(const[e,t]of this.Map)n.push(i(e,t));try{await Promise.all(n),r.unshift(`import { ${a.join(", ")} } from '${this.config.requestMethodsImportPath||"./api"}';`,"\n"),await e.clearDir(this.config.saveApiListFolderPath+"/index.ts"),await e.writeFileRecursive(this.config.saveApiListFolderPath+"/index.ts",r.join("\n")),this.Map=new Map,this.errors.length>0&&e.log.warning(`Completed with ${this.errors.length} errors`)}catch(e){throw this.handleError({type:"FILE_WRITE",message:"Failed to write API list file",details:e}),e}}async handle(){try{await this.parseData(),await this.writeFile(),e.log.success("Path parse & write done!")}catch(e){if(this.handleError({type:"SCHEMA",message:"Failed to handle schema",details:e}),this.config.errorHandling?.throwOnError)throw e}}}exports.PathParse=s,exports.default=s;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const t="\t";var r;!function(e){e.GET="get",e.PUT="put",e.POST="post",e.DELETE="delete",e.OPTIONS="options",e.HEAD="head",e.PATCH="patch",e.TRACE="trace"}(r||(r={}));const n={typeMapping:new Map([["integer","number"],["string","string"],["boolean","boolean"],["binary","File"]]),errorHandling:{throwOnError:!1,logErrors:!0}},s="#/components/schemas/",a="#/components/parameters/",i="#/definitions/";class o{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",requestPath:"",summary:"",apiName:"",typeName:"",deprecated:!1};Map=new Map;config;errors=[];referenceCache=new Map;parameters={};templates={exportConst:e=>`export const ${e}`,typeDefinition:(e,t)=>`type ${e} = ${t}`,interfaceDefinition:e=>`interface ${e}`};constructor(e,t,r){this.pathsObject=e,this.parameters=t??{},this.config={...n,...r,typeMapping:new Map([...n.typeMapping||[],...r.typeMapping||[]])}}handleError(t){if(this.errors.push(t),this.config.errorHandling?.logErrors&&e.log.error(`${t.type}: ${t.message}${t.path?` at ${t.path}`:""}`),this.config.errorHandling?.throwOnError)throw new Error(`${t.type}: ${t.message}`)}getIndentation(){return this.config.formatting?.indentation||t}typeNameToFileName(e){return e=(e=(e=e.replace(/_/g,"-")).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()).replace(/-+/g,"-")}handleComplexType(e){try{return e.oneOf?e.oneOf.map((e=>this.schemaParse(e))).join(" | "):e.allOf?e.allOf.map((e=>this.schemaParse(e))).join(" & "):e.anyOf?e.anyOf.map((e=>this.schemaParse(e))).join(" | "):e.enum?"number"===e.type||"integer"===e.type?e.enum.join(" | "):e.enum.map((e=>`'${e}'`)).join(" | "):"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to handle complex type",details:e}),"unknown"}}propertiesParse(e){if(!e)return[];const r=[];for(const n in e){const s=e[n],a=this.schemaParse(s);let i="";i=Array.isArray(a)?`${t}${t}${n}: {${a.join("\n")}};`:`${t}${t}${n}: ${a};`,r.push(i)}return r}nonArraySchemaObjectParse(e){if(!e)return"unknown";if("binary"===e.format||"string"===e.type&&"binary"===e.format)return"File";switch(e.type){case"boolean":return"boolean";case"integer":case"number":return"number";case"object":return this.propertiesParse(e.properties);case"string":return"binary"===e.format?"File":"string";default:return"unknown"}}arraySchemaObjectParse(e){if("array"!==e.type)return"";const{items:t}=e,r="$ref"in t?t:null,n=t;if(r){return`Array<${this.referenceObjectParse(r)}>`}if(n){const e=this.schemaParse(t);return Array.isArray(e)?`Array<{${e.join("\n")}}>`:`Array<${e}>`}return""}referenceObjectParse(e){try{const t=e.$ref,r=this.referenceCache.get(t);if(r)return r;let n=t;t.startsWith(s)&&(n=t.replace(s,"")),t.startsWith(a)&&(n=t.replace(a,"")),t.startsWith(i)&&(n=t.replace(i,""));const o=this.typeNameToFileName(n),p=/enum/gi.test(n)?`import('${this.config.importEnumPath}/${o}').${n}`:`import('../models/${o}').${n}`;return this.referenceCache.set(t,p),p}catch(e){return this.handleError({type:"REFERENCE",message:"Failed to parse reference object",details:e}),"unknown"}}schemaParse(e){try{if(!e)return"unknown";if("oneOf"in e||"allOf"in e||"anyOf"in e||"enum"in e)return this.handleComplexType(e);if("$ref"in e)return this.referenceObjectParse(e);const t=e,r=t.type,n=!0===t.nullable?" | null":"";if(e.format&&this.config.typeMapping?.has(e.format))return this.config.typeMapping.get(e.format)+n;if(r&&this.config.typeMapping?.has(r))return this.config.typeMapping.get(r)+n;if("array"===r&&t.items){const e=this.schemaParse(t.items);if(Array.isArray(e)){const t=this.config.formatting?.lineEnding,r=this.config.formatting?.indentation;return`Array<{${t}${e.join("\n")}${t}${r}${r}}>`}return`Array<${e}>`}if("object"===r){if(t.properties){const e=this.propertiesParse(t.properties);return e.length?e:["unknown"]}if(!0===t.additionalProperties)return"Record<string, unknown>"+n;if("object"==typeof t.additionalProperties){return`Record<string, ${this.schemaParse(t.additionalProperties)}>`+n}}return"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),"unknown"}}responseObjectParse(e){try{const t=e.content;if(!t)return"";const r=["application/json","text/json","text/plain","application/octet-stream","*/*"];let n;for(const e of r)if(t[e]?.schema){n=t[e].schema;break}return n?this.schemaParse(n):""}catch(e){return this.handleError({type:"RESPONSE",message:"Failed to parse response object",details:e}),""}}responseHandle(e){const t=e[200];if(!t)return;const r="content"in t?t:null,n="$ref"in t?t:null;if(null===r&&null===n&&(this.contentBody.response="type Response = unknown",this.contentBody._response="unknown"),n){const e=this.referenceObjectParse(n);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(r){const e=this.responseObjectParse(r);if(Array.isArray(e)){if(1===e.length&&"unknown"===e[0])this.contentBody.response=`type Response = ${e.join("\n")};`;else{const t=this.config.formatting?.lineEnding,r=this.config.formatting?.indentation;this.contentBody.response=`interface Response {${t}${e.join("\n")}${t}${r}};`}this.contentBody._response=`${e.join("\n")}`}else this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`}}requestBodyObjectParse(e){const r=Object.values(e.content),{schema:n}=r[0]||{schema:null};if(n){const e=n?.type,r="$ref"in n?n:null,s="array"===e?n:null,a=e&&this.nonArrayType.includes(e)?n:null;if(r){const e=this.referenceObjectParse(r);return`${t}type Body = ${e}`}if(s){const e=this.arraySchemaObjectParse(s);return`${t}type Body = ${e}`}if(a){const e=this.nonArraySchemaObjectParse(a);return Array.isArray(e)?0===e.length?[`${t}type Body = ${a.type};`]:[`${t}interface Body {`,...e.map((e=>e.replace(/: string;/,": File;"))),"}"]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return"{}";const r="$ref"in e?e:null,n="content"in e?e:null;if(r){const e=this.referenceObjectParse(r);return`${t}type Body = ${e}`}return n&&"[object Object]"===String(e)&&0!==Reflect.ownKeys(e).length?this.requestBodyObjectParse(n):"{}"}parametersItemHandle(e,r,n){const s="$ref"in e?e:null,i="name"in e?e:null;if(s&&s.$ref&&s.$ref.startsWith(a)&&this.parameters){const e=s.$ref.replace(a,""),t=this.parameters[e];this.parametersItemHandle(t,r,n)}if(i){if("path"===i.in){const e=this.schemaParse(i.schema);r.push(`${t}${t}type ${i.name} = ${e};`),this.contentBody.payload._path?"string"==typeof e?this.contentBody.payload._path[i.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._path={[i.name]:e}:console.log("Unexpected v2value type:",e)}if("query"===i.in){const e=this.schemaParse(i.schema);n.push(`${t}${t}${i.name}: ${e};`),this.contentBody.payload._query?"string"==typeof e?this.contentBody.payload._query[i.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._query={[i.name]:e}:console.log("Unexpected v2value type:",e)}}}requestParametersParse(e){const r=[],n=[];e?.map((e=>this.parametersItemHandle(e,r,n))),0!==r.length&&(r.unshift(`${t}namespace Path {`),r.push(`${t}}`)),0!==n.length&&(n.unshift(`${t}interface Query {`),n.push(`${t}}`)),this.contentBody.payload.path=r,this.contentBody.payload.query=n}requestHandle(e){if(e.parameters&&this.requestParametersParse(e.parameters),e.requestBody){const t=this.requestBodyParse(e.requestBody);if(Array.isArray(t))this.contentBody.payload.body=t;else if(t){const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}apiRequestItemHandle(e){const{payload:t,requestPath:r,_response:n,method:s,typeName:a,apiName:i}=e,{_path:o,_query:p,body:c}=t,h=c.some((e=>e.includes("File:")||e.includes(": File"))),l=e=>{const t=[];for(const r in e)t.push(`${r}: ${a}.Path.${r}`);return t.length>1?t.join(","):t.join("")},y=o?l(o):"",d=p?`params: ${a}.Query`:"",m=c.length>0?`params: ${a}.Body`:"",u={};y&&(u.apiParamsPath=y),d&&(u.apiParamsQuery=d),m&&(u.apiParamsBody=m);const f=Object.keys(u).length>=2,$=h?`,${this.config.dataLevel}`:"",g=h?", { headers: { 'Content-Type': 'multipart/form-data' } }":"";return[`export const ${i} = `,"(",o?l(o):"",""+(f?",":""),p?`params: ${a}.Query`:"",c.length>0?`params: ${a}.Body`:"",")"," => ",`${s}${n?`<${a}.Response>`:""}`,"(`"+r+"`"+(d||m?", params":"")+$+g+");"].join("")}parsePathItemObject(e,t){if(e)for(const r in e){const n=e[r];if(n){const e=r.toUpperCase(),s=t+"|"+e,{apiName:a,typeName:i,fileName:o,path:p}=this.convertEndpointString(s);this.contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:o,method:e,typeName:i,requestPath:p,apiName:a,summary:n.summary,deprecated:n.deprecated??!1},this.requestHandle(n),this.responseHandle(n.responses),this.Map.has(s)||this.Map.set(s,JSON.parse(JSON.stringify(this.contentBody)))}}}convertEndpointString(e){let t=e;e.startsWith("/")||(t="/"+e);const[r,n]=t.split("|"),s=`${r.replace("/api/","").split("/").map((e=>e.includes("{")?`$${e.slice(1,-1)}`:e.charAt(0).toUpperCase()+e.slice(1))).join("")}_${n}`;return{apiName:s.charAt(0).toLowerCase()+s.slice(1),fileName:(r.slice(1).replace(/\//g,"-").replace("api-","")+"-"+n).toLowerCase(),typeName:s.charAt(0).toUpperCase()+s.slice(1),path:r.replace(/(\/api)|(api)/g,"").replace(/\{\w+\}/g,(e=>`$${e}`))}}parseData(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];t&&this.parsePathItemObject(t,e)}e(this.Map)}catch(e){this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),t(e)}}))}async writeFile(){const r=[],n=[],s=this.config.saveTypeFolderPath,a=[],i=(r,i)=>new Promise(((o,p)=>{try{const{payload:c,response:h,fileName:l,summary:y,typeName:d,deprecated:m}=i,[,u]=r.split("|");!a.includes(u)&&a.push(u);const f=[`declare namespace ${d} {`,...c.path,...c.query,...c.body,`${t}${h}`,"}"];y&&n.push(["/**","\n",m?` * @deprecated ${y}`:` * ${y}`,"\n"," */"].join(""));const $=this.apiRequestItemHandle(i);n.push($,"\n"),e.writeFileRecursive(`${s}/connectors/${l}.d.ts`,f.join("\n")).then((()=>o(1))).catch((e=>{this.handleError({type:"FILE_WRITE",message:"Failed to write type definition file",path:l,details:e}),p(e)}))}catch(e){this.handleError({type:"PATH",message:"Failed to process path item",path:r,details:e}),p(e)}}));for(const[e,t]of this.Map)r.push(i(e,t));try{await Promise.all(r),n.unshift(`import { ${a.join(", ")} } from '${this.config.requestMethodsImportPath||"./api"}';`,"\n"),await e.clearDir(this.config.saveApiListFolderPath+"/index.ts"),await e.writeFileRecursive(this.config.saveApiListFolderPath+"/index.ts",n.join("\n")),this.Map=new Map,this.errors.length>0&&e.log.warning(`Completed with ${this.errors.length} errors`)}catch(e){throw this.handleError({type:"FILE_WRITE",message:"Failed to write API list file",details:e}),e}}async handle(){try{await this.parseData(),await this.writeFile(),e.log.success("Path parse & write done!")}catch(e){if(this.handleError({type:"SCHEMA",message:"Failed to handle schema",details:e}),this.config.errorHandling?.throwOnError)throw e}}}exports.PathParse=o,exports.default=o;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("../utils/index.js"),s=require("./core/components.js"),r=require("./core/get-data.js"),a=require("./core/path.js"),o=require("shelljs"),n=require("chalk"),i=require("path");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(e),p=c(n),d=c(i);let u;const h={saveTypeFolderPath:"development"===process.env.NODE_ENV?"apps/types":"src/api/types",saveApiListFolderPath:"development"===process.env.NODE_ENV?"apps/types":"src/api",saveEnumFolderPath:"development"===process.env.NODE_ENV?"apps/types/enums":"src/enums",importEnumPath:"../../../enums",requestMethodsImportPath:"./fetch",dataLevel:"serve",swaggerJsonUrl:"www.example.swagger.json.url",headers:{},formatting:{indentation:"\t",lineEnding:"\n"}};class f{schemas={};paths={};async handle(e){try{let t;if(t="development"===process.env.NODE_ENV?(await Promise.resolve().then((function(){return require("../../data/consolego.openapi.3.0.json.js")}))).default:await r.getSwaggerJson(e),!t)throw new Error("无法获取 Swagger 数据");this.schemas=t.components?.schemas||{},this.paths=t.paths||{};const o=new s.default(this.schemas,e),n=new a.PathParse(this.paths,e);return await Promise.all([o.handle(),n.handle()]),!0}catch(e){if(e instanceof Error)throw new Error(`处理 Swagger 数据失败: ${e.message}`);throw new Error("处理 Swagger 数据失败: 未知错误")}}async formatGeneratedFiles(e){const s=`npx prettier --write "${e.saveTypeFolderPath}/**/*.{ts,d.ts}"`;try{await l.default.promises.access(e.saveTypeFolderPath);const{stderr:r}=await new Promise(((e,t)=>{o.exec(s,((s,r,a)=>{s?t(s):e({stdout:r,stderr:a})}))}));if(r)throw new Error(r);t.log.success("文件格式化成功")}catch(e){console.log(""),t.log.error("格式化失败,请手动执行以下命令:"),console.log("$",p.default.yellow(s)),console.log("")}}async copyAjaxConfigFiles(e){try{const s=["config.ts","error-message.ts","fetch.ts"],r=d.default.join(__dirname,"..","..","ajax-config"),a=e;for(const e of s){const s=d.default.join(r,e),o=d.default.join(a,e);try{await l.default.promises.access(s);try{await l.default.promises.access(o),t.log.info(`${e} 已存在,跳过生成.`)}catch{await l.default.promises.copyFile(s,o),t.log.success(`${e} create done.`)}}catch(e){t.log.error(`源文件 ${s} 不存在`);continue}}}catch(e){return e}}async initialize(){const e=process.cwd()+"/an.config.json";try{const s=await this.getConfig(e);if(!u)return;await l.default.promises.mkdir(s.saveApiListFolderPath,{recursive:!0}),await this.copyAjaxConfigFiles(s.saveApiListFolderPath),await t.clearDir(s.saveTypeFolderPath),await t.clearDir(s.saveEnumFolderPath),await this.handle(s),await this.formatGeneratedFiles(s)}catch(e){const s=e instanceof Error?e.message:"未知错误";t.log.error(`初始化失败: ${s}`)}}async getConfig(e){try{const t=await l.default.promises.readFile(e,"utf8");return u=!0,JSON.parse(t)}catch(s){return u=!1,t.log.warning("配置文件不存在,将自动创建配置文件。"),await t.writeFileRecursive(e,JSON.stringify(h,null,2)),t.log.success("请查看项目根目录下的 an.config.json 文件"),h}}}if("development"===process.env.NODE_ENV){(new f).initialize()}exports.Main=f;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("../utils/index.js"),s=require("./core/components.js"),a=require("./core/get-data.js"),r=require("./core/path.js"),o=require("shelljs"),i=require("chalk"),n=require("path");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(e),p=c(i),u=c(n);let h;const d="development"===process.env.NODE_ENV,f={saveTypeFolderPath:d?"apps/types":"src/api/types",saveApiListFolderPath:d?"apps/types":"src/api",saveEnumFolderPath:d?"apps/types/enums":"src/enums",importEnumPath:"../../../enums",requestMethodsImportPath:"./fetch",dataLevel:"serve",swaggerJsonUrl:"www.example.swagger.json.url",headers:{},formatting:{indentation:"\t",lineEnding:"\n"}};class w{schemas={};paths={};async handle(e){try{let t;if(t="development"===process.env.NODE_ENV?(await Promise.resolve().then((function(){return require("../../data/open-api.json.js")}))).default:await a.getSwaggerJson(e),!t)throw new Error("无法获取 Swagger 数据");this.schemas=t.components?.schemas||{},this.paths=t.paths||{};const o=new s.default(this.schemas,e),i=new r.PathParse(this.paths,t.components?.parameters,e);return await Promise.all([o.handle(),i.handle()]),!0}catch(e){if(e instanceof Error)throw new Error(`处理 Swagger 数据失败: ${e.message}`);throw new Error("处理 Swagger 数据失败: 未知错误")}}async formatGeneratedFiles(e){const s=`npx prettier --write "${e.saveTypeFolderPath}/**/*.{ts,d.ts}"`;try{await l.default.promises.access(e.saveTypeFolderPath);const{stderr:a}=await new Promise(((e,t)=>{o.exec(s,((s,a,r)=>{s?t(s):e({stdout:a,stderr:r})}))}));if(a)throw new Error(a);t.log.success("文件格式化成功")}catch(e){console.log(""),t.log.error("格式化失败,请手动执行以下命令:"),console.log("$",p.default.yellow(s)),console.log("")}}async copyAjaxConfigFiles(e){try{const s=["config.ts","error-message.ts","fetch.ts"],a=u.default.join(__dirname,"..","..","ajax-config"),r=e;for(const e of s){const s=u.default.join(a,e),o=u.default.join(r,e);try{await l.default.promises.access(s);try{await l.default.promises.access(o),t.log.info(`${e} 已存在,跳过生成.`)}catch{await l.default.promises.copyFile(s,o),t.log.success(`${e} create done.`)}}catch(e){t.log.error(`源文件 ${s} 不存在`);continue}}}catch(e){return e}}async initialize(){const e=process.cwd()+"/an.config.json";try{const s=await this.getConfig(e);if(!h)return;await l.default.promises.mkdir(s.saveApiListFolderPath,{recursive:!0}),await this.copyAjaxConfigFiles(s.saveApiListFolderPath),await t.clearDir(s.saveTypeFolderPath),await t.clearDir(s.saveEnumFolderPath),await this.handle(s),await this.formatGeneratedFiles(s)}catch(e){const s=e instanceof Error?e.message:"未知错误";t.log.error(`初始化失败: ${s}`)}}async getConfig(e){try{const t=await l.default.promises.readFile(e,"utf8");return h=!0,JSON.parse(t)}catch(s){return h=!1,t.log.warning("配置文件不存在,将自动创建配置文件。"),await t.writeFileRecursive(e,JSON.stringify(f,null,2)),t.log.success("请查看项目根目录下的 an.config.json 文件"),f}}}if("development"===process.env.NODE_ENV){(new w).initialize()}exports.Main=w;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anl",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "FE command line tool",
5
5
  "main": "bin/an-cli.js",
6
6
  "scripts": {
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={title:"consolego",description:"",version:"1.0.0"},t="3.0.0",i=[{url:"",description:"默认环境",variables:{}},{url:"127.0.0.1:18080",description:"孟可localKeyScrt",variables:{url:{default:"127.0.0.1:18080",description:""}}},{url:"127.0.0.1:18081",description:"孟可localModelRPC",variables:{url:{default:"127.0.0.1:18081",description:""}}},{url:"10.4.156.14:38001",description:"测试modelRPC156.14",variables:{url:{default:"10.4.156.14:38001",description:""}}},{url:"127.0.0.1:18180",description:"孟可localconsolegoRPC",variables:{url:{default:"127.0.0.1:18180",description:""}}},{url:"127.0.0.1:8888",description:"胡正阳本地http测试环境",variables:{}},{url:"10.4.156.14:8004",description:"测试环境keyscrtRpc",variables:{url:{default:"10.4.156.14:8004",description:""}}},{url:"127.0.0.1:20033",description:"孟可localconsolegohttp",variables:{"{{url}}":{default:"127.0.0.1:20033",description:""}}},{url:"10.4.156.14:8007",description:"孟可testconsolegohttp",variables:{url:{default:"10.4.156.14:8007",description:""}}}],p={schemas:{AttachmentDeleteResp:{type:"object",title:"AttachmentDeleteResp",required:["id","type","deleted"],properties:{id:{type:"string"},type:{type:"string"},deleted:{type:"boolean",format:"boolean"}}},AttachmentListRequest:{type:"object",title:"AttachmentListRequest",required:["page_num","page_size"],properties:{user_id:{type:"string"},org_id:{type:"string"},purpose:{type:"string"},page_num:{type:"integer",format:"int32",default:"1"},page_size:{type:"integer",format:"int32",default:"10"}}},AttachmentListResp:{type:"object",title:"AttachmentListResp",required:["total","data"],properties:{total:{type:"integer",format:"int64"},data:{type:"array",items:{ref:"be1dd9176003c",type:"object",properties:{id:{type:"string"},type:{type:"string"},bytes:{type:"integer",format:"int64"},purpose:{type:"string"},filename:{type:"string"}}}}}},AttachmentResp:{type:"object",title:"AttachmentResp",required:["id","type","bytes","filename","purpose"],properties:{id:{type:"string"},type:{type:"string"},bytes:{type:"integer",format:"int64"},filename:{type:"string"},purpose:{type:"string"}}},AttachmentRetriveContentResp:{type:"object",title:"AttachmentRetriveContentResp"},AttachmentRetriveRequest:{type:"object",title:"AttachmentRetriveRequest"},AttachmentUploadRequest:{type:"object",title:"AttachmentUploadRequest",properties:{purpose:{type:"string"},user_id:{type:"string"}}}}},s={"/account/email":{get:{summary:"给email发送验证码",description:"",tags:["开放平台consolego/用户相关"],parameters:[{name:"email",in:"query",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:""}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:"{}"}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/account/update":{put:{summary:"修改用户信息",description:"",tags:["开放平台consolego/用户相关/需要登录"],parameters:[{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:'{\n "name":"xiaoming2"\n}'}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:"{}"}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/login":{post:{summary:"登录",description:"",tags:["开放平台consolego/用户相关","开放平台consolego/附件文件"],parameters:[],requestBody:{content:{"application/json":{schema:{type:"object"},example:'{\n "email":"michael_u@163.com",\n "code":"91200095"\n}'}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:'{"jwt":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiOTU4Y2UyM2ItOTU0Yy00M2ExLWIyMjMtNmVhNjAxODMwZGI0IiwiZXhwIjoxNzE5NTU1MTI1fQ.Aa9cHKuVZKiaF6JlrBxpuf9DK0_Ifu6uSxg4vAOeMxI"}'}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/userinfo":{get:{summary:"获取用户信息",description:"",tags:["开放平台consolego/用户相关/需要登录"],parameters:[{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object",properties:{}}}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:'{"id":"958ce23b-954c-43a1-b223-6ea601830db4","email":"michael_u@163.com","name":"xiaoming2","avatar":"","orgs":""}'}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/files":{get:{summary:"获取文件列表",description:"",tags:["开放平台consolego/附件文件/attach"],parameters:[{name:"user_id",in:"query",description:"",required:!1,example:"",schema:{type:"string"}},{name:"org_id",in:"query",description:"",required:!1,example:"",schema:{type:"string"}},{name:"purpose",in:"query",description:"",required:!1,example:"",schema:{type:"string"}},{name:"page_num",in:"query",description:"",required:!0,example:"",schema:{type:"integer"}},{name:"page_size",in:"query",description:"",required:!0,example:"",schema:{type:"integer"}},{name:"Content-Type",in:"header",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"multipart/form-data":{schema:{type:"object",properties:{},required:[]}}}},responses:{200:{description:"A successful response.",content:{"application/json":{schema:{type:"object",properties:{data:{type:"array",items:{ref:"be1dd9176003c",type:"object",properties:{id:{type:"string"},type:{type:"string"},bytes:{type:"integer",format:"int64"},purpose:{type:"string"},filename:{type:"string"}}}},total:{type:"integer",format:"int64"}}},example:'{\n\t"total": 0,\n\t"data": [\n\t\t{\n\t\t\t"id": "",\n\t\t\t"type": "",\n\t\t\t"bytes": 0,\n\t\t\t"filename": "",\n\t\t\t"purpose": ""\n\t\t}\n\t]\n}'}}}}},post:{summary:"上传文件",description:"",tags:["开放平台consolego/附件文件/attach"],parameters:[{name:"purpose",in:"query",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Content-Type",in:"header",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"multipart/form-data":{schema:{type:"object",properties:{file:{type:"file",example:"/lyndon/iData/kernel-math-py/Dockerfile",description:""},purpose:{type:"string",example:"test321",description:""}},required:["file","purpose"]}}}},responses:{200:{description:"A successful response.",content:{"application/json":{schema:{type:"object",properties:{id:{type:"string"},type:{type:"string"},bytes:{type:"integer",format:"int64"},purpose:{type:"string"},filename:{type:"string"}}},example:'{\n\t"id": "",\n\t"type": "",\n\t"bytes": 0,\n\t"filename": "",\n\t"purpose": ""\n}'}}}}}},"/files/{file_id}":{get:{summary:"获取文件",description:"",tags:["开放平台consolego/附件文件/attach"],parameters:[{name:"Content-Type",in:"header",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:""}}},responses:{200:{description:"A successful response.",content:{"application/json":{schema:{type:"object",properties:{id:{type:"string"},type:{type:"string"},bytes:{type:"integer",format:"int64"},purpose:{type:"string"},filename:{type:"string"}}},example:'{\n\t"id": "",\n\t"type": "",\n\t"bytes": 0,\n\t"filename": "",\n\t"purpose": ""\n}'}}}}},delete:{summary:"删除文件",description:"",tags:["开放平台consolego/附件文件/attach"],parameters:[{name:"Content-Type",in:"header",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object",properties:{}},example:"{}"}}},responses:{200:{description:"A successful response.",content:{"application/json":{schema:{type:"object",properties:{id:{type:"string"},type:{type:"string"},deleted:{type:"boolean",format:"boolean"}}},example:'{\n\t"id": "",\n\t"type": "",\n\t"deleted": ""\n}'}}}}}},"/files/{file_id}/content":{get:{summary:"获取文件内容",description:"",tags:["开放平台consolego/附件文件/attach"],parameters:[{name:"Content-Type",in:"header",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:""}}},responses:{200:{description:"A successful response.",content:{"application/json":{schema:{type:"object",properties:{}},example:"{}"}}}}}},"/keyscrt/list":{get:{summary:"获取keyscrt列表",description:"",tags:["开放平台consolego/secretkey管理"],parameters:[{name:"sort",in:"query",description:"",required:!0,example:"",schema:{type:"string"}},{name:"page",in:"query",description:"",required:!0,example:"",schema:{type:"string"}},{name:"size",in:"query",description:"",required:!0,example:"",schema:{type:"string"}},{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object",properties:{}}}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/keyscrt/add":{post:{summary:"新增keyscrt",description:"",tags:["开放平台consolego/secretkey管理"],parameters:[{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:'{\n "name":"fdesfdsa"\n}'}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}},"/keyscrt/del":{delete:{summary:"删除keyscrt",description:"",tags:["开放平台consolego/secretkey管理"],parameters:[{name:"Authorization",in:"header",description:"",required:!0,example:"",schema:{type:"string"}}],requestBody:{content:{"application/json":{schema:{type:"object"},example:'{\n "id":"dcef3606-6f41-445b-bc40-a41b0e92aa91"\n}'}}},responses:{200:{description:"成功",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}},404:{description:"失败",content:{"application/json":{schema:{type:"object",properties:{}},example:""}}}}}}},n=[{name:"开放平台consolego",description:""},{name:"用户相关",description:""},{name:"需要登录",description:""},{name:"secretkey管理",description:""},{name:"附件文件",description:""},{name:"attach",description:""},{name:"RPC",description:""}],r={info:e,openapi:t,servers:i,components:p,paths:s,tags:n};exports.components=p,exports.default=r,exports.info=e,exports.openapi=t,exports.paths=s,exports.servers=i,exports.tags=n;