feat(tsbundle): add configurable maxLineLength for base64ts output and improve build/error handling in child builds

This commit is contained in:
2026-01-12 01:41:08 +00:00
parent 54f84ba114
commit 8b6ae043a2
7 changed files with 108 additions and 53 deletions

View File

@@ -77,18 +77,26 @@ export class Base64TsOutput {
/**
* Generate TypeScript file content
* @param maxLineLength - Max chars per line for base64 strings. 0 or undefined = unlimited (default)
*/
public generateTypeScript(): string {
const MAX_LINE_LENGTH = 200;
public generateTypeScript(maxLineLength?: number): string {
// Default behavior: no line splitting (unlimited)
if (!maxLineLength || maxLineLength <= 0) {
const filesJson = JSON.stringify(this.files, null, 2);
return `// Auto-generated by tsbundle - do not edit
export const files: { path: string; contentBase64: string }[] = ${filesJson};
`;
}
// Split base64 strings into chunks when maxLineLength is specified
const formatBase64 = (base64: string): string => {
if (base64.length <= MAX_LINE_LENGTH) {
if (base64.length <= maxLineLength) {
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));
for (let i = 0; i < base64.length; i += maxLineLength) {
chunks.push(base64.slice(i, i + maxLineLength));
}
return `"" +\n "${chunks.join('" +\n "')}"`;
@@ -110,12 +118,14 @@ ${filesFormatted}
/**
* Write the TypeScript file to disk
* @param outputPath - Output file path
* @param maxLineLength - Max chars per line for base64 strings. 0 or undefined = unlimited (default)
*/
public async writeToFile(outputPath: string): Promise<void> {
public async writeToFile(outputPath: string, maxLineLength?: number): Promise<void> {
const absolutePath = plugins.smartpath.transform.toAbsolute(outputPath, this.cwd) as string;
const outputDir = plugins.path.dirname(absolutePath);
await plugins.fs.directory(outputDir).create();
const content = this.generateTypeScript();
const content = this.generateTypeScript(maxLineLength);
await plugins.fs.file(absolutePath).encoding('utf8').write(content);
console.log(`Generated base64ts output: ${outputPath}`);
}