-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathprepare-evaluations.ts
More file actions
42 lines (40 loc) · 1.35 KB
/
prepare-evaluations.ts
File metadata and controls
42 lines (40 loc) · 1.35 KB
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
import * as path from 'node:path';
import * as fs from 'node:fs/promises';
import { pathToFileURL } from 'node:url';
import { addDevDependency } from 'nypm';
import type { ExperimentArgs } from '../../types.ts';
export async function prepareEvaluations({ projectPath }: ExperimentArgs) {
await addDevDependency(
[
'vitest@catalog:experiments',
'@vitest/browser-playwright@catalog:experiments',
'storybook@catalog:experiments',
'@storybook/addon-docs@catalog:experiments',
'@storybook/addon-a11y@catalog:experiments',
'@storybook/addon-vitest@catalog:experiments',
'@storybook/react-vite@catalog:experiments',
'eslint-plugin-storybook@catalog:experiments',
],
{ cwd: projectPath, silent: true },
);
const evaluationTemplateDir = path.resolve(
path.join('templates', 'evaluation'),
);
await fs.cp(evaluationTemplateDir, projectPath, {
recursive: true,
filter: (source) =>
!source.includes('node_modules') && !source.includes('dist'),
});
const { default: pkgJson } = await import(
pathToFileURL(path.join(projectPath, 'package.json')).href,
{
with: { type: 'json' },
}
);
// add the storybook script after agent execution, so it does not taint the experiment
pkgJson.scripts.storybook = 'storybook dev --port 6006';
await fs.writeFile(
path.join(projectPath, 'package.json'),
JSON.stringify(pkgJson, null, 2),
);
}