storybook/scripts/create-nx-sandbox-projects.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-08-10 21:54:29 +02:00
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import * as templates from '../code/lib/cli-storybook/src/sandbox-templates';
2024-08-08 11:23:52 +02:00
// @ts-expect-error somehow TS thinks there is a default export
2024-05-08 18:02:08 +02:00
const { allTemplates, merged, daily, normal } = (templates.default ||
templates) as typeof templates;
const projectJson = (name: string, framework: string, tags: string[]) => ({
name,
projectType: 'application',
implicitDependencies: [
'cli',
'test',
2024-03-20 10:33:03 +01:00
'essentials',
'interactions',
'links',
'onboarding',
'blocks',
...(!['storybook-framework-qwik', 'storybook-solidjs-vite'].includes(framework)
? [framework]
: []),
],
targets: {
sandbox: {},
'sb:dev': {},
'sb:build': {},
},
tags,
});
Object.entries(allTemplates).forEach(([key, value]) => {
const p = key.replaceAll('/', '-');
2024-08-10 21:54:29 +02:00
const full = join(process.cwd(), '../code/sandbox', p, 'project.json');
console.log(full);
const framework = value.expected.framework.replace('@storybook/', '');
console.log(framework);
console.log();
const tags = [
...(normal.includes(key as any) ? ['ci:normal'] : []),
...(merged.includes(key as any) ? ['ci:merged'] : []),
...(daily.includes(key as any) ? ['ci:daily'] : []),
];
ensureDirectoryExistence(full);
console.log(full);
2024-08-10 21:54:29 +02:00
writeFileSync(
full,
'// auto-generated from scripts/create-nx-sandbox-projects.ts\n' +
JSON.stringify(projectJson(key, framework, tags), null, 2),
{
encoding: 'utf-8',
}
);
});
function ensureDirectoryExistence(filePath: string): void {
2024-08-10 21:54:29 +02:00
const dir = dirname(filePath);
if (existsSync(dir)) {
return;
}
2024-08-10 21:54:29 +02:00
ensureDirectoryExistence(dir);
mkdirSync(dir);
}