Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
232be50225 | |||
a00bb0c4db | |||
5517d6baf4 | |||
e2975503a4 | |||
1231c92198 | |||
64ca0bc0ca | |||
2bceb9385c |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "11.3.22",
|
||||
"version": "11.3.24",
|
||||
"description": "Framework to create custom Keycloak UIs",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -56,7 +56,8 @@ export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
||||
``,
|
||||
`$ npx keycloakify eject-file --file ${fileRelativePath.split(pathSep).join("/")}`,
|
||||
``,
|
||||
`This file comes from ${uiModuleName} version ${uiModuleVersion}.`
|
||||
`This file comes from ${uiModuleName} version ${uiModuleVersion}.`,
|
||||
`This file has been copied over to your repo by your postinstall script: \`npx keycloakify postinstall\``
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -9,6 +9,8 @@ import { dirname as pathDirname } from "path";
|
||||
import { join as pathJoin } from "path";
|
||||
import { existsAsync } from "../tools/fs.existsAsync";
|
||||
import * as fsPr from "fs/promises";
|
||||
import { getIsTrackedByGit } from "../tools/isTrackedByGit";
|
||||
import { untrackFromGit } from "../tools/untrackFromGit";
|
||||
|
||||
export async function command(params: { buildContext: BuildContext }) {
|
||||
const { buildContext } = params;
|
||||
@ -45,8 +47,10 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
fileRelativePath
|
||||
);
|
||||
|
||||
const doesFileExist = await existsAsync(destFilePath);
|
||||
|
||||
skip_condition: {
|
||||
if (!(await existsAsync(destFilePath))) {
|
||||
if (!doesFileExist) {
|
||||
break skip_condition;
|
||||
}
|
||||
|
||||
@ -61,8 +65,26 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
return;
|
||||
}
|
||||
|
||||
git_untrack: {
|
||||
if (!doesFileExist) {
|
||||
break git_untrack;
|
||||
}
|
||||
|
||||
const isTracked = await getIsTrackedByGit({
|
||||
filePath: destFilePath
|
||||
});
|
||||
|
||||
if (!isTracked) {
|
||||
break git_untrack;
|
||||
}
|
||||
|
||||
await untrackFromGit({
|
||||
filePath: destFilePath
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const dirName = pathDirname(copyableFilePath);
|
||||
const dirName = pathDirname(destFilePath);
|
||||
|
||||
if (!(await existsAsync(dirName))) {
|
||||
await fsPr.mkdir(dirName, { recursive: true });
|
||||
|
29
src/bin/tools/isTrackedByGit.ts
Normal file
29
src/bin/tools/isTrackedByGit.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as child_process from "child_process";
|
||||
import { dirname as pathDirname, basename as pathBasename } from "path";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
|
||||
export function getIsTrackedByGit(params: { filePath: string }): Promise<boolean> {
|
||||
const { filePath } = params;
|
||||
|
||||
const dIsTracked = new Deferred<boolean>();
|
||||
|
||||
child_process.exec(
|
||||
`git ls-files --error-unmatch ${pathBasename(filePath)}`,
|
||||
{ cwd: pathDirname(filePath) },
|
||||
error => {
|
||||
if (error === null) {
|
||||
dIsTracked.resolve(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error.code === 1) {
|
||||
dIsTracked.resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
dIsTracked.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return dIsTracked.pr;
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
import { getNodeModulesBinDirPath } from "./nodeModulesBinDirPath";
|
||||
import { join as pathJoin } from "path";
|
||||
import { join as pathJoin, resolve as pathResolve } from "path";
|
||||
import * as fsPr from "fs/promises";
|
||||
import { id } from "tsafe/id";
|
||||
import { assert } from "tsafe/assert";
|
||||
import chalk from "chalk";
|
||||
import * as crypto from "crypto";
|
||||
import { is } from "tsafe/is";
|
||||
import { symToStr } from "tsafe/symToStr";
|
||||
import { readThisNpmPackageVersion } from "./readThisNpmPackageVersion";
|
||||
|
||||
getIsPrettierAvailable.cache = id<boolean | undefined>(undefined);
|
||||
|
||||
@ -40,7 +43,25 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
|
||||
return getPrettier.cache;
|
||||
}
|
||||
|
||||
const prettier = await import("prettier");
|
||||
let prettier = id<typeof import("prettier") | undefined>(undefined);
|
||||
|
||||
import_prettier: {
|
||||
// NOTE: When module is linked we want to make sure we import the correct version
|
||||
// of prettier, that is the one of the project, not the one of this repo.
|
||||
// So we do a sketchy eval to bypass ncc.
|
||||
// We make sure to only do that when linking, otherwise we import properly.
|
||||
if (readThisNpmPackageVersion() === "0.0.0") {
|
||||
eval(
|
||||
`${symToStr({ prettier })} = require("${pathResolve(pathJoin(getNodeModulesBinDirPath(), "..", "prettier"))}")`
|
||||
);
|
||||
|
||||
assert(!is<undefined>(prettier));
|
||||
|
||||
break import_prettier;
|
||||
}
|
||||
|
||||
prettier = await import("prettier");
|
||||
}
|
||||
|
||||
const configHash = await (async () => {
|
||||
const configFilePath = await prettier.resolveConfigFile(
|
||||
|
24
src/bin/tools/untrackFromGit.ts
Normal file
24
src/bin/tools/untrackFromGit.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as child_process from "child_process";
|
||||
import { dirname as pathDirname, basename as pathBasename } from "path";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
|
||||
export async function untrackFromGit(params: { filePath: string }): Promise<void> {
|
||||
const { filePath } = params;
|
||||
|
||||
const dDone = new Deferred<void>();
|
||||
|
||||
child_process.exec(
|
||||
`git rm --cached ${pathBasename(filePath)}`,
|
||||
{ cwd: pathDirname(filePath) },
|
||||
error => {
|
||||
if (error !== null) {
|
||||
dDone.reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
dDone.resolve();
|
||||
}
|
||||
);
|
||||
|
||||
await dDone.pr;
|
||||
}
|
Reference in New Issue
Block a user