This commit is contained in:
Turbobot
2024-03-21 13:41:16 +08:00
committed by giancarlo
commit bb58169fe9
204 changed files with 26228 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
import { execSync } from "node:child_process";
import type { PackageJson, PlopTypes } from "@turbo/gen";
export default function generator(plop: PlopTypes.NodePlopAPI): void {
plop.setGenerator("init", {
description: "Generate a new package for the Acme Monorepo",
prompts: [
{
type: "input",
name: "name",
message:
"What is the name of the package? (You can skip the `@acme/` 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("@acme/")) {
answers.name = answers.name.replace("@acme/", "");
}
}
return "Config sanitized";
},
{
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) {
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);
pkg.dependencies![dep] = `^${version}`;
}
return JSON.stringify(pkg, null, 2);
},
},
async (answers) => {
/**
* Install deps and format everything
*/
execSync("pnpm manypkg fix", {
stdio: "inherit",
});
execSync(
`pnpm prettier --write packages/${
(answers as { name: string }).name
}/** --list-different`,
);
return "Package scaffolded";
},
],
});
}

View File

@@ -0,0 +1,38 @@
{
"name": "@acme/{{ name }}",
"private": true,
"version": "0.1.0",
"exports": {
".": "./index.ts"
},
"typesVersions": {
"*": {
"*": [
"src/*"
]
}
}
"license": "MIT",
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "eslint .",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"typecheck": "tsc --noEmit"
},
"dependencies": {
},
"devDependencies": {
"@acme/eslint-config": "0.2.0",
"@acme/prettier-config": "^0.1.0",
"@acme/tsconfig": "^0.1.0",
"eslint": "^8.56.0",
"prettier": "^3.1.1",
"typescript": "^5.3.3"
},
"eslintConfig": {
"extends": [
"@acme/eslint-config/base"
]
},
"prettier": "@acme/prettier-config"
}

View File

@@ -0,0 +1,8 @@
{
"extends": "@acme/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["."],
"exclude": ["node_modules"]
}