-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace.mjs
78 lines (73 loc) · 2.31 KB
/
workspace.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// @ts-check
import { defineConfig } from "@dreamkit/workspace";
import { readFileSync } from "fs";
import { markdownTable } from "markdown-table";
const readmeTpl = readFileSync("./docs/readme.tpl.md", "utf8");
const readmePackageTpl = readFileSync("./docs/readme-package.tpl.md", "utf8");
export default defineConfig((pkg, { packages, dir }) => {
if (pkg.name === "@dreamkit/root") {
const dreamkitPkg = packages.find(
(pkg) => pkg.manifest.name === "dreamkit",
);
if (!dreamkitPkg) throw new Error("dreamkit package not found");
const docPackages = [
dreamkitPkg,
...packages.filter(
(pkg) =>
!pkg.manifest.private &&
pkg.manifest.name !== "@dreamkit/site" &&
pkg !== dreamkitPkg,
),
];
const packagesTable = markdownTable([
["Name", "Version", "Description"],
...docPackages.map((pkg, index) => [
`[${pkg.manifest.name}](${pkg.dir})`,
`[![npm-badge-${index}]](https://www.npmjs.com/package/${pkg.manifest.name})`,
pkg.manifest.description,
]),
]);
const packagesBadges = docPackages
.map(
(pkg, index) =>
`[npm-badge-${index}]: https://img.shields.io/npm/v/${pkg.manifest.name}`,
)
.join("\n");
return {
files: {
"README.md": readmeTpl
.replaceAll("{packagesTable}", packagesTable)
.replaceAll("{packagesBadges}", packagesBadges),
},
};
}
if (!pkg.files) throw new Error('"files" field is required');
if (pkg.name === "@dreamkit/site") return;
return {
files: {
"README.md": readmePackageTpl
.replaceAll("{packageName}", pkg.name ?? "")
.replaceAll("{packageDescription}", pkg.description ?? ""),
"package.json": {
...pkg,
type: pkg.name === "@dreamkit/prettier-config" ? "commonjs" : "module",
sideEffects: false,
author: "Juanra GM",
license: "MIT",
homepage: "https://dreamkit.dev",
repository: {
type: "git",
url: new URL(`https://github.com/swordev/dreamkit/tree/main/${dir}`)
.href,
},
contributors: [
{
name: "Juanra GM",
email: "[email protected]",
url: "https://github.com/juanrgm",
},
],
},
},
};
});