@fluffjs/cli 0.1.3 → 0.1.5
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 +4 -0
- package/Cli.js +129 -51
- package/package.json +1 -1
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
|
@@ -311,6 +311,9 @@ Examples:
|
|
|
311
311
|
const styleContents = [];
|
|
312
312
|
for (const styleGlob of target.styles) {
|
|
313
313
|
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
314
|
+
if (styleFiles.length === 0) {
|
|
315
|
+
console.warn(` ⚠ Style not found: ${path.resolve(srcDir, styleGlob)}`);
|
|
316
|
+
}
|
|
314
317
|
for (const styleFile of styleFiles) {
|
|
315
318
|
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
316
319
|
}
|
|
@@ -403,34 +406,7 @@ Examples:
|
|
|
403
406
|
}
|
|
404
407
|
}
|
|
405
408
|
if (target.assets) {
|
|
406
|
-
|
|
407
|
-
const assetFiles = this.findFiles(srcDir, target.assets);
|
|
408
|
-
for (const filePath of assetFiles) {
|
|
409
|
-
if (filePath.endsWith('.component.ts'))
|
|
410
|
-
continue;
|
|
411
|
-
if (filePath.endsWith('.component.html'))
|
|
412
|
-
continue;
|
|
413
|
-
if (filePath.endsWith('.component.css'))
|
|
414
|
-
continue;
|
|
415
|
-
if (target.indexHtml && filePath.endsWith(target.indexHtml))
|
|
416
|
-
continue;
|
|
417
|
-
const relativePath = path.relative(srcDir, filePath);
|
|
418
|
-
const outPath = path.join(outDir, relativePath);
|
|
419
|
-
const outFileDir = path.dirname(outPath);
|
|
420
|
-
if (!fs.existsSync(outFileDir)) {
|
|
421
|
-
fs.mkdirSync(outFileDir, { recursive: true });
|
|
422
|
-
}
|
|
423
|
-
if (filePath.endsWith('.ts')) {
|
|
424
|
-
let content = fs.readFileSync(filePath, 'utf-8');
|
|
425
|
-
content = await compiler.stripTypeScript(content, filePath);
|
|
426
|
-
fs.writeFileSync(outPath.replace('.ts', '.js'), content);
|
|
427
|
-
console.log(` ✓ Processed ${relativePath}`);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
fs.copyFileSync(filePath, outPath);
|
|
431
|
-
console.log(` ✓ Copied ${relativePath}`);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
409
|
+
await this.copyAssets(target.assets, projectRoot, srcDir, outDir);
|
|
434
410
|
}
|
|
435
411
|
console.log(`✅ Target '${target.name}' built successfully!`);
|
|
436
412
|
}
|
|
@@ -516,6 +492,9 @@ Examples:
|
|
|
516
492
|
const styleContents = [];
|
|
517
493
|
for (const styleGlob of target.styles) {
|
|
518
494
|
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
495
|
+
if (styleFiles.length === 0) {
|
|
496
|
+
console.warn(` ⚠ Style not found: ${path.resolve(srcDir, styleGlob)}`);
|
|
497
|
+
}
|
|
519
498
|
for (const styleFile of styleFiles) {
|
|
520
499
|
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
521
500
|
}
|
|
@@ -541,26 +520,7 @@ Examples:
|
|
|
541
520
|
}
|
|
542
521
|
}
|
|
543
522
|
if (target.assets) {
|
|
544
|
-
|
|
545
|
-
for (const filePath of assetFiles) {
|
|
546
|
-
if (filePath.endsWith('.component.ts'))
|
|
547
|
-
continue;
|
|
548
|
-
if (filePath.endsWith('.component.html'))
|
|
549
|
-
continue;
|
|
550
|
-
if (filePath.endsWith('.component.css'))
|
|
551
|
-
continue;
|
|
552
|
-
if (target.indexHtml && filePath.endsWith(target.indexHtml))
|
|
553
|
-
continue;
|
|
554
|
-
if (filePath.endsWith('.ts'))
|
|
555
|
-
continue;
|
|
556
|
-
const relativePath = path.relative(srcDir, filePath);
|
|
557
|
-
const outPath = path.join(outDir, relativePath);
|
|
558
|
-
const outFileDir = path.dirname(outPath);
|
|
559
|
-
if (!fs.existsSync(outFileDir)) {
|
|
560
|
-
fs.mkdirSync(outFileDir, { recursive: true });
|
|
561
|
-
}
|
|
562
|
-
fs.copyFileSync(filePath, outPath);
|
|
563
|
-
}
|
|
523
|
+
this.copyAssetsForServe(target.assets, projectRoot, srcDir, outDir);
|
|
564
524
|
}
|
|
565
525
|
console.log(`🚀 Starting dev server for '${target.name}'...`);
|
|
566
526
|
const tsconfigRaw = target.tsConfigPath
|
|
@@ -623,7 +583,7 @@ Examples:
|
|
|
623
583
|
}
|
|
624
584
|
else if (entry.isFile()) {
|
|
625
585
|
const relativePath = path.relative(dir, fullPath);
|
|
626
|
-
if (this.matchesPatterns(relativePath, patterns)) {
|
|
586
|
+
if (this.matchesPatterns(relativePath, patterns, dir)) {
|
|
627
587
|
files.push(fullPath);
|
|
628
588
|
}
|
|
629
589
|
}
|
|
@@ -632,9 +592,17 @@ Examples:
|
|
|
632
592
|
walk(dir);
|
|
633
593
|
return files;
|
|
634
594
|
}
|
|
635
|
-
matchesPatterns(filePath, patterns) {
|
|
595
|
+
matchesPatterns(filePath, patterns, baseDir) {
|
|
636
596
|
for (const pattern of patterns) {
|
|
637
|
-
|
|
597
|
+
const patternPath = path.join(baseDir, pattern);
|
|
598
|
+
if (fs.existsSync(patternPath) && fs.statSync(patternPath).isDirectory()) {
|
|
599
|
+
const normalizedFile = filePath.replace(/\\/g, '/');
|
|
600
|
+
const normalizedPattern = pattern.replace(/\\/g, '/');
|
|
601
|
+
if (normalizedFile.startsWith(normalizedPattern + '/') || normalizedFile === normalizedPattern) {
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
else if (this.matchGlob(filePath, pattern)) {
|
|
638
606
|
return true;
|
|
639
607
|
}
|
|
640
608
|
}
|
|
@@ -645,6 +613,116 @@ Examples:
|
|
|
645
613
|
const isMatch = picomatch(pattern, { dot: false });
|
|
646
614
|
return isMatch(normalizedPath);
|
|
647
615
|
}
|
|
616
|
+
async copyAssets(assets, projectRoot, srcDir, outDir) {
|
|
617
|
+
const compiler = new ComponentCompiler();
|
|
618
|
+
for (const asset of assets) {
|
|
619
|
+
const assetPath = path.resolve(srcDir, asset);
|
|
620
|
+
if (fs.existsSync(assetPath) && fs.statSync(assetPath).isDirectory()) {
|
|
621
|
+
const dirName = path.basename(assetPath);
|
|
622
|
+
const targetDir = path.join(outDir, dirName);
|
|
623
|
+
await this.copyDirectoryRecursive(assetPath, targetDir, compiler);
|
|
624
|
+
console.log(` ✓ Copied directory ${dirName}/`);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
const files = this.findFiles(srcDir, [asset]);
|
|
628
|
+
for (const filePath of files) {
|
|
629
|
+
if (filePath.endsWith('.component.ts'))
|
|
630
|
+
continue;
|
|
631
|
+
if (filePath.endsWith('.component.html'))
|
|
632
|
+
continue;
|
|
633
|
+
if (filePath.endsWith('.component.css'))
|
|
634
|
+
continue;
|
|
635
|
+
const relativePath = path.relative(srcDir, filePath);
|
|
636
|
+
const outPath = path.join(outDir, relativePath);
|
|
637
|
+
const outFileDir = path.dirname(outPath);
|
|
638
|
+
if (!fs.existsSync(outFileDir)) {
|
|
639
|
+
fs.mkdirSync(outFileDir, { recursive: true });
|
|
640
|
+
}
|
|
641
|
+
if (filePath.endsWith('.ts')) {
|
|
642
|
+
let content = fs.readFileSync(filePath, 'utf-8');
|
|
643
|
+
content = await compiler.stripTypeScript(content, filePath);
|
|
644
|
+
fs.writeFileSync(outPath.replace('.ts', '.js'), content);
|
|
645
|
+
console.log(` ✓ Processed ${relativePath}`);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
fs.copyFileSync(filePath, outPath);
|
|
649
|
+
console.log(` ✓ Copied ${relativePath}`);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
copyAssetsForServe(assets, projectRoot, srcDir, outDir) {
|
|
656
|
+
for (const asset of assets) {
|
|
657
|
+
const assetPath = path.resolve(srcDir, asset);
|
|
658
|
+
if (fs.existsSync(assetPath) && fs.statSync(assetPath).isDirectory()) {
|
|
659
|
+
const dirName = path.basename(assetPath);
|
|
660
|
+
const targetDir = path.join(outDir, dirName);
|
|
661
|
+
this.copyDirectoryRecursiveSync(assetPath, targetDir);
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
const files = this.findFiles(srcDir, [asset]);
|
|
665
|
+
for (const filePath of files) {
|
|
666
|
+
if (filePath.endsWith('.component.ts'))
|
|
667
|
+
continue;
|
|
668
|
+
if (filePath.endsWith('.component.html'))
|
|
669
|
+
continue;
|
|
670
|
+
if (filePath.endsWith('.component.css'))
|
|
671
|
+
continue;
|
|
672
|
+
if (filePath.endsWith('.ts'))
|
|
673
|
+
continue;
|
|
674
|
+
const relativePath = path.relative(srcDir, filePath);
|
|
675
|
+
const outPath = path.join(outDir, relativePath);
|
|
676
|
+
const outFileDir = path.dirname(outPath);
|
|
677
|
+
if (!fs.existsSync(outFileDir)) {
|
|
678
|
+
fs.mkdirSync(outFileDir, { recursive: true });
|
|
679
|
+
}
|
|
680
|
+
fs.copyFileSync(filePath, outPath);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
async copyDirectoryRecursive(srcPath, destPath, compiler) {
|
|
686
|
+
if (!fs.existsSync(destPath)) {
|
|
687
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
688
|
+
}
|
|
689
|
+
const entries = fs.readdirSync(srcPath, { withFileTypes: true });
|
|
690
|
+
for (const entry of entries) {
|
|
691
|
+
const srcEntry = path.join(srcPath, entry.name);
|
|
692
|
+
const destEntry = path.join(destPath, entry.name);
|
|
693
|
+
if (entry.isDirectory()) {
|
|
694
|
+
await this.copyDirectoryRecursive(srcEntry, destEntry, compiler);
|
|
695
|
+
}
|
|
696
|
+
else if (entry.isFile()) {
|
|
697
|
+
if (srcEntry.endsWith('.ts')) {
|
|
698
|
+
let content = fs.readFileSync(srcEntry, 'utf-8');
|
|
699
|
+
content = await compiler.stripTypeScript(content, srcEntry);
|
|
700
|
+
fs.writeFileSync(destEntry.replace('.ts', '.js'), content);
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
fs.copyFileSync(srcEntry, destEntry);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
copyDirectoryRecursiveSync(srcPath, destPath) {
|
|
709
|
+
if (!fs.existsSync(destPath)) {
|
|
710
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
711
|
+
}
|
|
712
|
+
const entries = fs.readdirSync(srcPath, { withFileTypes: true });
|
|
713
|
+
for (const entry of entries) {
|
|
714
|
+
const srcEntry = path.join(srcPath, entry.name);
|
|
715
|
+
const destEntry = path.join(destPath, entry.name);
|
|
716
|
+
if (entry.isDirectory()) {
|
|
717
|
+
this.copyDirectoryRecursiveSync(srcEntry, destEntry);
|
|
718
|
+
}
|
|
719
|
+
else if (entry.isFile()) {
|
|
720
|
+
if (!srcEntry.endsWith('.ts')) {
|
|
721
|
+
fs.copyFileSync(srcEntry, destEntry);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
648
726
|
static parseArgs(argv) {
|
|
649
727
|
const options = {};
|
|
650
728
|
const args = [];
|