@progress/kendo-e2e
Version:
Kendo UI end-to-end test utilities.
130 lines (111 loc) • 4.18 kB
JavaScript
#!/usr/bin/env node
/**
* postinstall script for @progress/kendo-e2e
*
* Automatically installs the SKILL.md file into the consumer's workspace
* so AI coding agents (Copilot, Claude Code, Cursor) can discover kendo-e2e
* CLI commands out of the box.
*
* This runs after `npm install`. If npm scripts are disabled (--ignore-scripts),
* users can run `npx kendo-e2e install --skills` manually (Option B).
*
* Set KENDO_E2E_SKIP_POSTINSTALL=1 to skip this step.
*/
const fs = require("fs");
const path = require("path");
// Skip if explicitly opted out
if (process.env.KENDO_E2E_SKIP_POSTINSTALL === "1") {
process.exit(0);
}
// Skip if running in CI (don't pollute CI builds)
if (process.env.CI === "true" || process.env.CI === "1") {
process.exit(0);
}
// Skip if this is the kendo-e2e repo itself (npm install during development)
const packageJson = path.join(process.cwd(), "package.json");
if (fs.existsSync(packageJson)) {
try {
const pkg = JSON.parse(fs.readFileSync(packageJson, "utf-8"));
if (pkg.name === "@progress/kendo-e2e") {
process.exit(0);
}
} catch {
// Ignore parse errors
}
}
// Find the project root (walk up from node_modules/@progress/kendo-e2e)
function findProjectRoot() {
// During postinstall, cwd might be the package dir inside node_modules
// or the actual project root. Check both.
let dir = process.cwd();
// If we're inside node_modules, walk up
if (dir.includes("node_modules")) {
while (dir.includes("node_modules") && dir !== path.dirname(dir)) {
dir = path.dirname(dir);
}
return dir;
}
// Already at project root
return dir;
}
// Find the SKILL.md source
function findSkillSource() {
const candidates = [
path.resolve(__dirname, "../skills/kendo-e2e/SKILL.md"),
path.resolve(__dirname, "../../skills/kendo-e2e/SKILL.md"),
path.resolve(__dirname, "../skills/SKILL.md"),
];
for (const candidate of candidates) {
if (fs.existsSync(candidate)) {
return candidate;
}
}
return null;
}
function main() {
const projectRoot = findProjectRoot();
const skillSource = findSkillSource();
if (!skillSource) {
// Skill file not found — not a problem, just skip silently
process.exit(0);
}
const targetDir = path.join(projectRoot, ".github", "skills", "kendo-e2e");
const targetFile = path.join(targetDir, "SKILL.md");
// Don't overwrite if the user has customized it
if (fs.existsSync(targetFile)) {
const existing = fs.readFileSync(targetFile, "utf-8");
const source = fs.readFileSync(skillSource, "utf-8");
if (existing === source) {
// Already up to date
process.exit(0);
}
// Different content — user may have customized it, leave it alone
// but install a .latest version they can compare against
fs.writeFileSync(targetFile + ".latest", source);
console.log("kendo-e2e: SKILL.md has local changes. Updated .latest for comparison.");
process.exit(0);
}
// Install SKILL.md
try {
fs.mkdirSync(targetDir, { recursive: true });
fs.copyFileSync(skillSource, targetFile);
// Also copy references
const refsDir = path.join(path.dirname(skillSource), "references");
if (fs.existsSync(refsDir)) {
const targetRefsDir = path.join(targetDir, "references");
fs.mkdirSync(targetRefsDir, { recursive: true });
for (const file of fs.readdirSync(refsDir)) {
if (file.endsWith(".md")) {
fs.copyFileSync(path.join(refsDir, file), path.join(targetRefsDir, file));
}
}
}
console.log("kendo-e2e: Installed SKILL.md for AI coding agents.");
console.log(" Your agent can now discover kendo-e2e CLI commands automatically.");
console.log(" Set KENDO_E2E_SKIP_POSTINSTALL=1 to disable.");
} catch {
// Non-fatal — don't break the install
process.exit(0);
}
}
main();