Files
Homarr/turbo/generators/config.ts
homarr-renovate[bot] 1bae7352dc chore(deps): update dependency eslint to v9 (#452)
* chore(deps): update dependency eslint to v9

* chore: migrate eslint to v9

* fix: dependency issues

* fix: unit tests not working

* chore: disable lint check for Image component that does not work in ci

* fix: lint issue

---------

Co-authored-by: homarr-renovate[bot] <158783068+homarr-renovate[bot]@users.noreply.github.com>
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
2024-06-08 20:49:57 +02:00

95 lines
2.9 KiB
TypeScript

import { execSync } from "node:child_process";
import type { PlopTypes } from "@turbo/gen";
interface PackageJson {
name: string;
scripts: Record<string, string>;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
}
export default function generator(plop: PlopTypes.NodePlopAPI): void {
plop.setGenerator("init", {
description: "Generate a new package for the homarr Monorepo",
prompts: [
{
type: "input",
name: "name",
message: "What is the name of the package? (You can skip the `@homarr/` prefix)",
},
{
type: "input",
name: "deps",
message: "Enter a space separated list of dependencies you would like to install",
},
],
actions: [
(answers) => {
if ("name" in answers && typeof answers.name === "string") {
if (answers.name.startsWith("@homarr/")) {
answers.name = answers.name.replace("@homarr/", "");
}
}
return "Config sanitized";
},
{
type: "add",
path: "packages/{{ name }}/eslint.config.js",
templateFile: "templates/eslint.config.js.hbs",
},
{
type: "add",
path: "packages/{{ name }}/package.json",
templateFile: "templates/package.json.hbs",
},
{
type: "add",
path: "packages/{{ name }}/tsconfig.json",
templateFile: "templates/tsconfig.json.hbs",
},
{
type: "add",
path: "packages/{{ name }}/index.ts",
template: "export * from './src';",
},
{
type: "add",
path: "packages/{{ name }}/src/index.ts",
template: "export const name = '{{ name }}';",
},
{
type: "modify",
path: "packages/{{ name }}/package.json",
async transform(content, answers) {
if ("deps" in answers && typeof answers.deps === "string") {
const pkg = JSON.parse(content) as PackageJson;
for (const dep of answers.deps.split(" ").filter(Boolean)) {
const version = await fetch(`https://registry.npmjs.org/-/package/${dep}/dist-tags`)
.then((res) => res.json())
.then((json) => json.latest);
if (!pkg.dependencies) pkg.dependencies = {};
pkg.dependencies[dep] = `^${version}`;
}
return JSON.stringify(pkg, null, 2);
}
return content;
},
},
async (answers) => {
/**
* Install deps and format everything
*/
if ("name" in answers && typeof answers.name === "string") {
// execSync("pnpm dlx sherif@latest --fix", {
// stdio: "inherit",
// });
execSync("pnpm i", { stdio: "inherit" });
execSync(`pnpm prettier --write packages/${answers.name}/** --list-different`);
return "Package scaffolded";
}
return "Package not scaffolded";
},
],
});
}