keycloakify 11.6.2 → 11.7.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.
Files changed (69) hide show
  1. package/bin/{735.index.js → 288.index.js} +226 -360
  2. package/bin/313.index.js +377 -0
  3. package/bin/{174.index.js → 33.index.js} +37 -2
  4. package/bin/{840.index.js → 355.index.js} +348 -97
  5. package/bin/363.index.js +153 -144
  6. package/bin/453.index.js +5 -41
  7. package/bin/{503.index.js → 678.index.js} +577 -53
  8. package/bin/{921.index.js → 780.index.js} +54 -45
  9. package/bin/880.index.js +206 -21
  10. package/bin/9.index.js +850 -0
  11. package/bin/{525.index.js → 911.index.js} +1302 -2
  12. package/bin/930.index.js +3 -4
  13. package/bin/{153.index.js → 947.index.js} +22 -797
  14. package/bin/main.js +6 -6
  15. package/bin/shared/initializeSpa/index.d.ts +1 -0
  16. package/bin/shared/initializeSpa/initializeSpa.d.ts +9 -0
  17. package/bin/tools/getInstalledModuleDirPath.d.ts +0 -1
  18. package/bin/tools/isRootPath.d.ts +1 -0
  19. package/bin/tools/listInstalledModules.d.ts +0 -1
  20. package/package.json +22 -44
  21. package/src/bin/eject-page.ts +7 -81
  22. package/src/bin/initialize-account-theme/initialize-account-theme.ts +15 -14
  23. package/src/bin/initialize-admin-theme.ts +17 -124
  24. package/src/bin/initialize-email-theme.ts +10 -34
  25. package/src/bin/keycloakify/generateResources/generateResources.ts +49 -21
  26. package/src/bin/own.ts +1 -2
  27. package/src/bin/shared/{addSyncExtensionsToPostinstallScript.ts → initializeSpa/addSyncExtensionsToPostinstallScript.ts} +2 -2
  28. package/src/bin/shared/initializeSpa/index.ts +1 -0
  29. package/src/bin/shared/initializeSpa/initializeSpa.ts +149 -0
  30. package/src/bin/sync-extensions/extensionModuleMeta.ts +0 -1
  31. package/src/bin/tools/getInstalledModuleDirPath.ts +24 -22
  32. package/src/bin/tools/isRootPath.ts +22 -0
  33. package/src/bin/tools/listInstalledModules.ts +2 -4
  34. package/src/bin/tsconfig.json +1 -1
  35. package/bin/375.index.js +0 -4089
  36. package/bin/490.index.js +0 -1108
  37. package/bin/568.index.js +0 -1867
  38. package/bin/743.index.js +0 -69
  39. package/bin/initialize-account-theme/copyBoilerplate.d.ts +0 -4
  40. package/bin/initialize-account-theme/initializeAccountTheme_multiPage.d.ts +0 -3
  41. package/bin/initialize-account-theme/initializeAccountTheme_singlePage.d.ts +0 -11
  42. package/bin/shared/getLatestsSemVersionedTag.d.ts +0 -15
  43. package/bin/shared/promptKeycloakVersion.d.ts +0 -10
  44. package/bin/tools/OptionalIfCanBeUndefined.d.ts +0 -14
  45. package/bin/tools/crc32.d.ts +0 -9
  46. package/bin/tools/deflate.d.ts +0 -24
  47. package/bin/tools/octokit-addons/getLatestsSemVersionedTag.d.ts +0 -15
  48. package/bin/tools/octokit-addons/listTags.d.ts +0 -13
  49. package/bin/tools/tee.d.ts +0 -3
  50. package/bin/tools/trimIndent.d.ts +0 -5
  51. package/src/bin/initialize-account-theme/copyBoilerplate.ts +0 -32
  52. package/src/bin/initialize-account-theme/initializeAccountTheme_multiPage.ts +0 -21
  53. package/src/bin/initialize-account-theme/initializeAccountTheme_singlePage.ts +0 -142
  54. package/src/bin/initialize-account-theme/src/single-page/KcContext.ts +0 -7
  55. package/src/bin/initialize-account-theme/src/single-page/KcPage.tsx +0 -11
  56. package/src/bin/shared/getLatestsSemVersionedTag.ts +0 -201
  57. package/src/bin/shared/promptKeycloakVersion.ts +0 -72
  58. package/src/bin/tools/OptionalIfCanBeUndefined.ts +0 -12
  59. package/src/bin/tools/crc32.ts +0 -73
  60. package/src/bin/tools/deflate.ts +0 -61
  61. package/src/bin/tools/octokit-addons/getLatestsSemVersionedTag.ts +0 -47
  62. package/src/bin/tools/octokit-addons/listTags.ts +0 -60
  63. package/src/bin/tools/tee.ts +0 -39
  64. package/src/bin/tools/trimIndent.ts +0 -49
  65. /package/bin/shared/{addSyncExtensionsToPostinstallScript.d.ts → initializeSpa/addSyncExtensionsToPostinstallScript.d.ts} +0 -0
  66. /package/src/bin/initialize-account-theme/{src/multi-page → multi-page-boilerplate}/KcContext.ts +0 -0
  67. /package/src/bin/initialize-account-theme/{src/multi-page → multi-page-boilerplate}/KcPage.tsx +0 -0
  68. /package/src/bin/initialize-account-theme/{src/multi-page → multi-page-boilerplate}/KcPageStory.tsx +0 -0
  69. /package/src/bin/initialize-account-theme/{src/multi-page → multi-page-boilerplate}/i18n.ts +0 -0
package/bin/743.index.js DELETED
@@ -1,69 +0,0 @@
1
- "use strict";
2
- exports.id = 743;
3
- exports.ids = [743];
4
- exports.modules = {
5
-
6
- /***/ 81434:
7
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8
-
9
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
10
- /* harmony export */ "T": () => (/* binding */ copyBoilerplate)
11
- /* harmony export */ });
12
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(57147);
13
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__);
14
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(71017);
15
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
16
- /* harmony import */ var _tools_getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(58822);
17
- /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(29041);
18
-
19
-
20
-
21
-
22
- function copyBoilerplate(params) {
23
- const { accountThemeType, accountThemeSrcDirPath } = params;
24
- fs__WEBPACK_IMPORTED_MODULE_0__.cpSync((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_tools_getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_2__/* .getThisCodebaseRootDirPath */ .e)(), "src", "bin", "initialize-account-theme", "src", (() => {
25
- switch (accountThemeType) {
26
- case "Single-Page":
27
- return "single-page";
28
- case "Multi-Page":
29
- return "multi-page";
30
- }
31
- (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)(false);
32
- })()), accountThemeSrcDirPath, { recursive: true });
33
- }
34
- //# sourceMappingURL=copyBoilerplate.js.map
35
-
36
- /***/ }),
37
-
38
- /***/ 22743:
39
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
40
-
41
- __webpack_require__.r(__webpack_exports__);
42
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
43
- /* harmony export */ "initializeAccountTheme_multiPage": () => (/* binding */ initializeAccountTheme_multiPage)
44
- /* harmony export */ });
45
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(71017);
46
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
47
- /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(78818);
48
- /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(chalk__WEBPACK_IMPORTED_MODULE_1__);
49
- /* harmony import */ var _copyBoilerplate__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(81434);
50
-
51
-
52
-
53
- async function initializeAccountTheme_multiPage(params) {
54
- const { accountThemeSrcDirPath } = params;
55
- (0,_copyBoilerplate__WEBPACK_IMPORTED_MODULE_2__/* .copyBoilerplate */ .T)({
56
- accountThemeType: "Multi-Page",
57
- accountThemeSrcDirPath
58
- });
59
- console.log([
60
- chalk__WEBPACK_IMPORTED_MODULE_1___default().green("The Multi-Page account theme has been initialized."),
61
- `Directory created: ${chalk__WEBPACK_IMPORTED_MODULE_1___default().bold((0,path__WEBPACK_IMPORTED_MODULE_0__.relative)(process.cwd(), accountThemeSrcDirPath))}`
62
- ].join("\n"));
63
- }
64
- //# sourceMappingURL=initializeAccountTheme_multiPage.js.map
65
-
66
- /***/ })
67
-
68
- };
69
- ;
@@ -1,4 +0,0 @@
1
- export declare function copyBoilerplate(params: {
2
- accountThemeType: "Single-Page" | "Multi-Page";
3
- accountThemeSrcDirPath: string;
4
- }): void;
@@ -1,3 +0,0 @@
1
- export declare function initializeAccountTheme_multiPage(params: {
2
- accountThemeSrcDirPath: string;
3
- }): Promise<void>;
@@ -1,11 +0,0 @@
1
- import type { BuildContext } from "../shared/buildContext";
2
- import { type BuildContextLike as BuildContextLike_getLatestsSemVersionedTag } from "../shared/getLatestsSemVersionedTag";
3
- type BuildContextLike = BuildContextLike_getLatestsSemVersionedTag & {
4
- fetchOptions: BuildContext["fetchOptions"];
5
- packageJsonFilePath: string;
6
- };
7
- export declare function initializeAccountTheme_singlePage(params: {
8
- accountThemeSrcDirPath: string;
9
- buildContext: BuildContextLike;
10
- }): Promise<void>;
11
- export {};
@@ -1,15 +0,0 @@
1
- import { getLatestsSemVersionedTagFactory } from "../tools/octokit-addons/getLatestsSemVersionedTag";
2
- import type { ReturnType } from "tsafe";
3
- import type { Param0 } from "tsafe";
4
- import type { BuildContext } from "./buildContext";
5
- type GetLatestsSemVersionedTag = ReturnType<typeof getLatestsSemVersionedTagFactory>["getLatestsSemVersionedTag"];
6
- type Params = Param0<GetLatestsSemVersionedTag>;
7
- type R = ReturnType<GetLatestsSemVersionedTag>;
8
- export type BuildContextLike = {
9
- cacheDirPath: string;
10
- fetchOptions: BuildContext["fetchOptions"];
11
- };
12
- export declare function getLatestsSemVersionedTag({ buildContext, ...params }: Params & {
13
- buildContext: BuildContextLike;
14
- }): Promise<R>;
15
- export {};
@@ -1,10 +0,0 @@
1
- import { type BuildContextLike as BuildContextLike_getLatestsSemVersionedTag } from "./getLatestsSemVersionedTag";
2
- export type BuildContextLike = BuildContextLike_getLatestsSemVersionedTag & {};
3
- export declare function promptKeycloakVersion(params: {
4
- startingFromMajor: number | undefined;
5
- excludeMajorVersions: number[];
6
- doOmitPatch: boolean;
7
- buildContext: BuildContextLike;
8
- }): Promise<{
9
- keycloakVersion: string;
10
- }>;
@@ -1,14 +0,0 @@
1
- type PropertiesThatCanBeUndefined<T extends Record<string, unknown>> = {
2
- [Key in keyof T]: undefined extends T[Key] ? Key : never;
3
- }[keyof T];
4
- /**
5
- * OptionalIfCanBeUndefined<{ p1: string | undefined; p2: string; }>
6
- * is
7
- * { p1?: string | undefined; p2: string }
8
- */
9
- export type OptionalIfCanBeUndefined<T extends Record<string, unknown>> = {
10
- [K in PropertiesThatCanBeUndefined<T>]?: T[K];
11
- } & {
12
- [K in Exclude<keyof T, PropertiesThatCanBeUndefined<T>>]: T[K];
13
- };
14
- export {};
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Readable } from "stream";
4
- /**
5
- *
6
- * @param input either a byte stream, a string or a buffer, you want to have the checksum for
7
- * @returns a promise for a checksum (uint32)
8
- */
9
- export declare function crc32(input: Readable | String | Buffer): Promise<number>;
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Readable } from "stream";
4
- /**
5
- * @param data buffer containing the data to be compressed
6
- * @returns a buffer containing the compressed/deflated data and the crc32 checksum
7
- * of the source data
8
- */
9
- export declare function deflateBuffer(data: Buffer): Promise<{
10
- deflated: Buffer;
11
- crc32: number;
12
- }>;
13
- /**
14
- * @param input a byte stream, containing data to be compressed
15
- * @param sink a method that will accept chunks of compressed data; We don't pass
16
- * a writable here, since we don't want the writablestream to be closed after
17
- * a single file
18
- * @returns a promise, which will resolve with the crc32 checksum and the
19
- * compressed size
20
- */
21
- export declare function deflateStream(input: Readable, sink: (chunk: Buffer) => void): Promise<{
22
- crc32: number;
23
- compressedSize: number;
24
- }>;
@@ -1,15 +0,0 @@
1
- import type { Octokit } from "@octokit/rest";
2
- import { SemVer } from "../SemVer";
3
- export declare function getLatestsSemVersionedTagFactory(params: {
4
- octokit: Octokit;
5
- }): {
6
- getLatestsSemVersionedTag: (params: {
7
- owner: string;
8
- repo: string;
9
- count: number;
10
- doIgnoreReleaseCandidates: boolean;
11
- }) => Promise<{
12
- tag: string;
13
- version: SemVer;
14
- }[]>;
15
- };
@@ -1,13 +0,0 @@
1
- import type { Octokit } from "@octokit/rest";
2
- export declare function listTagsFactory(params: {
3
- octokit: Octokit;
4
- }): {
5
- listTags: (params: {
6
- owner: string;
7
- repo: string;
8
- }) => AsyncGenerator<string>;
9
- getLatestTag: (params: {
10
- owner: string;
11
- repo: string;
12
- }) => Promise<string | undefined>;
13
- };
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { PassThrough, Readable } from "stream";
3
- export default function tee(input: Readable): readonly [PassThrough, PassThrough];
@@ -1,5 +0,0 @@
1
- /**
2
- * Shift all lines left by the *smallest* indentation level,
3
- * and remove initial newline and all trailing spaces.
4
- */
5
- export default function trimIndent(strings: TemplateStringsArray, ...args: any[]): string;
@@ -1,32 +0,0 @@
1
- import * as fs from "fs";
2
- import { join as pathJoin } from "path";
3
- import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath";
4
- import { assert, type Equals } from "tsafe/assert";
5
-
6
- export function copyBoilerplate(params: {
7
- accountThemeType: "Single-Page" | "Multi-Page";
8
- accountThemeSrcDirPath: string;
9
- }) {
10
- const { accountThemeType, accountThemeSrcDirPath } = params;
11
-
12
- fs.cpSync(
13
- pathJoin(
14
- getThisCodebaseRootDirPath(),
15
- "src",
16
- "bin",
17
- "initialize-account-theme",
18
- "src",
19
- (() => {
20
- switch (accountThemeType) {
21
- case "Single-Page":
22
- return "single-page";
23
- case "Multi-Page":
24
- return "multi-page";
25
- }
26
- assert<Equals<typeof accountThemeType, never>>(false);
27
- })()
28
- ),
29
- accountThemeSrcDirPath,
30
- { recursive: true }
31
- );
32
- }
@@ -1,21 +0,0 @@
1
- import { relative as pathRelative } from "path";
2
- import chalk from "chalk";
3
- import { copyBoilerplate } from "./copyBoilerplate";
4
-
5
- export async function initializeAccountTheme_multiPage(params: {
6
- accountThemeSrcDirPath: string;
7
- }) {
8
- const { accountThemeSrcDirPath } = params;
9
-
10
- copyBoilerplate({
11
- accountThemeType: "Multi-Page",
12
- accountThemeSrcDirPath
13
- });
14
-
15
- console.log(
16
- [
17
- chalk.green("The Multi-Page account theme has been initialized."),
18
- `Directory created: ${chalk.bold(pathRelative(process.cwd(), accountThemeSrcDirPath))}`
19
- ].join("\n")
20
- );
21
- }
@@ -1,142 +0,0 @@
1
- import { relative as pathRelative, dirname as pathDirname } from "path";
2
- import type { BuildContext } from "../shared/buildContext";
3
- import * as fs from "fs";
4
- import chalk from "chalk";
5
- import {
6
- getLatestsSemVersionedTag,
7
- type BuildContextLike as BuildContextLike_getLatestsSemVersionedTag
8
- } from "../shared/getLatestsSemVersionedTag";
9
- import { SemVer } from "../tools/SemVer";
10
- import fetch from "make-fetch-happen";
11
- import { z } from "zod";
12
- import { assert, type Equals, is } from "tsafe/assert";
13
- import { id } from "tsafe/id";
14
- import { npmInstall } from "../tools/npmInstall";
15
- import { copyBoilerplate } from "./copyBoilerplate";
16
-
17
- type BuildContextLike = BuildContextLike_getLatestsSemVersionedTag & {
18
- fetchOptions: BuildContext["fetchOptions"];
19
- packageJsonFilePath: string;
20
- };
21
-
22
- assert<BuildContext extends BuildContextLike ? true : false>();
23
-
24
- export async function initializeAccountTheme_singlePage(params: {
25
- accountThemeSrcDirPath: string;
26
- buildContext: BuildContextLike;
27
- }) {
28
- const { accountThemeSrcDirPath, buildContext } = params;
29
-
30
- const OWNER = "keycloakify";
31
- const REPO = "keycloak-account-ui";
32
-
33
- const [semVersionedTag] = await getLatestsSemVersionedTag({
34
- owner: OWNER,
35
- repo: REPO,
36
- count: 1,
37
- doIgnoreReleaseCandidates: false,
38
- buildContext
39
- });
40
-
41
- const dependencies = await fetch(
42
- `https://raw.githubusercontent.com/${OWNER}/${REPO}/${semVersionedTag.tag}/dependencies.gen.json`,
43
- buildContext.fetchOptions
44
- )
45
- .then(r => r.json())
46
- .then(
47
- (() => {
48
- type Dependencies = {
49
- dependencies: Record<string, string>;
50
- devDependencies?: Record<string, string>;
51
- };
52
-
53
- const zDependencies = (() => {
54
- type TargetType = Dependencies;
55
-
56
- const zTargetType = z.object({
57
- dependencies: z.record(z.string()),
58
- devDependencies: z.record(z.string()).optional()
59
- });
60
-
61
- assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
62
-
63
- return id<z.ZodType<TargetType>>(zTargetType);
64
- })();
65
-
66
- return o => zDependencies.parse(o);
67
- })()
68
- );
69
-
70
- dependencies.dependencies["@keycloakify/keycloak-account-ui"] = SemVer.stringify(
71
- semVersionedTag.version
72
- );
73
-
74
- const parsedPackageJson = (() => {
75
- type ParsedPackageJson = {
76
- dependencies?: Record<string, string>;
77
- devDependencies?: Record<string, string>;
78
- };
79
-
80
- const zParsedPackageJson = (() => {
81
- type TargetType = ParsedPackageJson;
82
-
83
- const zTargetType = z.object({
84
- dependencies: z.record(z.string()).optional(),
85
- devDependencies: z.record(z.string()).optional()
86
- });
87
-
88
- assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
89
-
90
- return id<z.ZodType<TargetType>>(zTargetType);
91
- })();
92
- const parsedPackageJson = JSON.parse(
93
- fs.readFileSync(buildContext.packageJsonFilePath).toString("utf8")
94
- );
95
-
96
- zParsedPackageJson.parse(parsedPackageJson);
97
-
98
- assert(is<ParsedPackageJson>(parsedPackageJson));
99
-
100
- return parsedPackageJson;
101
- })();
102
-
103
- parsedPackageJson.dependencies = {
104
- ...parsedPackageJson.dependencies,
105
- ...dependencies.dependencies
106
- };
107
-
108
- parsedPackageJson.devDependencies = {
109
- ...parsedPackageJson.devDependencies,
110
- ...dependencies.devDependencies
111
- };
112
-
113
- if (Object.keys(parsedPackageJson.devDependencies).length === 0) {
114
- delete parsedPackageJson.devDependencies;
115
- }
116
-
117
- fs.writeFileSync(
118
- buildContext.packageJsonFilePath,
119
- JSON.stringify(parsedPackageJson, undefined, 4)
120
- );
121
-
122
- await npmInstall({
123
- packageJsonDirPath: pathDirname(buildContext.packageJsonFilePath)
124
- });
125
-
126
- copyBoilerplate({
127
- accountThemeType: "Single-Page",
128
- accountThemeSrcDirPath
129
- });
130
-
131
- console.log(
132
- [
133
- chalk.green(
134
- "The Single-Page account theme has been successfully initialized."
135
- ),
136
- `Using Account UI of Keycloak version: ${chalk.bold(semVersionedTag.tag.split("-")[0])}`,
137
- `Directory created: ${chalk.bold(pathRelative(process.cwd(), accountThemeSrcDirPath))}`,
138
- `Dependencies added to your project's package.json: `,
139
- chalk.bold(JSON.stringify(dependencies, null, 2))
140
- ].join("\n")
141
- );
142
- }
@@ -1,7 +0,0 @@
1
- import type { KcContextLike } from "@keycloakify/keycloak-account-ui";
2
- import type { KcEnvName } from "../kc.gen";
3
-
4
- export type KcContext = KcContextLike & {
5
- themeType: "account";
6
- properties: Record<KcEnvName, string>;
7
- };
@@ -1,11 +0,0 @@
1
- import { lazy } from "react";
2
- import { KcAccountUiLoader } from "@keycloakify/keycloak-account-ui";
3
- import type { KcContext } from "./KcContext";
4
-
5
- const KcAccountUi = lazy(() => import("@keycloakify/keycloak-account-ui/KcAccountUi"));
6
-
7
- export default function KcPage(props: { kcContext: KcContext }) {
8
- const { kcContext } = props;
9
-
10
- return <KcAccountUiLoader kcContext={kcContext} KcAccountUi={KcAccountUi} />;
11
- }
@@ -1,201 +0,0 @@
1
- import { getLatestsSemVersionedTagFactory } from "../tools/octokit-addons/getLatestsSemVersionedTag";
2
- import { Octokit } from "@octokit/rest";
3
- import type { ReturnType } from "tsafe";
4
- import type { Param0 } from "tsafe";
5
- import { join as pathJoin, dirname as pathDirname } from "path";
6
- import * as fs from "fs";
7
- import { z } from "zod";
8
- import { assert, type Equals } from "tsafe/assert";
9
- import { id } from "tsafe/id";
10
- import type { SemVer } from "../tools/SemVer";
11
- import { same } from "evt/tools/inDepth/same";
12
- import type { BuildContext } from "./buildContext";
13
- import fetch from "make-fetch-happen";
14
-
15
- type GetLatestsSemVersionedTag = ReturnType<
16
- typeof getLatestsSemVersionedTagFactory
17
- >["getLatestsSemVersionedTag"];
18
-
19
- type Params = Param0<GetLatestsSemVersionedTag>;
20
- type R = ReturnType<GetLatestsSemVersionedTag>;
21
-
22
- let getLatestsSemVersionedTag_stateless: GetLatestsSemVersionedTag | undefined =
23
- undefined;
24
-
25
- const CACHE_VERSION = 1;
26
-
27
- type Cache = {
28
- version: typeof CACHE_VERSION;
29
- entries: {
30
- time: number;
31
- params: Params;
32
- result: R;
33
- }[];
34
- };
35
-
36
- export type BuildContextLike = {
37
- cacheDirPath: string;
38
- fetchOptions: BuildContext["fetchOptions"];
39
- };
40
-
41
- assert<BuildContext extends BuildContextLike ? true : false>();
42
-
43
- export async function getLatestsSemVersionedTag({
44
- buildContext,
45
- ...params
46
- }: Params & {
47
- buildContext: BuildContextLike;
48
- }): Promise<R> {
49
- const cacheFilePath = pathJoin(
50
- buildContext.cacheDirPath,
51
- "latest-sem-versioned-tags.json"
52
- );
53
-
54
- const cacheLookupResult = (() => {
55
- const getResult_currentCache = (currentCacheEntries: Cache["entries"]) => ({
56
- hasCachedResult: false as const,
57
- currentCache: {
58
- version: CACHE_VERSION,
59
- entries: currentCacheEntries
60
- }
61
- });
62
-
63
- if (!fs.existsSync(cacheFilePath)) {
64
- return getResult_currentCache([]);
65
- }
66
-
67
- let cache_json;
68
-
69
- try {
70
- cache_json = fs.readFileSync(cacheFilePath).toString("utf8");
71
- } catch {
72
- return getResult_currentCache([]);
73
- }
74
-
75
- let cache_json_parsed: unknown;
76
-
77
- try {
78
- cache_json_parsed = JSON.parse(cache_json);
79
- } catch {
80
- return getResult_currentCache([]);
81
- }
82
-
83
- const zSemVer = (() => {
84
- type TargetType = SemVer;
85
-
86
- const zTargetType = z.object({
87
- major: z.number(),
88
- minor: z.number(),
89
- patch: z.number(),
90
- rc: z.number().optional(),
91
- parsedFrom: z.string()
92
- });
93
-
94
- assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
95
-
96
- return id<z.ZodType<TargetType>>(zTargetType);
97
- })();
98
-
99
- const zCache = (() => {
100
- type TargetType = Cache;
101
-
102
- const zTargetType = z.object({
103
- version: z.literal(CACHE_VERSION),
104
- entries: z.array(
105
- z.object({
106
- time: z.number(),
107
- params: z.object({
108
- owner: z.string(),
109
- repo: z.string(),
110
- count: z.number(),
111
- doIgnoreReleaseCandidates: z.boolean()
112
- }),
113
- result: z.array(
114
- z.object({
115
- tag: z.string(),
116
- version: zSemVer
117
- })
118
- )
119
- })
120
- )
121
- });
122
-
123
- assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
124
-
125
- return id<z.ZodType<TargetType>>(zTargetType);
126
- })();
127
-
128
- let cache: Cache;
129
-
130
- try {
131
- cache = zCache.parse(cache_json_parsed);
132
- } catch {
133
- return getResult_currentCache([]);
134
- }
135
-
136
- const cacheEntry = cache.entries.find(e => same(e.params, params));
137
-
138
- if (cacheEntry === undefined) {
139
- return getResult_currentCache(cache.entries);
140
- }
141
-
142
- if (Date.now() - cacheEntry.time > 3_600_000) {
143
- return getResult_currentCache(cache.entries.filter(e => e !== cacheEntry));
144
- }
145
- return {
146
- hasCachedResult: true as const,
147
- cachedResult: cacheEntry.result
148
- };
149
- })();
150
-
151
- if (cacheLookupResult.hasCachedResult) {
152
- return cacheLookupResult.cachedResult;
153
- }
154
-
155
- const { currentCache } = cacheLookupResult;
156
-
157
- getLatestsSemVersionedTag_stateless ??= (() => {
158
- const octokit = (() => {
159
- const githubToken = process.env.GITHUB_TOKEN;
160
-
161
- const octokit = new Octokit({
162
- ...(githubToken === undefined ? {} : { auth: githubToken }),
163
- request: {
164
- fetch: (url: string, options?: any) =>
165
- fetch(url, {
166
- ...options,
167
- ...buildContext.fetchOptions
168
- })
169
- }
170
- });
171
-
172
- return octokit;
173
- })();
174
-
175
- const { getLatestsSemVersionedTag } = getLatestsSemVersionedTagFactory({
176
- octokit
177
- });
178
-
179
- return getLatestsSemVersionedTag;
180
- })();
181
-
182
- const result = await getLatestsSemVersionedTag_stateless(params);
183
-
184
- currentCache.entries.push({
185
- time: Date.now(),
186
- params,
187
- result
188
- });
189
-
190
- {
191
- const dirPath = pathDirname(cacheFilePath);
192
-
193
- if (!fs.existsSync(dirPath)) {
194
- fs.mkdirSync(dirPath, { recursive: true });
195
- }
196
- }
197
-
198
- fs.writeFileSync(cacheFilePath, JSON.stringify(currentCache, null, 2));
199
-
200
- return result;
201
- }