@shell-shock/plugin-upgrade 0.1.4 → 0.1.6

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.
@@ -1,30 +1,41 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
3
+ let defu = require("defu");
4
+ defu = require_rolldown_runtime.__toESM(defu);
3
5
  let __alloy_js_core = require("@alloy-js/core");
4
6
  let __alloy_js_typescript = require("@alloy-js/typescript");
5
7
  let __powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
8
+ let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
6
9
  let __powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
7
10
  let __powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
8
- let defu = require("defu");
9
- defu = require_rolldown_runtime.__toESM(defu);
10
11
 
11
12
  //#region src/components/upgrade-builtin.tsx
12
13
  /**
13
14
  * The `locatePackageJson` handler function declaration code for the Shell Shock project.
14
15
  */
15
16
  function LocatePackageJsonFunctionDeclaration() {
17
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
16
18
  return [
17
19
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
18
20
  "export": true,
19
21
  name: "LocatePackageJsonOptions",
20
22
  doc: "Options for the `locatePackageJson` handler function.",
21
23
  get children() {
22
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
23
- name: "cwd",
24
- optional: true,
25
- type: "string",
26
- doc: "The current working directory to use. If not provided, the process's current working directory will be used."
27
- });
24
+ return [
25
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
26
+ name: "cwd",
27
+ optional: true,
28
+ type: "string",
29
+ doc: "The current working directory to use. If not provided, the process's current working directory will be used."
30
+ }),
31
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
32
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
33
+ name: "isDependencyRequired",
34
+ optional: true,
35
+ type: "boolean",
36
+ doc: "Whether to only locate a package.json file if it contains the application as a dependency. If set to `true`, the function will check if the located package.json file has the application listed as a dependency in its dependencies, devDependencies, peerDependencies, or optionalDependencies before returning its path. This can be useful in monorepo setups where multiple package.json files may exist, but only the one that includes the application as a dependency is relevant for upgrade purposes."
37
+ })
38
+ ];
28
39
  }
29
40
  }),
30
41
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
@@ -68,11 +79,32 @@ function LocatePackageJsonFunctionDeclaration() {
68
79
  }),
69
80
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
70
81
  __alloy_js_core.code`while (parentPath !== currentPath && currentPath !== homePath && currentPath !== tempPath) { `,
82
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
83
+ "const": true,
84
+ name: "packageJsonPath",
85
+ initializer: __alloy_js_core.code`join(currentPath, "package.json"); `
86
+ }),
71
87
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
72
- condition: __alloy_js_core.code`existsSync(join(currentPath, "package.json"))`,
73
- children: __alloy_js_core.code`return join(currentPath, "package.json"); `
88
+ condition: __alloy_js_core.code`existsSync(packageJsonPath)`,
89
+ get children() {
90
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
91
+ condition: __alloy_js_core.code`options.isDependencyRequired`,
92
+ get children() {
93
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
94
+ "const": true,
95
+ name: "packageJson",
96
+ initializer: __alloy_js_core.code`JSON.parse(await readFile(packageJsonPath, "utf8")); `
97
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
98
+ get condition() {
99
+ return __alloy_js_core.code`Object.keys(packageJson.dependencies || {}).concat(Object.keys(packageJson.devDependencies || {})).concat(Object.keys(packageJson.peerDependencies || {})).concat(Object.keys(packageJson.optionalDependencies || {})).some(dep => dep === "${context.packageJson.name}" || dep.startsWith("${context.packageJson.name}@"))`;
100
+ },
101
+ children: __alloy_js_core.code`return packageJsonPath; `
102
+ })];
103
+ }
104
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`return packageJsonPath; ` })];
105
+ }
74
106
  }),
75
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`currentPath = pathParent;
107
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`currentPath = parentPath;
76
108
  parentPath = resolve(currentPath, ".."); ` }),
77
109
  __alloy_js_core.code` }
78
110
 
@@ -117,7 +149,6 @@ function LocateLockfileFunctionDeclaration() {
117
149
  }),
118
150
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
119
151
  "export": true,
120
- async: true,
121
152
  name: "locateLockfile",
122
153
  parameters: [{
123
154
  name: "options",
@@ -162,7 +193,7 @@ function LocateLockfileFunctionDeclaration() {
162
193
  condition: __alloy_js_core.code`lockfile`,
163
194
  children: __alloy_js_core.code`return lockfile; `
164
195
  }),
165
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`currentPath = pathParent;
196
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`currentPath = parentPath;
166
197
  parentPath = resolve(currentPath, ".."); ` }),
167
198
  __alloy_js_core.code` }
168
199
 
@@ -177,6 +208,15 @@ function LocateLockfileFunctionDeclaration() {
177
208
  */
178
209
  function GetPackageManagerFunctionDeclaration() {
179
210
  return [
211
+ __alloy_js_core.code`declare global {
212
+ var Bun: any;
213
+ namespace NodeJS {
214
+ interface ProcessVersions {
215
+ bun?: string;
216
+ }
217
+ }
218
+ } `,
219
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
180
220
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TypeDeclaration, {
181
221
  "export": true,
182
222
  name: "GetPackageManagerOptions",
@@ -207,7 +247,7 @@ function GetPackageManagerFunctionDeclaration() {
207
247
  type: "GetPackageManagerOptions",
208
248
  default: "{}"
209
249
  }],
210
- returnType: __alloy_js_core.code`Promise<"npm" | "yarn" | "deno" | "pnpm" | "bun">`,
250
+ returnType: __alloy_js_core.code`"npm" | "yarn" | "deno" | "pnpm" | "bun"`,
211
251
  get children() {
212
252
  return [
213
253
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
@@ -265,7 +305,7 @@ function GetPackageManagerFunctionDeclaration() {
265
305
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
266
306
  "const": true,
267
307
  name: "packageJsonPath",
268
- initializer: __alloy_js_core.code`locatePackageJson(options); `
308
+ initializer: __alloy_js_core.code`await locatePackageJson(options); `
269
309
  }),
270
310
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
271
311
  condition: __alloy_js_core.code`packageJsonPath && existsSync(packageJsonPath)`,
@@ -492,7 +532,7 @@ function FetchNpmPackageFunctionDeclaration() {
492
532
  name: "packageName",
493
533
  type: "string"
494
534
  }],
495
- returnType: __alloy_js_core.code`Promise<NpmPackage | undefined>`,
535
+ returnType: __alloy_js_core.code`NpmPackage | undefined`,
496
536
  get children() {
497
537
  return [
498
538
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
@@ -512,9 +552,10 @@ function FetchNpmPackageFunctionDeclaration() {
512
552
  ];
513
553
  }
514
554
  /**
515
- * The `getLatest` handler function declaration code for the Shell Shock project.
555
+ * The `getLatestVersion` handler function declaration code for the Shell Shock project.
516
556
  */
517
- function GetLatestFunctionDeclaration() {
557
+ function GetLatestVersionFunctionDeclaration() {
558
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
518
559
  return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
519
560
  heading: "Get the latest version of the application from the npm registry.",
520
561
  get children() {
@@ -531,45 +572,124 @@ function GetLatestFunctionDeclaration() {
531
572
  }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
532
573
  "export": true,
533
574
  async: true,
534
- name: "getLatest",
575
+ name: "getLatestVersion",
576
+ get parameters() {
577
+ return [{
578
+ name: "packageName",
579
+ default: `"${context.packageJson.name}"`
580
+ }];
581
+ },
582
+ returnType: __alloy_js_core.code`string | undefined`,
583
+ get children() {
584
+ return [
585
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
586
+ "const": true,
587
+ name: "result",
588
+ initializer: __alloy_js_core.code`await fetchNpmPackage(packageName); `
589
+ }),
590
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
591
+ __alloy_js_core.code`return result?.version; `
592
+ ];
593
+ }
594
+ })];
595
+ }
596
+ /**
597
+ * The `upgrade` handler function declaration code for the Shell Shock project.
598
+ */
599
+ function GetUpgradeCommandFunctionDeclaration() {
600
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
601
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
602
+ heading: "A function to get the upgrade command for a specific package manager.",
603
+ get children() {
604
+ return [
605
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to get the appropriate upgrade command for a specific package manager. It can be used in the CLI upgrade command to determine which command to run based on the package manager being used by the application.` }),
606
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
607
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocParam, {
608
+ name: "packageManager",
609
+ children: `The name of the package manager to get the upgrade command for. This should be one of "npm", "yarn", "pnpm", "deno", or "bun".`
610
+ }),
611
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocParam, {
612
+ name: "cwd",
613
+ children: `The current working directory to use when determining the upgrade command. This can be used to locate the appropriate package.json and lockfile to determine how to run the upgrade command. If not provided, the process's current working directory will be used.`
614
+ }),
615
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `An array of strings representing the command and its arguments to run in order to upgrade the application dependencies using the specified package manager.` })
616
+ ];
617
+ }
618
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
619
+ "export": true,
620
+ async: true,
621
+ name: "getUpgradeCommand",
535
622
  parameters: [{
536
- name: "packageName",
623
+ name: "packageManager",
537
624
  type: "string"
625
+ }, {
626
+ name: "cwd",
627
+ type: "string",
628
+ default: "process.cwd()"
538
629
  }],
630
+ returnType: "string[]",
539
631
  get children() {
540
632
  return [
541
633
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
542
634
  "const": true,
543
- name: "package",
544
- initializer: __alloy_js_core.code`await fetchNpmPackage(packageName); `
635
+ name: "version",
636
+ get initializer() {
637
+ return __alloy_js_core.code`(await getLatestVersion("${context.packageJson.name}")) || "latest"; `;
638
+ }
545
639
  }),
546
640
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
547
- __alloy_js_core.code`return package?.version; `
641
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
642
+ condition: __alloy_js_core.code`packageManager === "yarn"`,
643
+ get children() {
644
+ return __alloy_js_core.code`return ["upgrade", \`${context.packageJson.name}@\${version}\`]; `;
645
+ }
646
+ }),
647
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
648
+ condition: __alloy_js_core.code`packageManager === "pnpm"`,
649
+ get children() {
650
+ return __alloy_js_core.code`return ["update", \`${context.packageJson.name}@\${version}\`]; `;
651
+ }
652
+ }),
653
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
654
+ condition: __alloy_js_core.code`packageManager === "deno"`,
655
+ get children() {
656
+ return __alloy_js_core.code`return ["outdated", "--update", \`${context.packageJson.name}@\${version}\`]; `;
657
+ }
658
+ }),
659
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
660
+ condition: __alloy_js_core.code`packageManager === "bun"`,
661
+ get children() {
662
+ return __alloy_js_core.code`return ["update", "--save", \`${context.packageJson.name}@\${version}\`]; `;
663
+ }
664
+ }),
665
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { get children() {
666
+ return __alloy_js_core.code`return ["update", "--save", "--bin-links", \`${context.packageJson.name}@\${version}\`]; `;
667
+ } })
548
668
  ];
549
669
  }
550
670
  })];
551
671
  }
552
672
  /**
553
- * The `install` handler function declaration code for the Shell Shock project.
673
+ * The `upgrade` handler function declaration code for the Shell Shock project.
554
674
  */
555
- function InstallFunctionDeclaration() {
675
+ function UpgradeFunctionDeclaration() {
556
676
  return [
557
677
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
558
- name: "InstallBaseOptions",
559
- doc: "Options for the `install` handler function.",
678
+ name: "UpgradeBaseOptions",
679
+ doc: "Options for the `upgrade` handler function.",
560
680
  get children() {
561
681
  return [
562
682
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
563
683
  name: "stdout",
564
684
  optional: true,
565
- type: "(string) => void",
685
+ type: "(data: string) => void",
566
686
  doc: "A callback function that is called with the stdout output of the command."
567
687
  }),
568
688
  (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
569
689
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
570
690
  name: "stderr",
571
691
  optional: true,
572
- type: "(string) => void",
692
+ type: "(err: string) => void",
573
693
  doc: "A callback function that is called with the stderr output of the command."
574
694
  })
575
695
  ];
@@ -578,32 +698,32 @@ function InstallFunctionDeclaration() {
578
698
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
579
699
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TypeDeclaration, {
580
700
  "export": true,
581
- name: "InstallOptions",
582
- doc: "Options for the `install` handler function.",
583
- children: __alloy_js_core.code`InstallBaseOptions & Parameters<typeof spawn>[2];`
701
+ name: "UpgradeOptions",
702
+ doc: "Options for the `upgrade` handler function.",
703
+ children: __alloy_js_core.code`UpgradeBaseOptions & GetPackageManagerOptions & Parameters<typeof spawn>[2];`
584
704
  }),
585
705
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
586
706
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
587
- heading: "Install the application dependencies.",
707
+ heading: "Upgrade the application dependencies.",
588
708
  get children() {
589
709
  return [
590
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to install the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are installed.` }),
710
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to upgrade the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are up-to-date.` }),
591
711
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
592
712
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocParam, {
593
713
  name: "options",
594
- children: `The options for the \`install\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
714
+ children: `The options for the \`upgrade\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
595
715
  }),
596
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `A promise that resolves when the installation of dependencies is complete.` })
716
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `A promise that resolves when the upgrade of dependencies is complete.` })
597
717
  ];
598
718
  }
599
719
  }),
600
720
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
601
721
  "export": true,
602
722
  async: true,
603
- name: "install",
723
+ name: "upgrade",
604
724
  parameters: [{
605
725
  name: "options",
606
- type: "InstallOptions",
726
+ type: "UpgradeOptions",
607
727
  default: "{}"
608
728
  }],
609
729
  get children() {
@@ -611,9 +731,15 @@ function InstallFunctionDeclaration() {
611
731
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
612
732
  "const": true,
613
733
  name: "packageManager",
614
- initializer: __alloy_js_core.code`getPackageManager(); `
734
+ initializer: __alloy_js_core.code`await getPackageManager(options); `
615
735
  }),
616
736
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
737
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
738
+ "const": true,
739
+ name: "args",
740
+ initializer: __alloy_js_core.code`await getUpgradeCommand(packageManager, options.cwd); `
741
+ }),
742
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
617
743
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
618
744
  "let": true,
619
745
  name: "output",
@@ -622,9 +748,9 @@ function InstallFunctionDeclaration() {
622
748
  (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
623
749
  __alloy_js_core.code`await spawn(
624
750
  \`\${packageManager}\${isWindows && packageManager !== "bun" ? ".cmd" : ""}\`,
625
- ["install"],
751
+ [args.join(" ")],
626
752
  {
627
- ...options
753
+ ...options,
628
754
  env: {
629
755
  ...options.env,
630
756
  ...(packageManager === "pnpm" ? { npm_config_strict_peer_dependencies: false } : null),
@@ -644,6 +770,240 @@ function InstallFunctionDeclaration() {
644
770
  ];
645
771
  }
646
772
  /**
773
+ * The `updateVersionCheckFile` handler function declaration code for the Shell Shock project.
774
+ */
775
+ function UpdateVersionCheckFileFunctionDeclaration() {
776
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
777
+ heading: "A helper function that updates the version check file.",
778
+ get children() {
779
+ return [
780
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to update the version check file with the current timestamp. It can be used in the CLI upgrade command to record the last time a check for updates was performed. The function writes a "version-check.json" file in the data directory, which contains a timestamp of the last check for updates.` }),
781
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
782
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `A promise that resolves to a boolean indicating whether a check for updates is required.` })
783
+ ];
784
+ }
785
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
786
+ "export": true,
787
+ async: true,
788
+ name: "updateVersionCheckFile",
789
+ returnType: "void",
790
+ get children() {
791
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
792
+ condition: __alloy_js_core.code`!existsSync(paths.data)`,
793
+ children: __alloy_js_core.code`await mkdir(paths.data, { recursive: true }); `
794
+ }), __alloy_js_core.code`await writeFile(join(paths.data, "version-check.json"), JSON.stringify({ timestamp: new Date().getTime() }), "utf8"); `];
795
+ }
796
+ })];
797
+ }
798
+ /**
799
+ * The `isCheckForUpdatesRequired` handler function declaration code for the Shell Shock project.
800
+ */
801
+ function IsCheckForUpdatesRequiredFunctionDeclaration() {
802
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
803
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
804
+ heading: "A helper function that verifies if a check for updates is required.",
805
+ get children() {
806
+ return [
807
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to determine if a check for updates is required based on the last time a check was performed. It can be used in the CLI upgrade command to avoid unnecessary checks for updates if one was recently performed. The function checks for the existence of a "version-check.json" file in the data directory, which contains a timestamp of the last check for updates. If the file does not exist or if the timestamp is older than a specified stale time, the function will return true, indicating that a check for updates is required. Otherwise, it will return false.` }),
808
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
809
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `A promise that resolves to a boolean indicating whether a check for updates is required.` })
810
+ ];
811
+ }
812
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
813
+ "export": true,
814
+ async: true,
815
+ name: "isCheckForUpdatesRequired",
816
+ get children() {
817
+ return [
818
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
819
+ condition: __alloy_js_core.code`!isInteractive || isCI || env.SKIP_VERSION_CHECK`,
820
+ children: __alloy_js_core.code`return false; `
821
+ }),
822
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
823
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
824
+ "const": true,
825
+ name: "filePath",
826
+ initializer: __alloy_js_core.code`join(paths.data, "version-check.json"); `
827
+ }),
828
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
829
+ condition: __alloy_js_core.code`existsSync(filePath)`,
830
+ get children() {
831
+ return [
832
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
833
+ "const": true,
834
+ name: "file",
835
+ type: "{ timestamp: number; }",
836
+ initializer: __alloy_js_core.code` JSON.parse(await readFile(filePath, "utf8")); `
837
+ }),
838
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
839
+ condition: __alloy_js_core.code`!file.timestamp`,
840
+ children: __alloy_js_core.code`await updateVersionCheckFile();
841
+ return true; `
842
+ }),
843
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
844
+ get condition() {
845
+ return __alloy_js_core.code`new Date().getTime() - file.timestamp < ${context.config.upgrade.staleTime}`;
846
+ },
847
+ children: __alloy_js_core.code`return false; `
848
+ })
849
+ ];
850
+ }
851
+ }),
852
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseClause, { children: __alloy_js_core.code`await updateVersionCheckFile();
853
+ return true; ` })
854
+ ];
855
+ }
856
+ })];
857
+ }
858
+ /**
859
+ * The `checkForUpdates` handler function declaration code for the Shell Shock project.
860
+ */
861
+ function CheckForUpdatesFunctionDeclaration() {
862
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
863
+ return [
864
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
865
+ "export": true,
866
+ name: "CheckForUpdatesOptions",
867
+ "extends": "GetPackageManagerOptions",
868
+ doc: "Options for the `checkForUpdates` handler function.",
869
+ get children() {
870
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
871
+ name: "force",
872
+ optional: true,
873
+ type: "boolean",
874
+ doc: "Whether to force a check for updates regardless of the last check timestamp. If set to `true`, the function will bypass the timestamp check and perform a check for updates, updating the timestamp in the process. This can be useful if you want to ensure that a check for updates is performed even if one was recently done, such as when the user explicitly requests it or when certain conditions are met that warrant an immediate check."
875
+ });
876
+ }
877
+ }),
878
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
879
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
880
+ name: "CheckForUpdatesBaseResult",
881
+ get children() {
882
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
883
+ name: "isError",
884
+ type: "boolean",
885
+ optional: true,
886
+ doc: "Indicates whether an error occurred while checking for updates."
887
+ });
888
+ }
889
+ }),
890
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
891
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
892
+ name: "CheckForUpdatesSuccessResult",
893
+ "extends": "CheckForUpdatesBaseResult",
894
+ get children() {
895
+ return [
896
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
897
+ name: "latestVersion",
898
+ type: "string",
899
+ doc: "The latest version of the application dependencies."
900
+ }),
901
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
902
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
903
+ name: "currentVersion",
904
+ type: "string",
905
+ doc: "The current version of the application dependencies."
906
+ }),
907
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
908
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
909
+ name: "isUpToDate",
910
+ type: "boolean",
911
+ doc: "Indicates whether the application dependencies are up-to-date."
912
+ }),
913
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
914
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
915
+ name: "package",
916
+ type: "NpmPackage",
917
+ optional: true,
918
+ doc: "The npm package that was checked for updates."
919
+ })
920
+ ];
921
+ }
922
+ }),
923
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
924
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
925
+ name: "CheckForUpdatesErrorResult",
926
+ "extends": "CheckForUpdatesBaseResult",
927
+ get children() {
928
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
929
+ name: "error",
930
+ type: "Error",
931
+ doc: "The error that occurred while checking for updates."
932
+ });
933
+ }
934
+ }),
935
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
936
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TypeDeclaration, {
937
+ "export": true,
938
+ name: "CheckForUpdatesResult",
939
+ doc: "The result for the `checkForUpdates` handler function.",
940
+ children: __alloy_js_core.code`CheckForUpdatesSuccessResult | CheckForUpdatesErrorResult;`
941
+ }),
942
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
943
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDoc, {
944
+ heading: "Check for updates to the application dependencies.",
945
+ get children() {
946
+ return [
947
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocRemarks, { children: `This function is used to check for updates to the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are up-to-date.` }),
948
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
949
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocParam, {
950
+ name: "options",
951
+ children: `The options for the \`checkForUpdates\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
952
+ }),
953
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TSDocReturns, { children: `A promise that resolves when the check for updates is complete or undefined if the check was not performed.` })
954
+ ];
955
+ }
956
+ }),
957
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
958
+ "export": true,
959
+ async: true,
960
+ name: "checkForUpdates",
961
+ parameters: [{
962
+ name: "options",
963
+ type: "CheckForUpdatesOptions",
964
+ default: "{}"
965
+ }],
966
+ returnType: "CheckForUpdatesResult",
967
+ get children() {
968
+ return [
969
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
970
+ condition: __alloy_js_core.code`!options.force && !(await isCheckForUpdatesRequired())`,
971
+ get children() {
972
+ return __alloy_js_core.code`return {
973
+ latestVersion: "${context.packageJson.version}",
974
+ currentVersion: "${context.packageJson.version}",
975
+ isUpToDate: true,
976
+ isError: false,
977
+ }; `;
978
+ }
979
+ }),
980
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
981
+ __alloy_js_core.code`try { `,
982
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
983
+ "const": true,
984
+ name: "pkg",
985
+ get initializer() {
986
+ return __alloy_js_core.code`await fetchNpmPackage("${context.packageJson.name}"); `;
987
+ }
988
+ }),
989
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
990
+ (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`
991
+ return {
992
+ latestVersion: pkg?.version || "${context.packageJson.version}",
993
+ currentVersion: "${context.packageJson.version}",
994
+ isUpToDate: pkg ? "${context.packageJson.version}" === pkg.version : true,
995
+ package: pkg,
996
+ isError: false,
997
+ };
998
+ } catch (err) {
999
+ return { isError: true, error: err instanceof Error ? err : new Error(String(err)) };
1000
+ } `)
1001
+ ];
1002
+ }
1003
+ })
1004
+ ];
1005
+ }
1006
+ /**
647
1007
  * A built-in upgrade module for Shell Shock.
648
1008
  */
649
1009
  function UpgradeBuiltin(props) {
@@ -657,7 +1017,11 @@ function UpgradeBuiltin(props) {
657
1017
  "node:os": "os",
658
1018
  "node:path": ["join", "resolve"],
659
1019
  "node:fs": ["existsSync"],
660
- "node:fs/promises": ["readFile", "writeFile"],
1020
+ "node:fs/promises": [
1021
+ "readFile",
1022
+ "writeFile",
1023
+ "mkdir"
1024
+ ],
661
1025
  "node:process": "process"
662
1026
  });
663
1027
  },
@@ -668,8 +1032,17 @@ function UpgradeBuiltin(props) {
668
1032
  "verbose",
669
1033
  "writeLine"
670
1034
  ],
671
- env: ["paths", "isWindows"],
672
- utils: ["isColorSupported", "spawn"]
1035
+ env: [
1036
+ "paths",
1037
+ "isWindows",
1038
+ "isCI",
1039
+ "env"
1040
+ ],
1041
+ utils: [
1042
+ "isColorSupported",
1043
+ "isInteractive",
1044
+ "spawn"
1045
+ ]
673
1046
  });
674
1047
  },
675
1048
  get children() {
@@ -688,15 +1061,25 @@ function UpgradeBuiltin(props) {
688
1061
  initializer: __alloy_js_core.code`os.tmpdir(); `
689
1062
  }),
690
1063
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1064
+ (0, __alloy_js_core_jsx_runtime.createComponent)(LocatePackageJsonFunctionDeclaration, {}),
1065
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
691
1066
  (0, __alloy_js_core_jsx_runtime.createComponent)(LocateLockfileFunctionDeclaration, {}),
692
1067
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
693
1068
  (0, __alloy_js_core_jsx_runtime.createComponent)(GetPackageManagerFunctionDeclaration, {}),
694
1069
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
695
1070
  (0, __alloy_js_core_jsx_runtime.createComponent)(FetchNpmPackageFunctionDeclaration, {}),
696
1071
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
697
- (0, __alloy_js_core_jsx_runtime.createComponent)(GetLatestFunctionDeclaration, {}),
1072
+ (0, __alloy_js_core_jsx_runtime.createComponent)(GetLatestVersionFunctionDeclaration, {}),
1073
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1074
+ (0, __alloy_js_core_jsx_runtime.createComponent)(GetUpgradeCommandFunctionDeclaration, {}),
1075
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1076
+ (0, __alloy_js_core_jsx_runtime.createComponent)(UpgradeFunctionDeclaration, {}),
1077
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1078
+ (0, __alloy_js_core_jsx_runtime.createComponent)(CheckForUpdatesFunctionDeclaration, {}),
1079
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1080
+ (0, __alloy_js_core_jsx_runtime.createComponent)(IsCheckForUpdatesRequiredFunctionDeclaration, {}),
698
1081
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
699
- (0, __alloy_js_core_jsx_runtime.createComponent)(InstallFunctionDeclaration, {}),
1082
+ (0, __alloy_js_core_jsx_runtime.createComponent)(UpdateVersionCheckFileFunctionDeclaration, {}),
700
1083
  (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
701
1084
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
702
1085
  get when() {
@@ -710,10 +1093,14 @@ function UpgradeBuiltin(props) {
710
1093
  }
711
1094
 
712
1095
  //#endregion
1096
+ exports.CheckForUpdatesFunctionDeclaration = CheckForUpdatesFunctionDeclaration;
713
1097
  exports.FetchNpmPackageFunctionDeclaration = FetchNpmPackageFunctionDeclaration;
714
- exports.GetLatestFunctionDeclaration = GetLatestFunctionDeclaration;
1098
+ exports.GetLatestVersionFunctionDeclaration = GetLatestVersionFunctionDeclaration;
715
1099
  exports.GetPackageManagerFunctionDeclaration = GetPackageManagerFunctionDeclaration;
716
- exports.InstallFunctionDeclaration = InstallFunctionDeclaration;
1100
+ exports.GetUpgradeCommandFunctionDeclaration = GetUpgradeCommandFunctionDeclaration;
1101
+ exports.IsCheckForUpdatesRequiredFunctionDeclaration = IsCheckForUpdatesRequiredFunctionDeclaration;
717
1102
  exports.LocateLockfileFunctionDeclaration = LocateLockfileFunctionDeclaration;
718
1103
  exports.LocatePackageJsonFunctionDeclaration = LocatePackageJsonFunctionDeclaration;
719
- exports.UpgradeBuiltin = UpgradeBuiltin;
1104
+ exports.UpdateVersionCheckFileFunctionDeclaration = UpdateVersionCheckFileFunctionDeclaration;
1105
+ exports.UpgradeBuiltin = UpgradeBuiltin;
1106
+ exports.UpgradeFunctionDeclaration = UpgradeFunctionDeclaration;