2024-08-10 21:54:29 +02:00
|
|
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
|
|
import { dirname, join } from 'node:path';
|
2024-03-06 12:26:54 +01:00
|
|
|
|
2024-07-11 11:45:22 +02:00
|
|
|
import * as templates from '../code/lib/cli-storybook/src/sandbox-templates';
|
2024-08-08 11:23:52 +02:00
|
|
|
|
2024-03-06 12:26:54 +01: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;
|
2024-03-06 12:26:54 +01:00
|
|
|
|
|
|
|
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',
|
2024-03-06 12:26:54 +01:00
|
|
|
'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');
|
2024-03-06 12:26:54 +01:00
|
|
|
|
|
|
|
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);
|
2024-03-19 16:36:54 +01:00
|
|
|
console.log(full);
|
2024-08-10 21:54:29 +02:00
|
|
|
writeFileSync(
|
2024-03-19 16:36:54 +01:00
|
|
|
full,
|
|
|
|
'// auto-generated from scripts/create-nx-sandbox-projects.ts\n' +
|
|
|
|
JSON.stringify(projectJson(key, framework, tags), null, 2),
|
|
|
|
{
|
|
|
|
encoding: 'utf-8',
|
|
|
|
}
|
|
|
|
);
|
2024-03-06 12:26:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function ensureDirectoryExistence(filePath: string): void {
|
2024-08-10 21:54:29 +02:00
|
|
|
const dir = dirname(filePath);
|
|
|
|
if (existsSync(dir)) {
|
2024-03-06 12:26:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-08-10 21:54:29 +02:00
|
|
|
ensureDirectoryExistence(dir);
|
|
|
|
mkdirSync(dir);
|
2024-03-06 12:26:54 +01:00
|
|
|
}
|