Better linking script

This commit is contained in:
garronej
2022-09-01 16:36:38 +02:00
parent 5b20ab2f7c
commit ce0ab8dccf

View File

@ -1,5 +1,6 @@
import { execSync } from "child_process"; import { execSync } from "child_process";
import { join as pathJoin, relative as pathRelative } from "path"; import { join as pathJoin, relative as pathRelative } from "path";
import { exclude } from "tsafe/exclude";
import * as fs from "fs"; import * as fs from "fs";
const keycloakifyDirPath = pathJoin(__dirname, "..", ".."); const keycloakifyDirPath = pathJoin(__dirname, "..", "..");
@ -60,11 +61,34 @@ const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => {
}); });
}; };
const testAppNames = [process.argv[2] ?? "keycloakify-starter"] as const; const testAppPaths = (() => {
const arg = process.argv[2];
const getTestAppPath = (testAppName: typeof testAppNames[number]) => pathJoin(keycloakifyDirPath, "..", testAppName); const testAppNames = arg !== undefined ? [arg] : ["keycloakify-starter", "keycloakify-advanced-starter"];
testAppNames.forEach(testAppName => execSync("yarn install", { "cwd": getTestAppPath(testAppName) })); return testAppNames
.map(testAppName => {
const testAppPath = pathJoin(keycloakifyDirPath, "..", testAppName);
if (fs.existsSync(testAppPath)) {
return testAppPath;
}
console.warn(`Skipping ${testAppName} since it cant be found here: ${testAppPath}`);
return undefined;
})
.filter(exclude(undefined));
})();
console.log(testAppPaths);
if (testAppPaths.length === 0) {
console.error("No test app to link into!");
process.exit(-1);
}
testAppPaths.forEach(testAppPath => execSync("yarn install", { "cwd": testAppPath }));
console.log("=== Linking common dependencies ==="); console.log("=== Linking common dependencies ===");
@ -81,22 +105,24 @@ commonThirdPartyDeps.forEach(commonThirdPartyDep => {
); );
execYarnLink({ "cwd": localInstallPath }); execYarnLink({ "cwd": localInstallPath });
});
testAppNames.forEach(testAppName => commonThirdPartyDeps.forEach(commonThirdPartyDep =>
testAppPaths.forEach(testAppPath =>
execYarnLink({ execYarnLink({
"cwd": getTestAppPath(testAppName), "cwd": testAppPath,
"targetModuleName": commonThirdPartyDep "targetModuleName": commonThirdPartyDep
}) })
)
); );
});
console.log("=== Linking in house dependencies ==="); console.log("=== Linking in house dependencies ===");
execYarnLink({ "cwd": pathJoin(keycloakifyDirPath, "dist") }); execYarnLink({ "cwd": pathJoin(keycloakifyDirPath, "dist") });
testAppNames.forEach(testAppName => testAppPaths.forEach(testAppPath =>
execYarnLink({ execYarnLink({
"cwd": getTestAppPath(testAppName), "cwd": testAppPath,
"targetModuleName": "keycloakify" "targetModuleName": "keycloakify"
}) })
); );