keycloakify 11.8.37 → 11.8.38

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,136 +0,0 @@
1
- import * as fsPr from "fs/promises";
2
- import {
3
- join as pathJoin,
4
- sep as pathSep,
5
- dirname as pathDirname,
6
- relative as pathRelative
7
- } from "path";
8
- import { assert } from "tsafe/assert";
9
- import type { BuildContext } from "../shared/buildContext";
10
- import type { ExtensionModuleMeta } from "./extensionModuleMeta";
11
- import { existsAsync } from "../tools/fs.existsAsync";
12
- import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatPath";
13
-
14
- export type BuildContextLike = {
15
- themeSrcDirPath: string;
16
- };
17
-
18
- assert<BuildContext extends BuildContextLike ? true : false>();
19
-
20
- const DELIMITER_START = `# === Owned files start ===`;
21
- const DELIMITER_END = `# === Owned files end =====`;
22
-
23
- export async function writeManagedGitignoreFile(params: {
24
- buildContext: BuildContextLike;
25
- extensionModuleMetas: ExtensionModuleMeta[];
26
- ownedFilesRelativePaths: string[];
27
- }): Promise<void> {
28
- const { buildContext, extensionModuleMetas, ownedFilesRelativePaths } = params;
29
-
30
- if (extensionModuleMetas.length === 0) {
31
- return;
32
- }
33
-
34
- const filePath = pathJoin(buildContext.themeSrcDirPath, ".gitignore");
35
-
36
- const content_new = Buffer.from(
37
- [
38
- `# This file is managed by Keycloakify, do not edit it manually.`,
39
- ``,
40
- DELIMITER_START,
41
- ...ownedFilesRelativePaths
42
- .map(fileRelativePath => fileRelativePath.split(pathSep).join("/"))
43
- .map(line => `# ${line}`),
44
- DELIMITER_END,
45
- ``,
46
- ...extensionModuleMetas
47
- .map(extensionModuleMeta => [
48
- `# === ${extensionModuleMeta.moduleName} v${extensionModuleMeta.version} ===`,
49
- ...extensionModuleMeta.files
50
- .map(({ fileRelativePath }) => fileRelativePath)
51
- .filter(
52
- fileRelativePath =>
53
- !ownedFilesRelativePaths.includes(fileRelativePath)
54
- )
55
- .map(
56
- fileRelativePath =>
57
- `/${fileRelativePath.split(pathSep).join("/").replace(/^\.\//, "")}`
58
- ),
59
-
60
- ``
61
- ])
62
- .flat()
63
- ].join("\n"),
64
- "utf8"
65
- );
66
-
67
- const content_current = await (async () => {
68
- if (!(await existsAsync(filePath))) {
69
- return undefined;
70
- }
71
-
72
- return await fsPr.readFile(filePath);
73
- })();
74
-
75
- if (content_current !== undefined && content_current.equals(content_new)) {
76
- return;
77
- }
78
-
79
- create_dir: {
80
- const dirPath = pathDirname(filePath);
81
-
82
- if (await existsAsync(dirPath)) {
83
- break create_dir;
84
- }
85
-
86
- await fsPr.mkdir(dirPath, { recursive: true });
87
- }
88
-
89
- await fsPr.writeFile(filePath, content_new);
90
- }
91
-
92
- export async function readManagedGitignoreFile(params: {
93
- buildContext: BuildContextLike;
94
- }): Promise<{
95
- ownedFilesRelativePaths: string[];
96
- }> {
97
- const { buildContext } = params;
98
-
99
- const filePath = pathJoin(buildContext.themeSrcDirPath, ".gitignore");
100
-
101
- if (!(await existsAsync(filePath))) {
102
- return { ownedFilesRelativePaths: [] };
103
- }
104
-
105
- const contentStr = (await fsPr.readFile(filePath)).toString("utf8");
106
-
107
- const payload = (() => {
108
- const index_start = contentStr.indexOf(DELIMITER_START);
109
- const index_end = contentStr.indexOf(DELIMITER_END);
110
-
111
- if (index_start === -1 || index_end === -1) {
112
- return undefined;
113
- }
114
-
115
- return contentStr.slice(index_start + DELIMITER_START.length, index_end).trim();
116
- })();
117
-
118
- if (payload === undefined) {
119
- return { ownedFilesRelativePaths: [] };
120
- }
121
-
122
- const ownedFilesRelativePaths = payload
123
- .split("\n")
124
- .map(line => line.trim())
125
- .map(line => line.replace(/^# /, ""))
126
- .filter(line => line !== "")
127
- .map(line =>
128
- getAbsoluteAndInOsFormatPath({
129
- cwd: buildContext.themeSrcDirPath,
130
- pathIsh: line
131
- })
132
- )
133
- .map(filePath => pathRelative(buildContext.themeSrcDirPath, filePath));
134
-
135
- return { ownedFilesRelativePaths };
136
- }