create-bench 0.1.1
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/README.md +32 -0
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# create-bench
|
|
2
|
+
|
|
3
|
+
Scaffold a new ComputeSDK benchmark project that uses [`@benchsdk/client`](https://github.com/computesdk/benchmarks/tree/master/packages/benchsdk).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx create-bench my-benchmark
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or with npm:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm create bench my-benchmark
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## What gets created
|
|
18
|
+
|
|
19
|
+
The CLI creates a directory with the given project name and writes:
|
|
20
|
+
|
|
21
|
+
- `package.json` — with `@benchsdk/client`, `tsx`, and benchmark scripts
|
|
22
|
+
- `tsconfig.json` — basic TypeScript configuration
|
|
23
|
+
- `bench.ts` — a minimal benchmark worker using `defineWorker`, `defineTask`, and `defineStep`
|
|
24
|
+
- `.env.example` — environment variables to configure the worker
|
|
25
|
+
- `README.md` — instructions for the new project
|
|
26
|
+
|
|
27
|
+
## Next steps
|
|
28
|
+
|
|
29
|
+
1. `cd my-benchmark`
|
|
30
|
+
2. `pnpm install`
|
|
31
|
+
3. Copy `.env.example` to `.env` and fill in the required values
|
|
32
|
+
4. `pnpm bench`
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import readline from "readline/promises";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
function scaffold(targetDir, projectName) {
|
|
9
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
10
|
+
const packageJson = {
|
|
11
|
+
name: projectName,
|
|
12
|
+
version: "0.0.0",
|
|
13
|
+
private: true,
|
|
14
|
+
type: "module",
|
|
15
|
+
scripts: {
|
|
16
|
+
bench: "tsx bench.ts",
|
|
17
|
+
typecheck: "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
dependencies: {
|
|
20
|
+
"@benchsdk/client": "^0.2.0"
|
|
21
|
+
},
|
|
22
|
+
devDependencies: {
|
|
23
|
+
tsx: "^4.22.4",
|
|
24
|
+
typescript: "^5.0.0"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
path.join(targetDir, "package.json"),
|
|
29
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
30
|
+
`
|
|
31
|
+
);
|
|
32
|
+
const tsconfigJson = {
|
|
33
|
+
compilerOptions: {
|
|
34
|
+
target: "ES2022",
|
|
35
|
+
module: "ESNext",
|
|
36
|
+
moduleResolution: "bundler",
|
|
37
|
+
strict: true,
|
|
38
|
+
esModuleInterop: true,
|
|
39
|
+
skipLibCheck: true,
|
|
40
|
+
resolveJsonModule: true,
|
|
41
|
+
noEmit: true
|
|
42
|
+
},
|
|
43
|
+
include: ["**/*.ts"]
|
|
44
|
+
};
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
path.join(targetDir, "tsconfig.json"),
|
|
47
|
+
`${JSON.stringify(tsconfigJson, null, 2)}
|
|
48
|
+
`
|
|
49
|
+
);
|
|
50
|
+
const benchTs = `import { defineStep, defineTask, defineWorker } from '@benchsdk/client';
|
|
51
|
+
|
|
52
|
+
const worker = defineWorker({
|
|
53
|
+
benchmarkSlug: process.env.BENCHMARK_SLUG ?? 'scale',
|
|
54
|
+
runId: process.env.BENCHMARK_RUN_ID!,
|
|
55
|
+
participantSlug: process.env.BENCHMARK_PARTICIPANT_SLUG ?? 'local',
|
|
56
|
+
processKind: 'container',
|
|
57
|
+
processKey: process.env.HOSTNAME ?? 'local',
|
|
58
|
+
concurrency: 1,
|
|
59
|
+
task: defineTask('example.lifecycle', [
|
|
60
|
+
defineStep('start', async ({ assignment }) => {
|
|
61
|
+
console.log(\`Worker \${assignment.workerId} starting task \${assignment.taskRange.start}\`);
|
|
62
|
+
}),
|
|
63
|
+
defineStep('work', async () => {
|
|
64
|
+
// Replace with your benchmark logic
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
66
|
+
}),
|
|
67
|
+
defineStep('done', async () => {
|
|
68
|
+
console.log('Task complete');
|
|
69
|
+
}),
|
|
70
|
+
]),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await worker.run();
|
|
74
|
+
`;
|
|
75
|
+
fs.writeFileSync(path.join(targetDir, "bench.ts"), benchTs);
|
|
76
|
+
const envExample = `# Copy to .env and fill in your values
|
|
77
|
+
COMPUTESDK_ADMIN_API_KEY=
|
|
78
|
+
BENCHMARK_SLUG=scale
|
|
79
|
+
BENCHMARK_RUN_ID=
|
|
80
|
+
BENCHMARK_PARTICIPANT_SLUG=local
|
|
81
|
+
`;
|
|
82
|
+
fs.writeFileSync(path.join(targetDir, ".env.example"), envExample);
|
|
83
|
+
const readme = `# ${projectName}
|
|
84
|
+
|
|
85
|
+
This project was scaffolded by [\`create-bench\`](https://github.com/computesdk/benchmarks/tree/master/packages/create-bench).
|
|
86
|
+
|
|
87
|
+
## Getting started
|
|
88
|
+
|
|
89
|
+
1. Install dependencies:
|
|
90
|
+
|
|
91
|
+
\`\`\`sh
|
|
92
|
+
pnpm install
|
|
93
|
+
\`\`\`
|
|
94
|
+
|
|
95
|
+
2. Copy \`.env.example\` to \`.env\` and fill in the required values.
|
|
96
|
+
|
|
97
|
+
3. Run the benchmark worker:
|
|
98
|
+
|
|
99
|
+
\`\`\`sh
|
|
100
|
+
pnpm bench
|
|
101
|
+
\`\`\`
|
|
102
|
+
`;
|
|
103
|
+
fs.writeFileSync(path.join(targetDir, "README.md"), readme);
|
|
104
|
+
}
|
|
105
|
+
async function askProjectName() {
|
|
106
|
+
const rl = readline.createInterface({
|
|
107
|
+
input: process.stdin,
|
|
108
|
+
output: process.stdout
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
const answer = await rl.question("Project name: ");
|
|
112
|
+
return answer.trim() || void 0;
|
|
113
|
+
} finally {
|
|
114
|
+
rl.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function createBench(projectName) {
|
|
118
|
+
const resolvedName = projectName ?? await askProjectName();
|
|
119
|
+
if (!resolvedName) {
|
|
120
|
+
throw new Error("A project name is required.");
|
|
121
|
+
}
|
|
122
|
+
const targetDir = path.isAbsolute(resolvedName) ? resolvedName : path.resolve(process.cwd(), resolvedName);
|
|
123
|
+
const packageName = path.basename(targetDir);
|
|
124
|
+
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
125
|
+
throw new Error(`Directory ${targetDir} is not empty.`);
|
|
126
|
+
}
|
|
127
|
+
scaffold(targetDir, packageName);
|
|
128
|
+
console.log(`Created ${packageName} at ${targetDir}`);
|
|
129
|
+
console.log("Next steps:");
|
|
130
|
+
console.log(` cd ${path.relative(process.cwd(), targetDir) || packageName}`);
|
|
131
|
+
console.log(" pnpm install");
|
|
132
|
+
console.log(" cp .env.example .env");
|
|
133
|
+
console.log(" pnpm bench");
|
|
134
|
+
}
|
|
135
|
+
async function main() {
|
|
136
|
+
const projectName = process.argv[2];
|
|
137
|
+
await createBench(projectName);
|
|
138
|
+
}
|
|
139
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
140
|
+
main().catch((err) => {
|
|
141
|
+
console.error(err);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
createBench
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport readline from 'node:readline/promises';\nimport { fileURLToPath } from 'node:url';\n\nfunction scaffold(targetDir: string, projectName: string): void {\n fs.mkdirSync(targetDir, { recursive: true });\n\n const packageJson = {\n name: projectName,\n version: '0.0.0',\n private: true,\n type: 'module',\n scripts: {\n bench: 'tsx bench.ts',\n typecheck: 'tsc --noEmit',\n },\n dependencies: {\n '@benchsdk/client': '^0.2.0',\n },\n devDependencies: {\n tsx: '^4.22.4',\n typescript: '^5.0.0',\n },\n };\n\n fs.writeFileSync(\n path.join(targetDir, 'package.json'),\n `${JSON.stringify(packageJson, null, 2)}\\n`,\n );\n\n const tsconfigJson = {\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'bundler',\n strict: true,\n esModuleInterop: true,\n skipLibCheck: true,\n resolveJsonModule: true,\n noEmit: true,\n },\n include: ['**/*.ts'],\n };\n\n fs.writeFileSync(\n path.join(targetDir, 'tsconfig.json'),\n `${JSON.stringify(tsconfigJson, null, 2)}\\n`,\n );\n\n const benchTs = `import { defineStep, defineTask, defineWorker } from '@benchsdk/client';\n\nconst worker = defineWorker({\n benchmarkSlug: process.env.BENCHMARK_SLUG ?? 'scale',\n runId: process.env.BENCHMARK_RUN_ID!,\n participantSlug: process.env.BENCHMARK_PARTICIPANT_SLUG ?? 'local',\n processKind: 'container',\n processKey: process.env.HOSTNAME ?? 'local',\n concurrency: 1,\n task: defineTask('example.lifecycle', [\n defineStep('start', async ({ assignment }) => {\n console.log(\\`Worker \\${assignment.workerId} starting task \\${assignment.taskRange.start}\\`);\n }),\n defineStep('work', async () => {\n // Replace with your benchmark logic\n await new Promise((resolve) => setTimeout(resolve, 100));\n }),\n defineStep('done', async () => {\n console.log('Task complete');\n }),\n ]),\n});\n\nawait worker.run();\n`;\n\n fs.writeFileSync(path.join(targetDir, 'bench.ts'), benchTs);\n\n const envExample = `# Copy to .env and fill in your values\nCOMPUTESDK_ADMIN_API_KEY=\nBENCHMARK_SLUG=scale\nBENCHMARK_RUN_ID=\nBENCHMARK_PARTICIPANT_SLUG=local\n`;\n\n fs.writeFileSync(path.join(targetDir, '.env.example'), envExample);\n\n const readme = `# ${projectName}\n\nThis project was scaffolded by [\\`create-bench\\`](https://github.com/computesdk/benchmarks/tree/master/packages/create-bench).\n\n## Getting started\n\n1. Install dependencies:\n\n \\`\\`\\`sh\n pnpm install\n \\`\\`\\`\n\n2. Copy \\`.env.example\\` to \\`.env\\` and fill in the required values.\n\n3. Run the benchmark worker:\n\n \\`\\`\\`sh\n pnpm bench\n \\`\\`\\`\n`;\n\n fs.writeFileSync(path.join(targetDir, 'README.md'), readme);\n}\n\nasync function askProjectName(): Promise<string | undefined> {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n try {\n const answer = await rl.question('Project name: ');\n return answer.trim() || undefined;\n } finally {\n rl.close();\n }\n}\n\nexport async function createBench(projectName?: string): Promise<void> {\n const resolvedName = projectName ?? (await askProjectName());\n\n if (!resolvedName) {\n throw new Error('A project name is required.');\n }\n\n const targetDir = path.isAbsolute(resolvedName)\n ? resolvedName\n : path.resolve(process.cwd(), resolvedName);\n const packageName = path.basename(targetDir);\n\n if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {\n throw new Error(`Directory ${targetDir} is not empty.`);\n }\n\n scaffold(targetDir, packageName);\n\n console.log(`Created ${packageName} at ${targetDir}`);\n console.log('Next steps:');\n console.log(` cd ${path.relative(process.cwd(), targetDir) || packageName}`);\n console.log(' pnpm install');\n console.log(' cp .env.example .env');\n console.log(' pnpm bench');\n}\n\nasync function main(): Promise<void> {\n const projectName = process.argv[2];\n await createBench(projectName);\n}\n\nif (process.argv[1] === fileURLToPath(import.meta.url)) {\n main().catch((err) => {\n console.error(err);\n process.exit(1);\n });\n}\n"],"mappings":";;;AACA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;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OAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,YAAQ,MAAM,GAAG;AACjB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-bench",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Scaffold a new ComputeSDK benchmark project with @benchsdk/client",
|
|
7
|
+
"author": "Garrison",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"bin": {
|
|
10
|
+
"create-bench": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"clean": "rimraf dist",
|
|
19
|
+
"dev": "tsup --watch",
|
|
20
|
+
"prepare": "tsup",
|
|
21
|
+
"pretest": "tsup",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"create",
|
|
27
|
+
"scaffold",
|
|
28
|
+
"benchmark",
|
|
29
|
+
"computesdk",
|
|
30
|
+
"benchsdk",
|
|
31
|
+
"cli"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/computesdk/benchmarks.git",
|
|
36
|
+
"directory": "packages/create-bench"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://www.computesdk.com",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/computesdk/benchmarks/issues"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^20.0.0",
|
|
48
|
+
"rimraf": "^5.0.0",
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.0.0",
|
|
51
|
+
"vitest": "^1.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|