@xylabs/toolchain 7.10.0 → 7.10.1
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/index.d.ts +3 -1
- package/dist/index.mjs +879 -782
- package/dist/index.mjs.map +1 -1
- package/dist/lib/deprecationMigrate.mjs +99 -0
- package/dist/lib/deprecationMigrate.mjs.map +1 -0
- package/dist/lib/index.mjs +238 -141
- package/dist/lib/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/lib/index.mjs
CHANGED
|
@@ -483,15 +483,111 @@ function printWorkspaceCycles(cycles) {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
+
// src/lib/deprecationMigrate.ts
|
|
487
|
+
import {
|
|
488
|
+
existsSync as existsSync2,
|
|
489
|
+
readFileSync as readFileSync4,
|
|
490
|
+
writeFileSync
|
|
491
|
+
} from "fs";
|
|
492
|
+
import PATH3 from "path";
|
|
493
|
+
import { createInterface } from "readline";
|
|
494
|
+
import chalk5 from "chalk";
|
|
495
|
+
function findProjectRoot() {
|
|
496
|
+
return process.env.INIT_CWD ?? process.cwd();
|
|
497
|
+
}
|
|
498
|
+
function askYesNo(question) {
|
|
499
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
500
|
+
return new Promise((resolve) => {
|
|
501
|
+
rl.question(question, (answer) => {
|
|
502
|
+
rl.close();
|
|
503
|
+
resolve(answer.trim().toLowerCase().startsWith("y"));
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function replaceInFile(filePath, oldStr, newStr) {
|
|
508
|
+
if (!existsSync2(filePath)) return false;
|
|
509
|
+
const content = readFileSync4(filePath, "utf8");
|
|
510
|
+
if (!content.includes(oldStr)) return false;
|
|
511
|
+
writeFileSync(filePath, content.replaceAll(oldStr, newStr), "utf8");
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
function migrateRootPackageJson(pkg, pkgPath, oldPackage, depField) {
|
|
515
|
+
const version = pkg[depField][oldPackage];
|
|
516
|
+
delete pkg[depField][oldPackage];
|
|
517
|
+
pkg[depField]["@xylabs/toolchain"] = version;
|
|
518
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
519
|
+
`, "utf8");
|
|
520
|
+
console.warn(chalk5.green(` \u2713 Replaced ${oldPackage} \u2192 @xylabs/toolchain in ${depField}`));
|
|
521
|
+
}
|
|
522
|
+
function migrateWorkspacePackageJson(wsPkgPath, dir, oldPackage) {
|
|
523
|
+
if (!existsSync2(wsPkgPath)) return;
|
|
524
|
+
const wsPkg = JSON.parse(readFileSync4(wsPkgPath, "utf8"));
|
|
525
|
+
let changed = false;
|
|
526
|
+
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
527
|
+
if (wsPkg[field]?.[oldPackage]) {
|
|
528
|
+
const ver = wsPkg[field][oldPackage];
|
|
529
|
+
delete wsPkg[field][oldPackage];
|
|
530
|
+
wsPkg[field]["@xylabs/toolchain"] = ver;
|
|
531
|
+
changed = true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (changed) {
|
|
535
|
+
writeFileSync(wsPkgPath, `${JSON.stringify(wsPkg, null, 2)}
|
|
536
|
+
`, "utf8");
|
|
537
|
+
console.warn(chalk5.green(` \u2713 Updated ${dir}/package.json`));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async function migrateWorkspaces(root, workspacesGlob, oldPackage) {
|
|
541
|
+
if (!Array.isArray(workspacesGlob)) return;
|
|
542
|
+
const { globSync } = await import("glob");
|
|
543
|
+
for (const pattern of workspacesGlob) {
|
|
544
|
+
const dirs = globSync(pattern, { cwd: root });
|
|
545
|
+
for (const dir of dirs) {
|
|
546
|
+
if (replaceInFile(PATH3.join(root, dir, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
|
|
547
|
+
console.warn(chalk5.green(` \u2713 Updated ${dir}/xy.config.ts imports`));
|
|
548
|
+
}
|
|
549
|
+
migrateWorkspacePackageJson(PATH3.join(root, dir, "package.json"), dir, oldPackage);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function printManualInstructions(oldPackage) {
|
|
554
|
+
console.warn(chalk5.gray(" Skipped. To migrate manually:\n"));
|
|
555
|
+
console.warn(chalk5.gray(` 1. Replace "${oldPackage}" with "@xylabs/toolchain" in package.json`));
|
|
556
|
+
console.warn(chalk5.gray(" 2. Update xy.config.ts imports"));
|
|
557
|
+
console.warn(chalk5.gray(" 3. Run your package manager install\n"));
|
|
558
|
+
}
|
|
559
|
+
async function deprecationMigrate(oldPackage) {
|
|
560
|
+
const root = findProjectRoot();
|
|
561
|
+
const pkgPath = PATH3.join(root, "package.json");
|
|
562
|
+
if (!existsSync2(pkgPath)) return;
|
|
563
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
564
|
+
const depField = pkg.dependencies?.[oldPackage] ? "dependencies" : pkg.devDependencies?.[oldPackage] ? "devDependencies" : void 0;
|
|
565
|
+
if (!depField) return;
|
|
566
|
+
console.warn(chalk5.yellow(`
|
|
567
|
+
\u26A0 ${oldPackage} is deprecated. Use @xylabs/toolchain instead.
|
|
568
|
+
`));
|
|
569
|
+
const shouldMigrate = await askYesNo(chalk5.cyan(" Auto-migrate to @xylabs/toolchain? [y/N] "));
|
|
570
|
+
if (!shouldMigrate) {
|
|
571
|
+
printManualInstructions(oldPackage);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
migrateRootPackageJson(pkg, pkgPath, oldPackage, depField);
|
|
575
|
+
if (replaceInFile(PATH3.join(root, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
|
|
576
|
+
console.warn(chalk5.green(" \u2713 Updated xy.config.ts imports"));
|
|
577
|
+
}
|
|
578
|
+
await migrateWorkspaces(root, pkg.workspaces, oldPackage);
|
|
579
|
+
console.warn(chalk5.yellow("\n Run your package manager install to complete the migration.\n"));
|
|
580
|
+
}
|
|
581
|
+
|
|
486
582
|
// src/lib/file/constants.ts
|
|
487
583
|
var WINDOWS_NEWLINE_REGEX = /\r\n/g;
|
|
488
584
|
var CROSS_PLATFORM_NEWLINE = "\n";
|
|
489
585
|
|
|
490
586
|
// src/lib/file/fileLines.ts
|
|
491
587
|
import {
|
|
492
|
-
existsSync as
|
|
493
|
-
readFileSync as
|
|
494
|
-
writeFileSync
|
|
588
|
+
existsSync as existsSync3,
|
|
589
|
+
readFileSync as readFileSync5,
|
|
590
|
+
writeFileSync as writeFileSync2
|
|
495
591
|
} from "fs";
|
|
496
592
|
|
|
497
593
|
// src/lib/string/empty.ts
|
|
@@ -505,18 +601,18 @@ var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
|
|
|
505
601
|
var defaultReadFileSyncOptions = { encoding: "utf8" };
|
|
506
602
|
|
|
507
603
|
// src/lib/file/fileLines.ts
|
|
508
|
-
var readLines = (uri, options = defaultReadFileSyncOptions) =>
|
|
604
|
+
var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync3(uri) ? readFileSync5(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
|
|
509
605
|
var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
|
|
510
606
|
var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
|
|
511
|
-
const existing =
|
|
607
|
+
const existing = existsSync3(uri) ? readFileSync5(uri, options) : void 0;
|
|
512
608
|
const desired = lines.join(CROSS_PLATFORM_NEWLINE);
|
|
513
|
-
if (existing !== desired)
|
|
609
|
+
if (existing !== desired) writeFileSync2(uri, desired, options);
|
|
514
610
|
};
|
|
515
611
|
|
|
516
612
|
// src/lib/file/tryReadFileSync.ts
|
|
517
|
-
import { existsSync as
|
|
613
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
518
614
|
var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
|
|
519
|
-
return
|
|
615
|
+
return existsSync4(uri) ? readFileSync6(uri, options) : void 0;
|
|
520
616
|
};
|
|
521
617
|
|
|
522
618
|
// src/lib/fillTemplate.ts
|
|
@@ -525,7 +621,7 @@ function fillTemplate(template, data) {
|
|
|
525
621
|
}
|
|
526
622
|
|
|
527
623
|
// src/lib/generateIgnoreFiles.ts
|
|
528
|
-
import
|
|
624
|
+
import chalk6 from "chalk";
|
|
529
625
|
|
|
530
626
|
// src/lib/initCwd.ts
|
|
531
627
|
function INIT_CWD() {
|
|
@@ -536,7 +632,7 @@ function INIT_CWD() {
|
|
|
536
632
|
var localeCompare = (a, b) => a.localeCompare(b);
|
|
537
633
|
var mergeEntries = (a, b) => [...union(a, b)].toSorted(localeCompare);
|
|
538
634
|
var generateIgnoreFiles = (filename, pkg) => {
|
|
539
|
-
console.log(
|
|
635
|
+
console.log(chalk6.green(`Generate ${filename} Files`));
|
|
540
636
|
const cwd = INIT_CWD();
|
|
541
637
|
const pm = getPackageManager();
|
|
542
638
|
const singleWorkspace = pkg ? pm.findWorkspace(pkg) : void 0;
|
|
@@ -559,27 +655,27 @@ var generateIgnoreFiles = (filename, pkg) => {
|
|
|
559
655
|
|
|
560
656
|
// src/lib/generateReadmeFiles.ts
|
|
561
657
|
import { execFile } from "child_process";
|
|
562
|
-
import FS, { readFileSync as
|
|
658
|
+
import FS, { readFileSync as readFileSync7 } from "fs";
|
|
563
659
|
import {
|
|
564
660
|
mkdir,
|
|
565
661
|
readFile,
|
|
566
662
|
writeFile
|
|
567
663
|
} from "fs/promises";
|
|
568
664
|
import { createRequire as createRequire2 } from "module";
|
|
569
|
-
import
|
|
570
|
-
import { createInterface } from "readline";
|
|
665
|
+
import PATH4 from "path";
|
|
666
|
+
import { createInterface as createInterface2 } from "readline";
|
|
571
667
|
import { promisify } from "util";
|
|
572
|
-
import
|
|
668
|
+
import chalk7 from "chalk";
|
|
573
669
|
var execFileAsync = promisify(execFile);
|
|
574
670
|
var require3 = createRequire2(import.meta.url);
|
|
575
|
-
var packageRoot2 =
|
|
576
|
-
var readmeTemplatesDir =
|
|
671
|
+
var packageRoot2 = PATH4.dirname(require3.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
672
|
+
var readmeTemplatesDir = PATH4.resolve(packageRoot2, "templates", "readme");
|
|
577
673
|
function fillReadmeTemplate(template, data) {
|
|
578
674
|
const additionalData = { ...data, safeName: data.name.replaceAll("/", "__").replaceAll("@", "") };
|
|
579
675
|
return fillTemplate(template, additionalData);
|
|
580
676
|
}
|
|
581
677
|
async function generateTypedoc(packageLocation, entryPoints) {
|
|
582
|
-
const tempDir =
|
|
678
|
+
const tempDir = PATH4.join(packageLocation, ".temp-typedoc");
|
|
583
679
|
try {
|
|
584
680
|
if (!FS.existsSync(tempDir)) {
|
|
585
681
|
FS.mkdirSync(tempDir, { recursive: true });
|
|
@@ -587,7 +683,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
587
683
|
const typedocConfig = {
|
|
588
684
|
disableSources: true,
|
|
589
685
|
entryPointStrategy: "expand",
|
|
590
|
-
entryPoints: entryPoints.map((ep) =>
|
|
686
|
+
entryPoints: entryPoints.map((ep) => PATH4.resolve(packageLocation, ep)),
|
|
591
687
|
excludeExternals: true,
|
|
592
688
|
excludeInternal: true,
|
|
593
689
|
excludePrivate: true,
|
|
@@ -603,7 +699,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
603
699
|
theme: "markdown",
|
|
604
700
|
useCodeBlocks: true
|
|
605
701
|
};
|
|
606
|
-
const typedocJsonPath =
|
|
702
|
+
const typedocJsonPath = PATH4.join(tempDir, "typedoc.json");
|
|
607
703
|
FS.writeFileSync(typedocJsonPath, JSON.stringify(typedocConfig, null, 2));
|
|
608
704
|
try {
|
|
609
705
|
await execFileAsync("npx", ["typedoc", "--options", typedocJsonPath], { cwd: process.cwd() });
|
|
@@ -622,7 +718,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
622
718
|
}
|
|
623
719
|
function consolidateMarkdown(tempDir) {
|
|
624
720
|
let consolidated = "## Reference\n\n";
|
|
625
|
-
const mainReadmePath =
|
|
721
|
+
const mainReadmePath = PATH4.join(tempDir, "README.md");
|
|
626
722
|
if (FS.existsSync(mainReadmePath)) {
|
|
627
723
|
const mainContent = FS.readFileSync(mainReadmePath, "utf8").replace(/^---(.|\n)*?---\n/, "").replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
628
724
|
consolidated += mainContent + "\n\n";
|
|
@@ -638,7 +734,7 @@ function processDirectory(dir, level = 0) {
|
|
|
638
734
|
for (const item of items) {
|
|
639
735
|
if (item.isDirectory()) continue;
|
|
640
736
|
if (item.name === "README.md" || !item.name.endsWith(".md")) continue;
|
|
641
|
-
const fileContent = FS.readFileSync(
|
|
737
|
+
const fileContent = FS.readFileSync(PATH4.join(dir, item.name), "utf8").replace(/^---(.|\n)*?---\n/, "");
|
|
642
738
|
const moduleName = item.name.replace(".md", "");
|
|
643
739
|
content += `
|
|
644
740
|
|
|
@@ -654,14 +750,14 @@ ${indent}### <a id="${moduleName}"></a>${moduleName}
|
|
|
654
750
|
|
|
655
751
|
${indent}### ${item.name}
|
|
656
752
|
`;
|
|
657
|
-
content += processDirectory(
|
|
753
|
+
content += processDirectory(PATH4.join(dir, item.name), level + 1);
|
|
658
754
|
}
|
|
659
755
|
} catch {
|
|
660
756
|
}
|
|
661
757
|
return content;
|
|
662
758
|
}
|
|
663
759
|
function askConfirmation(question) {
|
|
664
|
-
const rl =
|
|
760
|
+
const rl = createInterface2({ input: process.stdin, output: process.stdout });
|
|
665
761
|
return new Promise((resolve) => {
|
|
666
762
|
rl.question(question, (answer) => {
|
|
667
763
|
rl.close();
|
|
@@ -669,8 +765,8 @@ function askConfirmation(question) {
|
|
|
669
765
|
});
|
|
670
766
|
});
|
|
671
767
|
}
|
|
672
|
-
var DEFAULT_README_TEMPLATE =
|
|
673
|
-
var DEFAULT_README_BODY =
|
|
768
|
+
var DEFAULT_README_TEMPLATE = readFileSync7(PATH4.resolve(readmeTemplatesDir, "README.template.md"), "utf8");
|
|
769
|
+
var DEFAULT_README_BODY = readFileSync7(PATH4.resolve(readmeTemplatesDir, "README.body.md"), "utf8");
|
|
674
770
|
function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
675
771
|
let result = template;
|
|
676
772
|
if (logoUrl) {
|
|
@@ -686,14 +782,14 @@ function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
|
686
782
|
}
|
|
687
783
|
function resolveTemplatePath(templatePath) {
|
|
688
784
|
const cwd = INIT_CWD();
|
|
689
|
-
return templatePath ??
|
|
785
|
+
return templatePath ?? PATH4.join(cwd, ".xy", "README.template.md");
|
|
690
786
|
}
|
|
691
787
|
async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
692
788
|
try {
|
|
693
789
|
const template = await readFile(resolvedTemplatePath, "utf8");
|
|
694
790
|
return { created: false, template };
|
|
695
791
|
} catch {
|
|
696
|
-
console.log(
|
|
792
|
+
console.log(chalk7.yellow(`Template not found: ${resolvedTemplatePath}`));
|
|
697
793
|
const shouldCreate = await askConfirmation("Would you like to create a stock template? (y/N) ");
|
|
698
794
|
if (!shouldCreate) {
|
|
699
795
|
throw new Error("Template creation declined");
|
|
@@ -704,16 +800,16 @@ async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
|
704
800
|
}
|
|
705
801
|
}
|
|
706
802
|
async function scaffoldTemplate(resolvedTemplatePath, template) {
|
|
707
|
-
const xyDir =
|
|
803
|
+
const xyDir = PATH4.dirname(resolvedTemplatePath);
|
|
708
804
|
await mkdir(xyDir, { recursive: true });
|
|
709
805
|
await writeFile(resolvedTemplatePath, template);
|
|
710
|
-
console.log(
|
|
711
|
-
const bodyPath =
|
|
806
|
+
console.log(chalk7.green(`Created template: ${resolvedTemplatePath}`));
|
|
807
|
+
const bodyPath = PATH4.join(xyDir, "README.body.md");
|
|
712
808
|
await writeFile(bodyPath, DEFAULT_README_BODY);
|
|
713
|
-
console.log(
|
|
809
|
+
console.log(chalk7.green(`Created body template: ${bodyPath}`));
|
|
714
810
|
}
|
|
715
811
|
async function resolveBody(location, defaultBody) {
|
|
716
|
-
const localBodyPath =
|
|
812
|
+
const localBodyPath = PATH4.join(location, "README.body.md");
|
|
717
813
|
try {
|
|
718
814
|
return await readFile(localBodyPath, "utf8");
|
|
719
815
|
} catch {
|
|
@@ -722,7 +818,7 @@ async function resolveBody(location, defaultBody) {
|
|
|
722
818
|
}
|
|
723
819
|
async function generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose, pm) {
|
|
724
820
|
try {
|
|
725
|
-
const pkgJsonPath =
|
|
821
|
+
const pkgJsonPath = PATH4.join(location, "package.json");
|
|
726
822
|
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
|
|
727
823
|
const body = await resolveBody(location, defaultBody);
|
|
728
824
|
const typedocContent = typedoc ? await generateTypedoc(location, ["src/index*.ts"]) : "";
|
|
@@ -732,17 +828,17 @@ async function generateReadmeForWorkspace(location, name, template, defaultBody,
|
|
|
732
828
|
pm,
|
|
733
829
|
typedoc: typedocContent
|
|
734
830
|
});
|
|
735
|
-
await writeFile(
|
|
736
|
-
if (verbose) console.log(
|
|
831
|
+
await writeFile(PATH4.join(location, "README.md"), readmeContent);
|
|
832
|
+
if (verbose) console.log(chalk7.green(` ${name}`));
|
|
737
833
|
return true;
|
|
738
834
|
} catch (ex) {
|
|
739
835
|
const error = ex;
|
|
740
|
-
console.warn(
|
|
836
|
+
console.warn(chalk7.yellow(` Skipped ${location}: ${error.message}`));
|
|
741
837
|
return false;
|
|
742
838
|
}
|
|
743
839
|
}
|
|
744
840
|
async function loadDefaultBody(resolvedTemplatePath) {
|
|
745
|
-
const xyBodyPath =
|
|
841
|
+
const xyBodyPath = PATH4.join(PATH4.dirname(resolvedTemplatePath), "README.body.md");
|
|
746
842
|
try {
|
|
747
843
|
return await readFile(xyBodyPath, "utf8");
|
|
748
844
|
} catch {
|
|
@@ -768,7 +864,7 @@ async function generateReadmeFiles({
|
|
|
768
864
|
typedoc = false,
|
|
769
865
|
verbose = false
|
|
770
866
|
}) {
|
|
771
|
-
console.log(
|
|
867
|
+
console.log(chalk7.green("Generate README Files"));
|
|
772
868
|
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
773
869
|
let template;
|
|
774
870
|
let templateCreated;
|
|
@@ -779,7 +875,7 @@ async function generateReadmeFiles({
|
|
|
779
875
|
}
|
|
780
876
|
template = applyLogoConfig(template, logoUrl, logoLinkUrl);
|
|
781
877
|
if (templateCreated) {
|
|
782
|
-
console.log(
|
|
878
|
+
console.log(chalk7.green("Generating README files for all packages..."));
|
|
783
879
|
}
|
|
784
880
|
const defaultBody = await loadDefaultBody(resolvedTemplatePath);
|
|
785
881
|
const pmName = detectPackageManager();
|
|
@@ -803,18 +899,18 @@ async function generateReadmeFiles({
|
|
|
803
899
|
);
|
|
804
900
|
const failed = flushResults(results);
|
|
805
901
|
const ms = performance.now() - start;
|
|
806
|
-
console.log(
|
|
902
|
+
console.log(chalk7.blue(`Generated ${workspaces.length} README(s) in ${ms.toFixed(0)}ms`));
|
|
807
903
|
return failed ? 1 : 0;
|
|
808
904
|
}
|
|
809
905
|
|
|
810
906
|
// src/lib/gitignoreTemplate.ts
|
|
811
|
-
import { readFileSync as
|
|
907
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
812
908
|
import { createRequire as createRequire3 } from "module";
|
|
813
|
-
import
|
|
909
|
+
import PATH5 from "path";
|
|
814
910
|
var require4 = createRequire3(import.meta.url);
|
|
815
|
-
var packageRoot3 =
|
|
816
|
-
var templatesDir2 =
|
|
817
|
-
var gitignoreTemplate = () =>
|
|
911
|
+
var packageRoot3 = PATH5.dirname(require4.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
912
|
+
var templatesDir2 = PATH5.resolve(packageRoot3, "templates", "gitignore");
|
|
913
|
+
var gitignoreTemplate = () => readFileSync8(PATH5.resolve(templatesDir2, "template.gitignore"), "utf8");
|
|
818
914
|
|
|
819
915
|
// src/lib/latestVersions.ts
|
|
820
916
|
var latestVersions = {
|
|
@@ -826,7 +922,7 @@ var latestVersions = {
|
|
|
826
922
|
};
|
|
827
923
|
|
|
828
924
|
// src/lib/loadConfig.ts
|
|
829
|
-
import
|
|
925
|
+
import chalk8 from "chalk";
|
|
830
926
|
import { cosmiconfig } from "cosmiconfig";
|
|
831
927
|
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
832
928
|
import deepmerge from "deepmerge";
|
|
@@ -844,9 +940,9 @@ var loadConfig = async (params) => {
|
|
|
844
940
|
rootConfigPath = cosmicConfigResult?.filepath;
|
|
845
941
|
const configFilePath = cosmicConfigResult?.filepath;
|
|
846
942
|
if (configFilePath !== void 0) {
|
|
847
|
-
console.log(
|
|
943
|
+
console.log(chalk8.green(`Loaded config from ${configFilePath}`));
|
|
848
944
|
if (config.verbose) {
|
|
849
|
-
console.log(
|
|
945
|
+
console.log(chalk8.gray(`${JSON.stringify(config, null, 2)}`));
|
|
850
946
|
}
|
|
851
947
|
}
|
|
852
948
|
}
|
|
@@ -876,7 +972,7 @@ function resolveCommandField(cfg, commandName, configPath) {
|
|
|
876
972
|
const key = `${configPath ?? "unknown"}:${commandName}`;
|
|
877
973
|
if (!deprecationWarned.has(key)) {
|
|
878
974
|
deprecationWarned.add(key);
|
|
879
|
-
console.warn(
|
|
975
|
+
console.warn(chalk8.yellow(
|
|
880
976
|
`[xy] Deprecated: top-level "${commandName}" in ${configPath ?? "xy.config"} \u2014 move to "commands.${commandName}"`
|
|
881
977
|
));
|
|
882
978
|
}
|
|
@@ -894,7 +990,7 @@ async function loadWorkspaceCommandConfig(workspaceDir, commandName) {
|
|
|
894
990
|
}
|
|
895
991
|
|
|
896
992
|
// src/lib/packageName.ts
|
|
897
|
-
import { readFileSync as
|
|
993
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
898
994
|
import path from "path";
|
|
899
995
|
function packageName() {
|
|
900
996
|
if (process.env.npm_package_name) {
|
|
@@ -902,7 +998,7 @@ function packageName() {
|
|
|
902
998
|
}
|
|
903
999
|
try {
|
|
904
1000
|
const pkgPath = path.join(INIT_CWD(), "package.json");
|
|
905
|
-
const pkg = JSON.parse(
|
|
1001
|
+
const pkg = JSON.parse(readFileSync9(pkgPath, "utf8"));
|
|
906
1002
|
return pkg.name;
|
|
907
1003
|
} catch {
|
|
908
1004
|
return void 0;
|
|
@@ -910,29 +1006,29 @@ function packageName() {
|
|
|
910
1006
|
}
|
|
911
1007
|
|
|
912
1008
|
// src/lib/parsedPackageJSON.ts
|
|
913
|
-
import { readFileSync as
|
|
1009
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
914
1010
|
var parsedPackageJSON = (path2) => {
|
|
915
1011
|
const pathToPackageJSON = path2 ?? process.env.npm_package_json ?? "";
|
|
916
|
-
const packageJSON =
|
|
1012
|
+
const packageJSON = readFileSync10(pathToPackageJSON).toString();
|
|
917
1013
|
return JSON.parse(packageJSON);
|
|
918
1014
|
};
|
|
919
1015
|
|
|
920
1016
|
// src/lib/repoTemplates.ts
|
|
921
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
1017
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync11 } from "fs";
|
|
922
1018
|
import { createRequire as createRequire4 } from "module";
|
|
923
|
-
import
|
|
1019
|
+
import PATH6 from "path";
|
|
924
1020
|
var require5 = createRequire4(import.meta.url);
|
|
925
|
-
var packageRoot4 =
|
|
926
|
-
var repoTemplatesDir =
|
|
1021
|
+
var packageRoot4 = PATH6.dirname(require5.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
1022
|
+
var repoTemplatesDir = PATH6.resolve(packageRoot4, "templates", "repo");
|
|
927
1023
|
function collectFiles(dir, prefix) {
|
|
928
1024
|
const results = [];
|
|
929
1025
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
930
1026
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
931
1027
|
if (entry.isDirectory()) {
|
|
932
|
-
results.push(...collectFiles(
|
|
1028
|
+
results.push(...collectFiles(PATH6.resolve(dir, entry.name), rel));
|
|
933
1029
|
} else {
|
|
934
1030
|
results.push({
|
|
935
|
-
content:
|
|
1031
|
+
content: readFileSync11(PATH6.resolve(dir, entry.name), "utf8"),
|
|
936
1032
|
relativePath: rel
|
|
937
1033
|
});
|
|
938
1034
|
}
|
|
@@ -940,7 +1036,7 @@ function collectFiles(dir, prefix) {
|
|
|
940
1036
|
return results;
|
|
941
1037
|
}
|
|
942
1038
|
function loadRepoTemplateFiles(template, section) {
|
|
943
|
-
const dir =
|
|
1039
|
+
const dir = PATH6.resolve(repoTemplatesDir, template, section);
|
|
944
1040
|
return collectFiles(dir, "");
|
|
945
1041
|
}
|
|
946
1042
|
function listRepoTemplates() {
|
|
@@ -949,37 +1045,37 @@ function listRepoTemplates() {
|
|
|
949
1045
|
|
|
950
1046
|
// src/lib/runInstall.ts
|
|
951
1047
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
952
|
-
import
|
|
1048
|
+
import chalk9 from "chalk";
|
|
953
1049
|
function runInstall(cwd) {
|
|
954
1050
|
const pm = detectPackageManager();
|
|
955
|
-
console.log(
|
|
1051
|
+
console.log(chalk9.gray(`Running ${pm} install...`));
|
|
956
1052
|
const result = spawnSync3(pm, ["install"], {
|
|
957
1053
|
cwd,
|
|
958
1054
|
stdio: "inherit"
|
|
959
1055
|
});
|
|
960
1056
|
if (result.status !== 0) {
|
|
961
|
-
console.warn(
|
|
1057
|
+
console.warn(chalk9.yellow(`${pm} install failed`));
|
|
962
1058
|
return false;
|
|
963
1059
|
}
|
|
964
|
-
console.log(
|
|
1060
|
+
console.log(chalk9.green("Dependencies installed"));
|
|
965
1061
|
return true;
|
|
966
1062
|
}
|
|
967
1063
|
|
|
968
1064
|
// src/lib/runSteps.ts
|
|
969
1065
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
970
|
-
import { existsSync as
|
|
971
|
-
import
|
|
1066
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1067
|
+
import chalk10 from "chalk";
|
|
972
1068
|
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
973
1069
|
return safeExit(() => {
|
|
974
1070
|
const pkgName = packageName();
|
|
975
|
-
console.log(
|
|
1071
|
+
console.log(chalk10.green(`${name} [${pkgName}]`));
|
|
976
1072
|
let totalStatus = 0;
|
|
977
1073
|
for (const [i, [command, args, config2]] of steps.entries()) {
|
|
978
1074
|
if (messages?.[i]) {
|
|
979
|
-
console.log(
|
|
1075
|
+
console.log(chalk10.gray(messages?.[i]));
|
|
980
1076
|
}
|
|
981
1077
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
982
|
-
if (command === "node" && !
|
|
1078
|
+
if (command === "node" && !existsSync5(argList[0])) {
|
|
983
1079
|
throw new Error(`File not found [${argList[0]}]`);
|
|
984
1080
|
}
|
|
985
1081
|
const status = spawnSync4(command, Array.isArray(args) ? args : args.split(" "), {
|
|
@@ -998,16 +1094,16 @@ var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
|
998
1094
|
|
|
999
1095
|
// src/lib/runStepsAsync.ts
|
|
1000
1096
|
import { spawn } from "child_process";
|
|
1001
|
-
import { existsSync as
|
|
1002
|
-
import
|
|
1097
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1098
|
+
import chalk11 from "chalk";
|
|
1003
1099
|
var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
1004
1100
|
return new Promise((resolve) => {
|
|
1005
1101
|
const [command, args, config2] = step;
|
|
1006
1102
|
if (message) {
|
|
1007
|
-
console.log(
|
|
1103
|
+
console.log(chalk11.gray(message));
|
|
1008
1104
|
}
|
|
1009
1105
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
1010
|
-
if (command === "node" && !
|
|
1106
|
+
if (command === "node" && !existsSync6(argList[0])) {
|
|
1011
1107
|
throw new Error(`File not found [${argList[0]}]`);
|
|
1012
1108
|
}
|
|
1013
1109
|
spawn(command, Array.isArray(args) ? args : args.split(" "), {
|
|
@@ -1018,8 +1114,8 @@ var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
|
1018
1114
|
}).on("close", (code) => {
|
|
1019
1115
|
if (code) {
|
|
1020
1116
|
console.error(
|
|
1021
|
-
|
|
1022
|
-
`Command Exited With Non-Zero Result [${
|
|
1117
|
+
chalk11.red(
|
|
1118
|
+
`Command Exited With Non-Zero Result [${chalk11.gray(code)}] | ${chalk11.yellow(command)} ${chalk11.white(
|
|
1023
1119
|
Array.isArray(args) ? args.join(" ") : args
|
|
1024
1120
|
)}`
|
|
1025
1121
|
)
|
|
@@ -1035,7 +1131,7 @@ var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
|
1035
1131
|
var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
|
|
1036
1132
|
return await safeExitAsync(async () => {
|
|
1037
1133
|
const pkgName = packageName();
|
|
1038
|
-
console.log(
|
|
1134
|
+
console.log(chalk11.green(`${name} [${pkgName}]`));
|
|
1039
1135
|
let result = 0;
|
|
1040
1136
|
for (const [i, step] of steps.entries()) {
|
|
1041
1137
|
result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
|
|
@@ -1054,33 +1150,33 @@ var runXy = (command) => {
|
|
|
1054
1150
|
};
|
|
1055
1151
|
|
|
1056
1152
|
// src/lib/runXyWithWarning.ts
|
|
1057
|
-
import
|
|
1153
|
+
import chalk12 from "chalk";
|
|
1058
1154
|
var runXyWithWarning = (command) => {
|
|
1059
1155
|
const pm = getPackageManager();
|
|
1060
1156
|
const commandString = `${pm.command} ${command}`;
|
|
1061
1157
|
const commandXyString = `${pm.command} xy ${command}`;
|
|
1062
|
-
console.warn(
|
|
1063
|
-
console.warn(
|
|
1158
|
+
console.warn(chalk12.yellow(`WARNING: [${chalk12.white(commandString)}] is deprecated for XY Labs Scripts.`));
|
|
1159
|
+
console.warn(chalk12.gray(`Did you mean [${chalk12.magenta(commandXyString)}]?`));
|
|
1064
1160
|
return 1;
|
|
1065
1161
|
};
|
|
1066
1162
|
|
|
1067
1163
|
// src/lib/tryRunLocalScript.ts
|
|
1068
1164
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
1069
|
-
import { readFileSync as
|
|
1070
|
-
import
|
|
1071
|
-
import
|
|
1165
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
1166
|
+
import PATH7 from "path";
|
|
1167
|
+
import chalk13 from "chalk";
|
|
1072
1168
|
function tryRunLocalScript(commandName) {
|
|
1073
1169
|
if (process.env.XY_LOCAL_SCRIPT === "1") return void 0;
|
|
1074
|
-
const rootPkgPath =
|
|
1170
|
+
const rootPkgPath = PATH7.resolve(process.cwd(), "package.json");
|
|
1075
1171
|
let rootPkg;
|
|
1076
1172
|
try {
|
|
1077
|
-
rootPkg = JSON.parse(
|
|
1173
|
+
rootPkg = JSON.parse(readFileSync12(rootPkgPath, "utf8"));
|
|
1078
1174
|
} catch {
|
|
1079
1175
|
return void 0;
|
|
1080
1176
|
}
|
|
1081
1177
|
if (!rootPkg.scripts?.[commandName]) return void 0;
|
|
1082
1178
|
const extraArgs = process.argv.slice(process.argv.indexOf(commandName) + 1);
|
|
1083
|
-
console.log(
|
|
1179
|
+
console.log(chalk13.blue(`Delegating "${commandName}" to local script`));
|
|
1084
1180
|
const pm = getPackageManager();
|
|
1085
1181
|
const result = spawnSync5(pm.command, ["run", commandName, ...extraArgs], {
|
|
1086
1182
|
cwd: process.cwd(),
|
|
@@ -1097,17 +1193,17 @@ function tryRunLocalScript(commandName) {
|
|
|
1097
1193
|
}
|
|
1098
1194
|
|
|
1099
1195
|
// src/lib/updo/applyUpdates.ts
|
|
1100
|
-
import { readFileSync as
|
|
1101
|
-
import
|
|
1102
|
-
import
|
|
1196
|
+
import { readFileSync as readFileSync13, writeFileSync as writeFileSync3 } from "fs";
|
|
1197
|
+
import PATH8 from "path";
|
|
1198
|
+
import chalk14 from "chalk";
|
|
1103
1199
|
function applyUpdates(cwd, workspaces, updates) {
|
|
1104
1200
|
const updateMap = new Map(updates.map((u) => [u.name, u]));
|
|
1105
1201
|
let modified = 0;
|
|
1106
1202
|
for (const ws of workspaces) {
|
|
1107
|
-
const pkgPath =
|
|
1203
|
+
const pkgPath = PATH8.resolve(cwd, ws.location, "package.json");
|
|
1108
1204
|
let content;
|
|
1109
1205
|
try {
|
|
1110
|
-
content =
|
|
1206
|
+
content = readFileSync13(pkgPath, "utf8");
|
|
1111
1207
|
} catch {
|
|
1112
1208
|
continue;
|
|
1113
1209
|
}
|
|
@@ -1128,26 +1224,26 @@ function applyUpdates(cwd, workspaces, updates) {
|
|
|
1128
1224
|
}
|
|
1129
1225
|
}
|
|
1130
1226
|
if (changed) {
|
|
1131
|
-
|
|
1227
|
+
writeFileSync3(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
1132
1228
|
`);
|
|
1133
1229
|
modified++;
|
|
1134
|
-
console.log(
|
|
1230
|
+
console.log(chalk14.gray(` Updated ${ws.name}`));
|
|
1135
1231
|
}
|
|
1136
1232
|
}
|
|
1137
1233
|
return modified;
|
|
1138
1234
|
}
|
|
1139
1235
|
|
|
1140
1236
|
// src/lib/updo/collectWorkspaceDeps.ts
|
|
1141
|
-
import { readFileSync as
|
|
1142
|
-
import
|
|
1237
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
1238
|
+
import PATH9 from "path";
|
|
1143
1239
|
var DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
1144
1240
|
function collectWorkspaceDeps(cwd, workspaces, workspaceNames) {
|
|
1145
1241
|
const depMap = /* @__PURE__ */ new Map();
|
|
1146
1242
|
for (const ws of workspaces) {
|
|
1147
|
-
const pkgPath =
|
|
1243
|
+
const pkgPath = PATH9.resolve(cwd, ws.location, "package.json");
|
|
1148
1244
|
let pkg;
|
|
1149
1245
|
try {
|
|
1150
|
-
pkg = JSON.parse(
|
|
1246
|
+
pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
1151
1247
|
} catch {
|
|
1152
1248
|
continue;
|
|
1153
1249
|
}
|
|
@@ -1229,51 +1325,51 @@ import {
|
|
|
1229
1325
|
useRef,
|
|
1230
1326
|
useState
|
|
1231
1327
|
} from "@inquirer/core";
|
|
1232
|
-
import
|
|
1328
|
+
import chalk15 from "chalk";
|
|
1233
1329
|
import semver from "semver";
|
|
1234
1330
|
function versionColor(version, current) {
|
|
1235
|
-
if (!version || !current) return
|
|
1236
|
-
if (version === current) return
|
|
1331
|
+
if (!version || !current) return chalk15.gray;
|
|
1332
|
+
if (version === current) return chalk15.gray;
|
|
1237
1333
|
const diff = semver.diff(current, version);
|
|
1238
|
-
if (diff === "major" || diff === "premajor") return
|
|
1239
|
-
if (diff === "minor" || diff === "preminor") return
|
|
1240
|
-
return
|
|
1334
|
+
if (diff === "major" || diff === "premajor") return chalk15.red;
|
|
1335
|
+
if (diff === "minor" || diff === "preminor") return chalk15.yellow;
|
|
1336
|
+
return chalk15.green;
|
|
1241
1337
|
}
|
|
1242
1338
|
function pad(raw, colored, width) {
|
|
1243
1339
|
return colored + " ".repeat(Math.max(0, width - raw.length));
|
|
1244
1340
|
}
|
|
1245
1341
|
function dot(selected) {
|
|
1246
|
-
return selected ?
|
|
1342
|
+
return selected ? chalk15.green("\u25CF") : chalk15.dim("\u25CB");
|
|
1247
1343
|
}
|
|
1248
1344
|
function renderHeader(w) {
|
|
1249
1345
|
const header = [
|
|
1250
1346
|
" ",
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1347
|
+
chalk15.bold("Package".padEnd(w.name)),
|
|
1348
|
+
chalk15.bold("Current".padEnd(w.current)),
|
|
1349
|
+
chalk15.bold(" Wanted".padEnd(w.wanted + 2)),
|
|
1350
|
+
chalk15.bold(" Latest".padEnd(w.latest + 2)),
|
|
1351
|
+
chalk15.bold(" Next/RC".padEnd(w.next + 2))
|
|
1256
1352
|
].join(" ");
|
|
1257
1353
|
const totalWidth = w.name + w.current + w.wanted + w.latest + w.next + 24;
|
|
1258
1354
|
return `${header}
|
|
1259
|
-
${
|
|
1355
|
+
${chalk15.gray("\u2500".repeat(totalWidth))}`;
|
|
1260
1356
|
}
|
|
1261
1357
|
function renderRow(dep, selection, active, w) {
|
|
1262
|
-
const pointer = active ?
|
|
1358
|
+
const pointer = active ? chalk15.cyan("\u276F") : " ";
|
|
1263
1359
|
const rawName = dep.name;
|
|
1264
|
-
const name = active ?
|
|
1360
|
+
const name = active ? chalk15.white(rawName) : chalk15.gray(rawName);
|
|
1265
1361
|
const rawCurrent = dep.current ?? "-";
|
|
1266
|
-
const current =
|
|
1362
|
+
const current = chalk15.gray(rawCurrent);
|
|
1267
1363
|
const rawWanted = dep.wanted ?? "-";
|
|
1268
|
-
const wantedColorFn = dep.wanted ? versionColor(dep.wanted, dep.current) :
|
|
1364
|
+
const wantedColorFn = dep.wanted ? versionColor(dep.wanted, dep.current) : chalk15.gray;
|
|
1269
1365
|
const wantedDot = dep.wanted ? dot(selection === 0) : " ";
|
|
1270
1366
|
const wanted = `${wantedDot} ${pad(rawWanted, wantedColorFn(rawWanted), w.wanted)}`;
|
|
1271
1367
|
const rawLatest = dep.latest ?? "-";
|
|
1272
|
-
const latestColorFn = dep.latest ? versionColor(dep.latest, dep.current) :
|
|
1368
|
+
const latestColorFn = dep.latest ? versionColor(dep.latest, dep.current) : chalk15.gray;
|
|
1273
1369
|
const latestDot = dep.latest ? dot(selection === 1) : " ";
|
|
1274
1370
|
const latest = `${latestDot} ${pad(rawLatest, latestColorFn(rawLatest), w.latest)}`;
|
|
1275
1371
|
const rawNext = dep.next ?? "-";
|
|
1276
|
-
const nextColorFn = dep.next ? versionColor(dep.next, dep.current) :
|
|
1372
|
+
const nextColorFn = dep.next ? versionColor(dep.next, dep.current) : chalk15.gray;
|
|
1277
1373
|
const nextDot = dep.next ? dot(selection === 2) : " ";
|
|
1278
1374
|
const next = `${nextDot} ${pad(rawNext, nextColorFn(rawNext), w.next)}`;
|
|
1279
1375
|
return `${pointer} ${pad(rawName, name, w.name)} ${pad(rawCurrent, current, w.current)} ${wanted} ${latest} ${next}`;
|
|
@@ -1324,8 +1420,8 @@ function renderPage(rows, cursor, selections, w, pageSize) {
|
|
|
1324
1420
|
lines.push(renderRow(rows[i], selections[i], i === cursor, w));
|
|
1325
1421
|
}
|
|
1326
1422
|
if (total > pageSize) {
|
|
1327
|
-
if (start > 0) lines.unshift(
|
|
1328
|
-
if (end < total) lines.push(
|
|
1423
|
+
if (start > 0) lines.unshift(chalk15.dim(" \u2191 more"));
|
|
1424
|
+
if (end < total) lines.push(chalk15.dim(" \u2193 more"));
|
|
1329
1425
|
}
|
|
1330
1426
|
return lines.join("\n");
|
|
1331
1427
|
}
|
|
@@ -1374,7 +1470,7 @@ var updoPrompt = createPrompt((config2, done) => {
|
|
|
1374
1470
|
const header = renderHeader(w);
|
|
1375
1471
|
const page = renderPage(rows, cursor, selections.current, w, 20);
|
|
1376
1472
|
const selectedCount = selections.current.filter((s) => s >= 0).length;
|
|
1377
|
-
const status =
|
|
1473
|
+
const status = chalk15.gray(` ${selectedCount} selected \u2191/\u2193 navigate space cycle version enter confirm`);
|
|
1378
1474
|
return `${header}
|
|
1379
1475
|
${page}
|
|
1380
1476
|
${status}`;
|
|
@@ -1382,11 +1478,11 @@ ${status}`;
|
|
|
1382
1478
|
async function interactiveSelect(deps) {
|
|
1383
1479
|
const updatable = deps.filter((d) => d.updateAvailable);
|
|
1384
1480
|
if (updatable.length === 0) {
|
|
1385
|
-
console.log(
|
|
1481
|
+
console.log(chalk15.green("\nAll packages are up to date!"));
|
|
1386
1482
|
return [];
|
|
1387
1483
|
}
|
|
1388
1484
|
if (!process.stdout.isTTY) {
|
|
1389
|
-
console.log(
|
|
1485
|
+
console.log(chalk15.yellow("Non-interactive environment detected, skipping selection."));
|
|
1390
1486
|
return [];
|
|
1391
1487
|
}
|
|
1392
1488
|
try {
|
|
@@ -1400,24 +1496,24 @@ async function interactiveSelect(deps) {
|
|
|
1400
1496
|
}
|
|
1401
1497
|
|
|
1402
1498
|
// src/lib/updo/renderTable.ts
|
|
1403
|
-
import
|
|
1499
|
+
import chalk16 from "chalk";
|
|
1404
1500
|
import semver2 from "semver";
|
|
1405
1501
|
function versionColor2(version, current) {
|
|
1406
|
-
if (!version || !current) return
|
|
1407
|
-
if (version === current) return
|
|
1502
|
+
if (!version || !current) return chalk16.gray(version ?? "-");
|
|
1503
|
+
if (version === current) return chalk16.gray(version);
|
|
1408
1504
|
const diff = semver2.diff(current, version);
|
|
1409
|
-
if (diff === "major" || diff === "premajor") return
|
|
1410
|
-
if (diff === "minor" || diff === "preminor") return
|
|
1411
|
-
return
|
|
1505
|
+
if (diff === "major" || diff === "premajor") return chalk16.red(version);
|
|
1506
|
+
if (diff === "minor" || diff === "preminor") return chalk16.yellow(version);
|
|
1507
|
+
return chalk16.green(version);
|
|
1412
1508
|
}
|
|
1413
1509
|
var columns = [
|
|
1414
1510
|
{
|
|
1415
|
-
color: (_v, dep) => dep.updateAvailable ?
|
|
1511
|
+
color: (_v, dep) => dep.updateAvailable ? chalk16.white(dep.name) : chalk16.gray(dep.name),
|
|
1416
1512
|
header: "Package",
|
|
1417
1513
|
value: (dep) => dep.name
|
|
1418
1514
|
},
|
|
1419
1515
|
{
|
|
1420
|
-
color: (_v, dep) =>
|
|
1516
|
+
color: (_v, dep) => chalk16.gray(dep.current ?? "-"),
|
|
1421
1517
|
header: "Current",
|
|
1422
1518
|
value: (dep) => dep.current ?? "-"
|
|
1423
1519
|
},
|
|
@@ -1437,7 +1533,7 @@ var columns = [
|
|
|
1437
1533
|
value: (dep) => dep.next ?? "-"
|
|
1438
1534
|
},
|
|
1439
1535
|
{
|
|
1440
|
-
color: (_v, dep) =>
|
|
1536
|
+
color: (_v, dep) => chalk16.gray(dep.depTypes.join(", ")),
|
|
1441
1537
|
header: "Type",
|
|
1442
1538
|
value: (dep) => dep.depTypes.join(", ")
|
|
1443
1539
|
}
|
|
@@ -1445,7 +1541,7 @@ var columns = [
|
|
|
1445
1541
|
function renderTable(deps) {
|
|
1446
1542
|
const updatable = deps.filter((d) => d.updateAvailable);
|
|
1447
1543
|
if (updatable.length === 0) {
|
|
1448
|
-
console.log(
|
|
1544
|
+
console.log(chalk16.green("\nAll packages are up to date!"));
|
|
1449
1545
|
return;
|
|
1450
1546
|
}
|
|
1451
1547
|
const widths = columns.map((col) => {
|
|
@@ -1455,14 +1551,14 @@ function renderTable(deps) {
|
|
|
1455
1551
|
}
|
|
1456
1552
|
return Math.max(col.header.length, maxData);
|
|
1457
1553
|
});
|
|
1458
|
-
const header = columns.map((col, i) =>
|
|
1554
|
+
const header = columns.map((col, i) => chalk16.bold(col.header.padEnd(widths[i]))).join(" ");
|
|
1459
1555
|
console.log(`
|
|
1460
1556
|
${header}`);
|
|
1461
1557
|
let totalWidth = -2;
|
|
1462
1558
|
for (const w of widths) {
|
|
1463
1559
|
totalWidth += w + 2;
|
|
1464
1560
|
}
|
|
1465
|
-
console.log(
|
|
1561
|
+
console.log(chalk16.gray("\u2500".repeat(totalWidth)));
|
|
1466
1562
|
for (const dep of updatable) {
|
|
1467
1563
|
const row = columns.map((col, i) => {
|
|
1468
1564
|
const raw = col.value(dep);
|
|
@@ -1522,29 +1618,29 @@ function resolveVersions(deps, registry, installedVersions) {
|
|
|
1522
1618
|
}
|
|
1523
1619
|
|
|
1524
1620
|
// src/lib/updo/runUpdo.ts
|
|
1525
|
-
import
|
|
1621
|
+
import chalk17 from "chalk";
|
|
1526
1622
|
async function runUpdo(pm, _options = {}) {
|
|
1527
1623
|
const cwd = INIT_CWD();
|
|
1528
1624
|
const workspaces = pm.listWorkspaces();
|
|
1529
1625
|
const workspaceNames = new Set(workspaces.map((ws) => ws.name));
|
|
1530
|
-
console.log(
|
|
1626
|
+
console.log(chalk17.gray("Scanning workspace dependencies..."));
|
|
1531
1627
|
const declaredDeps = collectWorkspaceDeps(cwd, workspaces, workspaceNames);
|
|
1532
|
-
console.log(
|
|
1533
|
-
console.log(
|
|
1628
|
+
console.log(chalk17.gray(` Found ${declaredDeps.size} unique dependencies across ${workspaces.length} workspaces`));
|
|
1629
|
+
console.log(chalk17.gray("Fetching registry info..."));
|
|
1534
1630
|
const registryInfo = await fetchAllRegistryInfo([...declaredDeps.keys()]);
|
|
1535
|
-
console.log(
|
|
1631
|
+
console.log(chalk17.gray("Reading installed versions..."));
|
|
1536
1632
|
const installedVersions = pm.listInstalledVersions();
|
|
1537
1633
|
const resolved = resolveVersions(declaredDeps, registryInfo, installedVersions);
|
|
1538
1634
|
const updates = await interactiveSelect(resolved);
|
|
1539
1635
|
if (updates.length === 0) {
|
|
1540
|
-
console.log(
|
|
1636
|
+
console.log(chalk17.gray("No updates selected."));
|
|
1541
1637
|
return 0;
|
|
1542
1638
|
}
|
|
1543
|
-
console.log(
|
|
1639
|
+
console.log(chalk17.gray(`
|
|
1544
1640
|
Applying ${updates.length} updates...`));
|
|
1545
1641
|
const modified = applyUpdates(cwd, workspaces, updates);
|
|
1546
|
-
console.log(
|
|
1547
|
-
console.log(
|
|
1642
|
+
console.log(chalk17.gray(` Modified ${modified} package.json files`));
|
|
1643
|
+
console.log(chalk17.gray("Installing updated dependencies..."));
|
|
1548
1644
|
return runSteps("Updo", [
|
|
1549
1645
|
pm.install(),
|
|
1550
1646
|
pm.dedupe()
|
|
@@ -1575,6 +1671,7 @@ export {
|
|
|
1575
1671
|
defaultBuildConfig,
|
|
1576
1672
|
defaultReadFileSyncOptions,
|
|
1577
1673
|
deleteGlob,
|
|
1674
|
+
deprecationMigrate,
|
|
1578
1675
|
detectDuplicateDependencies,
|
|
1579
1676
|
detectWorkspaceCycles,
|
|
1580
1677
|
empty,
|