wsdl-to-ts
Advanced tools
Comparing version 0.1.0 to 0.1.1
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const wsdl_to_ts_1 = require("./wsdl-to-ts"); | ||
const mkdirp = require("mkdirp"); | ||
const fs_1 = require("fs"); | ||
const minimist = require("minimist"); | ||
const config = { outdir: "./wsdl", files: [] }; | ||
const mkdirp = require("mkdirp"); | ||
const wsdl_to_ts_1 = require("./wsdl-to-ts"); | ||
const config = { outdir: "./wsdl", files: [], tslintDisable: ["max-line-length"], tslintEnable: [] }; | ||
const args = minimist(process.argv.slice(2)); | ||
if (args.help) { | ||
// TODO | ||
} | ||
@@ -18,2 +19,16 @@ if (args.version) { | ||
} | ||
if (args.hasOwnProperty("tslint")) { | ||
if (args.tslint === "true") { | ||
config.tslintEnable = null; | ||
} | ||
else if (args.tslint === "false" || args.tslint === "disable") { | ||
config.tslintDisable = null; | ||
} | ||
else { | ||
config.tslintEnable = args.tslint ? args.tslint.split(",") : null; | ||
} | ||
} | ||
if (args.hasOwnProperty("tslint-disable")) { | ||
config.tslintDisable = args["tslint-disable"] ? args["tslint-disable"].split(",") : null; | ||
} | ||
if (args._) { | ||
@@ -51,3 +66,18 @@ config.files.push.apply(config.files, args._); | ||
const tsfile = file + ".ts.tmp"; | ||
fs_1.writeFile(tsfile, x.data.join("\n\n"), (err) => { | ||
const fileData = []; | ||
if (config.tslintEnable === null) { | ||
fileData.push("/* tslint:enable */"); | ||
} | ||
if (config.tslintDisable === null) { | ||
fileData.push("/* tslint:disable */"); | ||
} | ||
else if (config.tslintDisable.length !== 0) { | ||
fileData.push("/* tslint:disable:" + config.tslintDisable.join(" ") + " */"); | ||
} | ||
if (config.tslintEnable && config.tslintEnable.length !== 0) { | ||
fileData.push("/* tslint:enable:" + config.tslintEnable.join(" ") + " */"); | ||
} | ||
fileData.push(x.data.join("\n\n")); | ||
fileData.push(""); | ||
fs_1.writeFile(tsfile, fileData.join("\n"), (err) => { | ||
if (err) { | ||
@@ -54,0 +84,0 @@ reject(err); |
@@ -11,10 +11,15 @@ "use strict"; | ||
} | ||
const isArray = k.endsWith("[]"); | ||
const k2 = isArray ? k.substring(0, k.length - 2) : k; | ||
const v = obj[k]; | ||
const t = typeof v; | ||
if (t === "string") { | ||
const [typeName, superTypeClass, typeData] = v.split("|"); | ||
const typeFullName = obj["targetNamespace"] ? obj["targetNamespace"] + "#" + typeName : typeName; | ||
let typeClass = superTypeClass; | ||
const vstr = v; | ||
const [typeName, superTypeClass, typeData] = vstr.indexOf("|") === -1 ? [vstr, vstr, undefined] : vstr.split("|"); | ||
const typeFullName = obj.targetNamespace ? obj.targetNamespace + "#" + typeName : typeName; | ||
let typeClass = superTypeClass === "integer" ? "number" : superTypeClass; | ||
if (exports.nsEnums[typeFullName] || typeData) { | ||
const filter = exports.nsEnums[typeFullName] ? () => true : (x) => x !== "length" && x !== "pattern" && x !== "maxLength" && x !== "minLength"; | ||
const filter = exports.nsEnums[typeFullName] ? | ||
() => true : | ||
(x) => x !== "length" && x !== "pattern" && x !== "maxLength" && x !== "minLength"; | ||
const tdsplit = typeData.split(",").filter(filter); | ||
@@ -25,9 +30,28 @@ if (tdsplit.length) { | ||
} | ||
r[k] = "/** " + typeFullName + "(" + typeData + ") */ " + typeClass + ";"; | ||
if (isArray) { | ||
typeClass = "Array<" + typeClass + ">"; | ||
} | ||
r[k2] = "/** " + typeFullName + "(" + typeData + ") */ " + typeClass + ";"; | ||
} | ||
else { | ||
r[k] = wsdlTypeToInterfaceObj(obj[k]); | ||
const to = wsdlTypeToInterfaceObj(v); | ||
let tr; | ||
if (isArray) { | ||
let s = wsdlTypeToInterfaceString(to).replace(/\n/g, "\n "); | ||
if (s.startsWith("/**")) { | ||
const i = s.indexOf("*/") + 2; | ||
s = s.substring(0, i) + " Array<" + s.substring(i).trim().replace(/;$/, "") + ">;"; | ||
} | ||
else { | ||
s = "Array<" + s.trim().replace(/;$/, "") + ">;"; | ||
} | ||
tr = s; | ||
} | ||
else { | ||
tr = to; | ||
} | ||
r[k2] = tr; | ||
} | ||
} | ||
//console.log("wsdlTypeToInterfaceObj:", r); | ||
// console.log("wsdlTypeToInterfaceObj:", r); | ||
return r; | ||
@@ -51,3 +75,3 @@ } | ||
else { | ||
r.push(k + ": " + wsdlTypeToInterfaceString(d[k]).replace(/\n/g, "\n\t") + ";"); | ||
r.push(k + ": " + wsdlTypeToInterfaceString(d[k]).replace(/\n/g, "\n ") + ";"); | ||
} | ||
@@ -58,3 +82,3 @@ } | ||
} | ||
return "{\n\t" + r.join("\n\t") + "\n}"; | ||
return "{\n " + r.join("\n ") + "\n}"; | ||
} | ||
@@ -84,3 +108,3 @@ function wsdlTypeToInterface(obj) { | ||
for (const port of Object.keys(d[service])) { | ||
//console.log("-- %s.%s", service, port); | ||
// console.log("-- %s.%s", service, port); | ||
if (!r.types[service]) { | ||
@@ -97,3 +121,3 @@ r.types[service] = {}; | ||
for (const method of Object.keys(d[service][port])) { | ||
//console.log("---- %s", method); | ||
// console.log("---- %s", method); | ||
r.types[service][port]["I" + method + "Input"] = | ||
@@ -105,3 +129,3 @@ wsdlTypeToInterface(d[service][port][method].input || {}); | ||
"(input: I" + method + "Input, " + | ||
"(err: any | null," + | ||
"cb: (err: any | null," + | ||
" result: I" + method + "Output," + | ||
@@ -141,3 +165,3 @@ " raw: string, " + | ||
methods: cloneObj(a.methods), | ||
types: cloneObj(a.types) | ||
types: cloneObj(a.types), | ||
}; | ||
@@ -190,3 +214,3 @@ for (const b of bs) { | ||
if (ms.length) { | ||
d.data.push("export interface I" + port + "Soap {\n\t" + ms.join("\n\t") + "\n}"); | ||
d.data.push("export interface I" + port + "Soap {\n " + ms.join("\n ") + "\n}"); | ||
} | ||
@@ -193,0 +217,0 @@ } |
{ | ||
"name": "wsdl-to-ts", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Build TypeScript typings for SOAP WSDL", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
#!/usr/bin/env node | ||
import { wsdl2ts, mergeTypedWsdl, outputTypedWsdl, ITypedWsdl } from "./wsdl-to-ts"; | ||
import { rename, writeFile } from "fs"; | ||
import * as minimist from "minimist"; | ||
import * as mkdirp from "mkdirp"; | ||
import { writeFile, rename } from "fs"; | ||
import * as minimist from "minimist"; | ||
import { ITypedWsdl, mergeTypedWsdl, outputTypedWsdl, wsdl2ts } from "./wsdl-to-ts"; | ||
interface ConfigObject { | ||
interface IConfigObject { | ||
outdir: string; | ||
files: string[]; | ||
tslintDisable: null | string[]; | ||
tslintEnable: null | string[]; | ||
} | ||
const config: ConfigObject = { outdir: "./wsdl", files: [] }; | ||
const config: IConfigObject = { outdir: "./wsdl", files: [], tslintDisable: ["max-line-length"], tslintEnable: [] }; | ||
@@ -18,3 +20,3 @@ const args = minimist(process.argv.slice(2)); | ||
if (args.help) { | ||
// TODO | ||
} | ||
@@ -29,2 +31,16 @@ | ||
if (args.hasOwnProperty("tslint")) { | ||
if (args.tslint === "true") { | ||
config.tslintEnable = null; | ||
} else if (args.tslint === "false" || args.tslint === "disable") { | ||
config.tslintDisable = null; | ||
} else { | ||
config.tslintEnable = args.tslint ? args.tslint.split(",") : null; | ||
} | ||
} | ||
if (args.hasOwnProperty("tslint-disable")) { | ||
config.tslintDisable = args["tslint-disable"] ? args["tslint-disable"].split(",") : null; | ||
} | ||
if (args._) { | ||
@@ -64,3 +80,17 @@ config.files.push.apply(config.files, args._); | ||
const tsfile = file + ".ts.tmp"; | ||
writeFile(tsfile, x.data.join("\n\n"), (err) => { | ||
const fileData: string[] = []; | ||
if (config.tslintEnable === null) { | ||
fileData.push("/* tslint:enable */"); | ||
} | ||
if (config.tslintDisable === null) { | ||
fileData.push("/* tslint:disable */"); | ||
} else if (config.tslintDisable.length !== 0) { | ||
fileData.push("/* tslint:disable:" + config.tslintDisable.join(" ") + " */"); | ||
} | ||
if (config.tslintEnable && config.tslintEnable.length !== 0) { | ||
fileData.push("/* tslint:enable:" + config.tslintEnable.join(" ") + " */"); | ||
} | ||
fileData.push(x.data.join("\n\n")); | ||
fileData.push(""); | ||
writeFile(tsfile, fileData.join("\n"), (err) => { | ||
if (err) { | ||
@@ -67,0 +97,0 @@ reject(err); |
import * as soap from "soap"; | ||
export const nsEnums: { [k: string]: boolean } = {}; | ||
//nsEnums["https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/ssii/fact/ws/SuministroInformacion.xsd#VersionSiiType"] = true; | ||
//nsEnums["https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/ssii/fact/ws/SuministroInformacion.xsd#ClaveTipoComunicacionType"] = true; | ||
@@ -16,6 +14,6 @@ interface ITwoDown<T> { | ||
export interface ITypedWsdl { | ||
client: soap.Client | null, | ||
files: ITwoDown<string>, | ||
methods: ITwoDown<{ [k: string]: string }>, | ||
types: ITwoDown<{ [k: string]: string }>, | ||
client: soap.Client | null; | ||
files: ITwoDown<string>; | ||
methods: ITwoDown<{ [k: string]: string }>; | ||
types: ITwoDown<{ [k: string]: string }>; | ||
} | ||
@@ -29,10 +27,16 @@ | ||
} | ||
const isArray = k.endsWith("[]"); | ||
const k2 = isArray ? k.substring(0, k.length - 2) : k; | ||
const v = obj[k]; | ||
const t = typeof v; | ||
if (t === "string") { | ||
const [typeName, superTypeClass, typeData] = (v as string).split("|"); | ||
const typeFullName = obj["targetNamespace"] ? obj["targetNamespace"] + "#" + typeName : typeName; | ||
let typeClass = superTypeClass; | ||
const vstr = v as string; | ||
const [typeName, superTypeClass, typeData] = | ||
vstr.indexOf("|") === -1 ? [vstr, vstr, undefined] : vstr.split("|"); | ||
const typeFullName = obj.targetNamespace ? obj.targetNamespace + "#" + typeName : typeName; | ||
let typeClass = superTypeClass === "integer" ? "number" : superTypeClass; | ||
if (nsEnums[typeFullName] || typeData) { | ||
const filter = nsEnums[typeFullName] ? () => true : (x: string) => x !== "length" && x !== "pattern" && x !== "maxLength" && x !== "minLength"; | ||
const filter = nsEnums[typeFullName] ? | ||
() => true : | ||
(x: string) => x !== "length" && x !== "pattern" && x !== "maxLength" && x !== "minLength"; | ||
const tdsplit = typeData.split(",").filter(filter); | ||
@@ -43,8 +47,27 @@ if (tdsplit.length) { | ||
} | ||
r[k] = "/** " + typeFullName + "(" + typeData + ") */ " + typeClass + ";"; | ||
if (isArray) { | ||
typeClass = "Array<" + typeClass + ">"; | ||
} | ||
r[k2] = "/** " + typeFullName + "(" + typeData + ") */ " + typeClass + ";"; | ||
} else { | ||
r[k] = wsdlTypeToInterfaceObj(obj[k] as IInterfaceObject); | ||
const to = wsdlTypeToInterfaceObj(v as IInterfaceObject); | ||
let tr: { [k: string]: any } | string; | ||
if (isArray) { | ||
let s = wsdlTypeToInterfaceString(to).replace(/\n/g, "\n "); | ||
if (s.startsWith("/**")) { | ||
const i = s.indexOf("*/") + 2; | ||
s = s.substring(0, i) + " Array<" + s.substring(i).trim().replace(/;$/, "") + ">;"; | ||
} else { | ||
s = "Array<" + s.trim().replace(/;$/, "") + ">;"; | ||
} | ||
tr = s; | ||
} else { | ||
tr = to; | ||
} | ||
r[k2] = tr; | ||
} | ||
} | ||
//console.log("wsdlTypeToInterfaceObj:", r); | ||
// console.log("wsdlTypeToInterfaceObj:", r); | ||
return r; | ||
@@ -67,3 +90,3 @@ } | ||
} else { | ||
r.push(k + ": " + wsdlTypeToInterfaceString(d[k]).replace(/\n/g, "\n\t") + ";"); | ||
r.push(k + ": " + wsdlTypeToInterfaceString(d[k]).replace(/\n/g, "\n ") + ";"); | ||
} | ||
@@ -74,3 +97,3 @@ } | ||
} | ||
return "{\n\t" + r.join("\n\t") + "\n}"; | ||
return "{\n " + r.join("\n ") + "\n}"; | ||
} | ||
@@ -102,3 +125,3 @@ | ||
for (const port of Object.keys(d[service])) { | ||
//console.log("-- %s.%s", service, port); | ||
// console.log("-- %s.%s", service, port); | ||
if (!r.types[service]) { | ||
@@ -115,3 +138,3 @@ r.types[service] = {}; | ||
for (const method of Object.keys(d[service][port])) { | ||
//console.log("---- %s", method); | ||
// console.log("---- %s", method); | ||
r.types[service][port]["I" + method + "Input"] = | ||
@@ -123,3 +146,3 @@ wsdlTypeToInterface(d[service][port][method].input || {}); | ||
"(input: I" + method + "Input, " + | ||
"(err: any | null," + | ||
"cb: (err: any | null," + | ||
" result: I" + method + "Output," + | ||
@@ -159,3 +182,3 @@ " raw: string, " + | ||
methods: cloneObj(a.methods), | ||
types: cloneObj(a.types) | ||
types: cloneObj(a.types), | ||
}; | ||
@@ -206,3 +229,3 @@ for (const b of bs) { | ||
if (ms.length) { | ||
d.data.push("export interface I" + port + "Soap {\n\t" + ms.join("\n\t") + "\n}"); | ||
d.data.push("export interface I" + port + "Soap {\n " + ms.join("\n ") + "\n}"); | ||
} | ||
@@ -209,0 +232,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41536
12
694