@prnv/tuck 1.5.2 → 1.6.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/index.js +181 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -555,7 +555,7 @@ import { join, dirname } from "path";
|
|
|
555
555
|
import { readFileSync } from "fs";
|
|
556
556
|
import { fileURLToPath } from "url";
|
|
557
557
|
import figures4 from "figures";
|
|
558
|
-
var __dirname, packageJsonPath, VERSION_VALUE, VERSION, DESCRIPTION, HOME_DIR, DEFAULT_TUCK_DIR, MANIFEST_FILE, CONFIG_FILE, BACKUP_DIR, FILES_DIR, CATEGORIES;
|
|
558
|
+
var __dirname, packageJsonPath, VERSION_VALUE, VERSION, DESCRIPTION, APP_NAME, HOME_DIR, DEFAULT_TUCK_DIR, MANIFEST_FILE, CONFIG_FILE, BACKUP_DIR, FILES_DIR, CATEGORIES;
|
|
559
559
|
var init_constants = __esm({
|
|
560
560
|
"src/constants.ts"() {
|
|
561
561
|
"use strict";
|
|
@@ -563,12 +563,13 @@ var init_constants = __esm({
|
|
|
563
563
|
packageJsonPath = join(__dirname, "..", "package.json");
|
|
564
564
|
VERSION_VALUE = "1.0.0";
|
|
565
565
|
try {
|
|
566
|
-
const
|
|
567
|
-
VERSION_VALUE =
|
|
566
|
+
const pkg2 = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
567
|
+
VERSION_VALUE = pkg2.version;
|
|
568
568
|
} catch {
|
|
569
569
|
}
|
|
570
570
|
VERSION = VERSION_VALUE;
|
|
571
571
|
DESCRIPTION = "Modern dotfiles manager with a beautiful CLI";
|
|
572
|
+
APP_NAME = "tuck";
|
|
572
573
|
HOME_DIR = homedir();
|
|
573
574
|
DEFAULT_TUCK_DIR = join(HOME_DIR, ".tuck");
|
|
574
575
|
MANIFEST_FILE = ".tuckmanifest.json";
|
|
@@ -6322,7 +6323,7 @@ var init_sync = __esm({
|
|
|
6322
6323
|
|
|
6323
6324
|
// src/index.ts
|
|
6324
6325
|
import { Command as Command16 } from "commander";
|
|
6325
|
-
import
|
|
6326
|
+
import chalk6 from "chalk";
|
|
6326
6327
|
|
|
6327
6328
|
// src/commands/init.ts
|
|
6328
6329
|
init_ui();
|
|
@@ -10723,13 +10724,155 @@ init_secrets2();
|
|
|
10723
10724
|
// src/index.ts
|
|
10724
10725
|
init_errors();
|
|
10725
10726
|
init_constants();
|
|
10727
|
+
|
|
10728
|
+
// src/lib/updater.ts
|
|
10729
|
+
init_constants();
|
|
10730
|
+
import updateNotifier from "update-notifier";
|
|
10731
|
+
import { execSync, spawnSync } from "child_process";
|
|
10732
|
+
import chalk5 from "chalk";
|
|
10733
|
+
import boxen3 from "boxen";
|
|
10734
|
+
import { createInterface } from "readline";
|
|
10735
|
+
var pkg = {
|
|
10736
|
+
name: "@prnv/tuck",
|
|
10737
|
+
version: VERSION
|
|
10738
|
+
};
|
|
10739
|
+
var detectPackageManager = () => {
|
|
10740
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
10741
|
+
if (userAgent.includes("pnpm")) {
|
|
10742
|
+
return "pnpm";
|
|
10743
|
+
}
|
|
10744
|
+
try {
|
|
10745
|
+
const pnpmList = execSync("pnpm list -g --depth=0 2>/dev/null", {
|
|
10746
|
+
encoding: "utf-8",
|
|
10747
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
10748
|
+
});
|
|
10749
|
+
if (pnpmList.includes("@prnv/tuck")) {
|
|
10750
|
+
return "pnpm";
|
|
10751
|
+
}
|
|
10752
|
+
} catch {
|
|
10753
|
+
}
|
|
10754
|
+
return "npm";
|
|
10755
|
+
};
|
|
10756
|
+
var getUpdateCommand = (packageManager) => {
|
|
10757
|
+
if (packageManager === "pnpm") {
|
|
10758
|
+
return "pnpm update -g @prnv/tuck";
|
|
10759
|
+
}
|
|
10760
|
+
return "npm update -g @prnv/tuck";
|
|
10761
|
+
};
|
|
10762
|
+
var waitForEnterOrCancel = () => {
|
|
10763
|
+
return new Promise((resolve2) => {
|
|
10764
|
+
const rl = createInterface({
|
|
10765
|
+
input: process.stdin,
|
|
10766
|
+
output: process.stdout
|
|
10767
|
+
});
|
|
10768
|
+
rl.on("close", () => {
|
|
10769
|
+
resolve2(false);
|
|
10770
|
+
});
|
|
10771
|
+
rl.on("line", () => {
|
|
10772
|
+
rl.close();
|
|
10773
|
+
resolve2(true);
|
|
10774
|
+
});
|
|
10775
|
+
process.on("SIGINT", () => {
|
|
10776
|
+
rl.close();
|
|
10777
|
+
resolve2(false);
|
|
10778
|
+
});
|
|
10779
|
+
});
|
|
10780
|
+
};
|
|
10781
|
+
var executeUpdate = (packageManager) => {
|
|
10782
|
+
const command = getUpdateCommand(packageManager);
|
|
10783
|
+
console.log(chalk5.dim(`
|
|
10784
|
+
Updating ${APP_NAME} via ${packageManager}...`));
|
|
10785
|
+
try {
|
|
10786
|
+
const result = spawnSync(packageManager, ["update", "-g", "@prnv/tuck"], {
|
|
10787
|
+
stdio: "inherit",
|
|
10788
|
+
shell: true
|
|
10789
|
+
});
|
|
10790
|
+
if (result.status === 0) {
|
|
10791
|
+
console.log(chalk5.green(`
|
|
10792
|
+
Successfully updated ${APP_NAME}!`));
|
|
10793
|
+
console.log(chalk5.dim("Restart tuck to use the new version.\n"));
|
|
10794
|
+
return true;
|
|
10795
|
+
} else {
|
|
10796
|
+
console.log(chalk5.red("\nUpdate failed."));
|
|
10797
|
+
console.log(chalk5.dim(`Run manually: ${command}
|
|
10798
|
+
`));
|
|
10799
|
+
return false;
|
|
10800
|
+
}
|
|
10801
|
+
} catch (error) {
|
|
10802
|
+
console.log(chalk5.red("\nUpdate failed."));
|
|
10803
|
+
console.log(chalk5.dim(`Run manually: ${command}
|
|
10804
|
+
`));
|
|
10805
|
+
return false;
|
|
10806
|
+
}
|
|
10807
|
+
};
|
|
10808
|
+
var shouldSkipUpdateCheck = () => {
|
|
10809
|
+
if (process.env.CI) {
|
|
10810
|
+
return true;
|
|
10811
|
+
}
|
|
10812
|
+
const execPath = process.env.npm_execpath || "";
|
|
10813
|
+
if (execPath.includes("npx")) {
|
|
10814
|
+
return true;
|
|
10815
|
+
}
|
|
10816
|
+
if (process.env.NO_UPDATE_CHECK) {
|
|
10817
|
+
return true;
|
|
10818
|
+
}
|
|
10819
|
+
if (!process.stdin.isTTY) {
|
|
10820
|
+
return true;
|
|
10821
|
+
}
|
|
10822
|
+
return false;
|
|
10823
|
+
};
|
|
10824
|
+
var checkForUpdates = async () => {
|
|
10825
|
+
if (shouldSkipUpdateCheck()) {
|
|
10826
|
+
return;
|
|
10827
|
+
}
|
|
10828
|
+
const notifier = updateNotifier({
|
|
10829
|
+
pkg,
|
|
10830
|
+
updateCheckInterval: 1e3 * 60 * 60 * 24
|
|
10831
|
+
// 24 hours
|
|
10832
|
+
});
|
|
10833
|
+
if (!notifier.update || notifier.update.latest === VERSION) {
|
|
10834
|
+
return;
|
|
10835
|
+
}
|
|
10836
|
+
const { latest } = notifier.update;
|
|
10837
|
+
const packageManager = detectPackageManager();
|
|
10838
|
+
const updateCommand = getUpdateCommand(packageManager);
|
|
10839
|
+
const message = [
|
|
10840
|
+
"",
|
|
10841
|
+
chalk5.bold(`Update available: ${chalk5.red(VERSION)} ${chalk5.dim("->")} ${chalk5.green(latest)}`),
|
|
10842
|
+
"",
|
|
10843
|
+
chalk5.dim("Press Enter to update, or Ctrl+C to skip"),
|
|
10844
|
+
""
|
|
10845
|
+
].join("\n");
|
|
10846
|
+
console.log(
|
|
10847
|
+
boxen3(message, {
|
|
10848
|
+
padding: { top: 0, bottom: 0, left: 2, right: 2 },
|
|
10849
|
+
margin: { top: 1, bottom: 0, left: 0, right: 0 },
|
|
10850
|
+
borderStyle: "round",
|
|
10851
|
+
borderColor: "cyan",
|
|
10852
|
+
textAlignment: "center"
|
|
10853
|
+
})
|
|
10854
|
+
);
|
|
10855
|
+
const shouldUpdate = await waitForEnterOrCancel();
|
|
10856
|
+
if (shouldUpdate) {
|
|
10857
|
+
const success = executeUpdate(packageManager);
|
|
10858
|
+
if (success) {
|
|
10859
|
+
process.exit(0);
|
|
10860
|
+
}
|
|
10861
|
+
} else {
|
|
10862
|
+
console.log(chalk5.dim(`
|
|
10863
|
+
Skipped. Run '${updateCommand}' to update later.
|
|
10864
|
+
`));
|
|
10865
|
+
}
|
|
10866
|
+
};
|
|
10867
|
+
|
|
10868
|
+
// src/index.ts
|
|
10726
10869
|
init_banner();
|
|
10727
10870
|
init_paths();
|
|
10728
10871
|
init_manifest();
|
|
10729
10872
|
init_git();
|
|
10730
10873
|
var program = new Command16();
|
|
10731
10874
|
program.name("tuck").description(DESCRIPTION).version(VERSION, "-v, --version", "Display version number").configureOutput({
|
|
10732
|
-
outputError: (str, write) => write(
|
|
10875
|
+
outputError: (str, write) => write(chalk6.red(str))
|
|
10733
10876
|
}).addHelpText("before", customHelp(VERSION)).helpOption("-h, --help", "Display this help message").showHelpAfterError(false);
|
|
10734
10877
|
program.addCommand(initCommand);
|
|
10735
10878
|
program.addCommand(addCommand);
|
|
@@ -10750,12 +10893,12 @@ var runDefaultAction = async () => {
|
|
|
10750
10893
|
const tuckDir = getTuckDir();
|
|
10751
10894
|
if (!await pathExists(tuckDir)) {
|
|
10752
10895
|
miniBanner();
|
|
10753
|
-
console.log(
|
|
10754
|
-
console.log(
|
|
10755
|
-
console.log(
|
|
10896
|
+
console.log(chalk6.bold("Get started with tuck:\n"));
|
|
10897
|
+
console.log(chalk6.cyan(" tuck init") + chalk6.dim(" - Set up tuck and create a GitHub repo"));
|
|
10898
|
+
console.log(chalk6.cyan(" tuck scan") + chalk6.dim(" - Find dotfiles to track"));
|
|
10756
10899
|
console.log();
|
|
10757
|
-
console.log(
|
|
10758
|
-
console.log(
|
|
10900
|
+
console.log(chalk6.dim("On a new machine:"));
|
|
10901
|
+
console.log(chalk6.cyan(" tuck apply <username>") + chalk6.dim(" - Apply your dotfiles"));
|
|
10759
10902
|
console.log();
|
|
10760
10903
|
return;
|
|
10761
10904
|
}
|
|
@@ -10764,38 +10907,38 @@ var runDefaultAction = async () => {
|
|
|
10764
10907
|
const trackedCount = Object.keys(manifest.files).length;
|
|
10765
10908
|
const gitStatus = await getStatus(tuckDir);
|
|
10766
10909
|
miniBanner();
|
|
10767
|
-
console.log(
|
|
10768
|
-
console.log(` Tracked files: ${
|
|
10910
|
+
console.log(chalk6.bold("Status:\n"));
|
|
10911
|
+
console.log(` Tracked files: ${chalk6.cyan(trackedCount.toString())}`);
|
|
10769
10912
|
const pendingChanges = gitStatus.modified.length + gitStatus.staged.length;
|
|
10770
10913
|
if (pendingChanges > 0) {
|
|
10771
|
-
console.log(` Pending changes: ${
|
|
10914
|
+
console.log(` Pending changes: ${chalk6.yellow(pendingChanges.toString())}`);
|
|
10772
10915
|
} else {
|
|
10773
|
-
console.log(` Pending changes: ${
|
|
10916
|
+
console.log(` Pending changes: ${chalk6.dim("none")}`);
|
|
10774
10917
|
}
|
|
10775
10918
|
if (gitStatus.ahead > 0) {
|
|
10776
|
-
console.log(` Commits to push: ${
|
|
10919
|
+
console.log(` Commits to push: ${chalk6.yellow(gitStatus.ahead.toString())}`);
|
|
10777
10920
|
}
|
|
10778
10921
|
console.log();
|
|
10779
|
-
console.log(
|
|
10922
|
+
console.log(chalk6.bold("Next steps:\n"));
|
|
10780
10923
|
if (trackedCount === 0) {
|
|
10781
|
-
console.log(
|
|
10782
|
-
console.log(
|
|
10924
|
+
console.log(chalk6.cyan(" tuck scan") + chalk6.dim(" - Find dotfiles to track"));
|
|
10925
|
+
console.log(chalk6.cyan(" tuck add <file>") + chalk6.dim(" - Track a specific file"));
|
|
10783
10926
|
} else if (pendingChanges > 0) {
|
|
10784
|
-
console.log(
|
|
10785
|
-
console.log(
|
|
10927
|
+
console.log(chalk6.cyan(" tuck sync") + chalk6.dim(" - Commit and push your changes"));
|
|
10928
|
+
console.log(chalk6.cyan(" tuck diff") + chalk6.dim(" - Preview what changed"));
|
|
10786
10929
|
} else if (gitStatus.ahead > 0) {
|
|
10787
|
-
console.log(
|
|
10930
|
+
console.log(chalk6.cyan(" tuck push") + chalk6.dim(" - Push commits to GitHub"));
|
|
10788
10931
|
} else {
|
|
10789
|
-
console.log(
|
|
10932
|
+
console.log(chalk6.dim(" All synced! Your dotfiles are up to date."));
|
|
10790
10933
|
console.log();
|
|
10791
|
-
console.log(
|
|
10792
|
-
console.log(
|
|
10934
|
+
console.log(chalk6.cyan(" tuck scan") + chalk6.dim(" - Find more dotfiles to track"));
|
|
10935
|
+
console.log(chalk6.cyan(" tuck list") + chalk6.dim(" - See tracked files"));
|
|
10793
10936
|
}
|
|
10794
10937
|
console.log();
|
|
10795
10938
|
} catch {
|
|
10796
10939
|
miniBanner();
|
|
10797
|
-
console.log(
|
|
10798
|
-
console.log(
|
|
10940
|
+
console.log(chalk6.yellow("Tuck directory exists but may be corrupted."));
|
|
10941
|
+
console.log(chalk6.dim("Run `tuck init` to reinitialize."));
|
|
10799
10942
|
console.log();
|
|
10800
10943
|
}
|
|
10801
10944
|
};
|
|
@@ -10804,9 +10947,16 @@ process.on("uncaughtException", handleError);
|
|
|
10804
10947
|
process.on("unhandledRejection", (reason) => {
|
|
10805
10948
|
handleError(reason instanceof Error ? reason : new Error(String(reason)));
|
|
10806
10949
|
});
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
}
|
|
10950
|
+
var isHelpOrVersion = process.argv.includes("--help") || process.argv.includes("-h") || process.argv.includes("--version") || process.argv.includes("-v");
|
|
10951
|
+
var main = async () => {
|
|
10952
|
+
if (!isHelpOrVersion) {
|
|
10953
|
+
await checkForUpdates();
|
|
10954
|
+
}
|
|
10955
|
+
if (!hasCommand && !isHelpOrVersion) {
|
|
10956
|
+
await runDefaultAction();
|
|
10957
|
+
} else {
|
|
10958
|
+
await program.parseAsync(process.argv);
|
|
10959
|
+
}
|
|
10960
|
+
};
|
|
10961
|
+
main().catch(handleError);
|
|
10812
10962
|
//# sourceMappingURL=index.js.map
|