recipe/scripts/bootstrap.ts

111 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-08-18 19:16:25 +08:00
import { existsSync, readdirSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { version } from "../package.json";
const packagesDir = resolve(process.cwd(), "packages");
const files = readdirSync(packagesDir);
files.forEach((pkgName) => {
if (pkgName.startsWith(".") || pkgName === "theme") return;
const desc = `${pkgName} plugin for VuePress`;
const pkgPath = join(packagesDir, pkgName, "package.json");
// Generate package.json
if (!existsSync(pkgPath)) {
const pkgJSON = {
name: `vuepress-plugin-${pkgName}`,
version,
description: desc,
keywords: ["vuepress", "vuepress2", "vuepress-plugin", pkgName],
homepage: `https://github.com/vuepress-theme-hope/vuepress-theme-hope/packages/${pkgName}#readme`,
bugs: {
url: "https://github.com/vuepress-theme-hope/vuepress-theme-hope/issues",
},
repository: {
type: "git",
url: "git+https://github.com/vuepress-theme-hope/vuepress-theme-hope.git",
directory: `packages/${pkgName}`,
},
license: "MIT",
author: {
name: "Mr.Hope",
email: "mister-hope@outlook.com",
url: "https://mister-hope.com",
},
type: "module",
exports: {
// eslint-disable-next-line @typescript-eslint/naming-convention
".": "./lib/node/index.js",
// eslint-disable-next-line @typescript-eslint/naming-convention
"./package.json": "./package.json",
},
main: "lib/node/index.js",
types: "lib/node/index.d.ts",
files: ["lib"],
scripts: {
build: "rollup -c rollup.config.ts --configPlugin esbuild",
clean: "rimraf --glob ./lib ./*.tsbuildinfo",
dev: "pnpm dev:ts",
// eslint-disable-next-line @typescript-eslint/naming-convention
"dev:ts": "tsc -b tsconfig.build.json --watch",
},
engines: {
node: ">=18.16.0",
npm: ">=8",
pnpm: ">=7",
yarn: ">=2",
},
peerDependencies: {
vuepress: "2.0.0-rc.9",
},
publishConfig: {
access: "public",
},
};
writeFileSync(pkgPath, `${JSON.stringify(pkgJSON, null, 2)}\n`);
}
const readmePath = join(packagesDir, pkgName, "README.md");
// Generate README.md
if (!existsSync(readmePath))
writeFileSync(
readmePath,
`\
# vuepress-plugin-${pkgName}
[![Version](https://img.shields.io/npm/v/vuepress-plugin-${pkgName}.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/vuepress-plugin-${pkgName}.svg?style=flat-square&logo=npm)](https://www.npmjs.com/package/vuepress-plugin-${pkgName})
${desc}.
## Install
\`\`\`bash
# pnpm
pnpm add -D vuepress-plugin-${pkgName}
# npm
npm i -D vuepress-plugin-${pkgName}
# yarn
yarn add -D vuepress-plugin-${pkgName}
\`\`\`
---
##
\`\`\`bash
# pnpm
pnpm add -D vuepress-plugin-${pkgName}
# npm
npm i -D vuepress-plugin-${pkgName}
# yarn
yarn add -D vuepress-plugin-${pkgName}
\`\`\`
`,
);
});