@tenphi/create-cookbook 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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +116 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/scaffold-B1o_OYiO.js +121 -0
- package/dist/scaffold-B1o_OYiO.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Yamanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as scaffold } from "./scaffold-B1o_OYiO.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { stdin, stdout } from "node:process";
|
|
7
|
+
//#region src/prompts.ts
|
|
8
|
+
async function prompt(question) {
|
|
9
|
+
const readline = createInterface({
|
|
10
|
+
input: stdin,
|
|
11
|
+
output: stdout
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
return (await readline.question(question)).trim();
|
|
15
|
+
} finally {
|
|
16
|
+
readline.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function confirm(question) {
|
|
20
|
+
const answer = (await prompt(`${question} [y/N] `)).toLowerCase();
|
|
21
|
+
return answer === "y" || answer === "yes";
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/cli.ts
|
|
25
|
+
const { positionals, values } = parseArgs({
|
|
26
|
+
allowPositionals: true,
|
|
27
|
+
allowNegative: true,
|
|
28
|
+
options: {
|
|
29
|
+
package: { type: "string" },
|
|
30
|
+
yes: {
|
|
31
|
+
type: "boolean",
|
|
32
|
+
short: "y",
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
brand: { type: "string" },
|
|
36
|
+
site: { type: "string" },
|
|
37
|
+
base: { type: "string" },
|
|
38
|
+
deploy: { type: "string" },
|
|
39
|
+
"package-manager": { type: "string" },
|
|
40
|
+
install: {
|
|
41
|
+
type: "boolean",
|
|
42
|
+
default: true
|
|
43
|
+
},
|
|
44
|
+
open: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
default: false
|
|
47
|
+
},
|
|
48
|
+
vendor: {
|
|
49
|
+
type: "boolean",
|
|
50
|
+
default: false
|
|
51
|
+
},
|
|
52
|
+
"trust-package": {
|
|
53
|
+
type: "boolean",
|
|
54
|
+
default: false
|
|
55
|
+
},
|
|
56
|
+
help: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
short: "h",
|
|
59
|
+
default: false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (values.help) printHelp();
|
|
64
|
+
const packageSpecifier = values.package ?? (values.yes ? void 0 : await prompt("npm package: "));
|
|
65
|
+
if (!packageSpecifier) {
|
|
66
|
+
console.error("--package is required in non-interactive mode.");
|
|
67
|
+
printHelp(1);
|
|
68
|
+
}
|
|
69
|
+
const manager = values["package-manager"];
|
|
70
|
+
if (manager && ![
|
|
71
|
+
"npm",
|
|
72
|
+
"pnpm",
|
|
73
|
+
"yarn"
|
|
74
|
+
].includes(manager)) throw new Error(`Invalid package manager: ${manager}.`);
|
|
75
|
+
const deployment = values.deploy;
|
|
76
|
+
if (deployment && deployment !== "github-pages" && deployment !== "none") throw new Error(`Invalid deploy preset: ${deployment}.`);
|
|
77
|
+
const result = await scaffold({
|
|
78
|
+
package: packageSpecifier,
|
|
79
|
+
...positionals[0] ? { destination: positionals[0] } : {},
|
|
80
|
+
...manager ? { packageManager: manager } : {},
|
|
81
|
+
install: values.install,
|
|
82
|
+
...values.brand ? { brand: values.brand } : {},
|
|
83
|
+
...values.site ? { site: values.site } : {},
|
|
84
|
+
...values.base ? { base: values.base } : {},
|
|
85
|
+
...deployment ? { deploy: deployment } : {},
|
|
86
|
+
trustPackage: values["trust-package"],
|
|
87
|
+
vendor: values.vendor,
|
|
88
|
+
...!values.yes ? { confirmNonEmpty: (destination) => confirm(`${destination} is not empty. Continue and overwrite generated files?`) } : {}
|
|
89
|
+
});
|
|
90
|
+
console.log(`\nPackage ${result.lock.resolved}\nHome ${result.discovery.home ?? "(none)"}\nPages ${result.discovery.pages.length}\nAssets ${result.discovery.assets.length}\n\nCreated ${result.destination}`);
|
|
91
|
+
if (values.open) {
|
|
92
|
+
if (!values.install) throw new Error("--open requires dependency installation; remove --no-install.");
|
|
93
|
+
const args = result.packageManager === "npm" ? [
|
|
94
|
+
"run",
|
|
95
|
+
"dev",
|
|
96
|
+
"--",
|
|
97
|
+
"--open"
|
|
98
|
+
] : [
|
|
99
|
+
"run",
|
|
100
|
+
"dev",
|
|
101
|
+
"--open"
|
|
102
|
+
];
|
|
103
|
+
spawn(result.packageManager, args, {
|
|
104
|
+
cwd: result.destination,
|
|
105
|
+
detached: true,
|
|
106
|
+
stdio: "ignore"
|
|
107
|
+
}).unref();
|
|
108
|
+
}
|
|
109
|
+
function printHelp(code = 0) {
|
|
110
|
+
console.log(`Usage: create-cookbook [destination] --package <specifier> [options]\n\nOptions:\n --yes, -y\n --brand <color>\n --site <url>\n --base <path>\n --deploy github-pages|none\n --package-manager npm|pnpm|yarn\n --no-install\n --vendor\n --trust-package\n --open`);
|
|
111
|
+
process.exit(code);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export {};
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/prompts.ts","../src/cli.ts"],"sourcesContent":["import { createInterface } from \"node:readline/promises\";\nimport { stdin, stdout } from \"node:process\";\n\nexport async function prompt(question: string): Promise<string> {\n const readline = createInterface({ input: stdin, output: stdout });\n try {\n return (await readline.question(question)).trim();\n } finally {\n readline.close();\n }\n}\n\nexport async function confirm(question: string): Promise<boolean> {\n const answer = (await prompt(`${question} [y/N] `)).toLowerCase();\n return answer === \"y\" || answer === \"yes\";\n}\n","import { spawn } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport { confirm, prompt } from \"./prompts.js\";\nimport { scaffold, type PackageManager } from \"./scaffold.js\";\n\nconst { positionals, values } = parseArgs({\n allowPositionals: true,\n allowNegative: true,\n options: {\n package: { type: \"string\" },\n yes: { type: \"boolean\", short: \"y\", default: false },\n brand: { type: \"string\" },\n site: { type: \"string\" },\n base: { type: \"string\" },\n deploy: { type: \"string\" },\n \"package-manager\": { type: \"string\" },\n install: { type: \"boolean\", default: true },\n open: { type: \"boolean\", default: false },\n vendor: { type: \"boolean\", default: false },\n \"trust-package\": { type: \"boolean\", default: false },\n help: { type: \"boolean\", short: \"h\", default: false },\n },\n});\n\nif (values.help) printHelp();\n\nconst packageSpecifier =\n values.package ?? (values.yes ? undefined : await prompt(\"npm package: \"));\nif (!packageSpecifier) {\n console.error(\"--package is required in non-interactive mode.\");\n printHelp(1);\n}\n\nconst manager = values[\"package-manager\"];\nif (manager && ![\"npm\", \"pnpm\", \"yarn\"].includes(manager))\n throw new Error(`Invalid package manager: ${manager}.`);\nconst deployment = values.deploy;\nif (deployment && deployment !== \"github-pages\" && deployment !== \"none\")\n throw new Error(`Invalid deploy preset: ${deployment}.`);\n\nconst result = await scaffold({\n package: packageSpecifier,\n ...(positionals[0] ? { destination: positionals[0] } : {}),\n ...(manager ? { packageManager: manager as PackageManager } : {}),\n install: values.install,\n ...(values.brand ? { brand: values.brand } : {}),\n ...(values.site ? { site: values.site } : {}),\n ...(values.base ? { base: values.base } : {}),\n ...(deployment ? { deploy: deployment as \"github-pages\" | \"none\" } : {}),\n trustPackage: values[\"trust-package\"],\n vendor: values.vendor,\n ...(!values.yes\n ? {\n confirmNonEmpty: (destination: string) =>\n confirm(\n `${destination} is not empty. Continue and overwrite generated files?`,\n ),\n }\n : {}),\n});\n\nconsole.log(\n `\\nPackage ${result.lock.resolved}\\nHome ${result.discovery.home ?? \"(none)\"}\\nPages ${result.discovery.pages.length}\\nAssets ${result.discovery.assets.length}\\n\\nCreated ${result.destination}`,\n);\nif (values.open) {\n if (!values.install) {\n throw new Error(\n \"--open requires dependency installation; remove --no-install.\",\n );\n }\n const args =\n result.packageManager === \"npm\"\n ? [\"run\", \"dev\", \"--\", \"--open\"]\n : [\"run\", \"dev\", \"--open\"];\n const server = spawn(result.packageManager, args, {\n cwd: result.destination,\n detached: true,\n stdio: \"ignore\",\n });\n server.unref();\n}\n\nfunction printHelp(code = 0): never {\n console.log(\n `Usage: create-cookbook [destination] --package <specifier> [options]\\n\\nOptions:\\n --yes, -y\\n --brand <color>\\n --site <url>\\n --base <path>\\n --deploy github-pages|none\\n --package-manager npm|pnpm|yarn\\n --no-install\\n --vendor\\n --trust-package\\n --open`,\n );\n process.exit(code);\n}\n"],"mappings":";;;;;;;AAGA,eAAsB,OAAO,UAAmC;CAC9D,MAAM,WAAW,gBAAgB;EAAE,OAAO;EAAO,QAAQ;CAAO,CAAC;CACjE,IAAI;EACF,QAAQ,MAAM,SAAS,SAAS,QAAQ,EAAA,CAAG,KAAK;CAClD,UAAU;EACR,SAAS,MAAM;CACjB;AACF;AAEA,eAAsB,QAAQ,UAAoC;CAChE,MAAM,UAAU,MAAM,OAAO,GAAG,SAAS,QAAQ,EAAA,CAAG,YAAY;CAChE,OAAO,WAAW,OAAO,WAAW;AACtC;;;ACVA,MAAM,EAAE,aAAa,WAAW,UAAU;CACxC,kBAAkB;CAClB,eAAe;CACf,SAAS;EACP,SAAS,EAAE,MAAM,SAAS;EAC1B,KAAK;GAAE,MAAM;GAAW,OAAO;GAAK,SAAS;EAAM;EACnD,OAAO,EAAE,MAAM,SAAS;EACxB,MAAM,EAAE,MAAM,SAAS;EACvB,MAAM,EAAE,MAAM,SAAS;EACvB,QAAQ,EAAE,MAAM,SAAS;EACzB,mBAAmB,EAAE,MAAM,SAAS;EACpC,SAAS;GAAE,MAAM;GAAW,SAAS;EAAK;EAC1C,MAAM;GAAE,MAAM;GAAW,SAAS;EAAM;EACxC,QAAQ;GAAE,MAAM;GAAW,SAAS;EAAM;EAC1C,iBAAiB;GAAE,MAAM;GAAW,SAAS;EAAM;EACnD,MAAM;GAAE,MAAM;GAAW,OAAO;GAAK,SAAS;EAAM;CACtD;AACF,CAAC;AAED,IAAI,OAAO,MAAM,UAAU;AAE3B,MAAM,mB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AC7B;EAAC;EAAO;EAAO;CAAQ;CAM7B,MALqB,OAAO,gBAAgB,MAAM;EAChD,KAAK,OAAO;EACZ,UAAU;EACV,OAAO;CACT,CACK,CAAC,CAAC,MAAM;AACf;AAEA,SAAS,UAAU,OAAO,GAAU;CAClC,QAAQ,IACN,6QACF;CACA,QAAQ,KAAK,IAAI;AACnB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
import { PackageDiscovery, PackageLockSource } from "@tenphi/docs";
|
|
3
|
+
//#region src/scaffold.d.ts
|
|
4
|
+
type PackageManager = "npm" | "pnpm" | "yarn";
|
|
5
|
+
interface ScaffoldOptions {
|
|
6
|
+
package: string;
|
|
7
|
+
destination?: string;
|
|
8
|
+
packageManager?: PackageManager;
|
|
9
|
+
install?: boolean;
|
|
10
|
+
brand?: string;
|
|
11
|
+
site?: string;
|
|
12
|
+
base?: string;
|
|
13
|
+
deploy?: "github-pages" | "none";
|
|
14
|
+
trustPackage?: boolean;
|
|
15
|
+
vendor?: boolean;
|
|
16
|
+
confirmNonEmpty?: (destination: string) => Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
interface ScaffoldResult {
|
|
19
|
+
destination: string;
|
|
20
|
+
lock: PackageLockSource;
|
|
21
|
+
discovery: PackageDiscovery;
|
|
22
|
+
packageManager: PackageManager;
|
|
23
|
+
}
|
|
24
|
+
declare function scaffold(options: ScaffoldOptions): Promise<ScaffoldResult>;
|
|
25
|
+
declare function inferPackageManager(userAgent?: string | undefined): PackageManager;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { type PackageManager, type ScaffoldOptions, type ScaffoldResult, inferPackageManager, scaffold };
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/scaffold.ts"],"mappings":";;;KAcY;UAEK;EACf;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,mBAAmB,wBAAwB;;UAG5B;EACf;EACA,MAAM;EACN,WAAW;EACX,gBAAgB;;iBAGI,SACpB,SAAS,kBACR,QAAQ;iBAmJK,oBACd,iCACC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { cp, mkdir, readdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { defaultLock, discoverPackage, materializePackage, packageNameFromSpecifier, resolvePackageLock, writeDocsLock } from "@tenphi/docs";
|
|
6
|
+
//#region src/scaffold.ts
|
|
7
|
+
async function scaffold(options) {
|
|
8
|
+
const packageName = packageNameFromSpecifier(options.package);
|
|
9
|
+
const destination = resolve(options.destination ?? `${packageName.replace(/^@[^/]+\//, "")}-docs`);
|
|
10
|
+
const packageManager = options.packageManager ?? inferPackageManager();
|
|
11
|
+
const lock = await resolvePackageLock(options.package);
|
|
12
|
+
const packageRoot = await materializePackage(lock, {
|
|
13
|
+
strict: true,
|
|
14
|
+
ci: false,
|
|
15
|
+
base: "/",
|
|
16
|
+
cacheDir: "",
|
|
17
|
+
maxArtifactBytes: 26214400,
|
|
18
|
+
maxUnpackedBytes: 104857600,
|
|
19
|
+
maxFiles: 1e4,
|
|
20
|
+
maxPathDepth: 24,
|
|
21
|
+
maxAssetBytes: 20971520
|
|
22
|
+
});
|
|
23
|
+
const discovery = await discoverPackage(packageRoot);
|
|
24
|
+
await mkdir(destination, { recursive: true });
|
|
25
|
+
if ((await readdir(destination)).length > 0) {
|
|
26
|
+
if (!await options.confirmNonEmpty?.(destination)) throw new Error(`Destination is not empty: ${destination}.`);
|
|
27
|
+
}
|
|
28
|
+
const projectLock = options.vendor ? {
|
|
29
|
+
...lock,
|
|
30
|
+
vendored: ".cookbook/vendor/package"
|
|
31
|
+
} : lock;
|
|
32
|
+
if (options.vendor && projectLock.vendored) {
|
|
33
|
+
await mkdir(join(destination, ".cookbook", "vendor"), { recursive: true });
|
|
34
|
+
await cp(packageRoot, join(destination, projectLock.vendored), { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
await Promise.all([
|
|
37
|
+
writeFile(join(destination, "package.json"), packageJson(packageManager), "utf8"),
|
|
38
|
+
writeFile(join(destination, "astro.config.ts"), astroConfig(options), "utf8"),
|
|
39
|
+
writeFile(join(destination, "tsconfig.json"), tsconfig(), "utf8"),
|
|
40
|
+
writeFile(join(destination, ".gitignore"), "node_modules/\ndist/\n.astro/\n", "utf8"),
|
|
41
|
+
writeDocsLock(destination, defaultLock([projectLock]))
|
|
42
|
+
]);
|
|
43
|
+
if (options.deploy === "github-pages") await writeGithubWorkflow(destination);
|
|
44
|
+
if (options.install !== false) await installDependencies(destination, packageManager);
|
|
45
|
+
return {
|
|
46
|
+
destination,
|
|
47
|
+
lock: projectLock,
|
|
48
|
+
discovery,
|
|
49
|
+
packageManager
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function packageJson(packageManager) {
|
|
53
|
+
const packageManagerVersion = {
|
|
54
|
+
npm: "npm@11",
|
|
55
|
+
pnpm: "pnpm@11",
|
|
56
|
+
yarn: "yarn@4"
|
|
57
|
+
}[packageManager];
|
|
58
|
+
return `${JSON.stringify({
|
|
59
|
+
name: "cookbook-site",
|
|
60
|
+
version: "0.0.0",
|
|
61
|
+
private: true,
|
|
62
|
+
type: "module",
|
|
63
|
+
packageManager: packageManagerVersion,
|
|
64
|
+
scripts: {
|
|
65
|
+
dev: "astro dev",
|
|
66
|
+
build: "astro build",
|
|
67
|
+
preview: "astro preview",
|
|
68
|
+
doctor: "cookbook doctor",
|
|
69
|
+
update: "cookbook update"
|
|
70
|
+
},
|
|
71
|
+
dependencies: {
|
|
72
|
+
astro: "^7.2.9",
|
|
73
|
+
"@tenphi/cookbook": "^0.4.0"
|
|
74
|
+
}
|
|
75
|
+
}, null, 2)}\n`;
|
|
76
|
+
}
|
|
77
|
+
function astroConfig(options) {
|
|
78
|
+
const source = {
|
|
79
|
+
package: options.package,
|
|
80
|
+
...options.trustPackage ? { trust: "mdx" } : {}
|
|
81
|
+
};
|
|
82
|
+
const docsConfig = {
|
|
83
|
+
...options.site ? { site: { url: options.site } } : {},
|
|
84
|
+
content: { sources: [source] },
|
|
85
|
+
...options.brand ? { theme: { brand: { from: options.brand } } } : {},
|
|
86
|
+
...options.base ? { build: { base: options.base } } : {}
|
|
87
|
+
};
|
|
88
|
+
return `import { defineConfig } from 'astro/config';\nimport cookbook from '@tenphi/cookbook';\n\nconst docs = ${JSON.stringify(docsConfig, null, 2)};\n\nexport default defineConfig({\n ${options.site ? `site: ${JSON.stringify(options.site)},\n ` : ""}${options.base ? `base: ${JSON.stringify(options.base)},\n ` : ""}output: 'static',\n integrations: [cookbook({ config: docs })],\n});\n`;
|
|
89
|
+
}
|
|
90
|
+
function tsconfig() {
|
|
91
|
+
return `${JSON.stringify({
|
|
92
|
+
extends: "astro/tsconfigs/strict",
|
|
93
|
+
include: [".astro/types.d.ts", "**/*"],
|
|
94
|
+
exclude: ["dist"]
|
|
95
|
+
}, null, 2)}\n`;
|
|
96
|
+
}
|
|
97
|
+
async function writeGithubWorkflow(destination) {
|
|
98
|
+
const directory = join(destination, ".github", "workflows");
|
|
99
|
+
await mkdir(directory, { recursive: true });
|
|
100
|
+
await writeFile(join(directory, "deploy.yml"), `name: Deploy documentation\non:\n push:\n branches: [main]\npermissions:\n contents: read\n pages: write\n id-token: write\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - uses: actions/setup-node@v4\n with:\n node-version: 22\n - run: npm ci\n - run: npm run build\n - uses: actions/upload-pages-artifact@v3\n with:\n path: dist\n - uses: actions/deploy-pages@v4\n`);
|
|
101
|
+
}
|
|
102
|
+
async function installDependencies(destination, manager) {
|
|
103
|
+
await new Promise((resolvePromise, reject) => {
|
|
104
|
+
const child = spawn(manager, ["install"], {
|
|
105
|
+
cwd: destination,
|
|
106
|
+
stdio: "inherit",
|
|
107
|
+
shell: process.platform === "win32"
|
|
108
|
+
});
|
|
109
|
+
child.once("error", reject);
|
|
110
|
+
child.once("exit", (code) => code === 0 ? resolvePromise() : reject(/* @__PURE__ */ new Error(`${manager} install exited with ${code}.`)));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function inferPackageManager(userAgent = process.env.npm_config_user_agent) {
|
|
114
|
+
if (userAgent?.startsWith("pnpm/")) return "pnpm";
|
|
115
|
+
if (userAgent?.startsWith("yarn/")) return "yarn";
|
|
116
|
+
return "npm";
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { scaffold as n, inferPackageManager as t };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=scaffold-B1o_OYiO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold-B1o_OYiO.js","names":[],"sources":["../src/scaffold.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { cp, mkdir, readdir, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport {\n defaultLock,\n discoverPackage,\n materializePackage,\n packageNameFromSpecifier,\n resolvePackageLock,\n writeDocsLock,\n type PackageDiscovery,\n type PackageLockSource,\n} from \"@tenphi/docs\";\n\nexport type PackageManager = \"npm\" | \"pnpm\" | \"yarn\";\n\nexport interface ScaffoldOptions {\n package: string;\n destination?: string;\n packageManager?: PackageManager;\n install?: boolean;\n brand?: string;\n site?: string;\n base?: string;\n deploy?: \"github-pages\" | \"none\";\n trustPackage?: boolean;\n vendor?: boolean;\n confirmNonEmpty?: (destination: string) => Promise<boolean>;\n}\n\nexport interface ScaffoldResult {\n destination: string;\n lock: PackageLockSource;\n discovery: PackageDiscovery;\n packageManager: PackageManager;\n}\n\nexport async function scaffold(\n options: ScaffoldOptions,\n): Promise<ScaffoldResult> {\n const packageName = packageNameFromSpecifier(options.package);\n const destination = resolve(\n options.destination ?? `${packageName.replace(/^@[^/]+\\//, \"\")}-docs`,\n );\n const packageManager = options.packageManager ?? inferPackageManager();\n const lock = await resolvePackageLock(options.package);\n const buildDefaults = {\n strict: true,\n ci: false,\n base: \"/\",\n cacheDir: \"\",\n maxArtifactBytes: 25 * 1024 * 1024,\n maxUnpackedBytes: 100 * 1024 * 1024,\n maxFiles: 10_000,\n maxPathDepth: 24,\n maxAssetBytes: 20 * 1024 * 1024,\n };\n const packageRoot = await materializePackage(lock, buildDefaults);\n const discovery = await discoverPackage(packageRoot);\n\n await mkdir(destination, { recursive: true });\n const existing = await readdir(destination);\n if (existing.length > 0) {\n const confirmed = await options.confirmNonEmpty?.(destination);\n if (!confirmed)\n throw new Error(`Destination is not empty: ${destination}.`);\n }\n\n const projectLock = options.vendor\n ? { ...lock, vendored: \".cookbook/vendor/package\" }\n : lock;\n if (options.vendor && projectLock.vendored) {\n await mkdir(join(destination, \".cookbook\", \"vendor\"), {\n recursive: true,\n });\n await cp(packageRoot, join(destination, projectLock.vendored), {\n recursive: true,\n });\n }\n\n await Promise.all([\n writeFile(\n join(destination, \"package.json\"),\n packageJson(packageManager),\n \"utf8\",\n ),\n writeFile(\n join(destination, \"astro.config.ts\"),\n astroConfig(options),\n \"utf8\",\n ),\n writeFile(join(destination, \"tsconfig.json\"), tsconfig(), \"utf8\"),\n writeFile(\n join(destination, \".gitignore\"),\n \"node_modules/\\ndist/\\n.astro/\\n\",\n \"utf8\",\n ),\n writeDocsLock(destination, defaultLock([projectLock])),\n ]);\n if (options.deploy === \"github-pages\") await writeGithubWorkflow(destination);\n if (options.install !== false)\n await installDependencies(destination, packageManager);\n return { destination, lock: projectLock, discovery, packageManager };\n}\n\nfunction packageJson(packageManager: PackageManager): string {\n const packageManagerVersion = {\n npm: \"npm@11\",\n pnpm: \"pnpm@11\",\n yarn: \"yarn@4\",\n }[packageManager];\n return `${JSON.stringify(\n {\n name: \"cookbook-site\",\n version: \"0.0.0\",\n private: true,\n type: \"module\",\n packageManager: packageManagerVersion,\n scripts: {\n dev: \"astro dev\",\n build: \"astro build\",\n preview: \"astro preview\",\n doctor: \"cookbook doctor\",\n update: \"cookbook update\",\n },\n dependencies: { astro: \"^7.2.9\", \"@tenphi/cookbook\": \"^0.4.0\" },\n },\n null,\n 2,\n )}\\n`;\n}\n\nfunction astroConfig(options: ScaffoldOptions): string {\n const source = {\n package: options.package,\n ...(options.trustPackage ? { trust: \"mdx\" as const } : {}),\n };\n const docsConfig = {\n ...(options.site ? { site: { url: options.site } } : {}),\n content: { sources: [source] },\n ...(options.brand ? { theme: { brand: { from: options.brand } } } : {}),\n ...(options.base ? { build: { base: options.base } } : {}),\n };\n return `import { defineConfig } from 'astro/config';\\nimport cookbook from '@tenphi/cookbook';\\n\\nconst docs = ${JSON.stringify(docsConfig, null, 2)};\\n\\nexport default defineConfig({\\n ${options.site ? `site: ${JSON.stringify(options.site)},\\n ` : \"\"}${options.base ? `base: ${JSON.stringify(options.base)},\\n ` : \"\"}output: 'static',\\n integrations: [cookbook({ config: docs })],\\n});\\n`;\n}\n\nfunction tsconfig(): string {\n return `${JSON.stringify(\n {\n extends: \"astro/tsconfigs/strict\",\n include: [\".astro/types.d.ts\", \"**/*\"],\n exclude: [\"dist\"],\n },\n null,\n 2,\n )}\\n`;\n}\n\nasync function writeGithubWorkflow(destination: string): Promise<void> {\n const directory = join(destination, \".github\", \"workflows\");\n await mkdir(directory, { recursive: true });\n await writeFile(\n join(directory, \"deploy.yml\"),\n `name: Deploy documentation\\non:\\n push:\\n branches: [main]\\npermissions:\\n contents: read\\n pages: write\\n id-token: write\\njobs:\\n build:\\n runs-on: ubuntu-latest\\n steps:\\n - uses: actions/checkout@v4\\n - uses: actions/setup-node@v4\\n with:\\n node-version: 22\\n - run: npm ci\\n - run: npm run build\\n - uses: actions/upload-pages-artifact@v3\\n with:\\n path: dist\\n - uses: actions/deploy-pages@v4\\n`,\n );\n}\n\nasync function installDependencies(\n destination: string,\n manager: PackageManager,\n): Promise<void> {\n await new Promise<void>((resolvePromise, reject) => {\n const child = spawn(manager, [\"install\"], {\n cwd: destination,\n stdio: \"inherit\",\n shell: process.platform === \"win32\",\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code) =>\n code === 0\n ? resolvePromise()\n : reject(new Error(`${manager} install exited with ${code}.`)),\n );\n });\n}\n\nexport function inferPackageManager(\n userAgent = process.env.npm_config_user_agent,\n): PackageManager {\n if (userAgent?.startsWith(\"pnpm/\")) return \"pnpm\";\n if (userAgent?.startsWith(\"yarn/\")) return \"yarn\";\n return \"npm\";\n}\n"],"mappings":";;;;;;AAqCA,eAAsB,SACpB,SACyB;CACzB,MAAM,cAAc,yBAAyB,QAAQ,OAAO;CAC5D,MAAM,cAAc,QAClB,QAAQ,eAAe,GAAG,YAAY,QAAQ,aAAa,EAAE,EAAE,MACjE;CACA,MAAM,iBAAiB,QAAQ,kBAAkB,oBAAoB;CACrE,MAAM,OAAO,MAAM,mBAAmB,QAAQ,OAAO;CAYrD,MAAM,cAAc,MAAM,mBAAmB,MAAM;EAVjD,QAAQ;EACR,IAAI;EACJ,MAAM;EACN,UAAU;EACV,kBAAkB;EAClB,kBAAkB;EAClB,UAAU;EACV,cAAc;EACd,eAAe;CAE8C,CAAC;CAChE,MAAM,YAAY,MAAM,gBAAgB,WAAW;CAEnD,MAAM,MAAM,aAAa,EAAE,WAAW,KAAK,CAAC;CAE5C,KAAI,MADmB,QAAQ,WAAW,EAAA,CAC7B,SAAS,GAEhB;MAAA,CAAC,MADmB,QAAQ,kBAAkB,WAAW,GAE3D,MAAM,IAAI,MAAM,6BAA6B,YAAY,EAAE;CAAA;CAG/D,MAAM,cAAc,QAAQ,SACxB;EAAE,GAAG;EAAM,UAAU;CAA2B,IAChD;CACJ,IAAI,QAAQ,UAAU,YAAY,UAAU;EAC1C,MAAM,MAAM,KAAK,aAAa,aAAa,QAAQ,GAAG,EACpD,WAAW,KACb,CAAC;EACD,MAAM,GAAG,aAAa,KAAK,aAAa,YAAY,QAAQ,GAAG,EAC7D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QAAQ,KAAK,EAAE,IAAI,CAAC;CAC1D;CACA,OAAO,0GAA0G,KAAK,UAAU,YAAY,MAAM,CAAC,EAAE,wCAAwC,QAAQ,OAAO,SAAS,KAAK,UAAU,QAAQ,IAAI,EAAE,SAAS,KAAK,QAAQ,OAAO,SAAS,KAAK,UAAU,QAAQ,IAAI,EAAE,SAAS,GAAG;AACnU;AAEA,SAAS,WAAmB;CAC1B,OAAO,GAAG,KAAK,UACb;EACE,SAAS;EACT,SAAS,CAAC,qBAAqB,MAAM;EACrC,SAAS,CAAC,MAAM;CAClB,GACA,MACA,CACF,EAAE;AACJ;AAEA,eAAe,oBAAoB,aAAoC;CACrE,MAAM,YAAY,KAAK,aAAa,WAAW,WAAW;CAC1D,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;CAC1C,MAAM,UACJ,KAAK,WAAW,YAAY,GAC5B,8dACF;AACF;AAEA,eAAe,oBACb,aACA,SACe;CACf,MAAM,IAAI,SAAe,gBAAgB,WAAW;EAClD,MAAM,QAAQ,MAAM,SAAS,CAAC,SAAS,GAAG;GACxC,KAAK;GACL,OAAO;GACP,OAAO,QAAQ,aAAa;EAC9B,CAAC;EACD,MAAM,KAAK,SAAS,MAAM;EAC1B,MAAM,KAAK,SAAS,SAClB,SAAS,IACL,eAAe,IACf,uBAAO,IAAI,MAAM,GAAG,QAAQ,uBAAuB,KAAK,EAAE,CAAC,CACjE;CACF,CAAC;AACH;AAEA,SAAgB,oBACd,YAAY,QAAQ,IAAI,uBACR;CAChB,IAAI,WAAW,WAAW,OAAO,GAAG,OAAO;CAC3C,IAAI,WAAW,WAAW,OAAO,GAAG,OAAO;CAC3C,OAAO;AACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tenphi/create-cookbook",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Create a reproducible Cookbook site from a published npm package",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-cookbook": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.14"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/tenphi/cookbook.git",
|
|
29
|
+
"directory": "packages/create"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/tenphi/cookbook#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/tenphi/cookbook/issues"
|
|
34
|
+
},
|
|
35
|
+
"author": "Andrey Yamanov",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@tenphi/docs": "0.4.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.15.2",
|
|
42
|
+
"tsdown": "^0.22.14",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"vitest": "^4.1.11"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsdown --config tsdown.config.ts",
|
|
48
|
+
"clean": "rm -rf dist",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
}
|
|
52
|
+
}
|