create-o2s-app 1.2.1 → 2.0.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/CHANGELOG.md +21 -0
- package/README.md +91 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +73 -0
- package/dist/index.js +57 -89
- package/dist/scaffold/cleanup.d.ts +2 -0
- package/dist/scaffold/cleanup.d.ts.map +1 -0
- package/dist/scaffold/cleanup.js +86 -0
- package/dist/scaffold/clone.d.ts +3 -0
- package/dist/scaffold/clone.d.ts.map +1 -0
- package/dist/scaffold/clone.js +82 -0
- package/dist/scaffold/generate-env.d.ts +2 -0
- package/dist/scaffold/generate-env.d.ts.map +1 -0
- package/dist/scaffold/generate-env.js +68 -0
- package/dist/scaffold/index.d.ts +6 -0
- package/dist/scaffold/index.d.ts.map +1 -0
- package/dist/scaffold/index.js +83 -0
- package/dist/scaffold/install.d.ts +8 -0
- package/dist/scaffold/install.d.ts.map +1 -0
- package/dist/scaffold/install.js +79 -0
- package/dist/scaffold/transform-app-config.d.ts +2 -0
- package/dist/scaffold/transform-app-config.d.ts.map +1 -0
- package/dist/scaffold/transform-app-config.js +27 -0
- package/dist/scaffold/transform-app-module.d.ts +2 -0
- package/dist/scaffold/transform-app-module.d.ts.map +1 -0
- package/dist/scaffold/transform-app-module.js +78 -0
- package/dist/scaffold/transform-apps-package-json.d.ts +2 -0
- package/dist/scaffold/transform-apps-package-json.d.ts.map +1 -0
- package/dist/scaffold/transform-apps-package-json.js +64 -0
- package/dist/scaffold/transform-integration-configs.d.ts +3 -0
- package/dist/scaffold/transform-integration-configs.d.ts.map +1 -0
- package/dist/scaffold/transform-integration-configs.js +116 -0
- package/dist/scaffold/transform-package-json.d.ts +2 -0
- package/dist/scaffold/transform-package-json.d.ts.map +1 -0
- package/dist/scaffold/transform-package-json.js +61 -0
- package/dist/scaffold/transform-page-model.d.ts +2 -0
- package/dist/scaffold/transform-page-model.d.ts.map +1 -0
- package/dist/scaffold/transform-page-model.js +78 -0
- package/dist/scaffold/transform-render-blocks.d.ts +2 -0
- package/dist/scaffold/transform-render-blocks.d.ts.map +1 -0
- package/dist/scaffold/transform-render-blocks.js +102 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +33 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils/block-discovery.d.ts +3 -0
- package/dist/utils/block-discovery.d.ts.map +1 -0
- package/dist/utils/block-discovery.js +79 -0
- package/dist/utils/integration-discovery.d.ts +3 -0
- package/dist/utils/integration-discovery.d.ts.map +1 -0
- package/dist/utils/integration-discovery.js +79 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +62 -0
- package/dist/wizard/env-prompts.d.ts +10 -0
- package/dist/wizard/env-prompts.d.ts.map +1 -0
- package/dist/wizard/env-prompts.js +66 -0
- package/dist/wizard/index.d.ts +3 -0
- package/dist/wizard/index.d.ts.map +1 -0
- package/dist/wizard/index.js +38 -0
- package/dist/wizard/prompts.d.ts +7 -0
- package/dist/wizard/prompts.d.ts.map +1 -0
- package/dist/wizard/prompts.js +106 -0
- package/dist/wizard/templates.d.ts +11 -0
- package/dist/wizard/templates.d.ts.map +1 -0
- package/dist/wizard/templates.js +47 -0
- package/package.json +25 -4
- package/src/constants.ts +76 -0
- package/src/index.ts +72 -106
- package/src/scaffold/cleanup.ts +63 -0
- package/src/scaffold/clone.ts +47 -0
- package/src/scaffold/generate-env.ts +44 -0
- package/src/scaffold/index.ts +69 -0
- package/src/scaffold/install.ts +47 -0
- package/src/scaffold/transform-app-config.ts +24 -0
- package/src/scaffold/transform-app-module.ts +50 -0
- package/src/scaffold/transform-apps-package-json.ts +39 -0
- package/src/scaffold/transform-integration-configs.ts +112 -0
- package/src/scaffold/transform-package-json.ts +29 -0
- package/src/scaffold/transform-page-model.ts +50 -0
- package/src/scaffold/transform-render-blocks.ts +79 -0
- package/src/types.ts +37 -0
- package/src/utils/block-discovery.ts +54 -0
- package/src/utils/integration-discovery.ts +58 -0
- package/src/utils/logger.ts +68 -0
- package/src/wizard/env-prompts.ts +83 -0
- package/src/wizard/index.ts +49 -0
- package/src/wizard/prompts.ts +119 -0
- package/src/wizard/templates.ts +61 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
const FILE_PATH = 'apps/api-harmonization/src/app.module.ts';
|
|
5
|
+
|
|
6
|
+
// Regex matches: import * as Alias from '@o2s/blocks.<name>/api-harmonization';
|
|
7
|
+
const BLOCK_IMPORT_REGEX = /^import \* as (\w+) from '@o2s\/blocks\.([^/]+)\/api-harmonization';$/;
|
|
8
|
+
|
|
9
|
+
// Regex matches: Alias.Module.register(AppConfig),
|
|
10
|
+
const BLOCK_REGISTRATION_REGEX = /^\s+(\w+)\.Module\.register\(AppConfig\),\s*$/;
|
|
11
|
+
|
|
12
|
+
export const transformAppModule = async (projectDir: string, selectedBlockNames: string[]): Promise<void> => {
|
|
13
|
+
const filePath = path.join(projectDir, FILE_PATH);
|
|
14
|
+
|
|
15
|
+
if (!(await fs.pathExists(filePath))) return;
|
|
16
|
+
|
|
17
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
18
|
+
const lines = content.split('\n');
|
|
19
|
+
|
|
20
|
+
// Discover alias → blockName map from the actual file (handles special aliases)
|
|
21
|
+
const aliasToBlock = new Map<string, string>();
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
const match = line.match(BLOCK_IMPORT_REGEX);
|
|
24
|
+
if (match && match[1] && match[2]) {
|
|
25
|
+
aliasToBlock.set(match[1], match[2]); // alias → blockName
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Build set of aliases for blocks the user did NOT select
|
|
30
|
+
const aliasesToRemove = new Set<string>();
|
|
31
|
+
for (const [alias, blockName] of aliasToBlock.entries()) {
|
|
32
|
+
if (!selectedBlockNames.includes(blockName)) {
|
|
33
|
+
aliasesToRemove.add(alias);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (aliasesToRemove.size === 0) return;
|
|
38
|
+
|
|
39
|
+
const filteredLines = lines.filter((line) => {
|
|
40
|
+
const importMatch = line.match(BLOCK_IMPORT_REGEX);
|
|
41
|
+
if (importMatch && importMatch[1] && aliasesToRemove.has(importMatch[1])) return false;
|
|
42
|
+
|
|
43
|
+
const regMatch = line.match(BLOCK_REGISTRATION_REGEX);
|
|
44
|
+
if (regMatch && regMatch[1] && aliasesToRemove.has(regMatch[1])) return false;
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await fs.writeFile(filePath, filteredLines.join('\n'), 'utf-8');
|
|
50
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
const APP_PACKAGE_JSON_PATHS = ['apps/api-harmonization/package.json', 'apps/frontend/package.json'];
|
|
5
|
+
|
|
6
|
+
export const transformAppsPackageJson = async (
|
|
7
|
+
projectDir: string,
|
|
8
|
+
selectedBlockNames: string[],
|
|
9
|
+
selectedIntegrationNames: string[],
|
|
10
|
+
): Promise<void> => {
|
|
11
|
+
for (const relPath of APP_PACKAGE_JSON_PATHS) {
|
|
12
|
+
const filePath = path.join(projectDir, relPath);
|
|
13
|
+
|
|
14
|
+
if (!(await fs.pathExists(filePath))) continue;
|
|
15
|
+
|
|
16
|
+
const packageJson = await fs.readJson(filePath);
|
|
17
|
+
|
|
18
|
+
if (packageJson.dependencies) {
|
|
19
|
+
for (const depName of Object.keys(packageJson.dependencies)) {
|
|
20
|
+
const blockMatch = depName.match(/^@o2s\/blocks\.(.+)$/);
|
|
21
|
+
if (blockMatch && blockMatch[1] && !selectedBlockNames.includes(blockMatch[1])) {
|
|
22
|
+
delete packageJson.dependencies[depName];
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const integrationMatch = depName.match(/^@o2s\/integrations\.(.+)$/);
|
|
27
|
+
if (
|
|
28
|
+
integrationMatch &&
|
|
29
|
+
integrationMatch[1] &&
|
|
30
|
+
!selectedIntegrationNames.includes(integrationMatch[1])
|
|
31
|
+
) {
|
|
32
|
+
delete packageJson.dependencies[depName];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await fs.writeJson(filePath, packageJson, { spaces: 4 });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ConflictResolution } from '../types';
|
|
2
|
+
import * as fs from 'fs-extra';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
const CONFIGS_MODELS_PATH = 'packages/configs/integrations/src/models';
|
|
6
|
+
const CONFIGS_PACKAGE_JSON_PATH = 'packages/configs/integrations/package.json';
|
|
7
|
+
const MOCKED_IMPORT = `@o2s/integrations.mocked/integration`;
|
|
8
|
+
|
|
9
|
+
// Build a map from framework module name → winning integration.
|
|
10
|
+
// Integrations without o2sModules entries (e.g. mocked) contribute no modules.
|
|
11
|
+
const buildModuleIntegrationMap = (
|
|
12
|
+
selectedIntegrations: string[],
|
|
13
|
+
conflictResolutions: ConflictResolution[],
|
|
14
|
+
integrationModules: Record<string, string[]>,
|
|
15
|
+
): Map<string, string> => {
|
|
16
|
+
const moduleMap = new Map<string, string>();
|
|
17
|
+
|
|
18
|
+
for (const integration of selectedIntegrations) {
|
|
19
|
+
const modules = integrationModules[integration] ?? [];
|
|
20
|
+
for (const module of modules) {
|
|
21
|
+
if (!moduleMap.has(module)) {
|
|
22
|
+
moduleMap.set(module, integration);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const resolution of conflictResolutions) {
|
|
28
|
+
moduleMap.set(resolution.module, resolution.winner);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return moduleMap;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const updateConfigsPackageJson = async (
|
|
35
|
+
projectDir: string,
|
|
36
|
+
selectedIntegrations: string[],
|
|
37
|
+
integrationModules: Record<string, string[]>,
|
|
38
|
+
): Promise<void> => {
|
|
39
|
+
const pkgPath = path.join(projectDir, CONFIGS_PACKAGE_JSON_PATH);
|
|
40
|
+
|
|
41
|
+
if (!(await fs.pathExists(pkgPath))) return;
|
|
42
|
+
|
|
43
|
+
const pkg = await fs.readJson(pkgPath);
|
|
44
|
+
|
|
45
|
+
// Remove integration deps that were not selected
|
|
46
|
+
for (const key of Object.keys((pkg.dependencies || {}) as Record<string, string>)) {
|
|
47
|
+
if (key.startsWith('@o2s/integrations.')) {
|
|
48
|
+
const name = key.replace('@o2s/integrations.', '');
|
|
49
|
+
if (!selectedIntegrations.includes(name)) {
|
|
50
|
+
delete pkg.dependencies[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Add deps for selected integrations that have module mappings
|
|
56
|
+
for (const integration of selectedIntegrations) {
|
|
57
|
+
if (integrationModules[integration]?.length) {
|
|
58
|
+
pkg.dependencies[`@o2s/integrations.${integration}`] = '*';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await fs.writeJson(pkgPath, pkg, { spaces: 4 });
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const transformIntegrationConfigs = async (
|
|
66
|
+
projectDir: string,
|
|
67
|
+
selectedIntegrations: string[],
|
|
68
|
+
conflictResolutions: ConflictResolution[],
|
|
69
|
+
integrationModules: Record<string, string[]>,
|
|
70
|
+
): Promise<string[]> => {
|
|
71
|
+
const moduleMap = buildModuleIntegrationMap(selectedIntegrations, conflictResolutions, integrationModules);
|
|
72
|
+
|
|
73
|
+
if (moduleMap.size === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const modelsDir = path.join(projectDir, CONFIGS_MODELS_PATH);
|
|
78
|
+
|
|
79
|
+
if (!(await fs.pathExists(modelsDir))) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const [module, integration] of moduleMap.entries()) {
|
|
84
|
+
const filePath = path.join(modelsDir, `${module}.ts`);
|
|
85
|
+
|
|
86
|
+
if (!(await fs.pathExists(filePath))) continue;
|
|
87
|
+
|
|
88
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
89
|
+
const updatedContent = content.replaceAll(MOCKED_IMPORT, `@o2s/integrations.${integration}/integration`);
|
|
90
|
+
|
|
91
|
+
await fs.writeFile(filePath, updatedContent, 'utf-8');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await updateConfigsPackageJson(projectDir, selectedIntegrations, integrationModules);
|
|
95
|
+
|
|
96
|
+
// Detect model files that still import mocked but mocked is not selected.
|
|
97
|
+
// Skip only when 'mocked' (full) is selected — it covers all modules.
|
|
98
|
+
// 'mocked-dxp' covers only cms/articles/search, so uncovered detection runs normally.
|
|
99
|
+
const uncoveredModules: string[] = [];
|
|
100
|
+
if (!selectedIntegrations.includes('mocked')) {
|
|
101
|
+
const files = await fs.readdir(modelsDir);
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
if (file === 'index.ts' || !file.endsWith('.ts')) continue;
|
|
104
|
+
const content = await fs.readFile(path.join(modelsDir, file), 'utf-8');
|
|
105
|
+
if (content.includes(MOCKED_IMPORT)) {
|
|
106
|
+
uncoveredModules.push(file.replace('.ts', ''));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return uncoveredModules;
|
|
112
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
// Workspace globs to remove (their parent directories are deleted during cleanup)
|
|
5
|
+
const REMOVED_WORKSPACE_GLOBS = ['packages/cli/*', 'packages/modules/*', 'packages/utils/*'];
|
|
6
|
+
|
|
7
|
+
export const transformRootPackageJson = async (projectDir: string): Promise<void> => {
|
|
8
|
+
const filePath = path.join(projectDir, 'package.json');
|
|
9
|
+
const packageJson = await fs.readJson(filePath);
|
|
10
|
+
|
|
11
|
+
// Remove workspace entries for deleted directories
|
|
12
|
+
if (Array.isArray(packageJson.workspaces)) {
|
|
13
|
+
packageJson.workspaces = packageJson.workspaces.filter((ws: string) => !REMOVED_WORKSPACE_GLOBS.includes(ws));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Clean up scripts that reference removed directories
|
|
17
|
+
if (packageJson.scripts) {
|
|
18
|
+
for (const [key, value] of Object.entries(packageJson.scripts)) {
|
|
19
|
+
if (typeof value === 'string') {
|
|
20
|
+
// Remove turbo filter flags referencing packages/cli
|
|
21
|
+
packageJson.scripts[key] = value
|
|
22
|
+
.replace(/\s*-F=!\{\.\/packages\/cli\/\*\}/g, '')
|
|
23
|
+
.replace(/\s*-F=!\{\.\/packages\/telemetry\}/g, '');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await fs.writeJson(filePath, packageJson, { spaces: 4 });
|
|
29
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
const FILE_PATH = 'apps/api-harmonization/src/modules/page/page.model.ts';
|
|
5
|
+
|
|
6
|
+
// Regex matches: import * as Alias from '@o2s/blocks.<name>/api-harmonization';
|
|
7
|
+
const BLOCK_IMPORT_REGEX = /^import \* as (\w+) from '@o2s\/blocks\.([^/]+)\/api-harmonization';$/;
|
|
8
|
+
|
|
9
|
+
// Regex matches: | Alias.Model.SomeTypenameBlock['__typename']
|
|
10
|
+
const UNION_TYPE_REGEX = /^\s+\| (\w+)\.Model\.\w+\['__typename'\]/;
|
|
11
|
+
|
|
12
|
+
export const transformPageModel = async (projectDir: string, selectedBlockNames: string[]): Promise<void> => {
|
|
13
|
+
const filePath = path.join(projectDir, FILE_PATH);
|
|
14
|
+
|
|
15
|
+
if (!(await fs.pathExists(filePath))) return;
|
|
16
|
+
|
|
17
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
18
|
+
const lines = content.split('\n');
|
|
19
|
+
|
|
20
|
+
// Discover alias → blockName map from the actual file
|
|
21
|
+
const aliasToBlock = new Map<string, string>();
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
const match = line.match(BLOCK_IMPORT_REGEX);
|
|
24
|
+
if (match && match[1] && match[2]) {
|
|
25
|
+
aliasToBlock.set(match[1], match[2]); // alias → blockName
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Build set of aliases for blocks the user did NOT select
|
|
30
|
+
const aliasesToRemove = new Set<string>();
|
|
31
|
+
for (const [alias, blockName] of aliasToBlock.entries()) {
|
|
32
|
+
if (!selectedBlockNames.includes(blockName)) {
|
|
33
|
+
aliasesToRemove.add(alias);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (aliasesToRemove.size === 0) return;
|
|
38
|
+
|
|
39
|
+
const filteredLines = lines.filter((line) => {
|
|
40
|
+
const importMatch = line.match(BLOCK_IMPORT_REGEX);
|
|
41
|
+
if (importMatch && importMatch[1] && aliasesToRemove.has(importMatch[1])) return false;
|
|
42
|
+
|
|
43
|
+
const unionMatch = line.match(UNION_TYPE_REGEX);
|
|
44
|
+
if (unionMatch && unionMatch[1] && aliasesToRemove.has(unionMatch[1])) return false;
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await fs.writeFile(filePath, filteredLines.join('\n'), 'utf-8');
|
|
50
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
const FILE_PATH = 'apps/frontend/src/blocks/renderBlocks.tsx';
|
|
5
|
+
|
|
6
|
+
// Regex matches: import * as Alias from '@o2s/blocks.<name>/frontend';
|
|
7
|
+
const BLOCK_IMPORT_REGEX = /^import \* as (\w+) from '@o2s\/blocks\.([^/]+)\/frontend';$/;
|
|
8
|
+
|
|
9
|
+
// Regex matches: case 'SomeBlock':
|
|
10
|
+
const CASE_LINE_REGEX = /^\s+case '(\w+)':\s*$/;
|
|
11
|
+
|
|
12
|
+
// Regex matches: return <Alias.Renderer (handles extra props like onSignOut, renderBlocks)
|
|
13
|
+
const RETURN_RENDERER_REGEX = /^\s+return <(\w+)\.Renderer/;
|
|
14
|
+
|
|
15
|
+
export const transformRenderBlocks = async (projectDir: string, selectedBlockNames: string[]): Promise<void> => {
|
|
16
|
+
const filePath = path.join(projectDir, FILE_PATH);
|
|
17
|
+
|
|
18
|
+
if (!(await fs.pathExists(filePath))) return;
|
|
19
|
+
|
|
20
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
21
|
+
const lines = content.split('\n');
|
|
22
|
+
|
|
23
|
+
// Discover alias → blockName map from the actual file
|
|
24
|
+
const aliasToBlock = new Map<string, string>();
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
const match = line.match(BLOCK_IMPORT_REGEX);
|
|
27
|
+
if (match && match[1] && match[2]) {
|
|
28
|
+
aliasToBlock.set(match[1], match[2]); // alias → blockName
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Build set of aliases for blocks the user did NOT select
|
|
33
|
+
const aliasesToRemove = new Set<string>();
|
|
34
|
+
for (const [alias, blockName] of aliasToBlock.entries()) {
|
|
35
|
+
if (!selectedBlockNames.includes(blockName)) {
|
|
36
|
+
aliasesToRemove.add(alias);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (aliasesToRemove.size === 0) return;
|
|
41
|
+
|
|
42
|
+
// Process line by line — switch case/return pairs must be removed together
|
|
43
|
+
const result: string[] = [];
|
|
44
|
+
let skipNext = false;
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < lines.length; i++) {
|
|
47
|
+
if (skipNext) {
|
|
48
|
+
skipNext = false;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const line = lines[i];
|
|
53
|
+
if (line === undefined) continue;
|
|
54
|
+
|
|
55
|
+
// Remove block import lines
|
|
56
|
+
const importMatch = line.match(BLOCK_IMPORT_REGEX);
|
|
57
|
+
if (importMatch && importMatch[1] && aliasesToRemove.has(importMatch[1])) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Detect switch case line and peek at the return line below it
|
|
62
|
+
const caseMatch = line.match(CASE_LINE_REGEX);
|
|
63
|
+
if (caseMatch && i + 1 < lines.length) {
|
|
64
|
+
const nextLine = lines[i + 1];
|
|
65
|
+
if (nextLine !== undefined) {
|
|
66
|
+
const returnMatch = nextLine.match(RETURN_RENDERER_REGEX);
|
|
67
|
+
if (returnMatch && returnMatch[1] && aliasesToRemove.has(returnMatch[1])) {
|
|
68
|
+
// Skip both the case line (current) and the return line (next)
|
|
69
|
+
skipNext = true;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
result.push(line);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await fs.writeFile(filePath, result.join('\n'), 'utf-8');
|
|
79
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type TemplateType = 'o2s' | 'dxp' | 'custom';
|
|
2
|
+
|
|
3
|
+
export interface BlockInfo {
|
|
4
|
+
name: string;
|
|
5
|
+
packageName: string;
|
|
6
|
+
description: string;
|
|
7
|
+
category: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IntegrationInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
packageName: string;
|
|
13
|
+
description: string;
|
|
14
|
+
category: string[];
|
|
15
|
+
modules: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface EnvVar {
|
|
19
|
+
key: string;
|
|
20
|
+
description: string;
|
|
21
|
+
required: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ConflictResolution {
|
|
25
|
+
module: string;
|
|
26
|
+
winner: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WizardAnswers {
|
|
30
|
+
projectName: string;
|
|
31
|
+
template: TemplateType;
|
|
32
|
+
selectedBlocks: string[];
|
|
33
|
+
selectedIntegrations: string[];
|
|
34
|
+
integrationModules: Record<string, string[]>;
|
|
35
|
+
conflictResolutions: ConflictResolution[];
|
|
36
|
+
envVars: Record<string, string>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BLOCKS_PATH } from '../constants';
|
|
2
|
+
import { BlockInfo } from '../types';
|
|
3
|
+
import { getAllTemplateCategories } from '../wizard/templates';
|
|
4
|
+
import * as fs from 'fs-extra';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
interface BlockPackageJson {
|
|
8
|
+
description?: string;
|
|
9
|
+
o2sTemplate?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const discoverBlocks = async (repoDir: string): Promise<BlockInfo[]> => {
|
|
13
|
+
try {
|
|
14
|
+
const blocksDir = path.join(repoDir, BLOCKS_PATH);
|
|
15
|
+
const entries = await fs.readdir(blocksDir, { withFileTypes: true });
|
|
16
|
+
|
|
17
|
+
const blocks: BlockInfo[] = [];
|
|
18
|
+
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if (!entry.isDirectory()) continue;
|
|
21
|
+
|
|
22
|
+
const blockName = entry.name;
|
|
23
|
+
const packageJson = await readBlockPackageJson(repoDir, blockName);
|
|
24
|
+
|
|
25
|
+
blocks.push({
|
|
26
|
+
name: blockName,
|
|
27
|
+
packageName: `@o2s/blocks.${blockName}`,
|
|
28
|
+
description: packageJson.description || `Block: ${blockName}`,
|
|
29
|
+
// Fallback to all templates when o2sTemplate is not declared
|
|
30
|
+
category: packageJson.o2sTemplate ?? getAllTemplateCategories(),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return blocks.sort((a, b) => a.name.localeCompare(b.name));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error fetching the block list:', error);
|
|
37
|
+
throw new Error('Failed to fetch the block list.');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const readBlockPackageJson = async (repoDir: string, blockName: string): Promise<BlockPackageJson> => {
|
|
42
|
+
try {
|
|
43
|
+
const packageJsonPath = path.join(repoDir, BLOCKS_PATH, blockName, 'package.json');
|
|
44
|
+
|
|
45
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
46
|
+
return await fs.readJson(packageJsonPath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.warn(`Warning: Could not read package.json for block "${blockName}":`, error);
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { INTEGRATIONS_PATH } from '../constants';
|
|
2
|
+
import { IntegrationInfo } from '../types';
|
|
3
|
+
import * as fs from 'fs-extra';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
|
|
6
|
+
interface IntegrationPackageJson {
|
|
7
|
+
description?: string;
|
|
8
|
+
o2sTemplate?: string[];
|
|
9
|
+
o2sModules?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const discoverIntegrations = async (repoDir: string): Promise<IntegrationInfo[]> => {
|
|
13
|
+
try {
|
|
14
|
+
const integrationsDir = path.join(repoDir, INTEGRATIONS_PATH);
|
|
15
|
+
const entries = await fs.readdir(integrationsDir, { withFileTypes: true });
|
|
16
|
+
|
|
17
|
+
const integrations: IntegrationInfo[] = [];
|
|
18
|
+
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if (!entry.isDirectory()) continue;
|
|
21
|
+
|
|
22
|
+
const integrationName = entry.name;
|
|
23
|
+
const packageJson = await readIntegrationPackageJson(repoDir, integrationName);
|
|
24
|
+
|
|
25
|
+
integrations.push({
|
|
26
|
+
name: integrationName,
|
|
27
|
+
packageName: `@o2s/integrations.${integrationName}`,
|
|
28
|
+
description: packageJson.description || `Integration: ${integrationName}`,
|
|
29
|
+
// No o2sTemplate = integration only available in Custom template
|
|
30
|
+
category: packageJson.o2sTemplate ?? [],
|
|
31
|
+
modules: packageJson.o2sModules ?? [],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return integrations.sort((a, b) => a.name.localeCompare(b.name));
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Error fetching the integration list:', error);
|
|
38
|
+
throw new Error('Failed to fetch the integration list.');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const readIntegrationPackageJson = async (
|
|
43
|
+
repoDir: string,
|
|
44
|
+
integrationName: string,
|
|
45
|
+
): Promise<IntegrationPackageJson> => {
|
|
46
|
+
try {
|
|
47
|
+
const packageJsonPath = path.join(repoDir, INTEGRATIONS_PATH, integrationName, 'package.json');
|
|
48
|
+
|
|
49
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
50
|
+
return await fs.readJson(packageJsonPath);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.warn(`Warning: Could not read package.json for integration "${integrationName}":`, error);
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DOCS_URL } from '../constants';
|
|
2
|
+
import { TemplateType } from '../types';
|
|
3
|
+
import { TEMPLATES } from '../wizard/templates';
|
|
4
|
+
import kleur from 'kleur';
|
|
5
|
+
|
|
6
|
+
export const printSummary = (
|
|
7
|
+
targetDir: string,
|
|
8
|
+
template: TemplateType,
|
|
9
|
+
blockCount: number,
|
|
10
|
+
integrationCount: number,
|
|
11
|
+
uncoveredModules: string[] = [],
|
|
12
|
+
skipInstall = false,
|
|
13
|
+
): void => {
|
|
14
|
+
const templateName = TEMPLATES[template].name;
|
|
15
|
+
|
|
16
|
+
console.log();
|
|
17
|
+
console.log(kleur.green().bold('Project created successfully!'));
|
|
18
|
+
console.log();
|
|
19
|
+
console.log(` Location: ${kleur.cyan(targetDir)}`);
|
|
20
|
+
console.log(` Template: ${templateName}`);
|
|
21
|
+
console.log(` Blocks: ${blockCount} blocks`);
|
|
22
|
+
console.log(` Integrations: ${integrationCount} integrations`);
|
|
23
|
+
console.log();
|
|
24
|
+
|
|
25
|
+
if (uncoveredModules.length > 0) {
|
|
26
|
+
console.log(kleur.yellow().bold('⚠ Warning: the following modules have no integration assigned:'));
|
|
27
|
+
console.log();
|
|
28
|
+
for (const mod of uncoveredModules) {
|
|
29
|
+
console.log(kleur.yellow(` - ${mod}`));
|
|
30
|
+
}
|
|
31
|
+
console.log();
|
|
32
|
+
console.log(kleur.red(' The project will NOT start until these modules are configured.'));
|
|
33
|
+
console.log(' To fix this, edit packages/configs/integrations/src/models/<module>.ts');
|
|
34
|
+
console.log(' and replace the @o2s/integrations.mocked import with a real integration.');
|
|
35
|
+
console.log();
|
|
36
|
+
console.log(kleur.bold('Next steps:'));
|
|
37
|
+
console.log();
|
|
38
|
+
console.log(` cd ${targetDir}`);
|
|
39
|
+
console.log(kleur.dim(' # 1. Configure the modules listed above'));
|
|
40
|
+
console.log(kleur.dim(' # 2. Add the required env vars to apps/api-harmonization/.env.local'));
|
|
41
|
+
console.log(kleur.dim(' # 3. npm run dev'));
|
|
42
|
+
} else {
|
|
43
|
+
console.log(kleur.bold('Next steps:'));
|
|
44
|
+
console.log();
|
|
45
|
+
console.log(` cd ${targetDir}`);
|
|
46
|
+
if (skipInstall) {
|
|
47
|
+
console.log(kleur.dim(' # Install dependencies (npm install was skipped)'));
|
|
48
|
+
console.log(' npm install');
|
|
49
|
+
}
|
|
50
|
+
console.log(' npm run dev');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log();
|
|
54
|
+
console.log(kleur.bold('Documentation:'));
|
|
55
|
+
console.log(kleur.cyan(` ${DOCS_URL}`));
|
|
56
|
+
console.log();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const printError = (message: string, error?: unknown): void => {
|
|
60
|
+
console.error();
|
|
61
|
+
console.error(kleur.red().bold(`Error: ${message}`));
|
|
62
|
+
|
|
63
|
+
if (error instanceof Error) {
|
|
64
|
+
console.error(kleur.red(`Details: ${error.message}`));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.error();
|
|
68
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { INTEGRATION_ENV_VARS } from '../constants';
|
|
2
|
+
import { ConflictResolution } from '../types';
|
|
3
|
+
import kleur from 'kleur';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
|
|
6
|
+
interface ModuleConflict {
|
|
7
|
+
module: string;
|
|
8
|
+
integrations: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const detectConflicts = (
|
|
12
|
+
selectedIntegrations: string[],
|
|
13
|
+
integrationModules: Record<string, string[]>,
|
|
14
|
+
): ModuleConflict[] => {
|
|
15
|
+
const moduleToIntegrations: Record<string, string[]> = {};
|
|
16
|
+
|
|
17
|
+
for (const integration of selectedIntegrations) {
|
|
18
|
+
const modules = integrationModules[integration] ?? [];
|
|
19
|
+
for (const module of modules) {
|
|
20
|
+
moduleToIntegrations[module] = [...(moduleToIntegrations[module] ?? []), integration];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return Object.entries(moduleToIntegrations)
|
|
25
|
+
.filter(([, integrations]) => integrations.length > 1)
|
|
26
|
+
.map(([module, integrations]) => ({ module, integrations }));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const promptConflictResolutions = async (conflicts: ModuleConflict[]): Promise<ConflictResolution[]> => {
|
|
30
|
+
const resolutions: ConflictResolution[] = [];
|
|
31
|
+
|
|
32
|
+
for (const conflict of conflicts) {
|
|
33
|
+
const { winner } = await prompts({
|
|
34
|
+
type: 'select',
|
|
35
|
+
name: 'winner',
|
|
36
|
+
message: `Which integration should handle the "${conflict.module}" module?`,
|
|
37
|
+
choices: conflict.integrations.map((integration) => ({
|
|
38
|
+
title: integration,
|
|
39
|
+
value: integration,
|
|
40
|
+
})),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!winner) {
|
|
44
|
+
throw new Error(`Conflict resolution for module "${conflict.module}" is required`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
resolutions.push({ module: conflict.module, winner });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return resolutions;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const promptEnvVars = async (selectedIntegrations: string[]): Promise<Record<string, string>> => {
|
|
54
|
+
const envVars: Record<string, string> = {};
|
|
55
|
+
// Only integrations with defined env vars need configuration
|
|
56
|
+
const realIntegrations = selectedIntegrations.filter((integration) => !!INTEGRATION_ENV_VARS[integration]);
|
|
57
|
+
|
|
58
|
+
if (realIntegrations.length === 0) {
|
|
59
|
+
return envVars;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const integration of realIntegrations) {
|
|
63
|
+
const vars = INTEGRATION_ENV_VARS[integration] ?? [];
|
|
64
|
+
|
|
65
|
+
console.log(
|
|
66
|
+
`\n${kleur.cyan().bold(`Configuring ${integration}`)} environment variables ${kleur.dim('(press Enter to skip)')}:`,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
for (const envVar of vars) {
|
|
70
|
+
const requiredLabel = envVar.required ? ' [required]' : ' [optional]';
|
|
71
|
+
const { value } = await prompts({
|
|
72
|
+
type: 'text',
|
|
73
|
+
name: 'value',
|
|
74
|
+
message: `${envVar.key}${requiredLabel}`,
|
|
75
|
+
hint: envVar.description,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
envVars[envVar.key] = value ?? '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return envVars;
|
|
83
|
+
};
|