@fluffjs/cli 0.1.2 → 0.1.4

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/Cli.d.ts CHANGED
@@ -26,6 +26,10 @@ export declare class Cli {
26
26
  private findFiles;
27
27
  private matchesPatterns;
28
28
  private matchGlob;
29
+ private copyAssets;
30
+ private copyAssetsForServe;
31
+ private copyDirectoryRecursive;
32
+ private copyDirectoryRecursiveSync;
29
33
  static parseArgs(argv: string[]): {
30
34
  options: CliOptions;
31
35
  args: string[];
package/Cli.js CHANGED
@@ -328,6 +328,9 @@ Examples:
328
328
  }
329
329
  }
330
330
  console.log(' Building with esbuild...');
331
+ const tsconfigRaw = target.tsConfigPath
332
+ ? fs.readFileSync(path.resolve(projectRoot, target.tsConfigPath), 'utf-8')
333
+ : '{}';
331
334
  const result = await esbuild.build({
332
335
  entryPoints: [entryPoint],
333
336
  bundle: true,
@@ -350,7 +353,7 @@ Examples:
350
353
  ],
351
354
  external: bundleOptions.external ?? [],
352
355
  logLevel: 'warning',
353
- tsconfigRaw: '{}'
356
+ tsconfigRaw
354
357
  });
355
358
  const outputs = Object.keys(result.metafile?.outputs ?? {});
356
359
  const jsBundle = outputs.find(f => f.endsWith('.js'));
@@ -400,34 +403,7 @@ Examples:
400
403
  }
401
404
  }
402
405
  if (target.assets) {
403
- const compiler = new ComponentCompiler();
404
- const assetFiles = this.findFiles(srcDir, target.assets);
405
- for (const filePath of assetFiles) {
406
- if (filePath.endsWith('.component.ts'))
407
- continue;
408
- if (filePath.endsWith('.component.html'))
409
- continue;
410
- if (filePath.endsWith('.component.css'))
411
- continue;
412
- if (target.indexHtml && filePath.endsWith(target.indexHtml))
413
- continue;
414
- const relativePath = path.relative(srcDir, filePath);
415
- const outPath = path.join(outDir, relativePath);
416
- const outFileDir = path.dirname(outPath);
417
- if (!fs.existsSync(outFileDir)) {
418
- fs.mkdirSync(outFileDir, { recursive: true });
419
- }
420
- if (filePath.endsWith('.ts')) {
421
- let content = fs.readFileSync(filePath, 'utf-8');
422
- content = await compiler.stripTypeScript(content, filePath);
423
- fs.writeFileSync(outPath.replace('.ts', '.js'), content);
424
- console.log(` ✓ Processed ${relativePath}`);
425
- }
426
- else {
427
- fs.copyFileSync(filePath, outPath);
428
- console.log(` ✓ Copied ${relativePath}`);
429
- }
430
- }
406
+ await this.copyAssets(target.assets, projectRoot, srcDir, outDir);
431
407
  }
432
408
  console.log(`✅ Target '${target.name}' built successfully!`);
433
409
  }
@@ -538,28 +514,12 @@ Examples:
538
514
  }
539
515
  }
540
516
  if (target.assets) {
541
- const assetFiles = this.findFiles(srcDir, target.assets);
542
- for (const filePath of assetFiles) {
543
- if (filePath.endsWith('.component.ts'))
544
- continue;
545
- if (filePath.endsWith('.component.html'))
546
- continue;
547
- if (filePath.endsWith('.component.css'))
548
- continue;
549
- if (target.indexHtml && filePath.endsWith(target.indexHtml))
550
- continue;
551
- if (filePath.endsWith('.ts'))
552
- continue;
553
- const relativePath = path.relative(srcDir, filePath);
554
- const outPath = path.join(outDir, relativePath);
555
- const outFileDir = path.dirname(outPath);
556
- if (!fs.existsSync(outFileDir)) {
557
- fs.mkdirSync(outFileDir, { recursive: true });
558
- }
559
- fs.copyFileSync(filePath, outPath);
560
- }
517
+ this.copyAssetsForServe(target.assets, projectRoot, srcDir, outDir);
561
518
  }
562
519
  console.log(`🚀 Starting dev server for '${target.name}'...`);
520
+ const tsconfigRaw = target.tsConfigPath
521
+ ? fs.readFileSync(path.resolve(projectRoot, target.tsConfigPath), 'utf-8')
522
+ : '{}';
563
523
  const ctx = await esbuild.context({
564
524
  entryPoints: [entryPoint],
565
525
  bundle: true,
@@ -580,7 +540,8 @@ Examples:
580
540
  production: false
581
541
  })
582
542
  ],
583
- logLevel: 'info'
543
+ logLevel: 'info',
544
+ tsconfigRaw
584
545
  });
585
546
  await ctx.watch();
586
547
  console.log(' Watching for changes...');
@@ -616,7 +577,7 @@ Examples:
616
577
  }
617
578
  else if (entry.isFile()) {
618
579
  const relativePath = path.relative(dir, fullPath);
619
- if (this.matchesPatterns(relativePath, patterns)) {
580
+ if (this.matchesPatterns(relativePath, patterns, dir)) {
620
581
  files.push(fullPath);
621
582
  }
622
583
  }
@@ -625,9 +586,17 @@ Examples:
625
586
  walk(dir);
626
587
  return files;
627
588
  }
628
- matchesPatterns(filePath, patterns) {
589
+ matchesPatterns(filePath, patterns, baseDir) {
629
590
  for (const pattern of patterns) {
630
- if (this.matchGlob(filePath, pattern)) {
591
+ const patternPath = path.join(baseDir, pattern);
592
+ if (fs.existsSync(patternPath) && fs.statSync(patternPath).isDirectory()) {
593
+ const normalizedFile = filePath.replace(/\\/g, '/');
594
+ const normalizedPattern = pattern.replace(/\\/g, '/');
595
+ if (normalizedFile.startsWith(normalizedPattern + '/') || normalizedFile === normalizedPattern) {
596
+ return true;
597
+ }
598
+ }
599
+ else if (this.matchGlob(filePath, pattern)) {
631
600
  return true;
632
601
  }
633
602
  }
@@ -638,6 +607,116 @@ Examples:
638
607
  const isMatch = picomatch(pattern, { dot: false });
639
608
  return isMatch(normalizedPath);
640
609
  }
610
+ async copyAssets(assets, projectRoot, srcDir, outDir) {
611
+ const compiler = new ComponentCompiler();
612
+ for (const asset of assets) {
613
+ const assetPath = path.resolve(srcDir, asset);
614
+ if (fs.existsSync(assetPath) && fs.statSync(assetPath).isDirectory()) {
615
+ const dirName = path.basename(assetPath);
616
+ const targetDir = path.join(outDir, dirName);
617
+ await this.copyDirectoryRecursive(assetPath, targetDir, compiler);
618
+ console.log(` ✓ Copied directory ${dirName}/`);
619
+ }
620
+ else {
621
+ const files = this.findFiles(srcDir, [asset]);
622
+ for (const filePath of files) {
623
+ if (filePath.endsWith('.component.ts'))
624
+ continue;
625
+ if (filePath.endsWith('.component.html'))
626
+ continue;
627
+ if (filePath.endsWith('.component.css'))
628
+ continue;
629
+ const relativePath = path.relative(srcDir, filePath);
630
+ const outPath = path.join(outDir, relativePath);
631
+ const outFileDir = path.dirname(outPath);
632
+ if (!fs.existsSync(outFileDir)) {
633
+ fs.mkdirSync(outFileDir, { recursive: true });
634
+ }
635
+ if (filePath.endsWith('.ts')) {
636
+ let content = fs.readFileSync(filePath, 'utf-8');
637
+ content = await compiler.stripTypeScript(content, filePath);
638
+ fs.writeFileSync(outPath.replace('.ts', '.js'), content);
639
+ console.log(` ✓ Processed ${relativePath}`);
640
+ }
641
+ else {
642
+ fs.copyFileSync(filePath, outPath);
643
+ console.log(` ✓ Copied ${relativePath}`);
644
+ }
645
+ }
646
+ }
647
+ }
648
+ }
649
+ copyAssetsForServe(assets, projectRoot, srcDir, outDir) {
650
+ for (const asset of assets) {
651
+ const assetPath = path.resolve(srcDir, asset);
652
+ if (fs.existsSync(assetPath) && fs.statSync(assetPath).isDirectory()) {
653
+ const dirName = path.basename(assetPath);
654
+ const targetDir = path.join(outDir, dirName);
655
+ this.copyDirectoryRecursiveSync(assetPath, targetDir);
656
+ }
657
+ else {
658
+ const files = this.findFiles(srcDir, [asset]);
659
+ for (const filePath of files) {
660
+ if (filePath.endsWith('.component.ts'))
661
+ continue;
662
+ if (filePath.endsWith('.component.html'))
663
+ continue;
664
+ if (filePath.endsWith('.component.css'))
665
+ continue;
666
+ if (filePath.endsWith('.ts'))
667
+ continue;
668
+ const relativePath = path.relative(srcDir, filePath);
669
+ const outPath = path.join(outDir, relativePath);
670
+ const outFileDir = path.dirname(outPath);
671
+ if (!fs.existsSync(outFileDir)) {
672
+ fs.mkdirSync(outFileDir, { recursive: true });
673
+ }
674
+ fs.copyFileSync(filePath, outPath);
675
+ }
676
+ }
677
+ }
678
+ }
679
+ async copyDirectoryRecursive(srcPath, destPath, compiler) {
680
+ if (!fs.existsSync(destPath)) {
681
+ fs.mkdirSync(destPath, { recursive: true });
682
+ }
683
+ const entries = fs.readdirSync(srcPath, { withFileTypes: true });
684
+ for (const entry of entries) {
685
+ const srcEntry = path.join(srcPath, entry.name);
686
+ const destEntry = path.join(destPath, entry.name);
687
+ if (entry.isDirectory()) {
688
+ await this.copyDirectoryRecursive(srcEntry, destEntry, compiler);
689
+ }
690
+ else if (entry.isFile()) {
691
+ if (srcEntry.endsWith('.ts')) {
692
+ let content = fs.readFileSync(srcEntry, 'utf-8');
693
+ content = await compiler.stripTypeScript(content, srcEntry);
694
+ fs.writeFileSync(destEntry.replace('.ts', '.js'), content);
695
+ }
696
+ else {
697
+ fs.copyFileSync(srcEntry, destEntry);
698
+ }
699
+ }
700
+ }
701
+ }
702
+ copyDirectoryRecursiveSync(srcPath, destPath) {
703
+ if (!fs.existsSync(destPath)) {
704
+ fs.mkdirSync(destPath, { recursive: true });
705
+ }
706
+ const entries = fs.readdirSync(srcPath, { withFileTypes: true });
707
+ for (const entry of entries) {
708
+ const srcEntry = path.join(srcPath, entry.name);
709
+ const destEntry = path.join(destPath, entry.name);
710
+ if (entry.isDirectory()) {
711
+ this.copyDirectoryRecursiveSync(srcEntry, destEntry);
712
+ }
713
+ else if (entry.isFile()) {
714
+ if (!srcEntry.endsWith('.ts')) {
715
+ fs.copyFileSync(srcEntry, destEntry);
716
+ }
717
+ }
718
+ }
719
+ }
641
720
  static parseArgs(argv) {
642
721
  const options = {};
643
722
  const args = [];
package/Generator.js CHANGED
@@ -128,6 +128,7 @@ export class Generator {
128
128
  srcDir: 'src',
129
129
  outDir: 'dist',
130
130
  componentsDir: 'app',
131
+ tsConfigPath: 'tsconfig.json',
131
132
  entryPoint: 'main.ts',
132
133
  indexHtml: 'index.html',
133
134
  components: ['**/*.component.ts'],
@@ -5,6 +5,7 @@ export interface FluffTarget {
5
5
  srcDir: string;
6
6
  outDir: string;
7
7
  componentsDir?: string;
8
+ tsConfigPath?: string;
8
9
  entryPoint?: string;
9
10
  indexHtml?: string;
10
11
  components: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluffjs/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",