@reddoorla/maintenance 0.2.0 → 0.4.0
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/dist/cli/bin.js +183 -6
- package/dist/cli/bin.js.map +1 -1
- package/dist/configs/svelte.d.ts +39 -0
- package/dist/configs/svelte.js +30 -0
- package/dist/configs/svelte.js.map +1 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.js +119 -2
- package/dist/index.js.map +1 -1
- package/dist/recipes/sync-configs.d.ts +1 -1
- package/dist/recipes/sync-configs.js +19 -1
- package/dist/recipes/sync-configs.js.map +1 -1
- package/dist/{sync-configs-7XIzzN_L.d.ts → sync-configs-C56tK7Go.d.ts} +2 -2
- package/package.json +5 -1
package/dist/cli/bin.js
CHANGED
|
@@ -10,7 +10,7 @@ import { resolve as resolve2 } from "path";
|
|
|
10
10
|
|
|
11
11
|
// src/audits/util/spawn.ts
|
|
12
12
|
import { spawn } from "child_process";
|
|
13
|
-
var defaultSpawn = (cmd, args, opts = {}) => new Promise((
|
|
13
|
+
var defaultSpawn = (cmd, args, opts = {}) => new Promise((resolve8, reject) => {
|
|
14
14
|
const streaming = opts.streaming === true;
|
|
15
15
|
const child = spawn(cmd, [...args], {
|
|
16
16
|
cwd: opts.cwd,
|
|
@@ -33,7 +33,7 @@ var defaultSpawn = (cmd, args, opts = {}) => new Promise((resolve7, reject) => {
|
|
|
33
33
|
});
|
|
34
34
|
child.on("close", (code) => {
|
|
35
35
|
if (timer) clearTimeout(timer);
|
|
36
|
-
|
|
36
|
+
resolve8({ code: code ?? -1, stdout, stderr });
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -881,7 +881,25 @@ var playwrightA11y = {
|
|
|
881
881
|
contents: `export { default } from "@reddoorla/maintenance/configs/playwright-a11y";
|
|
882
882
|
`
|
|
883
883
|
};
|
|
884
|
-
var
|
|
884
|
+
var svelte = {
|
|
885
|
+
config: "svelte",
|
|
886
|
+
path: "svelte.config.js",
|
|
887
|
+
contents: `import { createSvelteConfig } from "@reddoorla/maintenance/configs/svelte";
|
|
888
|
+
import adapter from "@sveltejs/adapter-auto";
|
|
889
|
+
|
|
890
|
+
/** @type {import('@sveltejs/kit').Config} */
|
|
891
|
+
export default createSvelteConfig({
|
|
892
|
+
kit: { adapter: adapter() },
|
|
893
|
+
});
|
|
894
|
+
`
|
|
895
|
+
};
|
|
896
|
+
var ALL_TEMPLATES = [
|
|
897
|
+
eslint,
|
|
898
|
+
prettier,
|
|
899
|
+
lighthouse,
|
|
900
|
+
playwrightA11y,
|
|
901
|
+
svelte
|
|
902
|
+
];
|
|
885
903
|
function templatesByName(which) {
|
|
886
904
|
return ALL_TEMPLATES.filter((t) => which.includes(t.config));
|
|
887
905
|
}
|
|
@@ -1689,12 +1707,154 @@ async function runConvertToPnpmCommand(site, opts) {
|
|
|
1689
1707
|
return { output, code };
|
|
1690
1708
|
}
|
|
1691
1709
|
|
|
1710
|
+
// src/cli/commands/onboard.ts
|
|
1711
|
+
import { resolve as resolve7 } from "path";
|
|
1712
|
+
|
|
1713
|
+
// src/recipes/onboard.ts
|
|
1714
|
+
import { stat as stat3 } from "fs/promises";
|
|
1715
|
+
import { join as join15 } from "path";
|
|
1716
|
+
var PACKAGE_NAME = "@reddoorla/maintenance";
|
|
1717
|
+
var DEFAULT_PACKAGE_VERSION = "^0.2.0";
|
|
1718
|
+
var AUDIT_DEPS = {
|
|
1719
|
+
lighthouse: [{ name: "@lhci/cli", version: "^0.15.1" }],
|
|
1720
|
+
a11y: [
|
|
1721
|
+
{ name: "@playwright/test", version: "^1.59.1" },
|
|
1722
|
+
{ name: "@axe-core/playwright", version: "^4.11.3" }
|
|
1723
|
+
]
|
|
1724
|
+
};
|
|
1725
|
+
async function exists2(path) {
|
|
1726
|
+
try {
|
|
1727
|
+
await stat3(path);
|
|
1728
|
+
return true;
|
|
1729
|
+
} catch {
|
|
1730
|
+
return false;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function siteLabel10(site) {
|
|
1734
|
+
return site.name ?? site.path;
|
|
1735
|
+
}
|
|
1736
|
+
function isDeclared(pkg, name) {
|
|
1737
|
+
return Boolean(pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]);
|
|
1738
|
+
}
|
|
1739
|
+
async function onboard(site, opts = {}) {
|
|
1740
|
+
const label = siteLabel10(site);
|
|
1741
|
+
const spawn2 = opts.spawn ?? defaultSpawn;
|
|
1742
|
+
const audits = opts.audits ?? ["lighthouse", "a11y"];
|
|
1743
|
+
const packageVersion = opts.packageVersion ?? DEFAULT_PACKAGE_VERSION;
|
|
1744
|
+
if (!await exists2(join15(site.path, "pnpm-lock.yaml"))) {
|
|
1745
|
+
return {
|
|
1746
|
+
recipe: "onboard",
|
|
1747
|
+
site: label,
|
|
1748
|
+
status: "failed",
|
|
1749
|
+
commits: [],
|
|
1750
|
+
notes: "no pnpm-lock.yaml at site root \u2014 run convert-to-pnpm first"
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
const pkgPath = join15(site.path, "package.json");
|
|
1754
|
+
const pkg = await readPackageJson(pkgPath);
|
|
1755
|
+
const toAdd = [];
|
|
1756
|
+
if (!isDeclared(pkg, PACKAGE_NAME)) {
|
|
1757
|
+
toAdd.push({ name: PACKAGE_NAME, version: packageVersion });
|
|
1758
|
+
}
|
|
1759
|
+
for (const audit of audits) {
|
|
1760
|
+
for (const dep of AUDIT_DEPS[audit]) {
|
|
1761
|
+
if (!isDeclared(pkg, dep.name)) toAdd.push(dep);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (toAdd.length === 0) {
|
|
1765
|
+
return {
|
|
1766
|
+
recipe: "onboard",
|
|
1767
|
+
site: label,
|
|
1768
|
+
status: "noop",
|
|
1769
|
+
commits: [],
|
|
1770
|
+
notes: `site already has ${PACKAGE_NAME} and audit deps (${audits.join("+")})`
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
if (!await isWorkingTreeClean(site.path)) {
|
|
1774
|
+
throw new Error(`refusing to run: working tree is not clean at ${site.path}`);
|
|
1775
|
+
}
|
|
1776
|
+
const branch = branchName("onboard");
|
|
1777
|
+
await createBranch(site.path, branch);
|
|
1778
|
+
let next = pkg;
|
|
1779
|
+
for (const dep of toAdd) {
|
|
1780
|
+
next = bumpDep(next, dep.name, dep.version);
|
|
1781
|
+
}
|
|
1782
|
+
await writePackageJson(pkgPath, next);
|
|
1783
|
+
const installResult = await spawn2("pnpm", ["install"], {
|
|
1784
|
+
cwd: site.path,
|
|
1785
|
+
streaming: true
|
|
1786
|
+
});
|
|
1787
|
+
if (installResult.code !== 0) {
|
|
1788
|
+
return {
|
|
1789
|
+
recipe: "onboard",
|
|
1790
|
+
site: label,
|
|
1791
|
+
status: "failed",
|
|
1792
|
+
commits: [],
|
|
1793
|
+
notes: `pnpm install failed (exit ${installResult.code}). branch ${branch} left for inspection.`
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
const sha = await commit(
|
|
1797
|
+
site.path,
|
|
1798
|
+
`chore(reddoor): onboard with ${PACKAGE_NAME} ${packageVersion}`
|
|
1799
|
+
);
|
|
1800
|
+
const shas = sha ? [sha] : [];
|
|
1801
|
+
return {
|
|
1802
|
+
recipe: "onboard",
|
|
1803
|
+
site: label,
|
|
1804
|
+
status: "applied",
|
|
1805
|
+
commits: shas,
|
|
1806
|
+
notes: `branch: ${branch}. Added ${toAdd.length} dep(s): ${toAdd.map((d) => d.name).join(", ")}`
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
// src/cli/commands/onboard.ts
|
|
1811
|
+
var ALL_AUDITS = ["lighthouse", "a11y"];
|
|
1812
|
+
function parseAudits(value) {
|
|
1813
|
+
if (!value) return void 0;
|
|
1814
|
+
const parsed = value.split(",").map((s) => s.trim());
|
|
1815
|
+
for (const a of parsed) {
|
|
1816
|
+
if (!ALL_AUDITS.includes(a)) {
|
|
1817
|
+
throw Object.assign(
|
|
1818
|
+
new Error(`unknown audit in --audits: ${a}. expected ${ALL_AUDITS.join(", ")}`),
|
|
1819
|
+
{ exitCode: 2 }
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
return parsed;
|
|
1824
|
+
}
|
|
1825
|
+
function formatResult5(r) {
|
|
1826
|
+
if (r.status === "noop") return `[${r.site}] noop: ${r.notes ?? ""}`;
|
|
1827
|
+
if (r.status === "failed") return `[${r.site}] failed: ${r.notes ?? ""}`;
|
|
1828
|
+
return `[${r.site}] applied: ${r.commits.length} commit(s)
|
|
1829
|
+
${r.notes ?? ""}`;
|
|
1830
|
+
}
|
|
1831
|
+
async function runOnboardCommand(site, opts) {
|
|
1832
|
+
const audits = parseAudits(opts.audits);
|
|
1833
|
+
const cwd = opts.cwd ? resolve7(opts.cwd) : process.cwd();
|
|
1834
|
+
let sites = await resolveSites({
|
|
1835
|
+
...site !== void 0 ? { site } : {},
|
|
1836
|
+
...opts.fleet !== void 0 ? { fleet: opts.fleet } : {},
|
|
1837
|
+
cwd
|
|
1838
|
+
});
|
|
1839
|
+
if (opts.fleet) {
|
|
1840
|
+
const workdir = opts.workdir ?? `${process.env.HOME ?? ""}/.reddoor-maint/sites`;
|
|
1841
|
+
sites = await Promise.all(sites.map((s) => cloneIfNeeded(s, { workdir })));
|
|
1842
|
+
}
|
|
1843
|
+
const results = [];
|
|
1844
|
+
for (const s of sites) {
|
|
1845
|
+
results.push(await onboard(s, audits ? { audits } : {}));
|
|
1846
|
+
}
|
|
1847
|
+
const output = results.map(formatResult5).join("\n");
|
|
1848
|
+
const code = results.some((r) => r.status === "failed") ? 1 : 0;
|
|
1849
|
+
return { output, code };
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1692
1852
|
// src/cli/version.ts
|
|
1693
1853
|
import { readFileSync } from "fs";
|
|
1694
|
-
import { join as
|
|
1854
|
+
import { join as join16 } from "path";
|
|
1695
1855
|
function resolvePackageVersion(fromDir) {
|
|
1696
1856
|
try {
|
|
1697
|
-
const raw = readFileSync(
|
|
1857
|
+
const raw = readFileSync(join16(fromDir, "..", "..", "package.json"), "utf-8");
|
|
1698
1858
|
const pkg = JSON.parse(raw);
|
|
1699
1859
|
return pkg.version ?? "unknown";
|
|
1700
1860
|
} catch {
|
|
@@ -1716,7 +1876,8 @@ var RECIPE_DESCRIPTIONS = {
|
|
|
1716
1876
|
"sync-configs": "Overwrite a site's canonical configs to match @reddoorla/maintenance.",
|
|
1717
1877
|
"bump-deps": "Bump dependencies and commit the lockfile change.",
|
|
1718
1878
|
"svelte-4-to-5": "Run the 7-commit Svelte 4 \u2192 5 upgrade recipe.",
|
|
1719
|
-
"convert-to-pnpm": "Convert an npm/yarn site to pnpm (lockfile, packageManager, scripts)."
|
|
1879
|
+
"convert-to-pnpm": "Convert an npm/yarn site to pnpm (lockfile, packageManager, scripts).",
|
|
1880
|
+
onboard: "Install @reddoorla/maintenance + audit deps on a site (preferred first step)."
|
|
1720
1881
|
};
|
|
1721
1882
|
var cli = cac("reddoor-maint");
|
|
1722
1883
|
cli.option("--cwd <path>", "Override working directory (default: process.cwd())");
|
|
@@ -1799,6 +1960,22 @@ cli.command(
|
|
|
1799
1960
|
}
|
|
1800
1961
|
}
|
|
1801
1962
|
);
|
|
1963
|
+
cli.command(
|
|
1964
|
+
"onboard [site]",
|
|
1965
|
+
"Install @reddoorla/maintenance + audit deps on a site (run after convert-to-pnpm)."
|
|
1966
|
+
).option("--audits <names>", "Comma-separated audit subset: lighthouse,a11y (default: both)").option("--fleet <inventory>", "Inventory file (.json or .mjs/.js)").option("--workdir <path>", "Clone target for fleet mode (default ~/.reddoor-maint/sites)").action(
|
|
1967
|
+
async (site, opts) => {
|
|
1968
|
+
try {
|
|
1969
|
+
const { output, code } = await runOnboardCommand(site, opts);
|
|
1970
|
+
console.log(output);
|
|
1971
|
+
process.exit(code);
|
|
1972
|
+
} catch (err) {
|
|
1973
|
+
const e = err;
|
|
1974
|
+
console.error(opts.verbose ? e.stack ?? e.message : e.message ?? String(err));
|
|
1975
|
+
process.exit(e.exitCode ?? 1);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
);
|
|
1802
1979
|
cli.help();
|
|
1803
1980
|
cli.version(version);
|
|
1804
1981
|
cli.parse();
|