@domain-first/project-structure 8.10.1 → 8.11.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/README.md +17 -7
- package/dist/115.js +142 -141
- package/dist/201.js +10 -1
- package/dist/287.js +983 -434
- package/dist/364.js +79 -0
- package/dist/38.js +29 -13
- package/dist/561.js +167 -93
- package/dist/agent-cli.d.ts +13 -2
- package/dist/agent-requests.d.ts +76 -2
- package/dist/config-file.d.ts +25 -1
- package/dist/frontend-cli.d.ts +3 -0
- package/dist/frontend-modules.d.ts +9 -0
- package/dist/graph.cjs +10 -1
- package/dist/index.cjs +3470 -2913
- package/dist/init.cjs +325 -83
- package/dist/integration.cjs +3470 -2913
- package/dist/integrations/openapi.d.ts +9 -2
- package/dist/integrations/orval.d.ts +31 -4
- package/dist/integrations/rest-endpoint-generator.d.ts +11 -7
- package/dist/integrations/storybook.d.ts +19 -1
- package/dist/lint.cjs +40 -15
- package/dist/lint.js +1 -1
- package/dist/page-router.d.ts +18 -0
- package/dist/react-module-move.d.ts +27 -12
- package/dist/react.cjs +1577 -993
- package/dist/react.js +2 -102
- package/dist/rest-adapters.d.ts +13 -0
- package/dist/svelte-agent-cli.spec.d.ts +1 -0
- package/dist/svelte.cjs +7311 -0
- package/dist/svelte.d.ts +2 -0
- package/dist/svelte.js +3 -0
- package/dist/sveltekit-app.d.ts +7 -0
- package/dist/upgrade-steps.d.ts +6 -1
- package/dist/upgrade.cjs +12 -2
- package/dist/use-cases/add-integration.d.ts +1 -1
- package/dist/use-cases/delete-react-module.d.ts +4 -4
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/move-react-module.d.ts +2 -2
- package/dist/use-cases/rest-endpoint-generator.d.ts +6 -4
- package/dist/use-cases/scaffold-svelte-modules.d.ts +22 -0
- package/package.json +2 -1
- package/skills/df-ps-implement/SKILL.md +3 -3
- package/skills/df-ps-plan-feature/SKILL.md +1 -1
- package/skills/df-ps-scaffold/SKILL.md +9 -8
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -1
- package/skills/df-ps-scaffold/references/agent-operations.md +8 -4
- package/skills/df-ps-scaffold/references/generators.md +1 -1
- package/skills/df-ps-scaffold/references/work-plan.md +1 -1
- package/skills/df-ps-svelte/SKILL.md +49 -0
- package/skills/df-ps-svelte/references/generators.md +56 -0
package/dist/287.js
CHANGED
|
@@ -3,8 +3,8 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
3
3
|
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, search, select as prompts_select } from "@inquirer/prompts";
|
|
4
4
|
import node_fs from "node:fs";
|
|
5
5
|
import { styleText } from "node:util";
|
|
6
|
-
import { scaffoldBackendRules, findWiredModules, UnknownFormatNaming, Folder, writePendingChanges, splitContextSegments, addBranchedImplementation, hasNeighboringBoundedContext, implementationLabelSchema, boundedContextLocation, branchNameSchema, wireDependencies, ProjectRoot, boundedContextsFolderName, crossContextImplementation, boundedContextName, availableDependencies, compilerOption, domainFirstPackages as config_file_domainFirstPackages, discardPendingChanges, implementationKinds, readWiredModule, boundedContextNames, withoutOverwrites, validateBoundedContextName, filesToOverwrite, ConfigFile, relativeImport, wireBranches, NestedName, implementationType as wiring_implementationType, File, crossContextImportAllowed, isSuggestedFor } from "./201.js";
|
|
7
|
-
import {
|
|
6
|
+
import { scaffoldBackendRules, findWiredModules, UnknownFormatNaming, Folder, writePendingChanges, splitContextSegments, addBranchedImplementation, hasNeighboringBoundedContext, implementationLabelSchema, boundedContextLocation, branchNameSchema, wireDependencies, ProjectRoot, boundedContextsFolderName, crossContextImplementation, boundedContextName, availableDependencies, compilerOption, domainFirstPackages as config_file_domainFirstPackages, discardPendingChanges, implementationKinds, readWiredModule, boundedContextNames, withoutOverwrites, validateBoundedContextName, filesToOverwrite, ConfigFile, relativeImport as wiring_relativeImport, wireBranches, NestedName, implementationType as wiring_implementationType, File, crossContextImportAllowed, isSuggestedFor } from "./201.js";
|
|
7
|
+
import { hasDependency, restControllers, missingDomainFirstPackages, isPathParameterName, keepInMemoryDbSection, projectImports, walk, wireInMemoryDb, escapeRegExp, pathParameterAsName, stageModuleMove, hasLegacyRootEndpoints, inMemoryImplementationType, toPosix, rootStaticSegments, inMemoryDbScaffolded, scaffoldInMemoryDb, injectInMemoryDb, isInMemoryDb, openapiExtractorPath, inMemoryDbTypeImport, addInMemoryDbSection, openapiExtractor, plural, missingPackages, inMemoryDbSectionMembers, codeExtension, usesInMemoryDb } from "./115.js";
|
|
8
8
|
const moduleId = (module)=>`${boundedContextLocation(module.typeFile)?.name ?? 'shared-kernel'}:${module.typeName}`;
|
|
9
9
|
const unitId = (unit)=>`${unit.kind}:${unit.aggregate ? `${unit.aggregate}/` : ''}${unit.name}`;
|
|
10
10
|
const savedImplementations = (kind, purpose)=>[
|
|
@@ -390,6 +390,11 @@ const nextAppFolder = (root)=>[
|
|
|
390
390
|
'app',
|
|
391
391
|
'src/app'
|
|
392
392
|
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
393
|
+
const usesSvelteKit = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.svelte?.framework === 'sveltekit';
|
|
394
|
+
const svelteKitRoutesFolder = (root)=>[
|
|
395
|
+
'src/routes',
|
|
396
|
+
'routes'
|
|
397
|
+
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'src/routes';
|
|
393
398
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
394
399
|
${[
|
|
395
400
|
...imports,
|
|
@@ -414,7 +419,7 @@ const scaffoldNextRoute = (name, pagePath)=>{
|
|
|
414
419
|
const route = node_path.join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
415
420
|
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
416
421
|
const routeFile = new File(route);
|
|
417
|
-
const content = nextRouteContent(name.ClassName,
|
|
422
|
+
const content = nextRouteContent(name.ClassName, wiring_relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
418
423
|
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
419
424
|
routeFile.data = content;
|
|
420
425
|
};
|
|
@@ -435,25 +440,550 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
435
440
|
if (hint) report(hint);
|
|
436
441
|
}
|
|
437
442
|
};
|
|
443
|
+
const frontendExtensions = {
|
|
444
|
+
react: {
|
|
445
|
+
component: '.tsx',
|
|
446
|
+
hook: '.ts'
|
|
447
|
+
},
|
|
448
|
+
svelte: {
|
|
449
|
+
component: '.svelte',
|
|
450
|
+
hook: '.svelte.ts'
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
const kindLayouts = (framework)=>{
|
|
454
|
+
const { component, hook } = frontendExtensions[framework];
|
|
455
|
+
return {
|
|
456
|
+
page: {
|
|
457
|
+
folder: 'pages',
|
|
458
|
+
nested: true,
|
|
459
|
+
inFolder: false,
|
|
460
|
+
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
461
|
+
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
462
|
+
classPrefix: '(use)?',
|
|
463
|
+
classSuffix: 'Page'
|
|
464
|
+
},
|
|
465
|
+
widget: {
|
|
466
|
+
folder: 'widgets',
|
|
467
|
+
nested: true,
|
|
468
|
+
inFolder: true,
|
|
469
|
+
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
470
|
+
classPrefix: '(use)?',
|
|
471
|
+
classSuffix: 'Widget|UIModel',
|
|
472
|
+
storyTitle: (segments)=>[
|
|
473
|
+
'Widgets',
|
|
474
|
+
...segments
|
|
475
|
+
].join('/')
|
|
476
|
+
},
|
|
477
|
+
'ui-kit': {
|
|
478
|
+
folder: 'ui-kit',
|
|
479
|
+
nested: false,
|
|
480
|
+
inFolder: true,
|
|
481
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
482
|
+
classPrefix: '()',
|
|
483
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
484
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
485
|
+
},
|
|
486
|
+
hook: {
|
|
487
|
+
folder: 'hooks',
|
|
488
|
+
nested: false,
|
|
489
|
+
inFolder: false,
|
|
490
|
+
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
491
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}${hook}`),
|
|
492
|
+
classPrefix: '(use)',
|
|
493
|
+
classSuffix: '(?![\\w$])'
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
const reactKindLayouts = kindLayouts('react');
|
|
498
|
+
const svelteKindLayouts = kindLayouts('svelte');
|
|
499
|
+
const frontendKindLayouts = (framework)=>'svelte' === framework ? svelteKindLayouts : reactKindLayouts;
|
|
500
|
+
const reactKindTitles = {
|
|
501
|
+
page: [
|
|
502
|
+
'Page',
|
|
503
|
+
'pages'
|
|
504
|
+
],
|
|
505
|
+
widget: [
|
|
506
|
+
'Widget',
|
|
507
|
+
'widgets'
|
|
508
|
+
],
|
|
509
|
+
'ui-kit': [
|
|
510
|
+
'UI-kit component',
|
|
511
|
+
'UI-kit components'
|
|
512
|
+
],
|
|
513
|
+
hook: [
|
|
514
|
+
'Shared hook',
|
|
515
|
+
'shared hooks'
|
|
516
|
+
]
|
|
517
|
+
};
|
|
518
|
+
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
519
|
+
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
520
|
+
const prefix = `${folders.join('-')}-`;
|
|
521
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
522
|
+
return [
|
|
523
|
+
...folders,
|
|
524
|
+
last
|
|
525
|
+
].join('/');
|
|
526
|
+
};
|
|
527
|
+
const declaredClassName = (filePaths, suffix, name)=>{
|
|
528
|
+
for (const filePath of filePaths){
|
|
529
|
+
if (!node_fs.existsSync(filePath)) continue;
|
|
530
|
+
const declared = node_fs.readFileSync(filePath, 'utf8').match(new RegExp(`(?:export\\s+(?:const|function)|\\bdefault\\s+as)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
531
|
+
if (declared) return declared;
|
|
532
|
+
}
|
|
533
|
+
return new NestedName(name).ClassName;
|
|
534
|
+
};
|
|
535
|
+
const findUiKit = (reactFolder, framework)=>{
|
|
536
|
+
const { component } = frontendExtensions[framework];
|
|
537
|
+
const root = node_path.join(reactFolder, 'ui-kit');
|
|
538
|
+
if (!node_fs.existsSync(root)) return [];
|
|
539
|
+
return node_fs.readdirSync(root, {
|
|
540
|
+
withFileTypes: true
|
|
541
|
+
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}${component}`))).map(({ name })=>({
|
|
542
|
+
kind: 'ui-kit',
|
|
543
|
+
name,
|
|
544
|
+
path: node_path.join(root, name),
|
|
545
|
+
fileBase: name,
|
|
546
|
+
ClassName: declaredClassName([
|
|
547
|
+
node_path.join(root, name, `${name}${component}`),
|
|
548
|
+
node_path.join(root, name, 'index.ts')
|
|
549
|
+
], '', name)
|
|
550
|
+
}));
|
|
551
|
+
};
|
|
552
|
+
const hookFile = {
|
|
553
|
+
react: /\.tsx?$/,
|
|
554
|
+
svelte: /\.svelte\.[jt]s$/
|
|
555
|
+
};
|
|
556
|
+
const findHooks = (reactFolder, framework)=>{
|
|
557
|
+
const root = node_path.join(reactFolder, 'hooks');
|
|
558
|
+
if (!node_fs.existsSync(root)) return [];
|
|
559
|
+
const extension = hookFile[framework];
|
|
560
|
+
return node_fs.readdirSync(root).filter((file)=>/^use-/.test(file) && extension.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
561
|
+
const name = file.replace(/^use-/, '').replace(extension, '');
|
|
562
|
+
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
563
|
+
return {
|
|
564
|
+
kind: 'hook',
|
|
565
|
+
name,
|
|
566
|
+
path: node_path.join(root, file),
|
|
567
|
+
fileBase: name,
|
|
568
|
+
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
const findReactModules = (reactFolder, kind, framework = 'react')=>{
|
|
573
|
+
const { component } = frontendExtensions[framework];
|
|
574
|
+
const modules = 'ui-kit' === kind ? findUiKit(reactFolder, framework) : 'hook' === kind ? findHooks(reactFolder, framework) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith(`-page${component}`)).map((file)=>{
|
|
575
|
+
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
576
|
+
const fileBase = node_path.basename(file, `-page${component}`);
|
|
577
|
+
const name = react_module_move_nestedName(folders, fileBase);
|
|
578
|
+
return {
|
|
579
|
+
kind,
|
|
580
|
+
name,
|
|
581
|
+
path: file,
|
|
582
|
+
fileBase,
|
|
583
|
+
ClassName: declaredClassName([
|
|
584
|
+
file
|
|
585
|
+
], 'Page', name)
|
|
586
|
+
};
|
|
587
|
+
}) : walk(node_path.join(reactFolder, 'widgets')).filter((file)=>file.endsWith(`-widget${component}`)).map((file)=>{
|
|
588
|
+
const folder = node_path.dirname(file);
|
|
589
|
+
const name = toPosix(node_path.relative(node_path.join(reactFolder, 'widgets'), folder));
|
|
590
|
+
return {
|
|
591
|
+
kind,
|
|
592
|
+
name,
|
|
593
|
+
path: folder,
|
|
594
|
+
fileBase: node_path.basename(file, `-widget${component}`),
|
|
595
|
+
ClassName: declaredClassName([
|
|
596
|
+
file,
|
|
597
|
+
node_path.join(folder, 'index.ts')
|
|
598
|
+
], 'Widget', name)
|
|
599
|
+
};
|
|
600
|
+
});
|
|
601
|
+
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
602
|
+
};
|
|
603
|
+
const targetPath = (reactFolder, module, rawName, framework)=>frontendKindLayouts(framework)[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
604
|
+
const validateMove = (reactFolder, module, rawName, framework = 'react')=>{
|
|
605
|
+
const nameError = NestedName.validate(rawName);
|
|
606
|
+
if (true !== nameError) return nameError;
|
|
607
|
+
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
608
|
+
const target = targetPath(reactFolder, module, rawName, framework);
|
|
609
|
+
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
610
|
+
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
611
|
+
return true;
|
|
612
|
+
};
|
|
613
|
+
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
614
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
615
|
+
return node_path.join(appFolder, ...folders, folderName);
|
|
616
|
+
};
|
|
617
|
+
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
618
|
+
withFileTypes: true
|
|
619
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
620
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route, framework = 'react')=>{
|
|
621
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
622
|
+
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
623
|
+
const target = targetPath(reactFolder, module, rawName, framework);
|
|
624
|
+
const newClassName = newName.ClassName;
|
|
625
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
626
|
+
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
627
|
+
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
628
|
+
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`) : node_path.dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(node_path.basename(candidate));
|
|
629
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
630
|
+
const routeTarget = (candidate)=>{
|
|
631
|
+
if (!route) return;
|
|
632
|
+
const file = [
|
|
633
|
+
...routeFileSet
|
|
634
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
635
|
+
if (!file) return;
|
|
636
|
+
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
637
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
638
|
+
};
|
|
639
|
+
const movedPath = (candidate)=>{
|
|
640
|
+
const routed = routeTarget(candidate);
|
|
641
|
+
if (routed) return routed;
|
|
642
|
+
if (!ownsPath(candidate)) return;
|
|
643
|
+
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
644
|
+
const last = segments.length - 1;
|
|
645
|
+
segments[last] = renameFile(segments[last]);
|
|
646
|
+
return node_path.join(newFolder, ...segments);
|
|
647
|
+
};
|
|
648
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
649
|
+
const moves = new Map([
|
|
650
|
+
...moduleFiles,
|
|
651
|
+
...routeFileSet
|
|
652
|
+
].map((file)=>[
|
|
653
|
+
file,
|
|
654
|
+
movedPath(file) ?? file
|
|
655
|
+
]));
|
|
656
|
+
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
657
|
+
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
658
|
+
module.ClassName
|
|
659
|
+
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
660
|
+
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
661
|
+
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
662
|
+
newClassName
|
|
663
|
+
] : newName.classNameSegments);
|
|
664
|
+
return stageModuleMove({
|
|
665
|
+
projectRoot,
|
|
666
|
+
stopAt: reactFolder,
|
|
667
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
668
|
+
moves,
|
|
669
|
+
movedPath,
|
|
670
|
+
rename: (content, { moved })=>{
|
|
671
|
+
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
672
|
+
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
};
|
|
676
|
+
const routePageFile = {
|
|
677
|
+
react: 'page.tsx',
|
|
678
|
+
svelte: '+page.svelte'
|
|
679
|
+
};
|
|
680
|
+
const pageRouteFolder = (appFolder, page, framework = 'react')=>{
|
|
681
|
+
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
682
|
+
const routePage = node_path.join(folder, routePageFile[framework]);
|
|
683
|
+
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
684
|
+
};
|
|
685
|
+
const reactModuleFiles = (module, framework)=>{
|
|
686
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
687
|
+
if (layout.inFolder) return walk(module.path);
|
|
688
|
+
const folder = node_path.dirname(module.path);
|
|
689
|
+
const own = layout.ownFile(module.fileBase);
|
|
690
|
+
return node_fs.readdirSync(folder, {
|
|
691
|
+
withFileTypes: true
|
|
692
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
693
|
+
};
|
|
694
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
695
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route, framework = 'react')=>{
|
|
696
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
697
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
698
|
+
const own = new Set([
|
|
699
|
+
...moduleFiles,
|
|
700
|
+
...routeFileList
|
|
701
|
+
]);
|
|
702
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
703
|
+
const isModule = (resolved)=>stems.has(resolved) || moduleFiles.includes(resolved) || frontendKindLayouts(framework)[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
704
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
705
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
706
|
+
const usedBy = [];
|
|
707
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
708
|
+
const target = resolve(specifier, file)?.resolved;
|
|
709
|
+
if (target && isModule(target)) usedBy.push([
|
|
710
|
+
relative(file),
|
|
711
|
+
relative(target)
|
|
712
|
+
]);
|
|
713
|
+
}
|
|
714
|
+
if (usedBy.length) return {
|
|
715
|
+
usedBy
|
|
716
|
+
};
|
|
717
|
+
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
718
|
+
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
719
|
+
return {
|
|
720
|
+
deleted: [
|
|
721
|
+
...moduleFiles,
|
|
722
|
+
...routeFileList
|
|
723
|
+
]
|
|
724
|
+
};
|
|
725
|
+
};
|
|
726
|
+
const svelteComponentContent = (propsType)=>`
|
|
727
|
+
<script lang="ts" module>
|
|
728
|
+
export type ${propsType} = {}
|
|
729
|
+
</script>
|
|
730
|
+
|
|
731
|
+
<script lang="ts">
|
|
732
|
+
let props: ${propsType} = $props()
|
|
733
|
+
</script>
|
|
734
|
+
`.trim();
|
|
735
|
+
const svelteStory = (storybookFramework, componentName, componentFile, title)=>`
|
|
736
|
+
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
737
|
+
import ${componentName} from './${componentFile}'
|
|
738
|
+
|
|
739
|
+
const meta = {
|
|
740
|
+
title: '${title}',
|
|
741
|
+
component: ${componentName}
|
|
742
|
+
} satisfies Meta<typeof ${componentName}>
|
|
743
|
+
|
|
744
|
+
export default meta
|
|
745
|
+
|
|
746
|
+
type Story = StoryObj<typeof meta>
|
|
747
|
+
|
|
748
|
+
export const Default: Story = {
|
|
749
|
+
args: {}
|
|
750
|
+
}
|
|
751
|
+
`.trim();
|
|
752
|
+
const scaffold_svelte_modules_storybookFramework = ()=>ConfigFile.Instance.data.frontend?.svelte?.storybookFramework;
|
|
753
|
+
const svelteKitRouteContent = (ClassName, pageImport)=>`
|
|
754
|
+
<script lang="ts">
|
|
755
|
+
import ${ClassName}Page from '${pageImport}'
|
|
756
|
+
</script>
|
|
757
|
+
|
|
758
|
+
<${ClassName}Page />
|
|
759
|
+
`.trim();
|
|
760
|
+
const relativeImport = (fromFile, toFile)=>{
|
|
761
|
+
const relative = node_path.relative(node_path.dirname(fromFile), toFile).split(node_path.sep).join('/');
|
|
762
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
763
|
+
};
|
|
764
|
+
const scaffoldSvelteKitRoute = (name, pagePath)=>{
|
|
765
|
+
const root = new ProjectRoot().path;
|
|
766
|
+
const route = node_path.join(root, svelteKitRoutesFolder(root), ...name.folders, name.folderName, routePageFile.svelte);
|
|
767
|
+
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
768
|
+
const routeFile = new File(route);
|
|
769
|
+
const content = svelteKitRouteContent(name.ClassName, relativeImport(route, pagePath));
|
|
770
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
771
|
+
routeFile.data = content;
|
|
772
|
+
};
|
|
773
|
+
const scaffoldSveltePage = async (presentationSvelteFolder)=>{
|
|
774
|
+
const name = await interaction_input({
|
|
775
|
+
key: 'name',
|
|
776
|
+
message: 'Provide name (folders split by "/"):',
|
|
777
|
+
validate: NestedName.validate
|
|
778
|
+
});
|
|
779
|
+
const nestedName = new NestedName(name);
|
|
780
|
+
const { folders, ClassName, fileName } = nestedName;
|
|
781
|
+
const pageFile = presentationSvelteFolder.subitem([
|
|
782
|
+
'pages',
|
|
783
|
+
...folders
|
|
784
|
+
]).createFile(`${fileName}-page.svelte`, svelteComponentContent(`${ClassName}PageProps`));
|
|
785
|
+
if (usesSvelteKit()) {
|
|
786
|
+
const hint = scaffoldSvelteKitRoute(nestedName, pageFile.path);
|
|
787
|
+
if (hint) report(hint);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const scaffoldSvelteWidget = async (presentationSvelteFolder)=>{
|
|
791
|
+
const widgetName = await interaction_input({
|
|
792
|
+
key: 'name',
|
|
793
|
+
message: 'Name (folders split by "/"): ',
|
|
794
|
+
validate: NestedName.validate
|
|
795
|
+
});
|
|
796
|
+
const widgetType = await interaction_select({
|
|
797
|
+
choices: [
|
|
798
|
+
'monolithic',
|
|
799
|
+
'with separated ui',
|
|
800
|
+
'headless'
|
|
801
|
+
],
|
|
802
|
+
key: 'widgetType',
|
|
803
|
+
message: 'Type: '
|
|
804
|
+
});
|
|
805
|
+
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
806
|
+
const folder = presentationSvelteFolder.subitem([
|
|
807
|
+
'widgets',
|
|
808
|
+
...folders,
|
|
809
|
+
folderName
|
|
810
|
+
]);
|
|
811
|
+
const storyTitle = [
|
|
812
|
+
'Widgets',
|
|
813
|
+
...classNameSegments
|
|
814
|
+
].join('/');
|
|
815
|
+
const widgetFileName = `${fileName}-widget`;
|
|
816
|
+
const uiFileName = `${fileName}-widget-ui`;
|
|
817
|
+
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
818
|
+
if ('monolithic' === widgetType) {
|
|
819
|
+
folder.createFile('index.ts', `
|
|
820
|
+
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
821
|
+
export type { ${ClassName}WidgetProps } from './${widgetFileName}.svelte'
|
|
822
|
+
`.trim());
|
|
823
|
+
folder.createFile(`${widgetFileName}.svelte`, svelteComponentContent(`${ClassName}WidgetProps`));
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
folder.createFile('index.ts', `
|
|
827
|
+
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
828
|
+
export type { ${ClassName}WidgetProps } from './types'
|
|
829
|
+
`.trim());
|
|
830
|
+
if ('with separated ui' === widgetType) {
|
|
831
|
+
folder.createFile('types.ts', `
|
|
832
|
+
export type ${ClassName}WidgetProps = { }
|
|
833
|
+
|
|
834
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
835
|
+
`.trim());
|
|
836
|
+
folder.createFile(`${widgetFileName}.svelte`, `
|
|
837
|
+
<script lang="ts">
|
|
838
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
839
|
+
import ${ClassName}WidgetUI from './ui/${uiFileName}.svelte'
|
|
840
|
+
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}.svelte'
|
|
841
|
+
|
|
842
|
+
let props: ${ClassName}WidgetProps = $props()
|
|
843
|
+
const uiModel = use${ClassName}UIModel(props)
|
|
844
|
+
</script>
|
|
845
|
+
|
|
846
|
+
<${ClassName}WidgetUI {...uiModel} />
|
|
847
|
+
`.trim());
|
|
848
|
+
folder.subitem([
|
|
849
|
+
'ui'
|
|
850
|
+
]).createFile(`${uiFileName}.svelte`, `
|
|
851
|
+
<script lang="ts">
|
|
852
|
+
import type { ${ClassName}WidgetUIProps } from '../types'
|
|
853
|
+
|
|
854
|
+
let props: ${ClassName}WidgetUIProps = $props()
|
|
855
|
+
</script>
|
|
856
|
+
`.trim());
|
|
857
|
+
const framework = scaffold_svelte_modules_storybookFramework();
|
|
858
|
+
if (framework) folder.subitem([
|
|
859
|
+
'ui'
|
|
860
|
+
]).createFile(`${uiFileName}.stories.ts`, svelteStory(framework, `${ClassName}WidgetUI`, `${uiFileName}.svelte`, storyTitle));
|
|
861
|
+
folder.subitem([
|
|
862
|
+
'hooks'
|
|
863
|
+
]).createFile(`${uiModelFileName}.svelte.ts`, `
|
|
864
|
+
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
865
|
+
|
|
866
|
+
export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
|
|
867
|
+
return {}
|
|
868
|
+
}
|
|
869
|
+
`.trim());
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
folder.createFile('types.ts', `
|
|
873
|
+
import type { Component } from 'svelte'
|
|
874
|
+
|
|
875
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
876
|
+
|
|
877
|
+
export type ${ClassName}WidgetProps = {
|
|
878
|
+
UI: Component<${ClassName}WidgetUIProps>
|
|
879
|
+
}
|
|
880
|
+
`.trim());
|
|
881
|
+
folder.createFile(`${widgetFileName}.svelte`, `
|
|
882
|
+
<script lang="ts">
|
|
883
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
884
|
+
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}.svelte'
|
|
885
|
+
|
|
886
|
+
let { UI, ...widgetProps }: ${ClassName}WidgetProps = $props()
|
|
887
|
+
const uiModel = use${ClassName}UIModel(widgetProps)
|
|
888
|
+
</script>
|
|
889
|
+
|
|
890
|
+
<UI {...uiModel} />
|
|
891
|
+
`.trim());
|
|
892
|
+
folder.subitem([
|
|
893
|
+
'hooks'
|
|
894
|
+
]).createFile(`${uiModelFileName}.svelte.ts`, `
|
|
895
|
+
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
896
|
+
|
|
897
|
+
export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
|
|
898
|
+
return {}
|
|
899
|
+
}
|
|
900
|
+
`.trim());
|
|
901
|
+
};
|
|
902
|
+
const scaffoldSvelteUIKitComponent = async (presentationSvelteFolder)=>{
|
|
903
|
+
const name = await interaction_input({
|
|
904
|
+
key: 'name',
|
|
905
|
+
message: 'Name: '
|
|
906
|
+
});
|
|
907
|
+
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
908
|
+
const componentFolder = presentationSvelteFolder.subitem([
|
|
909
|
+
'ui-kit',
|
|
910
|
+
fileName
|
|
911
|
+
]);
|
|
912
|
+
componentFolder.createFile('index.ts', `
|
|
913
|
+
export { default as ${ClassName} } from './${fileName}.svelte'
|
|
914
|
+
export type { ${ClassName}Props } from './${fileName}.svelte'
|
|
915
|
+
`.trim());
|
|
916
|
+
componentFolder.createFile(`${fileName}.svelte`, svelteComponentContent(`${ClassName}Props`));
|
|
917
|
+
const framework = scaffold_svelte_modules_storybookFramework();
|
|
918
|
+
if (framework) componentFolder.createFile(`${fileName}.stories.ts`, svelteStory(framework, ClassName, `${fileName}.svelte`, `UI-kit/${ClassName}`));
|
|
919
|
+
};
|
|
920
|
+
const scaffoldSvelteSharedHook = async (presentationSvelteFolder)=>{
|
|
921
|
+
const name = await interaction_input({
|
|
922
|
+
key: 'name',
|
|
923
|
+
message: 'Name without "use" (e.g. debounce): '
|
|
924
|
+
});
|
|
925
|
+
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
926
|
+
presentationSvelteFolder.subitem([
|
|
927
|
+
'hooks'
|
|
928
|
+
]).createFile(`use-${fileName}.svelte.ts`, `
|
|
929
|
+
export const use${ClassName} = () => {
|
|
930
|
+
return {}
|
|
931
|
+
}
|
|
932
|
+
`.trim());
|
|
933
|
+
};
|
|
438
934
|
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
439
|
-
const defaultOpenapiPath = (
|
|
935
|
+
const defaultOpenapiPath = ()=>usesNext() ? 'public/openapi.json' : usesSvelteKit() ? 'static/openapi.json' : 'openapi.json';
|
|
440
936
|
const extractorPackages = [
|
|
441
937
|
'ts-morph',
|
|
442
938
|
'@microsoft/tsdoc'
|
|
443
939
|
];
|
|
444
|
-
const swaggerPagePath = (rootFolder)=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
940
|
+
const swaggerPagePath = (rootFolder, framework = 'react')=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'svelte' === framework ? 'presentation/svelte/pages/swagger-page.svelte' : 'presentation/react/pages/swagger-page.tsx');
|
|
941
|
+
const specImportOf = (pagePath, outputPath)=>{
|
|
942
|
+
const specImport = node_path.posix.relative(node_path.posix.dirname(pagePath), outputPath);
|
|
943
|
+
return specImport.startsWith('.') ? specImport : `./${specImport}`;
|
|
944
|
+
};
|
|
445
945
|
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
446
|
-
const specImport = node_path.posix.relative(node_path.posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
447
946
|
const page = reactPageContent('Swagger', {
|
|
448
947
|
imports: [
|
|
449
948
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
450
949
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
451
|
-
`import spec from '${
|
|
950
|
+
`import spec from '${specImportOf(swaggerPagePath(rootFolder), outputPath)}' with { type: 'json' }`
|
|
452
951
|
],
|
|
453
952
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
454
953
|
});
|
|
455
954
|
return withNext ? `'use client'\n\n${page}` : page;
|
|
456
955
|
};
|
|
956
|
+
const svelteSwaggerPage = (rootFolder, outputPath)=>`
|
|
957
|
+
<script lang="ts" module>
|
|
958
|
+
export type SwaggerPageProps = {}
|
|
959
|
+
</script>
|
|
960
|
+
|
|
961
|
+
<script lang="ts">
|
|
962
|
+
import 'swagger-ui/dist/swagger-ui.css'
|
|
963
|
+
import { onMount } from 'svelte'
|
|
964
|
+
import spec from '${specImportOf(swaggerPagePath(rootFolder, 'svelte'), outputPath)}'
|
|
965
|
+
|
|
966
|
+
let props: SwaggerPageProps = $props()
|
|
967
|
+
let container: HTMLDivElement
|
|
968
|
+
|
|
969
|
+
onMount(async () => {
|
|
970
|
+
const { default: SwaggerUI } = await import('swagger-ui')
|
|
971
|
+
SwaggerUI({ domNode: container, spec, displayOperationId: true })
|
|
972
|
+
})
|
|
973
|
+
</script>
|
|
974
|
+
|
|
975
|
+
<div bind:this={container}></div>
|
|
976
|
+
`.trim();
|
|
977
|
+
const swaggerPackages = {
|
|
978
|
+
react: {
|
|
979
|
+
dependency: 'swagger-ui-react',
|
|
980
|
+
types: '@types/swagger-ui-react'
|
|
981
|
+
},
|
|
982
|
+
svelte: {
|
|
983
|
+
dependency: 'swagger-ui',
|
|
984
|
+
types: '@types/swagger-ui'
|
|
985
|
+
}
|
|
986
|
+
};
|
|
457
987
|
const openapiScripts = {
|
|
458
988
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
459
989
|
};
|
|
@@ -512,7 +1042,7 @@ const addOpenapi = async ()=>{
|
|
|
512
1042
|
const outputPath = await interaction_input({
|
|
513
1043
|
key: 'openapiPath',
|
|
514
1044
|
message: 'OpenAPI document path:',
|
|
515
|
-
default: defaultOpenapiPath(
|
|
1045
|
+
default: defaultOpenapiPath(),
|
|
516
1046
|
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
517
1047
|
});
|
|
518
1048
|
const withExtractor = await interaction_confirm({
|
|
@@ -520,7 +1050,9 @@ const addOpenapi = async ()=>{
|
|
|
520
1050
|
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
521
1051
|
default: true
|
|
522
1052
|
});
|
|
523
|
-
const
|
|
1053
|
+
const { frontend } = ConfigFile.Instance.data;
|
|
1054
|
+
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
1055
|
+
const withSwaggerPage = !!framework && await interaction_confirm({
|
|
524
1056
|
key: 'swaggerPage',
|
|
525
1057
|
message: 'Add a Swagger UI page?',
|
|
526
1058
|
default: true
|
|
@@ -534,15 +1066,16 @@ const addOpenapi = async ()=>{
|
|
|
534
1066
|
const generatorFile = new File(node_path.join(root, openapiScriptPath));
|
|
535
1067
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
536
1068
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
537
|
-
const
|
|
538
|
-
let
|
|
1069
|
+
const routeFile = withSwaggerPage && 'react' === framework && usesNext() ? `${nextAppFolder(root)}/swagger/page.tsx` : withSwaggerPage && 'svelte' === framework && usesSvelteKit() ? `${svelteKitRoutesFolder(root)}/swagger/+page.svelte` : void 0;
|
|
1070
|
+
let routeHint;
|
|
539
1071
|
if (withSwaggerPage) {
|
|
540
|
-
const pagePath = node_path.join(root, swaggerPagePath(rootFolder));
|
|
1072
|
+
const pagePath = node_path.join(root, swaggerPagePath(rootFolder, framework));
|
|
541
1073
|
const pageFile = new File(pagePath);
|
|
542
|
-
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'),
|
|
1074
|
+
const page = 'svelte' === framework ? svelteSwaggerPage(rootFolder, splitPath(outputPath).join('/')) : swaggerPage(rootFolder, splitPath(outputPath).join('/'), !!routeFile);
|
|
543
1075
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
544
|
-
if (
|
|
1076
|
+
if (routeFile) routeHint = ('svelte' === framework ? scaffoldSvelteKitRoute : scaffoldNextRoute)(new NestedName('swagger'), pagePath);
|
|
545
1077
|
}
|
|
1078
|
+
const packages = swaggerPackages[framework ?? 'react'];
|
|
546
1079
|
const resolveJsonModule = withSwaggerPage ? compilerOption(node_path.join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
547
1080
|
const hasRestHandlers = new File(node_path.join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
548
1081
|
const missingExtractorPackages = withExtractor ? extractorPackages.filter((name)=>!dependencies[name]) : [];
|
|
@@ -556,11 +1089,11 @@ const addOpenapi = async ()=>{
|
|
|
556
1089
|
...missingExtractorPackages.length ? [
|
|
557
1090
|
`npm install --save-dev ${missingExtractorPackages.join(' ')}`
|
|
558
1091
|
] : [],
|
|
559
|
-
...withSwaggerPage && !dependencies[
|
|
560
|
-
|
|
1092
|
+
...withSwaggerPage && !dependencies[packages.dependency] ? [
|
|
1093
|
+
`npm install ${packages.dependency}`
|
|
561
1094
|
] : [],
|
|
562
|
-
...withSwaggerPage && !dependencies[
|
|
563
|
-
|
|
1095
|
+
...withSwaggerPage && !dependencies[packages.types] ? [
|
|
1096
|
+
`npm install --save-dev ${packages.types}`
|
|
564
1097
|
] : [],
|
|
565
1098
|
...true === resolveJsonModule || null === resolveJsonModule ? [] : [
|
|
566
1099
|
'set "resolveJsonModule": true in compilerOptions of tsconfig.json — the Swagger UI page imports the OpenAPI document as JSON'
|
|
@@ -568,11 +1101,11 @@ const addOpenapi = async ()=>{
|
|
|
568
1101
|
...describeScripts(selected, {
|
|
569
1102
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
570
1103
|
}),
|
|
571
|
-
...withSwaggerPage && !
|
|
572
|
-
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1104
|
+
...withSwaggerPage && !routeFile ? [
|
|
1105
|
+
`SwaggerPage from ${swaggerPagePath(rootFolder, framework)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
573
1106
|
] : [],
|
|
574
|
-
...
|
|
575
|
-
|
|
1107
|
+
...routeFile ? [
|
|
1108
|
+
routeHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${routeFile}`
|
|
576
1109
|
] : [],
|
|
577
1110
|
...hasRestHandlers ? [] : [
|
|
578
1111
|
`restHandlers appear in ${node_path.posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
@@ -586,20 +1119,28 @@ const addGitignoreEntry = (root, entry)=>{
|
|
|
586
1119
|
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
587
1120
|
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
588
1121
|
};
|
|
589
|
-
const dataLayerFolder = (rootFolder, target)=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ?
|
|
590
|
-
const orvalScripts = (rootFolder, targets)=>({
|
|
591
|
-
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target)}/orval.config.ts`)}`).join(' && ')
|
|
1122
|
+
const dataLayerFolder = (rootFolder, target, framework = 'react')=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ? `presentation/${framework}/data-layer` : 'presentation/data-layer');
|
|
1123
|
+
const orvalScripts = (rootFolder, targets, framework = 'react')=>({
|
|
1124
|
+
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target, framework)}/orval.config.ts`)}`).join(' && ')
|
|
592
1125
|
});
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
1126
|
+
const orvalBaseUrls = {
|
|
1127
|
+
next: 'process.env.NEXT_PUBLIC_API_BASE_URL ?? ""',
|
|
1128
|
+
svelte: 'import.meta.env.VITE_API_BASE_URL ?? ""'
|
|
1129
|
+
};
|
|
1130
|
+
const orvalConfig = (rootFolder, openapiPath, baseUrlSource, target = 'hooks', mutatorPath = './api-client/mutator.ts', framework = 'react')=>{
|
|
1131
|
+
const inputPath = node_path.posix.relative(dataLayerFolder(rootFolder, target, framework), openapiPath);
|
|
1132
|
+
const baseUrl = baseUrlSource ? `
|
|
596
1133
|
baseUrl: {
|
|
597
|
-
runtime: '
|
|
1134
|
+
runtime: '${orvalBaseUrls[baseUrlSource]}'
|
|
598
1135
|
},` : '';
|
|
1136
|
+
const svelteQuery = 'hooks' === target && 'svelte' === framework;
|
|
599
1137
|
const client = 'hooks' === target ? `
|
|
600
|
-
client: 'react-query',
|
|
1138
|
+
client: '${svelteQuery ? 'svelte-query' : 'react-query'}',
|
|
601
1139
|
httpClient: 'fetch',` : `
|
|
602
1140
|
client: 'fetch',`;
|
|
1141
|
+
const packageJson = svelteQuery ? `
|
|
1142
|
+
// Svelte Query 6 (runes) even before it is installed; an installed version wins
|
|
1143
|
+
packageJson: './${svelteQueryPackageJsonFile}',` : '';
|
|
603
1144
|
const query = 'hooks' === target ? `,
|
|
604
1145
|
query: {
|
|
605
1146
|
version: 5
|
|
@@ -612,7 +1153,7 @@ export default defineConfig({
|
|
|
612
1153
|
output: {
|
|
613
1154
|
mode: 'tags-split',
|
|
614
1155
|
target: './orval',
|
|
615
|
-
schemas: './orval/model',${client}${baseUrl}
|
|
1156
|
+
schemas: './orval/model',${client}${packageJson}${baseUrl}
|
|
616
1157
|
clean: true,
|
|
617
1158
|
override: {
|
|
618
1159
|
mutator: {
|
|
@@ -628,6 +1169,14 @@ export default defineConfig({
|
|
|
628
1169
|
});
|
|
629
1170
|
`;
|
|
630
1171
|
};
|
|
1172
|
+
const svelteQueryPackageJsonFile = 'orval.package.json';
|
|
1173
|
+
const svelteQueryPackageJson = `${JSON.stringify({
|
|
1174
|
+
private: true,
|
|
1175
|
+
dependencies: {
|
|
1176
|
+
'@tanstack/svelte-query': '^6.0.0'
|
|
1177
|
+
}
|
|
1178
|
+
}, null, 4)}
|
|
1179
|
+
`;
|
|
631
1180
|
const orvalMutator = `/** Error of the generated requests, with the parsed response body. */
|
|
632
1181
|
export class ApiError<Body = unknown> extends Error {
|
|
633
1182
|
constructor(
|
|
@@ -674,6 +1223,43 @@ export const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
|
674
1223
|
);
|
|
675
1224
|
};
|
|
676
1225
|
`;
|
|
1226
|
+
const svelteQueryProvider = (withSvelteKit)=>`<script lang="ts">
|
|
1227
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
|
|
1228
|
+
import type { Snippet } from 'svelte'${withSvelteKit ? "\n import { browser } from '$app/environment'" : ''}
|
|
1229
|
+
|
|
1230
|
+
let { children }: { children: Snippet } = $props()
|
|
1231
|
+
|
|
1232
|
+
// One client per app instance; a module-level client would be shared between requests on the server
|
|
1233
|
+
const queryClient = new QueryClient(${withSvelteKit ? `{
|
|
1234
|
+
defaultOptions: { queries: { enabled: browser } }
|
|
1235
|
+
}` : ''})
|
|
1236
|
+
</script>
|
|
1237
|
+
|
|
1238
|
+
<QueryClientProvider client={queryClient}>
|
|
1239
|
+
{@render children()}
|
|
1240
|
+
</QueryClientProvider>
|
|
1241
|
+
`;
|
|
1242
|
+
const svelteKitQueryLayout = (providerImport)=>`<script lang="ts">
|
|
1243
|
+
import type { Snippet } from 'svelte'
|
|
1244
|
+
import QueryProvider from '${providerImport}'
|
|
1245
|
+
|
|
1246
|
+
let { children }: { children: Snippet } = $props()
|
|
1247
|
+
</script>
|
|
1248
|
+
|
|
1249
|
+
<QueryProvider>
|
|
1250
|
+
{@render children()}
|
|
1251
|
+
</QueryProvider>
|
|
1252
|
+
`;
|
|
1253
|
+
const connectSvelteKitProvider = (root, providerPath)=>{
|
|
1254
|
+
const layoutPath = node_path.posix.join(svelteKitRoutesFolder(root), '+layout.svelte');
|
|
1255
|
+
const layout = new File(node_path.join(root, layoutPath));
|
|
1256
|
+
if (!layout.exists) {
|
|
1257
|
+
const providerImport = node_path.posix.relative(node_path.posix.dirname(layoutPath), providerPath);
|
|
1258
|
+
layout.data = svelteKitQueryLayout(providerImport.startsWith('.') ? providerImport : `./${providerImport}`);
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
return layout.data.includes('QueryProvider') ? void 0 : `Wrap {@render children()} of ${layoutPath} in QueryProvider from ${providerPath}`;
|
|
1262
|
+
};
|
|
677
1263
|
const openapiOutputPath = (root)=>{
|
|
678
1264
|
const generator = new File(node_path.join(root, openapiScriptPath));
|
|
679
1265
|
if (!generator.exists) return;
|
|
@@ -681,7 +1267,7 @@ const openapiOutputPath = (root)=>{
|
|
|
681
1267
|
};
|
|
682
1268
|
const addOrval = async ()=>{
|
|
683
1269
|
const { project: { rootFolder }, frontend } = ConfigFile.Instance.data;
|
|
684
|
-
const
|
|
1270
|
+
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
685
1271
|
const root = new ProjectRoot().path;
|
|
686
1272
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
687
1273
|
const manifest = JSON.parse(manifestFile.data);
|
|
@@ -689,20 +1275,22 @@ const addOrval = async ()=>{
|
|
|
689
1275
|
...manifest.dependencies,
|
|
690
1276
|
...manifest.devDependencies
|
|
691
1277
|
};
|
|
692
|
-
const
|
|
1278
|
+
const withSvelteKit = usesSvelteKit();
|
|
1279
|
+
const baseUrl = 'svelte' === framework ? 'svelte' : usesNext() ? 'next' : void 0;
|
|
1280
|
+
const hooksFramework = framework ?? 'react';
|
|
693
1281
|
const generatedOpenapiPath = openapiOutputPath(root);
|
|
694
1282
|
const openapiPath = await interaction_input({
|
|
695
1283
|
key: 'openapiPath',
|
|
696
1284
|
message: 'OpenAPI document path:',
|
|
697
|
-
default: generatedOpenapiPath ?? defaultOpenapiPath(
|
|
1285
|
+
default: generatedOpenapiPath ?? defaultOpenapiPath(),
|
|
698
1286
|
validate: (value)=>value.trim() ? true : 'Path is required'
|
|
699
1287
|
});
|
|
700
|
-
const targets =
|
|
1288
|
+
const targets = framework ? await interaction_checkbox({
|
|
701
1289
|
key: 'targets',
|
|
702
1290
|
message: 'Generate:',
|
|
703
1291
|
choices: [
|
|
704
1292
|
{
|
|
705
|
-
name: 'React Query hooks',
|
|
1293
|
+
name: 'svelte' === framework ? 'Svelte Query hooks' : 'React Query hooks',
|
|
706
1294
|
value: 'hooks',
|
|
707
1295
|
checked: true
|
|
708
1296
|
},
|
|
@@ -715,16 +1303,23 @@ const addOrval = async ()=>{
|
|
|
715
1303
|
}) : [
|
|
716
1304
|
'client'
|
|
717
1305
|
];
|
|
718
|
-
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets));
|
|
1306
|
+
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets, hooksFramework));
|
|
1307
|
+
const layer = (target)=>dataLayerFolder(rootFolder, target, hooksFramework);
|
|
1308
|
+
const providerFile = 'svelte' === hooksFramework ? 'query-provider.svelte' : 'query-provider.tsx';
|
|
1309
|
+
const providerContent = 'svelte' === hooksFramework ? svelteQueryProvider(withSvelteKit) : queryProvider;
|
|
719
1310
|
const document = node_path.posix.normalize(openapiPath.trim().replaceAll('\\', '/'));
|
|
720
1311
|
const withClient = targets.includes('client');
|
|
721
1312
|
for (const target of targets){
|
|
722
|
-
const dataLayer =
|
|
1313
|
+
const dataLayer = layer(target);
|
|
723
1314
|
const sharedMutator = 'hooks' === target && withClient;
|
|
724
|
-
const mutatorPath = sharedMutator ? `${node_path.posix.relative(dataLayer,
|
|
1315
|
+
const mutatorPath = sharedMutator ? `${node_path.posix.relative(dataLayer, layer('client'))}/api-client/mutator.ts` : void 0;
|
|
725
1316
|
const configFile = new File(node_path.join(root, dataLayer, 'orval.config.ts'));
|
|
726
|
-
const content = orvalConfig(rootFolder, document,
|
|
1317
|
+
const content = orvalConfig(rootFolder, document, baseUrl, target, mutatorPath, hooksFramework);
|
|
727
1318
|
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
1319
|
+
if ('hooks' === target && 'svelte' === hooksFramework) {
|
|
1320
|
+
const versions = new File(node_path.join(root, dataLayer, svelteQueryPackageJsonFile));
|
|
1321
|
+
if (!versions.exists || versions.data !== svelteQueryPackageJson) versions.data = svelteQueryPackageJson;
|
|
1322
|
+
}
|
|
728
1323
|
for (const [name, fileContent] of [
|
|
729
1324
|
...sharedMutator ? [] : [
|
|
730
1325
|
[
|
|
@@ -734,8 +1329,8 @@ const addOrval = async ()=>{
|
|
|
734
1329
|
],
|
|
735
1330
|
...'hooks' === target ? [
|
|
736
1331
|
[
|
|
737
|
-
|
|
738
|
-
|
|
1332
|
+
providerFile,
|
|
1333
|
+
providerContent
|
|
739
1334
|
]
|
|
740
1335
|
] : []
|
|
741
1336
|
]){
|
|
@@ -744,10 +1339,14 @@ const addOrval = async ()=>{
|
|
|
744
1339
|
}
|
|
745
1340
|
addGitignoreEntry(root, `/${dataLayer}/orval/`);
|
|
746
1341
|
}
|
|
747
|
-
const
|
|
1342
|
+
const withHooks = targets.includes('hooks');
|
|
1343
|
+
const providerPath = `${layer('hooks')}/${providerFile}`;
|
|
1344
|
+
const layoutNote = withHooks && 'svelte' === hooksFramework && withSvelteKit ? connectSvelteKitProvider(root, providerPath) : void 0;
|
|
1345
|
+
const queryPackage = 'svelte' === hooksFramework ? '@tanstack/svelte-query' : '@tanstack/react-query';
|
|
1346
|
+
const generated = targets.map((target)=>'hooks' === target ? `${'svelte' === hooksFramework ? 'Svelte' : 'React'} Query hooks in ${layer('hooks')}/orval` : `a typed API client in ${layer('client')}/orval`);
|
|
748
1347
|
const missing = (names)=>names.filter((name)=>!dependencies[name]);
|
|
749
|
-
const runtime = missing(
|
|
750
|
-
|
|
1348
|
+
const runtime = missing(withHooks ? [
|
|
1349
|
+
queryPackage
|
|
751
1350
|
] : []);
|
|
752
1351
|
const development = missing([
|
|
753
1352
|
'orval'
|
|
@@ -762,8 +1361,11 @@ const addOrval = async ()=>{
|
|
|
762
1361
|
...describeScripts(selected, {
|
|
763
1362
|
'client:orval': `generate ${generated.join(' and ')} from ${openapiPath.trim()}`
|
|
764
1363
|
}),
|
|
765
|
-
...
|
|
766
|
-
`Wrap your app in QueryProvider from ${
|
|
1364
|
+
...withHooks && !('svelte' === hooksFramework && withSvelteKit) ? [
|
|
1365
|
+
`Wrap your app in QueryProvider from ${providerPath}`
|
|
1366
|
+
] : [],
|
|
1367
|
+
...layoutNote ? [
|
|
1368
|
+
layoutNote
|
|
767
1369
|
] : [],
|
|
768
1370
|
...generatedOpenapiPath ? [] : [
|
|
769
1371
|
'npx df-integration → OpenAPI generates the OpenAPI document the client is built from'
|
|
@@ -1003,6 +1605,22 @@ const addPrisma = async ()=>{
|
|
|
1003
1605
|
})
|
|
1004
1606
|
];
|
|
1005
1607
|
};
|
|
1608
|
+
const rest_adapters_restAdapters = {
|
|
1609
|
+
next: {
|
|
1610
|
+
package: '@domain-first/handlers-next',
|
|
1611
|
+
adapter: 'nextAdapter',
|
|
1612
|
+
endpoints: 'nextEndpoints',
|
|
1613
|
+
key: 'nextAdapter',
|
|
1614
|
+
routePath: (root)=>node_path.posix.join(nextAppFolder(root), 'api/[...path]/route.ts')
|
|
1615
|
+
},
|
|
1616
|
+
svelte: {
|
|
1617
|
+
package: '@domain-first/handlers-svelte',
|
|
1618
|
+
adapter: 'svelteAdapter',
|
|
1619
|
+
endpoints: 'svelteEndpoints',
|
|
1620
|
+
key: 'svelteAdapter',
|
|
1621
|
+
routePath: (root)=>node_path.posix.join(svelteKitRoutesFolder(root), 'api/[...path]/+server.ts')
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1006
1624
|
const kindTitles = {
|
|
1007
1625
|
repositories: 'Repositories',
|
|
1008
1626
|
'domain-services': 'Domain services',
|
|
@@ -1197,15 +1815,16 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
|
1197
1815
|
if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
1198
1816
|
};
|
|
1199
1817
|
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
1200
|
-
const scaffoldRestEndpointGenerator = (sharedFolder, {
|
|
1201
|
-
const
|
|
1818
|
+
const scaffoldRestEndpointGenerator = (sharedFolder, { adapter: framework } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
|
|
1819
|
+
const known = framework && rest_adapters_restAdapters[framework];
|
|
1820
|
+
const adapter = known ? known.adapter : 'adapter';
|
|
1202
1821
|
return `
|
|
1203
1822
|
import {
|
|
1204
|
-
${
|
|
1823
|
+
${known ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
1205
1824
|
createEndpoint,
|
|
1206
1825
|
invalidRequest
|
|
1207
1826
|
} from '@domain-first/handlers-rest'
|
|
1208
|
-
${
|
|
1827
|
+
${known ? `import { ${known.adapter} } from '${known.package}'` : `
|
|
1209
1828
|
/**
|
|
1210
1829
|
* The adapter of your HTTP framework.
|
|
1211
1830
|
*/
|
|
@@ -1230,16 +1849,17 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
1230
1849
|
wireFile: node_path.join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1231
1850
|
};
|
|
1232
1851
|
};
|
|
1233
|
-
const
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1852
|
+
const catchAllRoute = (adapter, restHandlersImport)=>{
|
|
1853
|
+
const { endpoints, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
1854
|
+
return `
|
|
1855
|
+
import { ${endpoints} } from '${packageName}'
|
|
1236
1856
|
${restHandlersImport ? `import { restHandlers } from '${restHandlersImport}'
|
|
1237
1857
|
|
|
1238
|
-
const handler =
|
|
1858
|
+
const handler = ${endpoints}(restHandlers)` : `
|
|
1239
1859
|
/**
|
|
1240
1860
|
* Pass the endpoints' handle here; their paths are relative to this route's folder.
|
|
1241
1861
|
*/
|
|
1242
|
-
const handler =
|
|
1862
|
+
const handler = ${endpoints}([])`}
|
|
1243
1863
|
|
|
1244
1864
|
export const GET = handler
|
|
1245
1865
|
export const POST = handler
|
|
@@ -1247,14 +1867,15 @@ export const PUT = handler
|
|
|
1247
1867
|
export const PATCH = handler
|
|
1248
1868
|
export const DELETE = handler
|
|
1249
1869
|
`.trim();
|
|
1250
|
-
|
|
1870
|
+
};
|
|
1871
|
+
const scaffoldCatchAllRoute = (root, adapter)=>{
|
|
1251
1872
|
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
1252
1873
|
const { domainFirstPackages } = ConfigFile.backend;
|
|
1253
|
-
const routePath =
|
|
1874
|
+
const routePath = rest_adapters_restAdapters[adapter].routePath(root);
|
|
1254
1875
|
const routeFile = node_path.join(root, routePath);
|
|
1255
1876
|
if (new File(routeFile).exists) return [];
|
|
1256
1877
|
if (!domainFirstPackages.includes('@domain-first/wire')) {
|
|
1257
|
-
new File(routeFile).data =
|
|
1878
|
+
new File(routeFile).data = catchAllRoute(adapter, void 0);
|
|
1258
1879
|
return [];
|
|
1259
1880
|
}
|
|
1260
1881
|
const restFolder = new Folder(root).subitem([
|
|
@@ -1262,16 +1883,21 @@ const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
|
1262
1883
|
'presentation',
|
|
1263
1884
|
'rest'
|
|
1264
1885
|
]);
|
|
1265
|
-
new File(routeFile).data =
|
|
1886
|
+
new File(routeFile).data = catchAllRoute(adapter, wiring_relativeImport(routeFile, restFolder.path));
|
|
1266
1887
|
return new File(node_path.join(restFolder.path, 'index.ts')).exists ? [] : [
|
|
1267
1888
|
`${routePath} serves restHandlers from ${node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest/index.ts')}, which appears with the first REST endpoint — generate one with df-scaffold (Presentation → New Handlers-REST Endpoint) and the route compiles`
|
|
1268
1889
|
];
|
|
1269
1890
|
};
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1891
|
+
const frameworkRestAdapter = ()=>usesNext() ? 'next' : usesSvelteKit() ? 'svelte' : void 0;
|
|
1892
|
+
const askRestAdapter = async ({ adapter = frameworkRestAdapter() } = {})=>{
|
|
1893
|
+
if (!adapter) return;
|
|
1894
|
+
const { key, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
1895
|
+
return await interaction_confirm({
|
|
1896
|
+
key,
|
|
1897
|
+
message: `Use ${packageName} for REST endpoints`
|
|
1898
|
+
}) ? adapter : void 0;
|
|
1899
|
+
};
|
|
1900
|
+
const scaffoldRestEndpointGeneratorFiles = ({ adapter })=>{
|
|
1275
1901
|
const root = new ProjectRoot().path;
|
|
1276
1902
|
const generatorExisted = restEndpointGeneratorApplied();
|
|
1277
1903
|
const routeNotes = withoutOverwrites(()=>{
|
|
@@ -1279,29 +1905,100 @@ const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
|
1279
1905
|
ConfigFile.Instance.data.project.rootFolder,
|
|
1280
1906
|
'shared-kernel'
|
|
1281
1907
|
]), {
|
|
1282
|
-
|
|
1908
|
+
adapter
|
|
1283
1909
|
});
|
|
1284
|
-
return
|
|
1910
|
+
return adapter ? scaffoldCatchAllRoute(root, adapter) : [];
|
|
1285
1911
|
});
|
|
1286
|
-
if (!
|
|
1912
|
+
if (!adapter) return [];
|
|
1913
|
+
const { adapter: adapterName, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
1287
1914
|
return [
|
|
1288
1915
|
...missingPackages([
|
|
1289
|
-
|
|
1916
|
+
packageName
|
|
1290
1917
|
]),
|
|
1291
1918
|
...routeNotes,
|
|
1292
1919
|
...generatorExisted ? [
|
|
1293
|
-
|
|
1920
|
+
`the existing endpoint generator was kept — pass ${adapterName} from ${packageName} to its createEndpoint calls`
|
|
1294
1921
|
] : []
|
|
1295
1922
|
];
|
|
1296
1923
|
};
|
|
1297
1924
|
const addRestEndpointGenerator = async ()=>scaffoldRestEndpointGeneratorFiles({
|
|
1298
|
-
|
|
1925
|
+
adapter: await askRestAdapter()
|
|
1299
1926
|
});
|
|
1300
1927
|
const restEndpointGeneratorApplied = ()=>Boolean(findRestEndpointGenerator(new Folder(new ProjectRoot().path).subitem([
|
|
1301
1928
|
ConfigFile.Instance.data.project.rootFolder,
|
|
1302
1929
|
'shared-kernel'
|
|
1303
1930
|
])));
|
|
1304
1931
|
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
1932
|
+
const svelteStorybookPackages = {
|
|
1933
|
+
svelte: '@storybook/svelte-vite',
|
|
1934
|
+
sveltekit: '@storybook/sveltekit'
|
|
1935
|
+
};
|
|
1936
|
+
const storybookPackageFor = (framework)=>'svelte' === framework || 'sveltekit' === framework ? svelteStorybookPackages[framework] : storybookFrameworkPackage;
|
|
1937
|
+
const storybookFamily = ()=>ConfigFile.Instance.data.frontend?.svelte ? 'svelte' : 'react';
|
|
1938
|
+
const storybookTitle = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.svelte ? 'sveltekit' === ConfigFile.Instance.data.frontend.svelte.framework ? 'Storybook (SvelteKit)' : 'Storybook (Svelte + Vite)' : 'Storybook (React + Vite)';
|
|
1939
|
+
const storybookFolder = ()=>`presentation/${storybookFamily()}/.storybook`;
|
|
1940
|
+
const storybookPreview = (frameworkPackage)=>`import type { Preview } from '${frameworkPackage}';
|
|
1941
|
+
|
|
1942
|
+
const preview: Preview = {
|
|
1943
|
+
parameters: {
|
|
1944
|
+
controls: {
|
|
1945
|
+
matchers: {
|
|
1946
|
+
color: /(background|color)$/i,
|
|
1947
|
+
date: /Date$/i
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
|
|
1953
|
+
export default preview;
|
|
1954
|
+
`;
|
|
1955
|
+
const svelteStorybookFiles = (relativeProjectRoot, frameworkPackage)=>{
|
|
1956
|
+
const withPlugin = frameworkPackage === svelteStorybookPackages.svelte;
|
|
1957
|
+
return {
|
|
1958
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
1959
|
+
import type { StorybookConfig } from '${frameworkPackage}';
|
|
1960
|
+
|
|
1961
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
1962
|
+
|
|
1963
|
+
const config: StorybookConfig = {
|
|
1964
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|svelte)'],
|
|
1965
|
+
framework: {
|
|
1966
|
+
name: '${frameworkPackage}',
|
|
1967
|
+
options: {}
|
|
1968
|
+
},
|
|
1969
|
+
core: {
|
|
1970
|
+
disableTelemetry: true
|
|
1971
|
+
},
|
|
1972
|
+
async viteFinal(viteConfig) {
|
|
1973
|
+
const { mergeConfig } = await import('vite');
|
|
1974
|
+
${withPlugin ? ` const { svelte } = await import('@sveltejs/vite-plugin-svelte');
|
|
1975
|
+
const hasSvelte = (viteConfig.plugins ?? [])
|
|
1976
|
+
.flat(Infinity)
|
|
1977
|
+
.some(
|
|
1978
|
+
(plugin) =>
|
|
1979
|
+
!!plugin &&
|
|
1980
|
+
typeof plugin === 'object' &&
|
|
1981
|
+
'name' in plugin &&
|
|
1982
|
+
String(plugin.name).startsWith('vite-plugin-svelte')
|
|
1983
|
+
);
|
|
1984
|
+
|
|
1985
|
+
return mergeConfig(viteConfig, {
|
|
1986
|
+
plugins: hasSvelte ? [] : [svelte()],` : `
|
|
1987
|
+
return mergeConfig(viteConfig, {`}
|
|
1988
|
+
resolve: {
|
|
1989
|
+
alias: {
|
|
1990
|
+
'@': projectRoot
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
export default config;
|
|
1998
|
+
`,
|
|
1999
|
+
'preview.ts': storybookPreview(frameworkPackage)
|
|
2000
|
+
};
|
|
2001
|
+
};
|
|
1305
2002
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
1306
2003
|
'main.ts': `import { resolve } from 'node:path';
|
|
1307
2004
|
import react from '@vitejs/plugin-react';
|
|
@@ -1334,32 +2031,79 @@ const config: StorybookConfig = {
|
|
|
1334
2031
|
|
|
1335
2032
|
export default config;
|
|
1336
2033
|
`,
|
|
1337
|
-
'preview.ts':
|
|
1338
|
-
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
2034
|
+
'preview.ts': storybookPreview(storybookFrameworkPackage)
|
|
2035
|
+
});
|
|
2036
|
+
const storybookScripts = (rootFolder, family = 'react')=>{
|
|
2037
|
+
const folder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), `presentation/${family}`);
|
|
2038
|
+
const quote = (value)=>JSON.stringify(value);
|
|
2039
|
+
return {
|
|
2040
|
+
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
2041
|
+
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
2042
|
+
};
|
|
1348
2043
|
};
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
2044
|
+
const addSvelteStorybook = async ()=>{
|
|
2045
|
+
const config = ConfigFile.Instance.data;
|
|
2046
|
+
const svelte = config.frontend?.svelte ?? {};
|
|
2047
|
+
const frameworkPackage = svelteStorybookPackages['sveltekit' === svelte.framework ? 'sveltekit' : 'svelte'];
|
|
2048
|
+
const root = new ProjectRoot().path;
|
|
2049
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
2050
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
2051
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder, 'svelte'));
|
|
2052
|
+
const folder = new Folder(root).subitem([
|
|
2053
|
+
config.project.rootFolder,
|
|
2054
|
+
'presentation',
|
|
2055
|
+
'svelte',
|
|
2056
|
+
'.storybook'
|
|
2057
|
+
]);
|
|
2058
|
+
for (const [name, content] of Object.entries(svelteStorybookFiles(node_path.relative(folder.path, root).split(node_path.sep).join('/'), frameworkPackage))){
|
|
2059
|
+
const file = new File(node_path.join(folder.path, name));
|
|
2060
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
2061
|
+
}
|
|
2062
|
+
if (svelte.storybookFramework !== frameworkPackage) ConfigFile.update({
|
|
2063
|
+
frontend: {
|
|
2064
|
+
...config.frontend,
|
|
2065
|
+
svelte: {
|
|
2066
|
+
...svelte,
|
|
2067
|
+
storybookFramework: frameworkPackage
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
1352
2070
|
});
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
2071
|
+
const buildFolder = node_path.posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/svelte/storybook-static');
|
|
2072
|
+
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
2073
|
+
const dependencies = {
|
|
2074
|
+
...manifest.dependencies,
|
|
2075
|
+
...manifest.devDependencies
|
|
1359
2076
|
};
|
|
2077
|
+
const missing = [
|
|
2078
|
+
'storybook',
|
|
2079
|
+
frameworkPackage,
|
|
2080
|
+
'vite',
|
|
2081
|
+
...frameworkPackage === svelteStorybookPackages.svelte ? [
|
|
2082
|
+
'@sveltejs/vite-plugin-svelte'
|
|
2083
|
+
] : []
|
|
2084
|
+
].filter((name)=>!dependencies[name]);
|
|
2085
|
+
const missingSvelte = ('sveltekit' === svelte.framework ? [
|
|
2086
|
+
'@sveltejs/kit',
|
|
2087
|
+
'svelte'
|
|
2088
|
+
] : [
|
|
2089
|
+
'svelte'
|
|
2090
|
+
]).filter((name)=>!dependencies[name]);
|
|
2091
|
+
return [
|
|
2092
|
+
...missing.length ? [
|
|
2093
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
2094
|
+
] : [],
|
|
2095
|
+
...missingSvelte.length ? [
|
|
2096
|
+
`npm install ${missingSvelte.join(' ')}`
|
|
2097
|
+
] : [],
|
|
2098
|
+
...describeScripts(selected, {
|
|
2099
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
2100
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
2101
|
+
})
|
|
2102
|
+
];
|
|
1360
2103
|
};
|
|
1361
2104
|
const addStorybook = async ()=>{
|
|
1362
2105
|
const config = ConfigFile.Instance.data;
|
|
2106
|
+
if (config.frontend?.svelte) return addSvelteStorybook();
|
|
1363
2107
|
if ((!config.frontend?.react || config.frontend?.react?.storybookFramework && config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) && !await interaction_confirm({
|
|
1364
2108
|
key: 'configureReact',
|
|
1365
2109
|
requestRequired: true,
|
|
@@ -1469,7 +2213,7 @@ const aggregateOwnFiles = (name)=>[
|
|
|
1469
2213
|
`${name}-repository.spec.ts`,
|
|
1470
2214
|
'index.ts'
|
|
1471
2215
|
];
|
|
1472
|
-
const
|
|
2216
|
+
const backend_module_move_kindLayouts = {
|
|
1473
2217
|
aggregate: {
|
|
1474
2218
|
title: 'Aggregates',
|
|
1475
2219
|
core: (ClassName)=>`${ClassName}Repository`,
|
|
@@ -1526,7 +2270,7 @@ const projectRootOf = (folder)=>{
|
|
|
1526
2270
|
}
|
|
1527
2271
|
};
|
|
1528
2272
|
const integrationSpecFile = (unit, label)=>{
|
|
1529
|
-
const layout =
|
|
2273
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
1530
2274
|
const place = {
|
|
1531
2275
|
ownerPath: unit.ownerPath,
|
|
1532
2276
|
name: unit.name
|
|
@@ -1552,9 +2296,9 @@ const subfolders = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(fo
|
|
|
1552
2296
|
}).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
|
|
1553
2297
|
const namesBySuffix = (folder, suffix)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder).filter((file)=>file.endsWith(suffix) && !file.endsWith('.spec.ts')).map((file)=>file.slice(0, -suffix.length)).sort() : [];
|
|
1554
2298
|
const labelsOf = (ownerPath, kind, name)=>{
|
|
1555
|
-
const { implementations } =
|
|
2299
|
+
const { implementations } = backend_module_move_kindLayouts[kind];
|
|
1556
2300
|
if (!implementations) return [];
|
|
1557
|
-
return subfolders(node_path.join(ownerPath, implementations)).filter((label)=>
|
|
2301
|
+
return subfolders(node_path.join(ownerPath, implementations)).filter((label)=>backend_module_move_kindLayouts[kind].files({
|
|
1558
2302
|
ownerPath,
|
|
1559
2303
|
name
|
|
1560
2304
|
}, [
|
|
@@ -1592,7 +2336,7 @@ const findBackendUnits = (ownerPath)=>{
|
|
|
1592
2336
|
const kebabName = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
1593
2337
|
const lowerFirst = (value)=>value[0].toLowerCase() + value.slice(1);
|
|
1594
2338
|
const unitMoves = (unit, target)=>{
|
|
1595
|
-
const layout =
|
|
2339
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
1596
2340
|
const from = layout.files(unit, unit.labels);
|
|
1597
2341
|
const to = layout.files(target, unit.labels);
|
|
1598
2342
|
const moves = new Map();
|
|
@@ -1619,7 +2363,7 @@ const unitMoves = (unit, target)=>{
|
|
|
1619
2363
|
};
|
|
1620
2364
|
const validateBackendMove = (unit, target, sharedKernelPath)=>{
|
|
1621
2365
|
if (!kebabName.test(target.name)) return 'Use kebab-case: lowercase words split by "-", e.g. place-order';
|
|
1622
|
-
if (target.ownerPath === sharedKernelPath && !
|
|
2366
|
+
if (target.ownerPath === sharedKernelPath && !backend_module_move_kindLayouts[unit.kind].sharedKernel) return `${backend_module_move_kindLayouts[unit.kind].title} are not part of the Shared Kernel`;
|
|
1623
2367
|
if (target.ownerPath === unit.ownerPath && target.name === unit.name && target.aggregate === unit.aggregate) return 'Nothing to change: enter a new name or pick another place';
|
|
1624
2368
|
for (const [from, to] of unitMoves(unit, target))if (to !== from && node_fs.existsSync(to)) return `${node_path.relative(target.ownerPath, to)} already exists`;
|
|
1625
2369
|
return true;
|
|
@@ -1648,7 +2392,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
1648
2392
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
1649
2393
|
};
|
|
1650
2394
|
const moveBackendUnit = (projectRoot, rootFolderPath, unit, target)=>{
|
|
1651
|
-
const layout =
|
|
2395
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
1652
2396
|
const moves = unitMoves(unit, target);
|
|
1653
2397
|
const withoutExtension = new Map([
|
|
1654
2398
|
...moves
|
|
@@ -1793,7 +2537,7 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
1793
2537
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
1794
2538
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1795
2539
|
};
|
|
1796
|
-
const
|
|
2540
|
+
const backend_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
1797
2541
|
const importLine = /^\s*(?:import|export)\b[^'"\n]*\bfrom\s*(['"])([^'"\n]+)\1;?\s*$/;
|
|
1798
2542
|
const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
1799
2543
|
const files = [
|
|
@@ -1835,7 +2579,7 @@ const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
|
1835
2579
|
for (const [file, original] of codeFiles){
|
|
1836
2580
|
if (fileSet.has(file)) continue;
|
|
1837
2581
|
const content = cleaned.get(file) ?? original;
|
|
1838
|
-
for (const [, , specifier] of content.matchAll(
|
|
2582
|
+
for (const [, , specifier] of content.matchAll(backend_module_move_importSpecifier)){
|
|
1839
2583
|
const target = resolved(specifier, file);
|
|
1840
2584
|
if (target && isUnit(target)) usedBy.push([
|
|
1841
2585
|
relative(file),
|
|
@@ -1870,18 +2614,18 @@ const contractKinds = [
|
|
|
1870
2614
|
];
|
|
1871
2615
|
const implementations_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
1872
2616
|
const withHandlers = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
1873
|
-
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` :
|
|
2617
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : backend_module_move_kindLayouts[unit.kind].files(unit, [])[0];
|
|
1874
2618
|
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
1875
2619
|
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
1876
|
-
const contractClassName = (unit)=>
|
|
2620
|
+
const contractClassName = (unit)=>backend_module_move_kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
1877
2621
|
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
1878
2622
|
const implementationFile = (unit, label)=>{
|
|
1879
|
-
const { implementations } =
|
|
1880
|
-
return
|
|
2623
|
+
const { implementations } = backend_module_move_kindLayouts[unit.kind];
|
|
2624
|
+
return backend_module_move_kindLayouts[unit.kind].files(unit, [
|
|
1881
2625
|
label
|
|
1882
2626
|
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
1883
2627
|
};
|
|
1884
|
-
const contractWireFile = (unit)=>
|
|
2628
|
+
const contractWireFile = (unit)=>backend_module_move_kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
1885
2629
|
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
1886
2630
|
import { defineHandler } from '@domain-first/handlers'
|
|
1887
2631
|
import { ${ContractName} } from '${contractImport}'
|
|
@@ -2047,7 +2791,7 @@ const scaffoldIntegrationSpec = (unit, label)=>{
|
|
|
2047
2791
|
if (!specPath) return;
|
|
2048
2792
|
const spec = new File(specPath);
|
|
2049
2793
|
if (spec.exists) return;
|
|
2050
|
-
const layout =
|
|
2794
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
2051
2795
|
const naming = new UnknownFormatNaming(unit.name);
|
|
2052
2796
|
const core = layout.core(naming.ClassName);
|
|
2053
2797
|
const files = layout.files({
|
|
@@ -2582,10 +3326,10 @@ const integrationIds = [
|
|
|
2582
3326
|
const integrations = [
|
|
2583
3327
|
{
|
|
2584
3328
|
id: 'storybook',
|
|
2585
|
-
name:
|
|
3329
|
+
name: storybookTitle,
|
|
2586
3330
|
group: 'frontend',
|
|
2587
3331
|
run: addStorybook,
|
|
2588
|
-
applied: ()=>createdInRoot(
|
|
3332
|
+
applied: ()=>createdInRoot(`${storybookFolder()}/main.ts`)
|
|
2589
3333
|
},
|
|
2590
3334
|
{
|
|
2591
3335
|
id: 'rest-endpoint-generator',
|
|
@@ -2651,9 +3395,10 @@ const integrations = [
|
|
|
2651
3395
|
group: 'frontend',
|
|
2652
3396
|
run: addOrval,
|
|
2653
3397
|
available: ()=>withHandlersRest(),
|
|
2654
|
-
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
3398
|
+
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/svelte/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
2655
3399
|
}
|
|
2656
3400
|
];
|
|
3401
|
+
const nameOf = ({ name })=>'string' == typeof name ? name : name();
|
|
2657
3402
|
const addIntegration = async ({ save = true } = {})=>{
|
|
2658
3403
|
const available = integrations.filter(({ group, available })=>('backend' !== group || Boolean(ConfigFile.Instance.data.backend)) && (available?.() ?? true)).map((value)=>({
|
|
2659
3404
|
value,
|
|
@@ -2667,7 +3412,7 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
2667
3412
|
return items.length ? [
|
|
2668
3413
|
new Separator(title),
|
|
2669
3414
|
...items.map(({ value })=>({
|
|
2670
|
-
name: `${value
|
|
3415
|
+
name: `${nameOf(value)} · ${value.group}`,
|
|
2671
3416
|
value
|
|
2672
3417
|
}))
|
|
2673
3418
|
] : [];
|
|
@@ -2690,269 +3435,10 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
2690
3435
|
};
|
|
2691
3436
|
const integrationDescriptions = ()=>integrations.map((integration)=>({
|
|
2692
3437
|
id: integration.id,
|
|
2693
|
-
name: integration
|
|
3438
|
+
name: nameOf(integration),
|
|
2694
3439
|
group: integration.group,
|
|
2695
3440
|
available: ('backend' !== integration.group || Boolean(ConfigFile.Instance.data.backend)) && (integration.available?.() ?? true)
|
|
2696
3441
|
}));
|
|
2697
|
-
const reactKindLayouts = {
|
|
2698
|
-
page: {
|
|
2699
|
-
folder: 'pages',
|
|
2700
|
-
nested: true,
|
|
2701
|
-
inFolder: false,
|
|
2702
|
-
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
2703
|
-
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
|
|
2704
|
-
classPrefix: '(use)?',
|
|
2705
|
-
classSuffix: 'Page'
|
|
2706
|
-
},
|
|
2707
|
-
widget: {
|
|
2708
|
-
folder: 'widgets',
|
|
2709
|
-
nested: true,
|
|
2710
|
-
inFolder: true,
|
|
2711
|
-
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
2712
|
-
classPrefix: '(use)?',
|
|
2713
|
-
classSuffix: 'Widget|UIModel',
|
|
2714
|
-
storyTitle: (segments)=>[
|
|
2715
|
-
'Widgets',
|
|
2716
|
-
...segments
|
|
2717
|
-
].join('/')
|
|
2718
|
-
},
|
|
2719
|
-
'ui-kit': {
|
|
2720
|
-
folder: 'ui-kit',
|
|
2721
|
-
nested: false,
|
|
2722
|
-
inFolder: true,
|
|
2723
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
2724
|
-
classPrefix: '()',
|
|
2725
|
-
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
2726
|
-
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
2727
|
-
},
|
|
2728
|
-
hook: {
|
|
2729
|
-
folder: 'hooks',
|
|
2730
|
-
nested: false,
|
|
2731
|
-
inFolder: false,
|
|
2732
|
-
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
2733
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}.ts`),
|
|
2734
|
-
classPrefix: '(use)',
|
|
2735
|
-
classSuffix: '(?![\\w$])'
|
|
2736
|
-
}
|
|
2737
|
-
};
|
|
2738
|
-
const reactKindTitles = {
|
|
2739
|
-
page: [
|
|
2740
|
-
'Page',
|
|
2741
|
-
'pages'
|
|
2742
|
-
],
|
|
2743
|
-
widget: [
|
|
2744
|
-
'Widget',
|
|
2745
|
-
'widgets'
|
|
2746
|
-
],
|
|
2747
|
-
'ui-kit': [
|
|
2748
|
-
'UI-kit component',
|
|
2749
|
-
'UI-kit components'
|
|
2750
|
-
],
|
|
2751
|
-
hook: [
|
|
2752
|
-
'Shared hook',
|
|
2753
|
-
'shared hooks'
|
|
2754
|
-
]
|
|
2755
|
-
};
|
|
2756
|
-
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
2757
|
-
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2758
|
-
const prefix = `${folders.join('-')}-`;
|
|
2759
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
2760
|
-
return [
|
|
2761
|
-
...folders,
|
|
2762
|
-
last
|
|
2763
|
-
].join('/');
|
|
2764
|
-
};
|
|
2765
|
-
const declaredClassName = (filePath, suffix, name)=>{
|
|
2766
|
-
const content = node_fs.readFileSync(filePath, 'utf8');
|
|
2767
|
-
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
2768
|
-
return declared ?? new NestedName(name).ClassName;
|
|
2769
|
-
};
|
|
2770
|
-
const findUiKit = (reactFolder)=>{
|
|
2771
|
-
const root = node_path.join(reactFolder, 'ui-kit');
|
|
2772
|
-
if (!node_fs.existsSync(root)) return [];
|
|
2773
|
-
return node_fs.readdirSync(root, {
|
|
2774
|
-
withFileTypes: true
|
|
2775
|
-
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
|
|
2776
|
-
kind: 'ui-kit',
|
|
2777
|
-
name,
|
|
2778
|
-
path: node_path.join(root, name),
|
|
2779
|
-
fileBase: name,
|
|
2780
|
-
ClassName: declaredClassName(node_path.join(root, name, `${name}.tsx`), '', name)
|
|
2781
|
-
}));
|
|
2782
|
-
};
|
|
2783
|
-
const findHooks = (reactFolder)=>{
|
|
2784
|
-
const root = node_path.join(reactFolder, 'hooks');
|
|
2785
|
-
if (!node_fs.existsSync(root)) return [];
|
|
2786
|
-
return node_fs.readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
2787
|
-
const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
|
|
2788
|
-
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
2789
|
-
return {
|
|
2790
|
-
kind: 'hook',
|
|
2791
|
-
name,
|
|
2792
|
-
path: node_path.join(root, file),
|
|
2793
|
-
fileBase: name,
|
|
2794
|
-
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
2795
|
-
};
|
|
2796
|
-
});
|
|
2797
|
-
};
|
|
2798
|
-
const findReactModules = (reactFolder, kind)=>{
|
|
2799
|
-
const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2800
|
-
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2801
|
-
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2802
|
-
const name = react_module_move_nestedName(folders, fileBase);
|
|
2803
|
-
return {
|
|
2804
|
-
kind,
|
|
2805
|
-
name,
|
|
2806
|
-
path: file,
|
|
2807
|
-
fileBase,
|
|
2808
|
-
ClassName: declaredClassName(file, 'Page', name)
|
|
2809
|
-
};
|
|
2810
|
-
}) : walk(node_path.join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
2811
|
-
const folder = node_path.dirname(file);
|
|
2812
|
-
const name = toPosix(node_path.relative(node_path.join(reactFolder, 'widgets'), folder));
|
|
2813
|
-
return {
|
|
2814
|
-
kind,
|
|
2815
|
-
name,
|
|
2816
|
-
path: folder,
|
|
2817
|
-
fileBase: node_path.basename(file, '-widget.tsx'),
|
|
2818
|
-
ClassName: declaredClassName(file, 'Widget', name)
|
|
2819
|
-
};
|
|
2820
|
-
});
|
|
2821
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
2822
|
-
};
|
|
2823
|
-
const targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
2824
|
-
const validateMove = (reactFolder, module, rawName)=>{
|
|
2825
|
-
const nameError = NestedName.validate(rawName);
|
|
2826
|
-
if (true !== nameError) return nameError;
|
|
2827
|
-
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
2828
|
-
const target = targetPath(reactFolder, module, rawName);
|
|
2829
|
-
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
2830
|
-
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2831
|
-
return true;
|
|
2832
|
-
};
|
|
2833
|
-
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2834
|
-
const { folders, folderName } = new NestedName(rawName);
|
|
2835
|
-
return node_path.join(appFolder, ...folders, folderName);
|
|
2836
|
-
};
|
|
2837
|
-
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
2838
|
-
withFileTypes: true
|
|
2839
|
-
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
2840
|
-
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
2841
|
-
const layout = reactKindLayouts[module.kind];
|
|
2842
|
-
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
2843
|
-
const target = targetPath(reactFolder, module, rawName);
|
|
2844
|
-
const newClassName = newName.ClassName;
|
|
2845
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
2846
|
-
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
2847
|
-
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
2848
|
-
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`) : node_path.dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(node_path.basename(candidate));
|
|
2849
|
-
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2850
|
-
const routeTarget = (candidate)=>{
|
|
2851
|
-
if (!route) return;
|
|
2852
|
-
const file = [
|
|
2853
|
-
...routeFileSet
|
|
2854
|
-
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
2855
|
-
if (!file) return;
|
|
2856
|
-
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
2857
|
-
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
2858
|
-
};
|
|
2859
|
-
const movedPath = (candidate)=>{
|
|
2860
|
-
const routed = routeTarget(candidate);
|
|
2861
|
-
if (routed) return routed;
|
|
2862
|
-
if (!ownsPath(candidate)) return;
|
|
2863
|
-
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
2864
|
-
const last = segments.length - 1;
|
|
2865
|
-
segments[last] = renameFile(segments[last]);
|
|
2866
|
-
return node_path.join(newFolder, ...segments);
|
|
2867
|
-
};
|
|
2868
|
-
const moduleFiles = reactModuleFiles(module);
|
|
2869
|
-
const moves = new Map([
|
|
2870
|
-
...moduleFiles,
|
|
2871
|
-
...routeFileSet
|
|
2872
|
-
].map((file)=>[
|
|
2873
|
-
file,
|
|
2874
|
-
movedPath(file) ?? file
|
|
2875
|
-
]));
|
|
2876
|
-
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
2877
|
-
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2878
|
-
module.ClassName
|
|
2879
|
-
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
2880
|
-
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
2881
|
-
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2882
|
-
newClassName
|
|
2883
|
-
] : newName.classNameSegments);
|
|
2884
|
-
return stageModuleMove({
|
|
2885
|
-
projectRoot,
|
|
2886
|
-
stopAt: reactFolder,
|
|
2887
|
-
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
2888
|
-
moves,
|
|
2889
|
-
movedPath,
|
|
2890
|
-
rename: (content, { moved })=>{
|
|
2891
|
-
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
2892
|
-
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2893
|
-
}
|
|
2894
|
-
});
|
|
2895
|
-
};
|
|
2896
|
-
const pageRouteFolder = (appFolder, page)=>{
|
|
2897
|
-
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
2898
|
-
const routePage = node_path.join(folder, 'page.tsx');
|
|
2899
|
-
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
2900
|
-
};
|
|
2901
|
-
const reactModuleFiles = (module)=>{
|
|
2902
|
-
const layout = reactKindLayouts[module.kind];
|
|
2903
|
-
if (layout.inFolder) return walk(module.path);
|
|
2904
|
-
const folder = node_path.dirname(module.path);
|
|
2905
|
-
const own = layout.ownFile(module.fileBase);
|
|
2906
|
-
return node_fs.readdirSync(folder, {
|
|
2907
|
-
withFileTypes: true
|
|
2908
|
-
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
2909
|
-
};
|
|
2910
|
-
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2911
|
-
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
2912
|
-
const moduleFiles = reactModuleFiles(module);
|
|
2913
|
-
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
2914
|
-
const own = new Set([
|
|
2915
|
-
...moduleFiles,
|
|
2916
|
-
...routeFileList
|
|
2917
|
-
]);
|
|
2918
|
-
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
2919
|
-
const isModule = (resolved)=>stems.has(resolved) || reactKindLayouts[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
2920
|
-
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2921
|
-
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2922
|
-
const usedBy = [];
|
|
2923
|
-
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(react_module_move_importSpecifier)){
|
|
2924
|
-
const target = resolve(specifier, file)?.resolved;
|
|
2925
|
-
if (target && isModule(target)) usedBy.push([
|
|
2926
|
-
relative(file),
|
|
2927
|
-
relative(target)
|
|
2928
|
-
]);
|
|
2929
|
-
}
|
|
2930
|
-
if (usedBy.length) return {
|
|
2931
|
-
usedBy
|
|
2932
|
-
};
|
|
2933
|
-
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
2934
|
-
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
2935
|
-
return {
|
|
2936
|
-
deleted: [
|
|
2937
|
-
...moduleFiles,
|
|
2938
|
-
...routeFileList
|
|
2939
|
-
]
|
|
2940
|
-
};
|
|
2941
|
-
};
|
|
2942
|
-
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2943
|
-
if ('ports' === kind) return crossContext ? [
|
|
2944
|
-
{
|
|
2945
|
-
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
2946
|
-
value: crossContextImplementation
|
|
2947
|
-
}
|
|
2948
|
-
] : [];
|
|
2949
|
-
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
2950
|
-
{
|
|
2951
|
-
name: 'System: in-memory (uses the shared in-memory database)',
|
|
2952
|
-
value: 'in-memory'
|
|
2953
|
-
}
|
|
2954
|
-
] : [];
|
|
2955
|
-
};
|
|
2956
3442
|
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
2957
3443
|
const root = new ProjectRoot().path;
|
|
2958
3444
|
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
@@ -2962,10 +3448,10 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
2962
3448
|
key: 'module',
|
|
2963
3449
|
id: unitId,
|
|
2964
3450
|
message: 'Module to delete:',
|
|
2965
|
-
choices: Object.keys(
|
|
3451
|
+
choices: Object.keys(backend_module_move_kindLayouts).flatMap((kind)=>{
|
|
2966
3452
|
const group = units.filter((x)=>x.kind === kind);
|
|
2967
3453
|
return group.length ? [
|
|
2968
|
-
new Separator(`── ${
|
|
3454
|
+
new Separator(`── ${backend_module_move_kindLayouts[group[0].kind].title}`),
|
|
2969
3455
|
...group.map((value)=>({
|
|
2970
3456
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
2971
3457
|
value
|
|
@@ -3004,10 +3490,32 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3004
3490
|
report('Cancelled: nothing was deleted.');
|
|
3005
3491
|
}
|
|
3006
3492
|
};
|
|
3007
|
-
const
|
|
3493
|
+
const pageRouter = (framework)=>{
|
|
3494
|
+
if ('react' === framework) return usesNext() ? {
|
|
3495
|
+
title: 'Next.js',
|
|
3496
|
+
folder: nextAppFolder,
|
|
3497
|
+
pageFile: routePageFile.react
|
|
3498
|
+
} : void 0;
|
|
3499
|
+
return usesSvelteKit() ? {
|
|
3500
|
+
title: 'SvelteKit',
|
|
3501
|
+
folder: svelteKitRoutesFolder,
|
|
3502
|
+
pageFile: routePageFile.svelte
|
|
3503
|
+
} : void 0;
|
|
3504
|
+
};
|
|
3505
|
+
const frameworkTitles = {
|
|
3506
|
+
react: {
|
|
3507
|
+
title: 'React',
|
|
3508
|
+
cli: 'df-react'
|
|
3509
|
+
},
|
|
3510
|
+
svelte: {
|
|
3511
|
+
title: 'Svelte',
|
|
3512
|
+
cli: 'df-svelte'
|
|
3513
|
+
}
|
|
3514
|
+
};
|
|
3515
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3008
3516
|
const reactFolder = presentationReactFolder.path;
|
|
3009
|
-
const modules = findReactModules(reactFolder, kind);
|
|
3010
|
-
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by
|
|
3517
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
3518
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3011
3519
|
const module = await interaction_select({
|
|
3012
3520
|
key: 'module',
|
|
3013
3521
|
id: (value)=>value.name,
|
|
@@ -3020,17 +3528,18 @@ const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3020
3528
|
});
|
|
3021
3529
|
const root = new ProjectRoot().path;
|
|
3022
3530
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3023
|
-
const
|
|
3024
|
-
const
|
|
3531
|
+
const router = 'page' === kind ? pageRouter(framework) : void 0;
|
|
3532
|
+
const appFolder = router && node_path.join(root, router.folder(root));
|
|
3533
|
+
const routeFolder = router && appFolder ? pageRouteFolder(appFolder, module, framework) : void 0;
|
|
3025
3534
|
const withRoute = !!routeFolder && await interaction_confirm({
|
|
3026
3535
|
key: 'deleteRoute',
|
|
3027
|
-
message: `Delete its
|
|
3536
|
+
message: `Delete its ${router?.title} route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
3028
3537
|
default: true
|
|
3029
3538
|
});
|
|
3030
|
-
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
3539
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder && appFolder ? {
|
|
3031
3540
|
appFolder,
|
|
3032
3541
|
folder: routeFolder
|
|
3033
|
-
} : void 0);
|
|
3542
|
+
} : void 0, framework);
|
|
3034
3543
|
if (result.usedBy) {
|
|
3035
3544
|
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
3036
3545
|
usedBy: result.usedBy
|
|
@@ -3195,9 +3704,27 @@ const configureBackend = async (config)=>{
|
|
|
3195
3704
|
if (envBranches && !envBranchedWireExisted) notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts doesn't compile until you write currentBranch: return the branch this process runs in (${envBranches.names.join(', ')})`);
|
|
3196
3705
|
return notes;
|
|
3197
3706
|
};
|
|
3707
|
+
const frontendPackages = {
|
|
3708
|
+
react: [
|
|
3709
|
+
'react',
|
|
3710
|
+
'react-dom'
|
|
3711
|
+
],
|
|
3712
|
+
next: [
|
|
3713
|
+
'next',
|
|
3714
|
+
'react',
|
|
3715
|
+
'react-dom'
|
|
3716
|
+
],
|
|
3717
|
+
svelte: [
|
|
3718
|
+
'svelte'
|
|
3719
|
+
],
|
|
3720
|
+
sveltekit: [
|
|
3721
|
+
'@sveltejs/kit',
|
|
3722
|
+
'svelte'
|
|
3723
|
+
]
|
|
3724
|
+
};
|
|
3725
|
+
const savedFrontendChoice = ({ frontend })=>frontend?.react?.framework ?? frontend?.svelte?.framework ?? (frontend?.react ? 'react' : frontend?.svelte ? 'svelte' : void 0);
|
|
3198
3726
|
const configureFrontend = async (config)=>{
|
|
3199
|
-
const
|
|
3200
|
-
const framework = await prompts_select({
|
|
3727
|
+
const choice = await prompts_select({
|
|
3201
3728
|
message: 'Frontend framework:',
|
|
3202
3729
|
choices: [
|
|
3203
3730
|
{
|
|
@@ -3207,51 +3734,58 @@ const configureFrontend = async (config)=>{
|
|
|
3207
3734
|
{
|
|
3208
3735
|
name: 'Next.js',
|
|
3209
3736
|
value: 'next'
|
|
3737
|
+
},
|
|
3738
|
+
{
|
|
3739
|
+
name: 'Svelte',
|
|
3740
|
+
value: 'svelte'
|
|
3741
|
+
},
|
|
3742
|
+
{
|
|
3743
|
+
name: 'SvelteKit',
|
|
3744
|
+
value: 'sveltekit'
|
|
3210
3745
|
}
|
|
3211
3746
|
],
|
|
3212
|
-
default:
|
|
3747
|
+
default: savedFrontendChoice(config) ?? (hasDependency('next') ? 'next' : hasDependency('@sveltejs/kit') ? 'sveltekit' : hasDependency('svelte') ? 'svelte' : 'react')
|
|
3213
3748
|
});
|
|
3214
|
-
const
|
|
3215
|
-
|
|
3216
|
-
|
|
3749
|
+
const family = 'react' === choice || 'next' === choice ? 'react' : 'svelte';
|
|
3750
|
+
const adapter = 'next' === choice ? 'next' : 'sveltekit' === choice ? 'svelte' : void 0;
|
|
3751
|
+
const restAdapter = adapter && config.backend ? {
|
|
3752
|
+
adapter: await askRestAdapter({
|
|
3753
|
+
adapter
|
|
3754
|
+
})
|
|
3755
|
+
} : {
|
|
3756
|
+
adapter: void 0
|
|
3757
|
+
};
|
|
3758
|
+
const current = config.frontend?.[family];
|
|
3217
3759
|
const withStorybook = await prompts_confirm({
|
|
3218
3760
|
message: 'Use Storybook',
|
|
3219
|
-
default:
|
|
3761
|
+
default: current ? Boolean(current.storybookFramework) : true
|
|
3220
3762
|
});
|
|
3221
|
-
const
|
|
3763
|
+
const { react, svelte, ...otherSettings } = config.frontend ?? {};
|
|
3222
3764
|
ConfigFile.update({
|
|
3223
3765
|
frontend: {
|
|
3224
|
-
...
|
|
3225
|
-
|
|
3226
|
-
...
|
|
3227
|
-
framework,
|
|
3228
|
-
storybookFramework
|
|
3766
|
+
...otherSettings,
|
|
3767
|
+
[family]: {
|
|
3768
|
+
...current,
|
|
3769
|
+
framework: choice,
|
|
3770
|
+
storybookFramework: withStorybook ? storybookPackageFor(choice) : void 0
|
|
3229
3771
|
}
|
|
3230
3772
|
}
|
|
3231
3773
|
});
|
|
3232
3774
|
return {
|
|
3233
|
-
|
|
3775
|
+
restAdapter,
|
|
3234
3776
|
nextSteps: [
|
|
3235
|
-
...missingPackages(
|
|
3236
|
-
'next',
|
|
3237
|
-
'react',
|
|
3238
|
-
'react-dom'
|
|
3239
|
-
] : [
|
|
3240
|
-
'react',
|
|
3241
|
-
'react-dom'
|
|
3242
|
-
]),
|
|
3777
|
+
...missingPackages(frontendPackages[choice]),
|
|
3243
3778
|
...withStorybook ? await addStorybook() : []
|
|
3244
3779
|
]
|
|
3245
3780
|
};
|
|
3246
3781
|
};
|
|
3247
|
-
const configureRest = async (
|
|
3782
|
+
const configureRest = async (restAdapter)=>{
|
|
3248
3783
|
const backend = ConfigFile.Instance.data.backend;
|
|
3249
3784
|
if (!backend) return [];
|
|
3250
3785
|
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
3251
|
-
const
|
|
3252
|
-
if (
|
|
3253
|
-
if (
|
|
3254
|
-
if (withNextAdapter && !withRest) ConfigFile.update({
|
|
3786
|
+
const adapter = restAdapter?.adapter ?? (restAdapter ? void 0 : await askRestAdapter());
|
|
3787
|
+
if (!withRest && !adapter) return [];
|
|
3788
|
+
if (adapter && !withRest) ConfigFile.update({
|
|
3255
3789
|
backend: {
|
|
3256
3790
|
...backend,
|
|
3257
3791
|
domainFirstPackages: [
|
|
@@ -3261,7 +3795,7 @@ const configureRest = async (withNextAdapter)=>{
|
|
|
3261
3795
|
}
|
|
3262
3796
|
});
|
|
3263
3797
|
return scaffoldRestEndpointGeneratorFiles({
|
|
3264
|
-
|
|
3798
|
+
adapter
|
|
3265
3799
|
});
|
|
3266
3800
|
};
|
|
3267
3801
|
const initializeUseCase = async (section)=>{
|
|
@@ -3298,7 +3832,7 @@ const initializeUseCase = async (section)=>{
|
|
|
3298
3832
|
}
|
|
3299
3833
|
const nextSteps = [];
|
|
3300
3834
|
let backendConfigured = false;
|
|
3301
|
-
let
|
|
3835
|
+
let restAdapter;
|
|
3302
3836
|
for (const currentSection of sections){
|
|
3303
3837
|
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
3304
3838
|
if (!section && sections.length > 1 && !await prompts_confirm({
|
|
@@ -3321,14 +3855,14 @@ const initializeUseCase = async (section)=>{
|
|
|
3321
3855
|
case 'frontend':
|
|
3322
3856
|
{
|
|
3323
3857
|
const frontend = await configureFrontend(config);
|
|
3324
|
-
|
|
3858
|
+
restAdapter = frontend.restAdapter;
|
|
3325
3859
|
nextSteps.push(...frontend.nextSteps);
|
|
3326
3860
|
break;
|
|
3327
3861
|
}
|
|
3328
3862
|
}
|
|
3329
3863
|
}
|
|
3330
|
-
if (backendConfigured ||
|
|
3331
|
-
const restSteps = await configureRest(
|
|
3864
|
+
if (backendConfigured || restAdapter?.adapter) {
|
|
3865
|
+
const restSteps = await configureRest(restAdapter);
|
|
3332
3866
|
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
3333
3867
|
}
|
|
3334
3868
|
return nextSteps;
|
|
@@ -3344,10 +3878,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3344
3878
|
key: 'module',
|
|
3345
3879
|
id: unitId,
|
|
3346
3880
|
message: 'Module:',
|
|
3347
|
-
choices: Object.keys(
|
|
3881
|
+
choices: Object.keys(backend_module_move_kindLayouts).flatMap((kind)=>{
|
|
3348
3882
|
const group = units.filter((x)=>x.kind === kind);
|
|
3349
3883
|
return group.length ? [
|
|
3350
|
-
new Separator(`── ${
|
|
3884
|
+
new Separator(`── ${backend_module_move_kindLayouts[group[0].kind].title}`),
|
|
3351
3885
|
...group.map((value)=>({
|
|
3352
3886
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3353
3887
|
value
|
|
@@ -3361,7 +3895,7 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3361
3895
|
const places = [
|
|
3362
3896
|
unit.ownerPath,
|
|
3363
3897
|
...contexts,
|
|
3364
|
-
...
|
|
3898
|
+
...backend_module_move_kindLayouts[unit.kind].sharedKernel ? [
|
|
3365
3899
|
sharedKernelPath
|
|
3366
3900
|
] : []
|
|
3367
3901
|
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
@@ -3429,17 +3963,18 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3429
3963
|
report('Cancelled: nothing was written.');
|
|
3430
3964
|
}
|
|
3431
3965
|
};
|
|
3432
|
-
const promptRouteMove = async (root, page, newName)=>{
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
const
|
|
3966
|
+
const promptRouteMove = async (root, page, newName, framework)=>{
|
|
3967
|
+
const router = pageRouter(framework);
|
|
3968
|
+
if (!router) return;
|
|
3969
|
+
const appFolder = node_path.join(root, router.folder(root));
|
|
3970
|
+
const from = pageRouteFolder(appFolder, page, framework);
|
|
3436
3971
|
const to = react_module_move_routeFolder(appFolder, newName);
|
|
3437
3972
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3438
3973
|
if (!from || from === to) return;
|
|
3439
|
-
if (node_fs.existsSync(node_path.join(to,
|
|
3974
|
+
if (node_fs.existsSync(node_path.join(to, router.pageFile))) return void report(`${relative(to)}/${router.pageFile} already exists: the route ${relative(from)} stays.`);
|
|
3440
3975
|
const move = await interaction_confirm({
|
|
3441
3976
|
key: 'moveRoute',
|
|
3442
|
-
message: `Move the
|
|
3977
|
+
message: `Move the ${router.title} route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
3443
3978
|
default: true
|
|
3444
3979
|
});
|
|
3445
3980
|
return move ? {
|
|
@@ -3448,10 +3983,10 @@ const promptRouteMove = async (root, page, newName)=>{
|
|
|
3448
3983
|
to
|
|
3449
3984
|
} : void 0;
|
|
3450
3985
|
};
|
|
3451
|
-
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3986
|
+
const moveReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3452
3987
|
const reactFolder = presentationReactFolder.path;
|
|
3453
|
-
const modules = findReactModules(reactFolder, kind);
|
|
3454
|
-
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by
|
|
3988
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
3989
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3455
3990
|
const module = await interaction_select({
|
|
3456
3991
|
key: 'module',
|
|
3457
3992
|
id: (value)=>value.name,
|
|
@@ -3464,14 +3999,14 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3464
3999
|
});
|
|
3465
4000
|
const name = await interaction_input({
|
|
3466
4001
|
key: 'name',
|
|
3467
|
-
message:
|
|
4002
|
+
message: frontendKindLayouts(framework)[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
|
|
3468
4003
|
default: module.name,
|
|
3469
|
-
validate: (value)=>validateMove(reactFolder, module, value)
|
|
4004
|
+
validate: (value)=>validateMove(reactFolder, module, value, framework)
|
|
3470
4005
|
});
|
|
3471
4006
|
const root = new ProjectRoot().path;
|
|
3472
4007
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3473
|
-
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
3474
|
-
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
4008
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name, framework) : void 0;
|
|
4009
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route, framework);
|
|
3475
4010
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
3476
4011
|
report([
|
|
3477
4012
|
'Files to move:',
|
|
@@ -3490,6 +4025,20 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3490
4025
|
report('Cancelled: nothing was written.');
|
|
3491
4026
|
}
|
|
3492
4027
|
};
|
|
4028
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
4029
|
+
if ('ports' === kind) return crossContext ? [
|
|
4030
|
+
{
|
|
4031
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
4032
|
+
value: crossContextImplementation
|
|
4033
|
+
}
|
|
4034
|
+
] : [];
|
|
4035
|
+
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
4036
|
+
{
|
|
4037
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
4038
|
+
value: 'in-memory'
|
|
4039
|
+
}
|
|
4040
|
+
] : [];
|
|
4041
|
+
};
|
|
3493
4042
|
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
3494
4043
|
const implementationTypeEntryChoices = [
|
|
3495
4044
|
{
|
|
@@ -4180,8 +4729,8 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
4180
4729
|
const handler = withWiring ? await promptEndpointHandler(boundedContextFolder) : void 0;
|
|
4181
4730
|
const endpointFile = node_path.join(endpointFolder.path, `${method.toUpperCase()}.ts`);
|
|
4182
4731
|
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
4183
|
-
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${
|
|
4184
|
-
import type { ${handler.typeName} } from '${
|
|
4732
|
+
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${wiring_relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
|
|
4733
|
+
import type { ${handler.typeName} } from '${wiring_relativeImport(endpointFile, handler.typeFile)}'` : ''}
|
|
4185
4734
|
|
|
4186
4735
|
export class ${endpointClassName} {
|
|
4187
4736
|
constructor(
|
|
@@ -4213,8 +4762,8 @@ export class ${endpointClassName} {
|
|
|
4213
4762
|
].filter((x)=>!!x) : [];
|
|
4214
4763
|
wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
|
|
4215
4764
|
import { wireClass } from '@domain-first/wire'
|
|
4216
|
-
import { ${endpointClassName} } from '${
|
|
4217
|
-
${dependencies.map((x)=>`import { ${x.wireName} } from '${
|
|
4765
|
+
import { ${endpointClassName} } from '${wiring_relativeImport(wireFile, endpointFile)}'
|
|
4766
|
+
${dependencies.map((x)=>`import { ${x.wireName} } from '${wiring_relativeImport(wireFile, x.wireFile)}'`).join('\n')}
|
|
4218
4767
|
|
|
4219
4768
|
export const wire${endpointClassName} = wireClass(
|
|
4220
4769
|
${endpointClassName},
|
|
@@ -4338,7 +4887,7 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
4338
4887
|
}) && primaryRole;
|
|
4339
4888
|
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
4340
4889
|
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
4341
|
-
importLine: `import { ${className} } from '${
|
|
4890
|
+
importLine: `import { ${className} } from '${wiring_relativeImport(wireFile.path, file.path)}'`,
|
|
4342
4891
|
className,
|
|
4343
4892
|
wireName: implementationWireName(label),
|
|
4344
4893
|
environments: chosenEnvironments
|
|
@@ -4766,4 +5315,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
4766
5315
|
break;
|
|
4767
5316
|
}
|
|
4768
5317
|
};
|
|
4769
|
-
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, helperImplementationTypes, initializeUseCase, integrationDescriptions, integrationIds, integrationSpecFile, integrationSpecsAvailable, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, rootControllerChoice, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureHelper, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|
|
5318
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, frameworkTitles, helperImplementationTypes, initializeUseCase, integrationDescriptions, integrationIds, integrationSpecFile, integrationSpecsAvailable, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, rootControllerChoice, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureHelper, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, scaffoldSveltePage, scaffoldSvelteSharedHook, scaffoldSvelteUIKitComponent, scaffoldSvelteWidget, systemImplementationChoices, unitId, wireDependency };
|