@git.zone/tsbundle 2.6.2 ā 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/interfaces/index.d.ts +17 -0
- package/dist_ts/mod_custom/index.d.ts +33 -0
- package/dist_ts/mod_custom/index.js +167 -0
- package/dist_ts/mod_custom/plugins.d.ts +1 -0
- package/dist_ts/mod_custom/plugins.js +2 -0
- package/dist_ts/mod_init/index.d.ts +33 -0
- package/dist_ts/mod_init/index.js +336 -0
- package/dist_ts/mod_init/plugins.d.ts +3 -0
- package/dist_ts/mod_init/plugins.js +4 -0
- package/dist_ts/mod_output/index.d.ts +30 -0
- package/dist_ts/mod_output/index.js +103 -0
- package/dist_ts/mod_output/plugins.d.ts +1 -0
- package/dist_ts/mod_output/plugins.js +2 -0
- package/dist_ts/plugins.d.ts +3 -1
- package/dist_ts/plugins.js +4 -2
- package/dist_ts/tsbundle.cli.js +11 -41
- package/npmextra.json +11 -5
- package/package.json +12 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/interfaces/index.ts +22 -0
- package/ts/mod_custom/index.ts +203 -0
- package/ts/mod_custom/plugins.ts +1 -0
- package/ts/mod_init/index.ts +377 -0
- package/ts/mod_init/plugins.ts +5 -0
- package/ts/mod_output/index.ts +113 -0
- package/ts/mod_output/plugins.ts +1 -0
- package/ts/plugins.ts +4 -0
- package/ts/tsbundle.cli.ts +11 -58
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as paths from '../paths.js';
|
|
3
|
+
import * as interfaces from '../interfaces/index.js';
|
|
4
|
+
|
|
5
|
+
// Preset configurations
|
|
6
|
+
const PRESETS: Record<string, { description: string; config: interfaces.IBundleConfig }> = {
|
|
7
|
+
element: {
|
|
8
|
+
description: 'Web component / element bundle',
|
|
9
|
+
config: {
|
|
10
|
+
from: './ts_web/index.ts',
|
|
11
|
+
to: './dist_bundle/bundle.js',
|
|
12
|
+
outputMode: 'bundle',
|
|
13
|
+
bundler: 'esbuild',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
website: {
|
|
17
|
+
description: 'Full website with HTML and assets',
|
|
18
|
+
config: {
|
|
19
|
+
from: './ts_web/index.ts',
|
|
20
|
+
to: './dist_serve/bundle.js',
|
|
21
|
+
outputMode: 'bundle',
|
|
22
|
+
bundler: 'esbuild',
|
|
23
|
+
includeFiles: ['./html/**/*.html', './assets/**/*'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
npm: {
|
|
27
|
+
description: 'NPM package bundle (from ts/)',
|
|
28
|
+
config: {
|
|
29
|
+
from: './ts/index.ts',
|
|
30
|
+
to: './dist_bundle/bundle.js',
|
|
31
|
+
outputMode: 'bundle',
|
|
32
|
+
bundler: 'esbuild',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export class InitHandler {
|
|
38
|
+
private cwd: string;
|
|
39
|
+
private npmextraPath: string;
|
|
40
|
+
|
|
41
|
+
constructor(cwd: string = paths.cwd) {
|
|
42
|
+
this.cwd = cwd;
|
|
43
|
+
this.npmextraPath = plugins.path.join(this.cwd, 'npmextra.json');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Load existing npmextra.json or create empty config
|
|
48
|
+
*/
|
|
49
|
+
private async loadExistingConfig(): Promise<any> {
|
|
50
|
+
const fileExists = await plugins.fs.file(this.npmextraPath).exists();
|
|
51
|
+
if (fileExists) {
|
|
52
|
+
const content = (await plugins.fs.file(this.npmextraPath).encoding('utf8').read()) as string;
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(content);
|
|
55
|
+
} catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Save config to npmextra.json
|
|
64
|
+
*/
|
|
65
|
+
private async saveConfig(config: any): Promise<void> {
|
|
66
|
+
const content = JSON.stringify(config, null, 2);
|
|
67
|
+
await plugins.fs.file(this.npmextraPath).encoding('utf8').write(content);
|
|
68
|
+
console.log(`\nā
Configuration saved to npmextra.json`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Run the interactive init wizard
|
|
73
|
+
*/
|
|
74
|
+
public async runWizard(): Promise<void> {
|
|
75
|
+
console.log('\nš tsbundle configuration wizard\n');
|
|
76
|
+
console.log('This wizard will help you configure bundle settings in npmextra.json.\n');
|
|
77
|
+
|
|
78
|
+
const npmextraJson = await this.loadExistingConfig();
|
|
79
|
+
|
|
80
|
+
if (!npmextraJson['@git.zone/tsbundle']) {
|
|
81
|
+
npmextraJson['@git.zone/tsbundle'] = { bundles: [] };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const existingBundles = npmextraJson['@git.zone/tsbundle'].bundles || [];
|
|
85
|
+
|
|
86
|
+
if (existingBundles.length > 0) {
|
|
87
|
+
console.log(`Found ${existingBundles.length} existing bundle configuration(s):\n`);
|
|
88
|
+
existingBundles.forEach((bundle: interfaces.IBundleConfig, i: number) => {
|
|
89
|
+
console.log(` ${i + 1}. ${bundle.from} ā ${bundle.to} (${bundle.outputMode || 'bundle'})`);
|
|
90
|
+
});
|
|
91
|
+
console.log('');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let addMore = true;
|
|
95
|
+
while (addMore) {
|
|
96
|
+
const bundle = await this.configureSingleBundle();
|
|
97
|
+
if (bundle) {
|
|
98
|
+
npmextraJson['@git.zone/tsbundle'].bundles.push(bundle);
|
|
99
|
+
console.log(`\nā
Bundle configuration added!`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const continueInteract = new plugins.smartinteract.SmartInteract();
|
|
103
|
+
continueInteract.addQuestions([
|
|
104
|
+
{
|
|
105
|
+
type: 'confirm',
|
|
106
|
+
name: 'addAnother',
|
|
107
|
+
message: 'Would you like to add another bundle configuration?',
|
|
108
|
+
default: false,
|
|
109
|
+
},
|
|
110
|
+
]);
|
|
111
|
+
const answers = await continueInteract.runQueue();
|
|
112
|
+
addMore = answers.getAnswerFor('addAnother');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await this.saveConfig(npmextraJson);
|
|
116
|
+
|
|
117
|
+
console.log('\nš Final configuration:\n');
|
|
118
|
+
const bundles = npmextraJson['@git.zone/tsbundle'].bundles;
|
|
119
|
+
bundles.forEach((bundle: interfaces.IBundleConfig, i: number) => {
|
|
120
|
+
console.log(` Bundle ${i + 1}:`);
|
|
121
|
+
console.log(` From: ${bundle.from}`);
|
|
122
|
+
console.log(` To: ${bundle.to}`);
|
|
123
|
+
console.log(` Mode: ${bundle.outputMode || 'bundle'}`);
|
|
124
|
+
console.log(` Bundler: ${bundle.bundler || 'esbuild'}`);
|
|
125
|
+
if (bundle.includeFiles && bundle.includeFiles.length > 0) {
|
|
126
|
+
console.log(` Include: ${bundle.includeFiles.join(', ')}`);
|
|
127
|
+
}
|
|
128
|
+
console.log('');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
console.log('Run `tsbundle` to build your bundles.\n');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Configure a single bundle interactively
|
|
136
|
+
*/
|
|
137
|
+
private async configureSingleBundle(): Promise<interfaces.IBundleConfig | null> {
|
|
138
|
+
// First, ask for preset or custom
|
|
139
|
+
const presetInteract = new plugins.smartinteract.SmartInteract();
|
|
140
|
+
presetInteract.addQuestions([
|
|
141
|
+
{
|
|
142
|
+
type: 'list',
|
|
143
|
+
name: 'preset',
|
|
144
|
+
message: 'Choose a configuration:',
|
|
145
|
+
choices: [
|
|
146
|
+
{ name: 'element - Web component / element bundle', value: 'element' },
|
|
147
|
+
{ name: 'website - Full website with HTML and assets', value: 'website' },
|
|
148
|
+
{ name: 'npm - NPM package bundle (from ts/)', value: 'npm' },
|
|
149
|
+
{ name: 'custom - Configure manually', value: 'custom' },
|
|
150
|
+
],
|
|
151
|
+
default: 'element',
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
const presetAnswers = await presetInteract.runQueue();
|
|
156
|
+
const selectedPreset = presetAnswers.getAnswerFor('preset') as string;
|
|
157
|
+
|
|
158
|
+
// If custom, go to full manual configuration
|
|
159
|
+
if (selectedPreset === 'custom') {
|
|
160
|
+
return this.configureManualBundle();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Show preset config and ask if user wants to use it or customize
|
|
164
|
+
const preset = PRESETS[selectedPreset];
|
|
165
|
+
console.log(`\nš¦ ${preset.description}:`);
|
|
166
|
+
console.log(` From: ${preset.config.from}`);
|
|
167
|
+
console.log(` To: ${preset.config.to}`);
|
|
168
|
+
console.log(` Mode: ${preset.config.outputMode}`);
|
|
169
|
+
console.log(` Bundler: ${preset.config.bundler}`);
|
|
170
|
+
if (preset.config.includeFiles && preset.config.includeFiles.length > 0) {
|
|
171
|
+
console.log(` Include: ${preset.config.includeFiles.join(', ')}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const confirmInteract = new plugins.smartinteract.SmartInteract();
|
|
175
|
+
confirmInteract.addQuestions([
|
|
176
|
+
{
|
|
177
|
+
type: 'list',
|
|
178
|
+
name: 'action',
|
|
179
|
+
message: 'Use this configuration?',
|
|
180
|
+
choices: [
|
|
181
|
+
{ name: 'Yes, use as-is', value: 'use' },
|
|
182
|
+
{ name: 'Customize it', value: 'customize' },
|
|
183
|
+
],
|
|
184
|
+
default: 'use',
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
const confirmAnswers = await confirmInteract.runQueue();
|
|
189
|
+
const action = confirmAnswers.getAnswerFor('action') as string;
|
|
190
|
+
|
|
191
|
+
if (action === 'use') {
|
|
192
|
+
// Return the preset config directly
|
|
193
|
+
return { ...preset.config };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Customize: pre-fill with preset values
|
|
197
|
+
return this.configureManualBundle(preset.config);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Configure a bundle manually with optional pre-filled values
|
|
202
|
+
*/
|
|
203
|
+
private async configureManualBundle(
|
|
204
|
+
prefill?: Partial<interfaces.IBundleConfig>
|
|
205
|
+
): Promise<interfaces.IBundleConfig> {
|
|
206
|
+
const interact = new plugins.smartinteract.SmartInteract();
|
|
207
|
+
|
|
208
|
+
// Basic configuration questions
|
|
209
|
+
interact.addQuestions([
|
|
210
|
+
{
|
|
211
|
+
type: 'input',
|
|
212
|
+
name: 'from',
|
|
213
|
+
message: 'Entry point TypeScript file:',
|
|
214
|
+
default: prefill?.from || './ts_web/index.ts',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: 'input',
|
|
218
|
+
name: 'to',
|
|
219
|
+
message: 'Output file path:',
|
|
220
|
+
default: prefill?.to || './dist_bundle/bundle.js',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: 'list',
|
|
224
|
+
name: 'outputMode',
|
|
225
|
+
message: 'Output mode:',
|
|
226
|
+
choices: [
|
|
227
|
+
{ name: 'bundle - Standard JavaScript bundle file', value: 'bundle' },
|
|
228
|
+
{
|
|
229
|
+
name: 'base64ts - TypeScript file with base64-encoded content (for Deno compile)',
|
|
230
|
+
value: 'base64ts',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
default: prefill?.outputMode || 'bundle',
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
type: 'list',
|
|
237
|
+
name: 'bundler',
|
|
238
|
+
message: 'Bundler to use:',
|
|
239
|
+
choices: [
|
|
240
|
+
{ name: 'esbuild (fastest, recommended)', value: 'esbuild' },
|
|
241
|
+
{ name: 'rolldown (Rust-based, Rollup compatible)', value: 'rolldown' },
|
|
242
|
+
{ name: 'rspack (Webpack compatible)', value: 'rspack' },
|
|
243
|
+
],
|
|
244
|
+
default: prefill?.bundler || 'esbuild',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
type: 'confirm',
|
|
248
|
+
name: 'production',
|
|
249
|
+
message: 'Enable production mode (minification)?',
|
|
250
|
+
default: prefill?.production || false,
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
type: 'confirm',
|
|
254
|
+
name: 'hasIncludeFiles',
|
|
255
|
+
message: 'Include additional files (HTML, assets)?',
|
|
256
|
+
default: prefill?.includeFiles && prefill.includeFiles.length > 0 ? true : false,
|
|
257
|
+
},
|
|
258
|
+
]);
|
|
259
|
+
|
|
260
|
+
const answers = await interact.runQueue();
|
|
261
|
+
|
|
262
|
+
const bundle: interfaces.IBundleConfig = {
|
|
263
|
+
from: answers.getAnswerFor('from'),
|
|
264
|
+
to: answers.getAnswerFor('to'),
|
|
265
|
+
outputMode: answers.getAnswerFor('outputMode') as interfaces.TOutputMode,
|
|
266
|
+
bundler: answers.getAnswerFor('bundler') as interfaces.TBundler,
|
|
267
|
+
production: answers.getAnswerFor('production'),
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Update default output path based on mode
|
|
271
|
+
if (bundle.outputMode === 'base64ts' && bundle.to === './dist_bundle/bundle.js') {
|
|
272
|
+
const suggestInteract = new plugins.smartinteract.SmartInteract();
|
|
273
|
+
suggestInteract.addQuestions([
|
|
274
|
+
{
|
|
275
|
+
type: 'input',
|
|
276
|
+
name: 'to',
|
|
277
|
+
message: 'For base64ts mode, suggest a .ts output path:',
|
|
278
|
+
default: './ts/embedded-bundle.ts',
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
const suggestAnswers = await suggestInteract.runQueue();
|
|
282
|
+
bundle.to = suggestAnswers.getAnswerFor('to');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Handle include files
|
|
286
|
+
if (answers.getAnswerFor('hasIncludeFiles')) {
|
|
287
|
+
bundle.includeFiles = await this.configureIncludeFiles(prefill?.includeFiles);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return bundle;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Configure files to include
|
|
295
|
+
*/
|
|
296
|
+
private async configureIncludeFiles(prefill?: string[]): Promise<string[]> {
|
|
297
|
+
const includeFiles: string[] = [];
|
|
298
|
+
let addMore = true;
|
|
299
|
+
|
|
300
|
+
// If we have prefilled values, show them first
|
|
301
|
+
if (prefill && prefill.length > 0) {
|
|
302
|
+
console.log('\nPre-configured include patterns:');
|
|
303
|
+
prefill.forEach((p) => console.log(` - ${p}`));
|
|
304
|
+
|
|
305
|
+
const keepInteract = new plugins.smartinteract.SmartInteract();
|
|
306
|
+
keepInteract.addQuestions([
|
|
307
|
+
{
|
|
308
|
+
type: 'confirm',
|
|
309
|
+
name: 'keepPrefill',
|
|
310
|
+
message: 'Keep these patterns?',
|
|
311
|
+
default: true,
|
|
312
|
+
},
|
|
313
|
+
]);
|
|
314
|
+
const keepAnswers = await keepInteract.runQueue();
|
|
315
|
+
if (keepAnswers.getAnswerFor('keepPrefill')) {
|
|
316
|
+
includeFiles.push(...prefill);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
console.log('\nAdd files or glob patterns to include (e.g., ./html/index.html, ./assets/**/*):\n');
|
|
321
|
+
|
|
322
|
+
// Ask if user wants to add more patterns
|
|
323
|
+
const addInteract = new plugins.smartinteract.SmartInteract();
|
|
324
|
+
addInteract.addQuestions([
|
|
325
|
+
{
|
|
326
|
+
type: 'confirm',
|
|
327
|
+
name: 'addPatterns',
|
|
328
|
+
message: includeFiles.length > 0 ? 'Add more patterns?' : 'Add include patterns?',
|
|
329
|
+
default: includeFiles.length === 0,
|
|
330
|
+
},
|
|
331
|
+
]);
|
|
332
|
+
const addAnswers = await addInteract.runQueue();
|
|
333
|
+
addMore = addAnswers.getAnswerFor('addPatterns');
|
|
334
|
+
|
|
335
|
+
while (addMore) {
|
|
336
|
+
const fileInteract = new plugins.smartinteract.SmartInteract();
|
|
337
|
+
fileInteract.addQuestions([
|
|
338
|
+
{
|
|
339
|
+
type: 'input',
|
|
340
|
+
name: 'pattern',
|
|
341
|
+
message: 'File or glob pattern:',
|
|
342
|
+
default: includeFiles.length === 0 ? './html/index.html' : '',
|
|
343
|
+
},
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
const fileAnswers = await fileInteract.runQueue();
|
|
347
|
+
const pattern = fileAnswers.getAnswerFor('pattern');
|
|
348
|
+
|
|
349
|
+
if (pattern && pattern.trim()) {
|
|
350
|
+
includeFiles.push(pattern.trim());
|
|
351
|
+
console.log(` Added: ${pattern}`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const continueInteract = new plugins.smartinteract.SmartInteract();
|
|
355
|
+
continueInteract.addQuestions([
|
|
356
|
+
{
|
|
357
|
+
type: 'confirm',
|
|
358
|
+
name: 'addMore',
|
|
359
|
+
message: 'Add another file/pattern?',
|
|
360
|
+
default: false,
|
|
361
|
+
},
|
|
362
|
+
]);
|
|
363
|
+
const continueAnswers = await continueInteract.runQueue();
|
|
364
|
+
addMore = continueAnswers.getAnswerFor('addMore');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return includeFiles;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Run the init command
|
|
373
|
+
*/
|
|
374
|
+
export async function runInit(): Promise<void> {
|
|
375
|
+
const handler = new InitHandler();
|
|
376
|
+
await handler.runWizard();
|
|
377
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as paths from '../paths.js';
|
|
3
|
+
import * as interfaces from '../interfaces/index.js';
|
|
4
|
+
|
|
5
|
+
export class Base64TsOutput {
|
|
6
|
+
private files: interfaces.IBase64File[] = [];
|
|
7
|
+
private cwd: string;
|
|
8
|
+
|
|
9
|
+
constructor(cwd: string = paths.cwd) {
|
|
10
|
+
this.cwd = cwd;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Add a file with its content to the output
|
|
15
|
+
*/
|
|
16
|
+
public addFile(filePath: string, content: Buffer | string): void {
|
|
17
|
+
const contentBuffer = typeof content === 'string' ? Buffer.from(content, 'utf-8') : content;
|
|
18
|
+
const contentBase64 = contentBuffer.toString('base64');
|
|
19
|
+
this.files.push({
|
|
20
|
+
path: filePath,
|
|
21
|
+
contentBase64,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Add files matching a glob pattern
|
|
27
|
+
*/
|
|
28
|
+
public async addFilesFromGlob(pattern: string): Promise<void> {
|
|
29
|
+
const absolutePattern = plugins.smartpath.transform.toAbsolute(pattern, this.cwd) as string;
|
|
30
|
+
const patternDir = plugins.path.dirname(absolutePattern);
|
|
31
|
+
const patternBase = plugins.path.basename(absolutePattern);
|
|
32
|
+
|
|
33
|
+
// Check if it's a directory pattern or file pattern
|
|
34
|
+
const isGlobPattern = patternBase.includes('*');
|
|
35
|
+
|
|
36
|
+
if (isGlobPattern) {
|
|
37
|
+
// Handle glob patterns
|
|
38
|
+
const dirPath = patternDir.replace(/\/\*\*$/, '');
|
|
39
|
+
const dirExists = await plugins.fs.directory(dirPath).exists();
|
|
40
|
+
if (!dirExists) {
|
|
41
|
+
console.log(`Directory does not exist: ${dirPath}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isRecursive = pattern.includes('**');
|
|
46
|
+
let entries;
|
|
47
|
+
if (isRecursive) {
|
|
48
|
+
entries = await plugins.fs.directory(dirPath).recursive().list();
|
|
49
|
+
} else {
|
|
50
|
+
entries = await plugins.fs.directory(dirPath).list();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Filter by pattern if needed
|
|
54
|
+
const filePattern = patternBase.replace('*', '.*');
|
|
55
|
+
const regex = new RegExp(filePattern);
|
|
56
|
+
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
if (!entry.isDirectory && regex.test(entry.name)) {
|
|
59
|
+
const fullPath = plugins.path.join(dirPath, entry.path);
|
|
60
|
+
const relativePath = plugins.path.relative(this.cwd, fullPath);
|
|
61
|
+
const content = await plugins.fs.file(fullPath).read();
|
|
62
|
+
this.addFile(relativePath, content);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// Handle single file path
|
|
67
|
+
const fileExists = await plugins.fs.file(absolutePattern).exists();
|
|
68
|
+
if (!fileExists) {
|
|
69
|
+
console.log(`File does not exist: ${absolutePattern}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const relativePath = plugins.path.relative(this.cwd, absolutePattern);
|
|
73
|
+
const content = await plugins.fs.file(absolutePattern).read();
|
|
74
|
+
this.addFile(relativePath, content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate TypeScript file content
|
|
80
|
+
*/
|
|
81
|
+
public generateTypeScript(): string {
|
|
82
|
+
const filesJson = JSON.stringify(this.files, null, 2);
|
|
83
|
+
return `// Auto-generated by tsbundle - do not edit
|
|
84
|
+
export const files: { path: string; contentBase64: string }[] = ${filesJson};
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Write the TypeScript file to disk
|
|
90
|
+
*/
|
|
91
|
+
public async writeToFile(outputPath: string): Promise<void> {
|
|
92
|
+
const absolutePath = plugins.smartpath.transform.toAbsolute(outputPath, this.cwd) as string;
|
|
93
|
+
const outputDir = plugins.path.dirname(absolutePath);
|
|
94
|
+
await plugins.fs.directory(outputDir).create();
|
|
95
|
+
const content = this.generateTypeScript();
|
|
96
|
+
await plugins.fs.file(absolutePath).encoding('utf8').write(content);
|
|
97
|
+
console.log(`Generated base64ts output: ${outputPath}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get all collected files
|
|
102
|
+
*/
|
|
103
|
+
public getFiles(): interfaces.IBase64File[] {
|
|
104
|
+
return this.files;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Clear all collected files
|
|
109
|
+
*/
|
|
110
|
+
public clear(): void {
|
|
111
|
+
this.files = [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../plugins.js';
|
package/ts/plugins.ts
CHANGED
|
@@ -4,8 +4,10 @@ import * as path from 'path';
|
|
|
4
4
|
export { path };
|
|
5
5
|
|
|
6
6
|
// pushrocks scope
|
|
7
|
+
import * as npmextra from '@push.rocks/npmextra';
|
|
7
8
|
import * as smartcli from '@push.rocks/smartcli';
|
|
8
9
|
import * as smartfs from '@push.rocks/smartfs';
|
|
10
|
+
import * as smartinteract from '@push.rocks/smartinteract';
|
|
9
11
|
import * as smartlog from '@push.rocks/smartlog';
|
|
10
12
|
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
|
|
11
13
|
import * as smartpath from '@push.rocks/smartpath';
|
|
@@ -13,8 +15,10 @@ import * as smartpromise from '@push.rocks/smartpromise';
|
|
|
13
15
|
import * as smartspawn from '@push.rocks/smartspawn';
|
|
14
16
|
|
|
15
17
|
export {
|
|
18
|
+
npmextra,
|
|
16
19
|
smartcli,
|
|
17
20
|
smartfs,
|
|
21
|
+
smartinteract,
|
|
18
22
|
smartlog,
|
|
19
23
|
smartlogDestinationLocal,
|
|
20
24
|
smartpath,
|
package/ts/tsbundle.cli.ts
CHANGED
|
@@ -1,70 +1,23 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { logger } from './tsbundle.logging.js';
|
|
5
|
-
import { AssetsHandler } from './mod_assets/index.js';
|
|
2
|
+
import { runCustomBundles } from './mod_custom/index.js';
|
|
3
|
+
import { runInit } from './mod_init/index.js';
|
|
6
4
|
|
|
7
5
|
export const runCli = async () => {
|
|
8
6
|
const tsBundleCli = new plugins.smartcli.Smartcli();
|
|
9
|
-
tsBundleCli.standardCommand().subscribe(async (argvArg) => {
|
|
10
|
-
const tsbundle = new TsBundle();
|
|
11
|
-
await tsbundle.build(process.cwd(), argvArg.from, argvArg.to, argvArg);
|
|
12
|
-
return;
|
|
13
|
-
});
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
await
|
|
18
|
-
process.cwd(),
|
|
19
|
-
'./ts_web/index.ts',
|
|
20
|
-
'./dist_bundle/bundle.js',
|
|
21
|
-
argvArg,
|
|
22
|
-
);
|
|
8
|
+
// Default command: run custom bundles from npmextra.json
|
|
9
|
+
tsBundleCli.standardCommand().subscribe(async (argvArg) => {
|
|
10
|
+
await runCustomBundles();
|
|
23
11
|
});
|
|
24
12
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await tsbundle.build(
|
|
29
|
-
process.cwd(),
|
|
30
|
-
'./ts/index.ts',
|
|
31
|
-
'./dist_bundle/bundle.js',
|
|
32
|
-
argvArg,
|
|
33
|
-
);
|
|
13
|
+
// Explicit custom command (same as default)
|
|
14
|
+
tsBundleCli.addCommand('custom').subscribe(async (argvArg) => {
|
|
15
|
+
await runCustomBundles();
|
|
34
16
|
});
|
|
35
17
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// lets deal with the html
|
|
40
|
-
const htmlHandler = new HtmlHandler();
|
|
41
|
-
await tsbundle.build(
|
|
42
|
-
process.cwd(),
|
|
43
|
-
'./ts_web/index.ts',
|
|
44
|
-
'./dist_serve/bundle.js',
|
|
45
|
-
argvArg,
|
|
46
|
-
);
|
|
47
|
-
const htmlDirPath = plugins.path.join(process.cwd(), './html');
|
|
48
|
-
let htmlFiles: string[] = [];
|
|
49
|
-
const htmlDirExists = await plugins.fs.directory(htmlDirPath).exists();
|
|
50
|
-
if (htmlDirExists) {
|
|
51
|
-
const entries = await plugins.fs
|
|
52
|
-
.directory(htmlDirPath)
|
|
53
|
-
.filter(/\.html$/)
|
|
54
|
-
.list();
|
|
55
|
-
htmlFiles = entries.map((entry) => entry.path);
|
|
56
|
-
}
|
|
57
|
-
for (const htmlFile of htmlFiles) {
|
|
58
|
-
await htmlHandler.processHtml({
|
|
59
|
-
from: `./html/${htmlFile}`,
|
|
60
|
-
to: `./dist_serve/${htmlFile}`,
|
|
61
|
-
minify: true,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// lets deal with the assets
|
|
66
|
-
const assetsHandler = new AssetsHandler();
|
|
67
|
-
await assetsHandler.processAssets();
|
|
18
|
+
// Interactive init wizard
|
|
19
|
+
tsBundleCli.addCommand('init').subscribe(async (argvArg) => {
|
|
20
|
+
await runInit();
|
|
68
21
|
});
|
|
69
22
|
|
|
70
23
|
tsBundleCli.startParse();
|