feat(includeFiles): support {from, to} object form for custom serve paths
includeFiles now accepts string | {from, to} entries. The object form
allows specifying a custom serve path (e.g. ./html/index.html -> index.html)
for base64ts bundled content.
This commit is contained in:
@@ -17,13 +17,15 @@ export interface IEnvTransportOptions {
|
|||||||
export type TOutputMode = 'bundle' | 'base64ts';
|
export type TOutputMode = 'bundle' | 'base64ts';
|
||||||
export type TBundler = 'esbuild' | 'rolldown' | 'rspack';
|
export type TBundler = 'esbuild' | 'rolldown' | 'rspack';
|
||||||
|
|
||||||
|
export type TIncludeFile = string | { from: string; to: string };
|
||||||
|
|
||||||
export interface IBundleConfig {
|
export interface IBundleConfig {
|
||||||
from: string;
|
from: string;
|
||||||
to: string;
|
to: string;
|
||||||
outputMode?: TOutputMode;
|
outputMode?: TOutputMode;
|
||||||
bundler?: TBundler;
|
bundler?: TBundler;
|
||||||
production?: boolean;
|
production?: boolean;
|
||||||
includeFiles?: string[];
|
includeFiles?: TIncludeFile[];
|
||||||
maxLineLength?: number; // For base64ts output: max chars per line. 0 or undefined = unlimited (default)
|
maxLineLength?: number; // For base64ts output: max chars per line. 0 or undefined = unlimited (default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,12 @@ export class CustomBundleHandler {
|
|||||||
|
|
||||||
// Add included files
|
// Add included files
|
||||||
if (bundleConfig.includeFiles && bundleConfig.includeFiles.length > 0) {
|
if (bundleConfig.includeFiles && bundleConfig.includeFiles.length > 0) {
|
||||||
for (const pattern of bundleConfig.includeFiles) {
|
for (const entry of bundleConfig.includeFiles) {
|
||||||
await base64Output.addFilesFromGlob(pattern);
|
if (typeof entry === 'string') {
|
||||||
|
await base64Output.addFilesFromGlob(entry);
|
||||||
|
} else {
|
||||||
|
await base64Output.addFileWithServePath(entry.from, entry.to);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +139,8 @@ export class CustomBundleHandler {
|
|||||||
const htmlHandler = new HtmlHandler();
|
const htmlHandler = new HtmlHandler();
|
||||||
const outputDir = plugins.path.dirname(toPath);
|
const outputDir = plugins.path.dirname(toPath);
|
||||||
|
|
||||||
for (const pattern of bundleConfig.includeFiles) {
|
for (const entry of bundleConfig.includeFiles) {
|
||||||
|
const pattern = typeof entry === 'string' ? entry : entry.from;
|
||||||
await this.copyIncludedFiles(pattern, outputDir);
|
await this.copyIncludedFiles(pattern, outputDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ export class InitHandler {
|
|||||||
console.log(` Mode: ${bundle.outputMode || 'bundle'}`);
|
console.log(` Mode: ${bundle.outputMode || 'bundle'}`);
|
||||||
console.log(` Bundler: ${bundle.bundler || 'esbuild'}`);
|
console.log(` Bundler: ${bundle.bundler || 'esbuild'}`);
|
||||||
if (bundle.includeFiles && bundle.includeFiles.length > 0) {
|
if (bundle.includeFiles && bundle.includeFiles.length > 0) {
|
||||||
console.log(` Include: ${bundle.includeFiles.join(', ')}`);
|
const display = bundle.includeFiles.map(f => typeof f === 'string' ? f : `${f.from} -> ${f.to}`);
|
||||||
|
console.log(` Include: ${display.join(', ')}`);
|
||||||
}
|
}
|
||||||
console.log('');
|
console.log('');
|
||||||
});
|
});
|
||||||
@@ -168,7 +169,8 @@ export class InitHandler {
|
|||||||
console.log(` Mode: ${preset.config.outputMode}`);
|
console.log(` Mode: ${preset.config.outputMode}`);
|
||||||
console.log(` Bundler: ${preset.config.bundler}`);
|
console.log(` Bundler: ${preset.config.bundler}`);
|
||||||
if (preset.config.includeFiles && preset.config.includeFiles.length > 0) {
|
if (preset.config.includeFiles && preset.config.includeFiles.length > 0) {
|
||||||
console.log(` Include: ${preset.config.includeFiles.join(', ')}`);
|
const display = preset.config.includeFiles.map(f => typeof f === 'string' ? f : `${f.from} -> ${f.to}`);
|
||||||
|
console.log(` Include: ${display.join(', ')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirmInteract = new plugins.smartinteract.SmartInteract();
|
const confirmInteract = new plugins.smartinteract.SmartInteract();
|
||||||
@@ -293,14 +295,14 @@ export class InitHandler {
|
|||||||
/**
|
/**
|
||||||
* Configure files to include
|
* Configure files to include
|
||||||
*/
|
*/
|
||||||
private async configureIncludeFiles(prefill?: string[]): Promise<string[]> {
|
private async configureIncludeFiles(prefill?: interfaces.TIncludeFile[]): Promise<interfaces.TIncludeFile[]> {
|
||||||
const includeFiles: string[] = [];
|
const includeFiles: interfaces.TIncludeFile[] = [];
|
||||||
let addMore = true;
|
let addMore = true;
|
||||||
|
|
||||||
// If we have prefilled values, show them first
|
// If we have prefilled values, show them first
|
||||||
if (prefill && prefill.length > 0) {
|
if (prefill && prefill.length > 0) {
|
||||||
console.log('\nPre-configured include patterns:');
|
console.log('\nPre-configured include patterns:');
|
||||||
prefill.forEach((p) => console.log(` - ${p}`));
|
prefill.forEach((p) => console.log(` - ${typeof p === 'string' ? p : `${p.from} -> ${p.to}`}`));
|
||||||
|
|
||||||
const keepInteract = new plugins.smartinteract.SmartInteract();
|
const keepInteract = new plugins.smartinteract.SmartInteract();
|
||||||
keepInteract.addQuestions([
|
keepInteract.addQuestions([
|
||||||
|
|||||||
@@ -22,6 +22,20 @@ export class Base64TsOutput {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a file with a custom serve path
|
||||||
|
*/
|
||||||
|
public async addFileWithServePath(fromPath: string, servePath: string): Promise<void> {
|
||||||
|
const absolutePath = plugins.smartpath.transform.toAbsolute(fromPath, this.cwd) as string;
|
||||||
|
const fileExists = await plugins.fs.file(absolutePath).exists();
|
||||||
|
if (!fileExists) {
|
||||||
|
console.log(`File does not exist: ${absolutePath}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const content = await plugins.fs.file(absolutePath).read();
|
||||||
|
this.addFile(servePath, content);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add files matching a glob pattern
|
* Add files matching a glob pattern
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user