io-ts-from-json-schema
Advanced tools
Comparing version 0.0.5 to 0.0.6-alpha1
@@ -39,2 +39,3 @@ #!/usr/bin/env node | ||
var path = require("path"); | ||
var crypto_1 = require("crypto"); | ||
var gen = require("io-ts-codegen"); | ||
@@ -49,2 +50,4 @@ var yargs = require("yargs"); | ||
.option('import', { type: 'string', array: true, default: [] }) | ||
.option('importHash', { type: 'string', default: 'sha256' }) | ||
.option('importHashLength', { type: 'number', default: 7 }) | ||
.help().argv; | ||
@@ -401,7 +404,14 @@ var imports = argv.import.map(function (imp) { return imp.split('^'); }); | ||
} | ||
function calculateImportName(filePath) { | ||
function importHash(str) { | ||
return crypto_1.default | ||
.createHash(argv.importHash) | ||
.update(str) | ||
.digest('hex') | ||
.slice(0, argv.importHashLength); | ||
} | ||
function calculateImportName(filePath, refString) { | ||
// eslint-disable-next-line | ||
var _a = __read(filePath.split("/").reverse(), 1), withoutPath = _a[0]; | ||
var _b = __read(withoutPath.split('.json'), 1), basefile = _b[0]; | ||
return typenameFromKebab(basefile) + "_"; | ||
return "" + typenameFromKebab(basefile) + importHash(refString) + "_"; | ||
} | ||
@@ -421,3 +431,3 @@ function fromRef(refString) { | ||
} | ||
var importName = calculateImportName(ref.filePath); | ||
var importName = calculateImportName(ref.filePath, refString); | ||
var importPath = calculateImportPath(ref.filePath); | ||
@@ -424,0 +434,0 @@ imps.add("import * as " + importName + " from '" + importPath + "';"); |
{ | ||
"name": "io-ts-from-json-schema", | ||
"version": "0.0.5", | ||
"version": "0.0.6-alpha1", | ||
"description": "Iotsfjs is a static code generation utility used for converting json schema files into static TypeScript types and io-ts runtime validators.", | ||
@@ -5,0 +5,0 @@ "main": "lib/cli.js", |
36155
866