fix(mod_output): wrap long base64 file contents and format generated TypeScript output to avoid extremely long lines
This commit is contained in:
@@ -79,9 +79,32 @@ export class Base64TsOutput {
|
||||
* Generate TypeScript file content
|
||||
*/
|
||||
public generateTypeScript(): string {
|
||||
const filesJson = JSON.stringify(this.files, null, 2);
|
||||
const MAX_LINE_LENGTH = 200;
|
||||
|
||||
const formatBase64 = (base64: string): string => {
|
||||
if (base64.length <= MAX_LINE_LENGTH) {
|
||||
return `"${base64}"`;
|
||||
}
|
||||
|
||||
const chunks: string[] = [];
|
||||
for (let i = 0; i < base64.length; i += MAX_LINE_LENGTH) {
|
||||
chunks.push(base64.slice(i, i + MAX_LINE_LENGTH));
|
||||
}
|
||||
|
||||
return `"" +\n "${chunks.join('" +\n "')}"`;
|
||||
};
|
||||
|
||||
const filesFormatted = this.files.map(file => {
|
||||
return ` {
|
||||
"path": "${file.path}",
|
||||
"contentBase64": ${formatBase64(file.contentBase64)}
|
||||
}`;
|
||||
}).join(',\n');
|
||||
|
||||
return `// Auto-generated by tsbundle - do not edit
|
||||
export const files: { path: string; contentBase64: string }[] = ${filesJson};
|
||||
export const files: { path: string; contentBase64: string }[] = [
|
||||
${filesFormatted}
|
||||
];
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user