Fix linking script on windows
This commit is contained in:
parent
12e632d221
commit
7326038424
@ -1,11 +1,5 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {
|
import { join as pathJoin, basename as pathBasename, dirname as pathDirname } from "path";
|
||||||
join as pathJoin,
|
|
||||||
relative as pathRelative,
|
|
||||||
basename as pathBasename,
|
|
||||||
dirname as pathDirname,
|
|
||||||
sep as pathSep
|
|
||||||
} from "path";
|
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { run } from "../shared/run";
|
import { run } from "../shared/run";
|
||||||
import { cacheDirPath as cacheDirPath_base } from "../shared/cacheDirPath";
|
import { cacheDirPath as cacheDirPath_base } from "../shared/cacheDirPath";
|
||||||
|
@ -55,7 +55,6 @@ const commonThirdPartyDeps = [
|
|||||||
Buffer.from(modifiedPackageJsonContent, "utf8")
|
Buffer.from(modifiedPackageJsonContent, "utf8")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const yarnGlobalDirPath = pathJoin(rootDirPath, ".yarn_home");
|
const yarnGlobalDirPath = pathJoin(rootDirPath, ".yarn_home");
|
||||||
|
|
||||||
fs.rmSync(yarnGlobalDirPath, { recursive: true, force: true });
|
fs.rmSync(yarnGlobalDirPath, { recursive: true, force: true });
|
||||||
@ -64,6 +63,21 @@ fs.mkdirSync(yarnGlobalDirPath);
|
|||||||
const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => {
|
const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => {
|
||||||
const { targetModuleName, cwd } = params;
|
const { targetModuleName, cwd } = params;
|
||||||
|
|
||||||
|
if (targetModuleName === undefined) {
|
||||||
|
const packageJsonFilePath = pathJoin(cwd, "package.json");
|
||||||
|
|
||||||
|
const packageJson = JSON.parse(
|
||||||
|
fs.readFileSync(packageJsonFilePath).toString("utf8")
|
||||||
|
);
|
||||||
|
|
||||||
|
delete packageJson["packageManager"];
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
packageJsonFilePath,
|
||||||
|
Buffer.from(JSON.stringify(packageJson, null, 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const cmd = [
|
const cmd = [
|
||||||
"yarn",
|
"yarn",
|
||||||
"link",
|
"link",
|
||||||
|
@ -1,49 +1,88 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join } from "path";
|
import { join as pathJoin, sep as pathSep } from "path";
|
||||||
import { startRebuildOnSrcChange } from "./shared/startRebuildOnSrcChange";
|
|
||||||
import { crawl } from "../src/bin/tools/crawl";
|
|
||||||
import { run } from "./shared/run";
|
import { run } from "./shared/run";
|
||||||
|
import cliSelect from "cli-select";
|
||||||
|
import { getThisCodebaseRootDirPath } from "../src/bin/tools/getThisCodebaseRootDirPath";
|
||||||
|
import chalk from "chalk";
|
||||||
|
import { removeNodeModules } from "./tools/removeNodeModules";
|
||||||
|
import { startRebuildOnSrcChange } from "./shared/startRebuildOnSrcChange";
|
||||||
|
|
||||||
{
|
(async () => {
|
||||||
const dirPath = "node_modules";
|
const parentDirPath = pathJoin(getThisCodebaseRootDirPath(), "..");
|
||||||
|
|
||||||
try {
|
const { starterName } = await (async () => {
|
||||||
fs.rmSync(dirPath, { recursive: true, force: true });
|
const starterNames = fs
|
||||||
} catch {
|
.readdirSync(parentDirPath)
|
||||||
// NOTE: This is a workaround for windows
|
.filter(
|
||||||
// we can't remove locked executables.
|
basename =>
|
||||||
|
basename.includes("starter") &&
|
||||||
|
basename.includes("angular") &&
|
||||||
|
fs.statSync(pathJoin(parentDirPath, basename)).isDirectory()
|
||||||
|
);
|
||||||
|
|
||||||
crawl({
|
if (starterNames.length === 0) {
|
||||||
dirPath,
|
console.log(
|
||||||
returnedPathsType: "absolute"
|
chalk.red(
|
||||||
}).forEach(filePath => {
|
`No starter found. Keycloakify Angular starter found in ${parentDirPath}`
|
||||||
try {
|
)
|
||||||
fs.rmSync(filePath, { force: true });
|
);
|
||||||
} catch (error) {
|
process.exit(-1);
|
||||||
if (filePath.endsWith(".exe")) {
|
}
|
||||||
return;
|
|
||||||
}
|
const starterName = await (async () => {
|
||||||
throw error;
|
if (starterNames.length === 1) {
|
||||||
|
return starterNames[0];
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.rmSync("dist", { recursive: true, force: true });
|
console.log(chalk.cyan(`\nSelect a starter to link in:`));
|
||||||
fs.rmSync(".yarn_home", { recursive: true, force: true });
|
|
||||||
|
|
||||||
run("yarn install");
|
const { value } = await cliSelect<string>({
|
||||||
run("yarn build");
|
values: starterNames.map(starterName => `..${pathSep}${starterName}`)
|
||||||
|
}).catch(() => {
|
||||||
|
process.exit(-1);
|
||||||
|
});
|
||||||
|
|
||||||
const starterName = "keycloakify-starter";
|
return value.split(pathSep)[1];
|
||||||
|
})();
|
||||||
|
|
||||||
fs.rmSync(join("..", starterName, "node_modules"), {
|
return { starterName };
|
||||||
recursive: true,
|
})();
|
||||||
force: true
|
|
||||||
});
|
|
||||||
|
|
||||||
run("yarn install", { cwd: join("..", starterName) });
|
const startTime = Date.now();
|
||||||
|
|
||||||
run(`npx tsx ${join("scripts", "link-in-app.ts")} ${starterName}`);
|
console.log(chalk.cyan(`\n\nLinking in ..${pathSep}${starterName}...`));
|
||||||
|
|
||||||
startRebuildOnSrcChange();
|
removeNodeModules({
|
||||||
|
nodeModulesDirPath: pathJoin(getThisCodebaseRootDirPath(), "node_modules")
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.rmSync(pathJoin(getThisCodebaseRootDirPath(), "dist"), {
|
||||||
|
recursive: true,
|
||||||
|
force: true
|
||||||
|
});
|
||||||
|
fs.rmSync(pathJoin(getThisCodebaseRootDirPath(), ".yarn_home"), {
|
||||||
|
recursive: true,
|
||||||
|
force: true
|
||||||
|
});
|
||||||
|
|
||||||
|
run("yarn install");
|
||||||
|
run("yarn build");
|
||||||
|
|
||||||
|
const starterDirPath = pathJoin(parentDirPath, starterName);
|
||||||
|
|
||||||
|
removeNodeModules({
|
||||||
|
nodeModulesDirPath: pathJoin(starterDirPath, "node_modules")
|
||||||
|
});
|
||||||
|
|
||||||
|
run("yarn install", { cwd: starterDirPath });
|
||||||
|
|
||||||
|
run(`npx tsx ${pathJoin("scripts", "link-in-app.ts")} ${starterName}`);
|
||||||
|
|
||||||
|
const durationSeconds = Math.round((Date.now() - startTime) / 1000);
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
|
startRebuildOnSrcChange();
|
||||||
|
|
||||||
|
console.log(chalk.green(`\n\nLinked in ${starterName} in ${durationSeconds}s`));
|
||||||
|
})();
|
||||||
|
27
scripts/tools/removeNodeModules.ts
Normal file
27
scripts/tools/removeNodeModules.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import * as fs from "fs";
|
||||||
|
import { crawl } from "../../src/bin/tools/crawl";
|
||||||
|
|
||||||
|
export function removeNodeModules(params: { nodeModulesDirPath: string }) {
|
||||||
|
const { nodeModulesDirPath } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.rmSync(nodeModulesDirPath, { recursive: true, force: true });
|
||||||
|
} catch {
|
||||||
|
// NOTE: This is a workaround for windows
|
||||||
|
// we can't remove locked executables.
|
||||||
|
|
||||||
|
crawl({
|
||||||
|
dirPath: nodeModulesDirPath,
|
||||||
|
returnedPathsType: "absolute"
|
||||||
|
}).forEach(filePath => {
|
||||||
|
try {
|
||||||
|
fs.rmSync(filePath, { force: true });
|
||||||
|
} catch (error) {
|
||||||
|
if (filePath.endsWith(".exe")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user