keycloakify 11.3.18 → 11.3.20
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/bin/124.index.js +675 -0
- package/bin/356.index.js +689 -0
- package/bin/40.index.js +41 -21
- package/bin/{903.index.js → 450.index.js} +2 -680
- package/bin/453.index.js +143 -83
- package/bin/573.index.js +51 -24
- package/bin/{599.index.js → 735.index.js} +438 -121
- package/bin/786.index.js +129 -76
- package/bin/805.index.js +674 -0
- package/bin/854.index.js +68 -0
- package/bin/{780.index.js → 921.index.js} +168 -107
- package/bin/932.index.js +41 -21
- package/bin/97.index.js +125 -73
- package/bin/eject-file.d.ts +7 -0
- package/bin/keycloakify/generateResources/generateMessageProperties.d.ts +1 -1
- package/bin/keycloakify/generateResources/readFieldNameUsage.d.ts +1 -1
- package/bin/main.js +70 -7
- package/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.d.ts +12 -0
- package/bin/postinstall/index.d.ts +1 -0
- package/bin/postinstall/installUiModulesPeerDependencies.d.ts +11 -0
- package/bin/postinstall/managedGitignoreFile.d.ts +14 -0
- package/bin/postinstall/postinstall.d.ts +4 -0
- package/bin/postinstall/uiModuleMeta.d.ts +21 -0
- package/bin/shared/buildContext.d.ts +3 -0
- package/bin/shared/constants.d.ts +2 -1
- package/bin/shared/constants.js +2 -1
- package/bin/shared/constants.js.map +1 -1
- package/bin/shared/customHandler.d.ts +1 -1
- package/bin/shared/customHandler.js.map +1 -1
- package/bin/shared/exitIfUncommittedChanges.d.ts +3 -0
- package/bin/tools/crawlAsync.d.ts +6 -0
- package/bin/tools/getInstalledModuleDirPath.d.ts +5 -0
- package/bin/tools/listInstalledModules.d.ts +12 -0
- package/bin/tools/nodeModulesBinDirPath.d.ts +1 -0
- package/bin/tools/runPrettier.d.ts +17 -0
- package/package.json +34 -6
- package/src/bin/add-story.ts +28 -10
- package/src/bin/eject-file.ts +68 -0
- package/src/bin/eject-page.ts +51 -31
- package/src/bin/initialize-account-theme/initialize-account-theme.ts +4 -32
- package/src/bin/initialize-account-theme/initializeAccountTheme_singlePage.ts +2 -16
- package/src/bin/keycloakify/generateResources/generateMessageProperties.ts +1 -1
- package/src/bin/keycloakify/generateResources/generateResources.ts +58 -26
- package/src/bin/keycloakify/generateResources/readFieldNameUsage.ts +1 -1
- package/src/bin/main.ts +50 -0
- package/src/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.ts +71 -0
- package/src/bin/postinstall/index.ts +1 -0
- package/src/bin/postinstall/installUiModulesPeerDependencies.ts +157 -0
- package/src/bin/postinstall/managedGitignoreFile.ts +135 -0
- package/src/bin/postinstall/postinstall.ts +79 -0
- package/src/bin/postinstall/uiModuleMeta.ts +303 -0
- package/src/bin/shared/buildContext.ts +11 -5
- package/src/bin/shared/constants.ts +3 -1
- package/src/bin/shared/customHandler.ts +1 -0
- package/src/bin/shared/customHandler_delegate.ts +2 -27
- package/src/bin/shared/exitIfUncommittedChanges.ts +36 -0
- package/src/bin/tools/crawlAsync.ts +51 -0
- package/src/bin/tools/getInstalledModuleDirPath.ts +51 -0
- package/src/bin/tools/listInstalledModules.ts +131 -0
- package/src/bin/tools/nodeModulesBinDirPath.ts +38 -0
- package/src/bin/tools/npmInstall.ts +411 -15
- package/src/bin/tools/readThisNpmPackageVersion.ts +8 -0
- package/src/bin/tools/runPrettier.ts +106 -0
- package/src/bin/update-kc-gen.ts +28 -17
- package/vite-plugin/index.js +9237 -9161
- package/bin/tools/runFormat.d.ts +0 -3
- package/src/bin/tools/runFormat.ts +0 -71
@@ -0,0 +1,38 @@
|
|
1
|
+
import { sep as pathSep } from "path";
|
2
|
+
|
3
|
+
let cache: string | undefined = undefined;
|
4
|
+
|
5
|
+
export function getNodeModulesBinDirPath() {
|
6
|
+
if (cache !== undefined) {
|
7
|
+
return cache;
|
8
|
+
}
|
9
|
+
|
10
|
+
const binPath = process.argv[1];
|
11
|
+
|
12
|
+
const segments: string[] = [".bin"];
|
13
|
+
|
14
|
+
let foundNodeModules = false;
|
15
|
+
|
16
|
+
for (const segment of binPath.split(pathSep).reverse()) {
|
17
|
+
skip_segment: {
|
18
|
+
if (foundNodeModules) {
|
19
|
+
break skip_segment;
|
20
|
+
}
|
21
|
+
|
22
|
+
if (segment === "node_modules") {
|
23
|
+
foundNodeModules = true;
|
24
|
+
break skip_segment;
|
25
|
+
}
|
26
|
+
|
27
|
+
continue;
|
28
|
+
}
|
29
|
+
|
30
|
+
segments.unshift(segment);
|
31
|
+
}
|
32
|
+
|
33
|
+
const nodeModulesBinDirPath = segments.join(pathSep);
|
34
|
+
|
35
|
+
cache = nodeModulesBinDirPath;
|
36
|
+
|
37
|
+
return nodeModulesBinDirPath;
|
38
|
+
}
|
@@ -1,7 +1,15 @@
|
|
1
1
|
import * as fs from "fs";
|
2
|
-
import { join as pathJoin } from "path";
|
2
|
+
import { join as pathJoin, dirname as pathDirname } from "path";
|
3
3
|
import * as child_process from "child_process";
|
4
4
|
import chalk from "chalk";
|
5
|
+
import { z } from "zod";
|
6
|
+
import { assert, type Equals } from "tsafe/assert";
|
7
|
+
import { id } from "tsafe/id";
|
8
|
+
import { is } from "tsafe/is";
|
9
|
+
import { objectKeys } from "tsafe/objectKeys";
|
10
|
+
import { getAbsoluteAndInOsFormatPath } from "./getAbsoluteAndInOsFormatPath";
|
11
|
+
import { exclude } from "tsafe/exclude";
|
12
|
+
import { rmSync } from "./fs.rmSync";
|
5
13
|
|
6
14
|
export function npmInstall(params: { packageJsonDirPath: string }) {
|
7
15
|
const { packageJsonDirPath } = params;
|
@@ -23,6 +31,10 @@ export function npmInstall(params: { packageJsonDirPath: string }) {
|
|
23
31
|
{
|
24
32
|
binName: "bun",
|
25
33
|
lockFileBasename: "bun.lockdb"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
binName: "deno",
|
37
|
+
lockFileBasename: "deno.lock"
|
26
38
|
}
|
27
39
|
] as const;
|
28
40
|
|
@@ -37,27 +49,411 @@ export function npmInstall(params: { packageJsonDirPath: string }) {
|
|
37
49
|
}
|
38
50
|
}
|
39
51
|
|
40
|
-
|
52
|
+
throw new Error(
|
53
|
+
"No lock file found, cannot tell which package manager to use for installing dependencies."
|
54
|
+
);
|
41
55
|
})();
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
console.log(`Installing the new dependencies...`);
|
58
|
+
|
59
|
+
install_without_breaking_links: {
|
60
|
+
if (packageManagerBinName !== "yarn") {
|
61
|
+
break install_without_breaking_links;
|
46
62
|
}
|
47
63
|
|
48
|
-
|
64
|
+
const garronejLinkInfos = getGarronejLinkInfos({ packageJsonDirPath });
|
65
|
+
|
66
|
+
if (garronejLinkInfos === undefined) {
|
67
|
+
break install_without_breaking_links;
|
68
|
+
}
|
69
|
+
|
70
|
+
console.log(chalk.green("Installing in a way that won't break the links..."));
|
71
|
+
|
72
|
+
installWithoutBreakingLinks({
|
73
|
+
packageJsonDirPath,
|
74
|
+
garronejLinkInfos
|
75
|
+
});
|
76
|
+
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
try {
|
81
|
+
child_process.execSync(`${packageManagerBinName} install`, {
|
82
|
+
cwd: packageJsonDirPath,
|
83
|
+
stdio: "inherit"
|
84
|
+
});
|
85
|
+
} catch {
|
86
|
+
console.log(
|
87
|
+
chalk.yellow(
|
88
|
+
`\`${packageManagerBinName} install\` failed, continuing anyway...`
|
89
|
+
)
|
90
|
+
);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
function getGarronejLinkInfos(params: {
|
95
|
+
packageJsonDirPath: string;
|
96
|
+
}): { linkedModuleNames: string[]; yarnHomeDirPath: string } | undefined {
|
97
|
+
const { packageJsonDirPath } = params;
|
98
|
+
|
99
|
+
const nodeModuleDirPath = pathJoin(packageJsonDirPath, "node_modules");
|
100
|
+
|
101
|
+
if (!fs.existsSync(nodeModuleDirPath)) {
|
102
|
+
return undefined;
|
103
|
+
}
|
104
|
+
|
105
|
+
const linkedModuleNames: string[] = [];
|
106
|
+
|
107
|
+
let yarnHomeDirPath: string | undefined = undefined;
|
108
|
+
|
109
|
+
const getIsLinkedByGarronejScript = (path: string) => {
|
110
|
+
let realPath: string;
|
49
111
|
|
50
112
|
try {
|
51
|
-
|
52
|
-
cwd: packageJsonDirPath,
|
53
|
-
stdio: "inherit"
|
54
|
-
});
|
113
|
+
realPath = fs.readlinkSync(path);
|
55
114
|
} catch {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
|
118
|
+
const doesIncludeYarnHome = realPath.includes(".yarn_home");
|
119
|
+
|
120
|
+
if (!doesIncludeYarnHome) {
|
121
|
+
return false;
|
122
|
+
}
|
123
|
+
|
124
|
+
set_yarnHomeDirPath: {
|
125
|
+
if (yarnHomeDirPath !== undefined) {
|
126
|
+
break set_yarnHomeDirPath;
|
127
|
+
}
|
128
|
+
|
129
|
+
const [firstElement] = getAbsoluteAndInOsFormatPath({
|
130
|
+
pathIsh: realPath,
|
131
|
+
cwd: pathDirname(path)
|
132
|
+
}).split(".yarn_home");
|
133
|
+
|
134
|
+
yarnHomeDirPath = pathJoin(firstElement, ".yarn_home");
|
135
|
+
}
|
136
|
+
|
137
|
+
return true;
|
138
|
+
};
|
139
|
+
|
140
|
+
for (const basename of fs.readdirSync(nodeModuleDirPath)) {
|
141
|
+
const path = pathJoin(nodeModuleDirPath, basename);
|
142
|
+
|
143
|
+
if (fs.lstatSync(path).isSymbolicLink()) {
|
144
|
+
if (basename.startsWith("@")) {
|
145
|
+
return undefined;
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!getIsLinkedByGarronejScript(path)) {
|
149
|
+
return undefined;
|
150
|
+
}
|
151
|
+
|
152
|
+
linkedModuleNames.push(basename);
|
153
|
+
continue;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (!fs.lstatSync(path).isDirectory()) {
|
157
|
+
continue;
|
158
|
+
}
|
159
|
+
|
160
|
+
if (basename.startsWith("@")) {
|
161
|
+
for (const subBasename of fs.readdirSync(path)) {
|
162
|
+
const subPath = pathJoin(path, subBasename);
|
163
|
+
|
164
|
+
if (!fs.lstatSync(subPath).isSymbolicLink()) {
|
165
|
+
continue;
|
166
|
+
}
|
167
|
+
|
168
|
+
if (!getIsLinkedByGarronejScript(subPath)) {
|
169
|
+
return undefined;
|
170
|
+
}
|
171
|
+
|
172
|
+
linkedModuleNames.push(`${basename}/${subBasename}`);
|
173
|
+
}
|
61
174
|
}
|
62
175
|
}
|
176
|
+
|
177
|
+
if (yarnHomeDirPath === undefined) {
|
178
|
+
return undefined;
|
179
|
+
}
|
180
|
+
|
181
|
+
return { linkedModuleNames, yarnHomeDirPath };
|
182
|
+
}
|
183
|
+
|
184
|
+
function installWithoutBreakingLinks(params: {
|
185
|
+
packageJsonDirPath: string;
|
186
|
+
garronejLinkInfos: Exclude<ReturnType<typeof getGarronejLinkInfos>, undefined>;
|
187
|
+
}) {
|
188
|
+
const {
|
189
|
+
packageJsonDirPath,
|
190
|
+
garronejLinkInfos: { linkedModuleNames, yarnHomeDirPath }
|
191
|
+
} = params;
|
192
|
+
|
193
|
+
const parsedPackageJson = (() => {
|
194
|
+
const packageJsonFilePath = pathJoin(packageJsonDirPath, "package.json");
|
195
|
+
|
196
|
+
type ParsedPackageJson = {
|
197
|
+
scripts?: Record<string, string>;
|
198
|
+
};
|
199
|
+
|
200
|
+
const zParsedPackageJson = (() => {
|
201
|
+
type TargetType = ParsedPackageJson;
|
202
|
+
|
203
|
+
const zTargetType = z.object({
|
204
|
+
scripts: z.record(z.string()).optional()
|
205
|
+
});
|
206
|
+
|
207
|
+
type InferredType = z.infer<typeof zTargetType>;
|
208
|
+
|
209
|
+
assert<Equals<TargetType, InferredType>>;
|
210
|
+
|
211
|
+
return id<z.ZodType<TargetType>>(zTargetType);
|
212
|
+
})();
|
213
|
+
|
214
|
+
const parsedPackageJson = JSON.parse(
|
215
|
+
fs.readFileSync(packageJsonFilePath).toString("utf8")
|
216
|
+
) as unknown;
|
217
|
+
|
218
|
+
zParsedPackageJson.parse(parsedPackageJson);
|
219
|
+
assert(is<ParsedPackageJson>(parsedPackageJson));
|
220
|
+
|
221
|
+
return parsedPackageJson;
|
222
|
+
})();
|
223
|
+
|
224
|
+
const isImplementedScriptByName = {
|
225
|
+
postinstall: false,
|
226
|
+
prepare: false
|
227
|
+
};
|
228
|
+
|
229
|
+
delete_postinstall_script: {
|
230
|
+
if (parsedPackageJson.scripts === undefined) {
|
231
|
+
break delete_postinstall_script;
|
232
|
+
}
|
233
|
+
|
234
|
+
for (const scriptName of objectKeys(isImplementedScriptByName)) {
|
235
|
+
if (parsedPackageJson.scripts[scriptName] === undefined) {
|
236
|
+
continue;
|
237
|
+
}
|
238
|
+
|
239
|
+
isImplementedScriptByName[scriptName] = true;
|
240
|
+
|
241
|
+
delete parsedPackageJson.scripts[scriptName];
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
const tmpProjectDirPath = pathJoin(yarnHomeDirPath, "tmpProject");
|
246
|
+
|
247
|
+
if (fs.existsSync(tmpProjectDirPath)) {
|
248
|
+
rmSync(tmpProjectDirPath, { recursive: true });
|
249
|
+
}
|
250
|
+
|
251
|
+
fs.mkdirSync(tmpProjectDirPath, { recursive: true });
|
252
|
+
|
253
|
+
fs.writeFileSync(
|
254
|
+
pathJoin(tmpProjectDirPath, "package.json"),
|
255
|
+
JSON.stringify(parsedPackageJson, undefined, 4)
|
256
|
+
);
|
257
|
+
|
258
|
+
const YARN_LOCK = "yarn.lock";
|
259
|
+
|
260
|
+
fs.copyFileSync(
|
261
|
+
pathJoin(packageJsonDirPath, YARN_LOCK),
|
262
|
+
pathJoin(tmpProjectDirPath, YARN_LOCK)
|
263
|
+
);
|
264
|
+
|
265
|
+
child_process.execSync(`yarn install`, {
|
266
|
+
cwd: tmpProjectDirPath,
|
267
|
+
stdio: "inherit"
|
268
|
+
});
|
269
|
+
|
270
|
+
// NOTE: Moving the modules from the tmp project to the actual project
|
271
|
+
// without messing up the links.
|
272
|
+
{
|
273
|
+
const { getAreSameVersions } = (() => {
|
274
|
+
type ParsedPackageJson = {
|
275
|
+
version: string;
|
276
|
+
};
|
277
|
+
|
278
|
+
const zParsedPackageJson = (() => {
|
279
|
+
type TargetType = ParsedPackageJson;
|
280
|
+
|
281
|
+
const zTargetType = z.object({
|
282
|
+
version: z.string()
|
283
|
+
});
|
284
|
+
|
285
|
+
type InferredType = z.infer<typeof zTargetType>;
|
286
|
+
|
287
|
+
assert<Equals<TargetType, InferredType>>;
|
288
|
+
|
289
|
+
return id<z.ZodType<TargetType>>(zTargetType);
|
290
|
+
})();
|
291
|
+
|
292
|
+
function readVersion(params: { moduleDirPath: string }): string {
|
293
|
+
const { moduleDirPath } = params;
|
294
|
+
|
295
|
+
const packageJsonFilePath = pathJoin(moduleDirPath, "package.json");
|
296
|
+
|
297
|
+
const packageJson = JSON.parse(
|
298
|
+
fs.readFileSync(packageJsonFilePath).toString("utf8")
|
299
|
+
);
|
300
|
+
|
301
|
+
zParsedPackageJson.parse(packageJson);
|
302
|
+
assert(is<ParsedPackageJson>(packageJson));
|
303
|
+
|
304
|
+
return packageJson.version;
|
305
|
+
}
|
306
|
+
|
307
|
+
function getAreSameVersions(params: {
|
308
|
+
moduleDirPath_a: string;
|
309
|
+
moduleDirPath_b: string;
|
310
|
+
}): boolean {
|
311
|
+
const { moduleDirPath_a, moduleDirPath_b } = params;
|
312
|
+
|
313
|
+
return (
|
314
|
+
readVersion({ moduleDirPath: moduleDirPath_a }) ===
|
315
|
+
readVersion({ moduleDirPath: moduleDirPath_b })
|
316
|
+
);
|
317
|
+
}
|
318
|
+
|
319
|
+
return { getAreSameVersions };
|
320
|
+
})();
|
321
|
+
|
322
|
+
const nodeModulesDirPath_tmpProject = pathJoin(tmpProjectDirPath, "node_modules");
|
323
|
+
const nodeModulesDirPath = pathJoin(packageJsonDirPath, "node_modules");
|
324
|
+
|
325
|
+
const modulePaths = fs
|
326
|
+
.readdirSync(nodeModulesDirPath_tmpProject)
|
327
|
+
.map(basename => {
|
328
|
+
if (basename.startsWith(".")) {
|
329
|
+
return undefined;
|
330
|
+
}
|
331
|
+
|
332
|
+
const path = pathJoin(nodeModulesDirPath_tmpProject, basename);
|
333
|
+
|
334
|
+
if (basename.startsWith("@")) {
|
335
|
+
return fs
|
336
|
+
.readdirSync(path)
|
337
|
+
.map(subBasename => {
|
338
|
+
if (subBasename.startsWith(".")) {
|
339
|
+
return undefined;
|
340
|
+
}
|
341
|
+
|
342
|
+
const subPath = pathJoin(path, subBasename);
|
343
|
+
|
344
|
+
if (!fs.lstatSync(subPath).isDirectory()) {
|
345
|
+
return undefined;
|
346
|
+
}
|
347
|
+
|
348
|
+
return {
|
349
|
+
moduleName: `${basename}/${subBasename}`,
|
350
|
+
moduleDirPath_tmpProject: subPath,
|
351
|
+
moduleDirPath: pathJoin(
|
352
|
+
nodeModulesDirPath,
|
353
|
+
basename,
|
354
|
+
subBasename
|
355
|
+
)
|
356
|
+
};
|
357
|
+
})
|
358
|
+
.filter(exclude(undefined));
|
359
|
+
}
|
360
|
+
|
361
|
+
if (!fs.lstatSync(path).isDirectory()) {
|
362
|
+
return undefined;
|
363
|
+
}
|
364
|
+
|
365
|
+
return [
|
366
|
+
{
|
367
|
+
moduleName: basename,
|
368
|
+
moduleDirPath_tmpProject: path,
|
369
|
+
moduleDirPath: pathJoin(nodeModulesDirPath, basename)
|
370
|
+
}
|
371
|
+
];
|
372
|
+
})
|
373
|
+
.filter(exclude(undefined))
|
374
|
+
.flat();
|
375
|
+
|
376
|
+
for (const {
|
377
|
+
moduleName,
|
378
|
+
moduleDirPath,
|
379
|
+
moduleDirPath_tmpProject
|
380
|
+
} of modulePaths) {
|
381
|
+
if (linkedModuleNames.includes(moduleName)) {
|
382
|
+
continue;
|
383
|
+
}
|
384
|
+
|
385
|
+
let doesTargetModuleExist = false;
|
386
|
+
|
387
|
+
skip_condition: {
|
388
|
+
if (!fs.existsSync(moduleDirPath)) {
|
389
|
+
break skip_condition;
|
390
|
+
}
|
391
|
+
|
392
|
+
doesTargetModuleExist = true;
|
393
|
+
|
394
|
+
const areSameVersions = getAreSameVersions({
|
395
|
+
moduleDirPath_a: moduleDirPath,
|
396
|
+
moduleDirPath_b: moduleDirPath_tmpProject
|
397
|
+
});
|
398
|
+
|
399
|
+
if (!areSameVersions) {
|
400
|
+
break skip_condition;
|
401
|
+
}
|
402
|
+
|
403
|
+
continue;
|
404
|
+
}
|
405
|
+
|
406
|
+
if (doesTargetModuleExist) {
|
407
|
+
rmSync(moduleDirPath, { recursive: true });
|
408
|
+
}
|
409
|
+
|
410
|
+
{
|
411
|
+
const dirPath = pathDirname(moduleDirPath);
|
412
|
+
|
413
|
+
if (!fs.existsSync(dirPath)) {
|
414
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
fs.renameSync(moduleDirPath_tmpProject, moduleDirPath);
|
419
|
+
}
|
420
|
+
|
421
|
+
move_bin: {
|
422
|
+
const binDirPath_tmpProject = pathJoin(nodeModulesDirPath_tmpProject, ".bin");
|
423
|
+
const binDirPath = pathJoin(nodeModulesDirPath, ".bin");
|
424
|
+
|
425
|
+
if (!fs.existsSync(binDirPath_tmpProject)) {
|
426
|
+
break move_bin;
|
427
|
+
}
|
428
|
+
|
429
|
+
for (const basename of fs.readdirSync(binDirPath_tmpProject)) {
|
430
|
+
const path_tmpProject = pathJoin(binDirPath_tmpProject, basename);
|
431
|
+
const path = pathJoin(binDirPath, basename);
|
432
|
+
|
433
|
+
if (fs.existsSync(path)) {
|
434
|
+
continue;
|
435
|
+
}
|
436
|
+
|
437
|
+
fs.renameSync(path_tmpProject, path);
|
438
|
+
}
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
fs.cpSync(
|
443
|
+
pathJoin(tmpProjectDirPath, YARN_LOCK),
|
444
|
+
pathJoin(packageJsonDirPath, YARN_LOCK)
|
445
|
+
);
|
446
|
+
|
447
|
+
rmSync(tmpProjectDirPath, { recursive: true });
|
448
|
+
|
449
|
+
for (const scriptName of objectKeys(isImplementedScriptByName)) {
|
450
|
+
if (!isImplementedScriptByName[scriptName]) {
|
451
|
+
continue;
|
452
|
+
}
|
453
|
+
|
454
|
+
child_process.execSync(`yarn run ${scriptName}`, {
|
455
|
+
cwd: packageJsonDirPath,
|
456
|
+
stdio: "inherit"
|
457
|
+
});
|
458
|
+
}
|
63
459
|
}
|
@@ -3,7 +3,13 @@ import { assert } from "tsafe/assert";
|
|
3
3
|
import * as fs from "fs";
|
4
4
|
import { join as pathJoin } from "path";
|
5
5
|
|
6
|
+
let cache: string | undefined = undefined;
|
7
|
+
|
6
8
|
export function readThisNpmPackageVersion(): string {
|
9
|
+
if (cache !== undefined) {
|
10
|
+
return cache;
|
11
|
+
}
|
12
|
+
|
7
13
|
const version = JSON.parse(
|
8
14
|
fs
|
9
15
|
.readFileSync(pathJoin(getThisCodebaseRootDirPath(), "package.json"))
|
@@ -12,5 +18,7 @@ export function readThisNpmPackageVersion(): string {
|
|
12
18
|
|
13
19
|
assert(typeof version === "string");
|
14
20
|
|
21
|
+
cache = version;
|
22
|
+
|
15
23
|
return version;
|
16
24
|
}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import { getNodeModulesBinDirPath } from "./nodeModulesBinDirPath";
|
2
|
+
import { join as pathJoin } from "path";
|
3
|
+
import * as fsPr from "fs/promises";
|
4
|
+
import { id } from "tsafe/id";
|
5
|
+
import { assert } from "tsafe/assert";
|
6
|
+
import chalk from "chalk";
|
7
|
+
import * as crypto from "crypto";
|
8
|
+
|
9
|
+
getIsPrettierAvailable.cache = id<boolean | undefined>(undefined);
|
10
|
+
|
11
|
+
export async function getIsPrettierAvailable(): Promise<boolean> {
|
12
|
+
if (getIsPrettierAvailable.cache !== undefined) {
|
13
|
+
return getIsPrettierAvailable.cache;
|
14
|
+
}
|
15
|
+
|
16
|
+
const nodeModulesBinDirPath = getNodeModulesBinDirPath();
|
17
|
+
|
18
|
+
const prettierBinPath = pathJoin(nodeModulesBinDirPath, "prettier");
|
19
|
+
|
20
|
+
const stats = await fsPr.stat(prettierBinPath).catch(() => undefined);
|
21
|
+
|
22
|
+
const isPrettierAvailable = stats?.isFile() ?? false;
|
23
|
+
|
24
|
+
getIsPrettierAvailable.cache = isPrettierAvailable;
|
25
|
+
|
26
|
+
return isPrettierAvailable;
|
27
|
+
}
|
28
|
+
|
29
|
+
type PrettierAndConfigHash = {
|
30
|
+
prettier: typeof import("prettier");
|
31
|
+
configHash: string;
|
32
|
+
};
|
33
|
+
|
34
|
+
getPrettier.cache = id<PrettierAndConfigHash | undefined>(undefined);
|
35
|
+
|
36
|
+
export async function getPrettier(): Promise<PrettierAndConfigHash> {
|
37
|
+
assert(getIsPrettierAvailable());
|
38
|
+
|
39
|
+
if (getPrettier.cache !== undefined) {
|
40
|
+
return getPrettier.cache;
|
41
|
+
}
|
42
|
+
|
43
|
+
const prettier = await import("prettier");
|
44
|
+
|
45
|
+
const configHash = await (async () => {
|
46
|
+
const configFilePath = await prettier.resolveConfigFile(
|
47
|
+
pathJoin(getNodeModulesBinDirPath(), "..")
|
48
|
+
);
|
49
|
+
|
50
|
+
if (configFilePath === null) {
|
51
|
+
return "";
|
52
|
+
}
|
53
|
+
|
54
|
+
const data = await fsPr.readFile(configFilePath);
|
55
|
+
|
56
|
+
return crypto.createHash("sha256").update(data).digest("hex");
|
57
|
+
})();
|
58
|
+
|
59
|
+
const prettierAndConfig: PrettierAndConfigHash = {
|
60
|
+
prettier,
|
61
|
+
configHash
|
62
|
+
};
|
63
|
+
|
64
|
+
getPrettier.cache = prettierAndConfig;
|
65
|
+
|
66
|
+
return prettierAndConfig;
|
67
|
+
}
|
68
|
+
|
69
|
+
export async function runPrettier(params: {
|
70
|
+
sourceCode: string;
|
71
|
+
filePath: string;
|
72
|
+
}): Promise<string> {
|
73
|
+
const { sourceCode, filePath } = params;
|
74
|
+
|
75
|
+
let formattedSourceCode: string;
|
76
|
+
|
77
|
+
try {
|
78
|
+
const { prettier } = await getPrettier();
|
79
|
+
|
80
|
+
const { ignored, inferredParser } = await prettier.getFileInfo(filePath, {
|
81
|
+
resolveConfig: true
|
82
|
+
});
|
83
|
+
|
84
|
+
if (ignored) {
|
85
|
+
return sourceCode;
|
86
|
+
}
|
87
|
+
|
88
|
+
const config = await prettier.resolveConfig(filePath);
|
89
|
+
|
90
|
+
formattedSourceCode = await prettier.format(sourceCode, {
|
91
|
+
...config,
|
92
|
+
filePath,
|
93
|
+
parser: inferredParser ?? undefined
|
94
|
+
});
|
95
|
+
} catch (error) {
|
96
|
+
console.log(
|
97
|
+
chalk.red(
|
98
|
+
`You probably need to upgrade the version of prettier in your project`
|
99
|
+
)
|
100
|
+
);
|
101
|
+
|
102
|
+
throw error;
|
103
|
+
}
|
104
|
+
|
105
|
+
return formattedSourceCode;
|
106
|
+
}
|
package/src/bin/update-kc-gen.ts
CHANGED
@@ -3,8 +3,8 @@ import * as fs from "fs/promises";
|
|
3
3
|
import { join as pathJoin } from "path";
|
4
4
|
import { existsAsync } from "./tools/fs.existsAsync";
|
5
5
|
import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_delegate";
|
6
|
-
import { runFormat } from "./tools/runFormat";
|
7
6
|
import * as crypto from "crypto";
|
7
|
+
import { getIsPrettierAvailable, runPrettier } from "./tools/runPrettier";
|
8
8
|
|
9
9
|
export async function command(params: { buildContext: BuildContext }) {
|
10
10
|
const { buildContext } = params;
|
@@ -18,12 +18,13 @@ export async function command(params: { buildContext: BuildContext }) {
|
|
18
18
|
return;
|
19
19
|
}
|
20
20
|
|
21
|
-
const filePath = pathJoin(buildContext.themeSrcDirPath,
|
21
|
+
const filePath = pathJoin(buildContext.themeSrcDirPath, "kc.gen.tsx");
|
22
22
|
|
23
23
|
const hasLoginTheme = buildContext.implementedThemeTypes.login.isImplemented;
|
24
24
|
const hasAccountTheme = buildContext.implementedThemeTypes.account.isImplemented;
|
25
|
+
const hasAdminTheme = buildContext.implementedThemeTypes.admin.isImplemented;
|
25
26
|
|
26
|
-
|
27
|
+
let newContent = [
|
27
28
|
``,
|
28
29
|
`/* eslint-disable */`,
|
29
30
|
``,
|
@@ -54,6 +55,7 @@ export async function command(params: { buildContext: BuildContext }) {
|
|
54
55
|
`type KcContext =`,
|
55
56
|
hasLoginTheme && ` | import("./login/KcContext").KcContext`,
|
56
57
|
hasAccountTheme && ` | import("./account/KcContext").KcContext`,
|
58
|
+
hasAdminTheme && ` | import("./admin/KcContext").KcContext`,
|
57
59
|
` ;`,
|
58
60
|
``,
|
59
61
|
`declare global {`,
|
@@ -66,6 +68,8 @@ export async function command(params: { buildContext: BuildContext }) {
|
|
66
68
|
`export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
|
67
69
|
hasAccountTheme &&
|
68
70
|
`export const KcAccountPage = lazy(() => import("./account/KcPage"));`,
|
71
|
+
hasAdminTheme &&
|
72
|
+
`export const KcAdminPage = lazy(() => import("./admin/KcPage"));`,
|
69
73
|
``,
|
70
74
|
`export function KcPage(`,
|
71
75
|
` props: {`,
|
@@ -82,6 +86,8 @@ export async function command(params: { buildContext: BuildContext }) {
|
|
82
86
|
` case "login": return <KcLoginPage kcContext={kcContext} />;`,
|
83
87
|
hasAccountTheme &&
|
84
88
|
` case "account": return <KcAccountPage kcContext={kcContext} />;`,
|
89
|
+
hasAdminTheme &&
|
90
|
+
` case "admin": return <KcAdminPage kcContext={kcContext} />;`,
|
85
91
|
` }`,
|
86
92
|
` })()}`,
|
87
93
|
` </Suspense>`,
|
@@ -108,20 +114,25 @@ export async function command(params: { buildContext: BuildContext }) {
|
|
108
114
|
return;
|
109
115
|
}
|
110
116
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
newContent = [
|
118
|
+
`// This file is auto-generated by the \`update-kc-gen\` command. Do not edit it manually.`,
|
119
|
+
`// Hash: ${hash}`,
|
120
|
+
``,
|
121
|
+
newContent
|
122
|
+
].join("\n");
|
123
|
+
|
124
|
+
format: {
|
125
|
+
if (!(await getIsPrettierAvailable())) {
|
126
|
+
break format;
|
127
|
+
}
|
128
|
+
|
129
|
+
newContent = await runPrettier({
|
130
|
+
filePath,
|
131
|
+
sourceCode: newContent
|
132
|
+
});
|
133
|
+
}
|
134
|
+
|
135
|
+
await fs.writeFile(filePath, Buffer.from(newContent, "utf8"));
|
125
136
|
|
126
137
|
delete_legacy_file: {
|
127
138
|
const legacyFilePath = filePath.replace(/tsx$/, "ts");
|