@databases/shared-print-types
Advanced tools
Comparing version 1.1.0-canary-1685 to 1.1.0-canary-1688
@@ -15,2 +15,3 @@ import PrintOptions from './PrintOptions'; | ||
private readonly _files; | ||
private readonly _rawFiles; | ||
readonly options: PrintOptions<TypeID>; | ||
@@ -22,2 +23,3 @@ constructor(options: PrintOptions<TypeID>); | ||
pushValueDeclaration(id: TypeID, declaration: (identifier: IdentifierName, imp: FileContext) => string[]): FileExport; | ||
writeFile(filename: FileName, content: string): void; | ||
getFiles(): { | ||
@@ -24,0 +26,0 @@ filename: FileName; |
@@ -148,2 +148,3 @@ "use strict"; | ||
this._files = new Map(); | ||
this._rawFiles = new Map(); | ||
this.options = options; | ||
@@ -167,7 +168,19 @@ } | ||
} | ||
writeFile(filename, content) { | ||
if (this._rawFiles.has(filename)) { | ||
throw new Error(`Cannot write the same file multiple times: ${filename}`); | ||
} | ||
this._rawFiles.set(filename, content); | ||
} | ||
getFiles() { | ||
return [...this._files.values()].map((file) => ({ | ||
filename: file.file, | ||
content: file.getContent(), | ||
})); | ||
return [ | ||
...[...this._files.values()].map((file) => ({ | ||
filename: file.file, | ||
content: file.getContent(), | ||
})), | ||
...[...this._rawFiles].map(([filename, content]) => ({ | ||
filename, | ||
content, | ||
})), | ||
]; | ||
} | ||
@@ -174,0 +187,0 @@ } |
@@ -25,32 +25,48 @@ "use strict"; | ||
const filename = (0, path_1.join)(directory, f.filename); | ||
const content = f.content.trim(); | ||
const checksum = `Checksum: ${(0, crypto_1.createHash)('sha512') | ||
.update(content) | ||
.digest('base64')}`; | ||
try { | ||
const existingSource = await fs_1.promises.readFile(filename, 'utf8'); | ||
if (existingSource.includes(checksum)) { | ||
return; | ||
if (filename.endsWith(`.ts`)) { | ||
const content = f.content.trim(); | ||
const checksum = `Checksum: ${(0, crypto_1.createHash)('sha512') | ||
.update(content) | ||
.digest('base64')}`; | ||
try { | ||
const existingSource = await fs_1.promises.readFile(filename, 'utf8'); | ||
if (existingSource.includes(checksum)) { | ||
return; | ||
} | ||
} | ||
catch (ex) { | ||
if (ex.code !== 'ENOENT') { | ||
throw ex; | ||
} | ||
} | ||
console.info(`Updating: ${f.filename}`); | ||
await fs_1.promises.writeFile(filename, [ | ||
`/**`, | ||
` * !!! This file is autogenerated do not edit by hand !!!`, | ||
` *`, | ||
` * ${generatedStatement}`, | ||
` * ${checksum}`, | ||
' */', | ||
'', | ||
`/* eslint-disable */`, | ||
`// tslint:disable`, | ||
``, | ||
content, | ||
'', | ||
].join('\n')); | ||
} | ||
catch (ex) { | ||
if (ex.code !== 'ENOENT') { | ||
throw ex; | ||
else { | ||
try { | ||
const existingSource = await fs_1.promises.readFile(filename, 'utf8'); | ||
if (existingSource === f.content) { | ||
return; | ||
} | ||
} | ||
catch (ex) { | ||
if (ex.code !== 'ENOENT') { | ||
throw ex; | ||
} | ||
} | ||
await fs_1.promises.writeFile(filename, f.content); | ||
} | ||
console.info(`Updating: ${f.filename}`); | ||
await fs_1.promises.writeFile(filename, [ | ||
`/**`, | ||
` * !!! This file is autogenerated do not edit by hand !!!`, | ||
` *`, | ||
` * ${generatedStatement}`, | ||
` * ${checksum}`, | ||
' */', | ||
'', | ||
`/* eslint-disable */`, | ||
`// tslint:disable`, | ||
``, | ||
content, | ||
'', | ||
].join('\n')); | ||
})); | ||
@@ -57,0 +73,0 @@ } |
{ | ||
"name": "@databases/shared-print-types", | ||
"version": "1.1.0-canary-1685", | ||
"version": "1.1.0-canary-1688", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72034
410