@fluffjs/cli 0.1.3 → 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 +4 -0
- package/Cli.js +123 -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
|
@@ -403,34 +403,7 @@ Examples:
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
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
|
-
}
|
|
406
|
+
await this.copyAssets(target.assets, projectRoot, srcDir, outDir);
|
|
434
407
|
}
|
|
435
408
|
console.log(`✅ Target '${target.name}' built successfully!`);
|
|
436
409
|
}
|
|
@@ -541,26 +514,7 @@ Examples:
|
|
|
541
514
|
}
|
|
542
515
|
}
|
|
543
516
|
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
|
-
}
|
|
517
|
+
this.copyAssetsForServe(target.assets, projectRoot, srcDir, outDir);
|
|
564
518
|
}
|
|
565
519
|
console.log(`🚀 Starting dev server for '${target.name}'...`);
|
|
566
520
|
const tsconfigRaw = target.tsConfigPath
|
|
@@ -623,7 +577,7 @@ Examples:
|
|
|
623
577
|
}
|
|
624
578
|
else if (entry.isFile()) {
|
|
625
579
|
const relativePath = path.relative(dir, fullPath);
|
|
626
|
-
if (this.matchesPatterns(relativePath, patterns)) {
|
|
580
|
+
if (this.matchesPatterns(relativePath, patterns, dir)) {
|
|
627
581
|
files.push(fullPath);
|
|
628
582
|
}
|
|
629
583
|
}
|
|
@@ -632,9 +586,17 @@ Examples:
|
|
|
632
586
|
walk(dir);
|
|
633
587
|
return files;
|
|
634
588
|
}
|
|
635
|
-
matchesPatterns(filePath, patterns) {
|
|
589
|
+
matchesPatterns(filePath, patterns, baseDir) {
|
|
636
590
|
for (const pattern of patterns) {
|
|
637
|
-
|
|
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)) {
|
|
638
600
|
return true;
|
|
639
601
|
}
|
|
640
602
|
}
|
|
@@ -645,6 +607,116 @@ Examples:
|
|
|
645
607
|
const isMatch = picomatch(pattern, { dot: false });
|
|
646
608
|
return isMatch(normalizedPath);
|
|
647
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
|
+
}
|
|
648
720
|
static parseArgs(argv) {
|
|
649
721
|
const options = {};
|
|
650
722
|
const args = [];
|