create-o2s-app 1.2.1 → 3.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 +27 -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 +75 -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 +55 -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 +82 -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 +110 -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 +78 -0
- package/src/index.ts +72 -106
- package/src/scaffold/cleanup.ts +21 -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 +59 -0
- package/src/scaffold/transform-integration-configs.ts +101 -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
package/package.json
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-o2s-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"description": "CLI tool to scaffold new O2S applications with Next.js and NestJS setup.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"o2s",
|
|
9
|
+
"cli",
|
|
10
|
+
"scaffold",
|
|
11
|
+
"create-app",
|
|
12
|
+
"nextjs",
|
|
13
|
+
"nestjs"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/o2sdev/openselfservice.git",
|
|
18
|
+
"directory": "packages/cli/create-o2s-app"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/o2sdev/openselfservice/tree/main/packages/cli/create-o2s-app#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/o2sdev/openselfservice/issues"
|
|
23
|
+
},
|
|
6
24
|
"main": "./dist/index.js",
|
|
7
25
|
"bin": {
|
|
8
26
|
"create-o2s-app": "./dist/index.js"
|
|
@@ -14,12 +32,14 @@
|
|
|
14
32
|
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,json}\""
|
|
15
33
|
},
|
|
16
34
|
"dependencies": {
|
|
17
|
-
"@o2s/telemetry": "^1.2.
|
|
35
|
+
"@o2s/telemetry": "^1.2.1",
|
|
18
36
|
"@types/prompts": "^2.4.9",
|
|
19
37
|
"cli-progress": "^3.12.0",
|
|
20
38
|
"commander": "^14.0.3",
|
|
39
|
+
"fs-extra": "^11.3.0",
|
|
40
|
+
"kleur": "^3.0.3",
|
|
21
41
|
"prompts": "^2.4.2",
|
|
22
|
-
"simple-git": "^3.
|
|
42
|
+
"simple-git": "^3.32.3",
|
|
23
43
|
"ts-node": "^10.9.2"
|
|
24
44
|
},
|
|
25
45
|
"devDependencies": {
|
|
@@ -28,7 +48,8 @@
|
|
|
28
48
|
"@o2s/prettier-config": "*",
|
|
29
49
|
"@o2s/typescript-config": "*",
|
|
30
50
|
"@types/cli-progress": "^3.11.6",
|
|
31
|
-
"
|
|
51
|
+
"@types/fs-extra": "^11.0.4",
|
|
52
|
+
"eslint": "^9.39.3",
|
|
32
53
|
"prettier": "^3.8.1",
|
|
33
54
|
"typescript": "^5.9.3"
|
|
34
55
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { EnvVar } from './types';
|
|
2
|
+
|
|
3
|
+
export const GITHUB_REPO_URL = 'https://github.com/o2sdev/openselfservice';
|
|
4
|
+
export const GITHUB_BRANCH = 'create-o2s-app/base';
|
|
5
|
+
export const PROJECT_PREFIX = 'o2s';
|
|
6
|
+
export const STORYBOOK_URL = 'https://storybook-o2s.openselfservice.com/';
|
|
7
|
+
export const DOCS_URL = 'https://docs.openselfservice.com/getting-started';
|
|
8
|
+
|
|
9
|
+
export const BLOCKS_PATH = 'packages/blocks';
|
|
10
|
+
export const INTEGRATIONS_PATH = 'packages/integrations';
|
|
11
|
+
|
|
12
|
+
// Directories always removed during scaffolding
|
|
13
|
+
export const ALWAYS_REMOVE_DIRS: string[] = [
|
|
14
|
+
'.git',
|
|
15
|
+
'.github',
|
|
16
|
+
'.changeset',
|
|
17
|
+
'apps/docs',
|
|
18
|
+
'packages/blocks',
|
|
19
|
+
'packages/framework',
|
|
20
|
+
'packages/integrations',
|
|
21
|
+
'packages/modules',
|
|
22
|
+
'packages/utils',
|
|
23
|
+
'packages/cli',
|
|
24
|
+
'packages/telemetry',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const ALWAYS_REMOVE_FILES: string[] = ['vercel.json'];
|
|
28
|
+
|
|
29
|
+
export const INTEGRATION_ENV_VARS: Record<string, EnvVar[]> = {
|
|
30
|
+
zendesk: [
|
|
31
|
+
{
|
|
32
|
+
key: 'ZENDESK_API_URL',
|
|
33
|
+
description: 'Zendesk API URL (e.g., https://your-domain.zendesk.com)',
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
{ key: 'ZENDESK_API_TOKEN', description: 'Zendesk API token for authentication', required: true },
|
|
37
|
+
{ key: 'ZENDESK_TOPIC_FIELD_ID', description: 'Zendesk custom field ID for ticket topic', required: false },
|
|
38
|
+
],
|
|
39
|
+
'strapi-cms': [
|
|
40
|
+
{
|
|
41
|
+
key: 'CMS_STRAPI_BASE_URL',
|
|
42
|
+
description: 'Strapi server URL (e.g., https://your-strapi.com)',
|
|
43
|
+
required: true,
|
|
44
|
+
},
|
|
45
|
+
{ key: 'CMS_STRAPI_API_KEY', description: 'Strapi API key', required: false },
|
|
46
|
+
],
|
|
47
|
+
'contentful-cms': [
|
|
48
|
+
{ key: 'CF_SPACE_ID', description: 'Contentful space identifier', required: true },
|
|
49
|
+
{ key: 'CF_ENV', description: 'Contentful environment (e.g., master)', required: true },
|
|
50
|
+
{ key: 'CF_TOKEN', description: 'Contentful Content Delivery API token', required: true },
|
|
51
|
+
{ key: 'CF_PREVIEW_TOKEN', description: 'Contentful Content Preview API token', required: false },
|
|
52
|
+
],
|
|
53
|
+
medusajs: [
|
|
54
|
+
{
|
|
55
|
+
key: 'MEDUSAJS_BASE_URL',
|
|
56
|
+
description: 'Medusa server URL (e.g., https://api.your-medusa.com)',
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: 'MEDUSAJS_PUBLISHABLE_API_KEY',
|
|
61
|
+
description: 'Medusa publishable API key for Store API',
|
|
62
|
+
required: true,
|
|
63
|
+
},
|
|
64
|
+
{ key: 'MEDUSAJS_ADMIN_API_KEY', description: 'Medusa admin API key for Admin API', required: true },
|
|
65
|
+
],
|
|
66
|
+
algolia: [
|
|
67
|
+
{ key: 'ALGOLIA_APP_ID', description: 'Algolia application ID', required: true },
|
|
68
|
+
{ key: 'ALGOLIA_API_KEY', description: 'Algolia API key', required: true },
|
|
69
|
+
{ key: 'ALGOLIA_INDEX_NAME', description: 'Default Algolia index name', required: false },
|
|
70
|
+
],
|
|
71
|
+
redis: [
|
|
72
|
+
{ key: 'CACHE_ENABLED', description: 'Enable Redis cache (true/false)', required: false },
|
|
73
|
+
{ key: 'CACHE_REDIS_HOST', description: 'Redis host (e.g., localhost)', required: false },
|
|
74
|
+
{ key: 'CACHE_REDIS_PORT', description: 'Redis port (e.g., 6379)', required: false },
|
|
75
|
+
{ key: 'CACHE_REDIS_PASS', description: 'Redis password (if required)', required: false },
|
|
76
|
+
{ key: 'CACHE_TTL', description: 'Cache TTL in seconds (default: 300)', required: false },
|
|
77
|
+
],
|
|
78
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,133 +1,99 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { cleanupTempDir, cloneRepository } from './scaffold/clone';
|
|
3
|
+
import { scaffold } from './scaffold/index';
|
|
4
|
+
import { TemplateType } from './types';
|
|
5
|
+
import { printError, printSummary } from './utils/logger';
|
|
6
|
+
import { runWizard } from './wizard/index';
|
|
2
7
|
import * as telemetry from '@o2s/telemetry';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import cliProgress from 'cli-progress';
|
|
5
8
|
import { Command } from 'commander';
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
7
|
-
import prompts from 'prompts';
|
|
8
|
-
import simpleGit from 'simple-git';
|
|
9
9
|
|
|
10
10
|
const program = new Command();
|
|
11
11
|
|
|
12
12
|
program
|
|
13
|
-
.name('create-
|
|
14
|
-
.description('Create a new O2S project')
|
|
13
|
+
.name('create-o2s-app')
|
|
14
|
+
.description('Create a new O2S project with interactive setup wizard')
|
|
15
15
|
.argument('[name]', 'Name of the new project')
|
|
16
|
-
.option('--directory [directory]', 'Specify the destination directory'
|
|
16
|
+
.option('--directory [directory]', 'Specify the destination directory')
|
|
17
|
+
.option('--template [template]', 'Template: o2s | dxp | custom')
|
|
18
|
+
.option('--blocks [blocks]', 'Comma-separated list of block names (for non-interactive mode)')
|
|
19
|
+
.option('--integrations [integrations]', 'Comma-separated list of integration names (for non-interactive mode)')
|
|
20
|
+
.option('--skip-install', 'Skip npm install step')
|
|
17
21
|
.action(async (name, options) => {
|
|
18
22
|
telemetry.sendEvent('o2s', 'create-o2s-app', 'create-project');
|
|
19
23
|
await telemetry.flushEvents();
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
: (
|
|
24
|
-
await prompts({
|
|
25
|
-
type: 'text',
|
|
26
|
-
name: 'name',
|
|
27
|
-
message: 'Enter the name of your project',
|
|
28
|
-
initial: 'my-o2s-project',
|
|
29
|
-
})
|
|
30
|
-
).name;
|
|
31
|
-
|
|
32
|
-
const targetDirectory = projectName || options.directory;
|
|
33
|
-
|
|
34
|
-
const githubRepo = 'https://github.com/o2sdev/openselfservice';
|
|
35
|
-
const githubBranch = 'create-o2s-app/base';
|
|
36
|
-
|
|
37
|
-
if (existsSync(targetDirectory)) {
|
|
38
|
-
console.error(
|
|
39
|
-
`Directory ${targetDirectory} already exists. Please choose a different name or remove the existing directory.`,
|
|
40
|
-
);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
25
|
+
let tempDir: string | undefined;
|
|
26
|
+
let phase: 'clone' | 'wizard' | 'scaffold' = 'clone';
|
|
45
27
|
|
|
46
28
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
rmSync(`${targetDirectory}/.git`, { recursive: true });
|
|
69
|
-
rmSync(`${targetDirectory}/.github`, { recursive: true });
|
|
70
|
-
rmSync(`${targetDirectory}/.changeset`, { recursive: true });
|
|
71
|
-
|
|
72
|
-
rmSync(`${targetDirectory}/vercel.json`, { recursive: true });
|
|
73
|
-
|
|
74
|
-
rmSync(`${targetDirectory}/apps/docs`, { recursive: true });
|
|
75
|
-
rmSync(`${targetDirectory}/packages/framework`, { recursive: true });
|
|
76
|
-
rmSync(`${targetDirectory}/packages/integrations`, { recursive: true });
|
|
77
|
-
rmSync(`${targetDirectory}/packages/blocks`, { recursive: true });
|
|
78
|
-
rmSync(`${targetDirectory}/packages/modules`, { recursive: true });
|
|
79
|
-
rmSync(`${targetDirectory}/packages/utils`, { recursive: true });
|
|
80
|
-
rmSync(`${targetDirectory}/packages/cli`, { recursive: true });
|
|
81
|
-
rmSync(`${targetDirectory}/packages/telemetry`, { recursive: true });
|
|
82
|
-
|
|
83
|
-
let file = readFileSync(targetDirectory + '/package-lock.json', 'utf8');
|
|
84
|
-
file = removeSymLinks(file);
|
|
85
|
-
writeFileSync(targetDirectory + '/package-lock.json', file);
|
|
86
|
-
|
|
87
|
-
console.log();
|
|
88
|
-
console.log(`Installing dependencies in "${targetDirectory}"...`);
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
execSync('npm install', {
|
|
92
|
-
cwd: targetDirectory,
|
|
93
|
-
stdio: 'inherit',
|
|
94
|
-
});
|
|
95
|
-
console.log(`Dependencies installed successfully.`);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error('Error while installing dependencies:', error);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
29
|
+
const cliTemplate = parseTemplate(options.template);
|
|
30
|
+
const cliBlocks = parseCommaSeparated(options.blocks);
|
|
31
|
+
const cliIntegrations = parseCommaSeparated(options.integrations);
|
|
32
|
+
|
|
33
|
+
// Step 1: Clone repository to temp directory
|
|
34
|
+
phase = 'clone';
|
|
35
|
+
tempDir = await cloneRepository();
|
|
36
|
+
|
|
37
|
+
// Step 2: Run wizard (interactive or non-interactive)
|
|
38
|
+
phase = 'wizard';
|
|
39
|
+
const answers = await runWizard(tempDir, name, cliTemplate, cliBlocks, cliIntegrations);
|
|
40
|
+
|
|
41
|
+
// Step 3: Scaffold project
|
|
42
|
+
phase = 'scaffold';
|
|
43
|
+
const { targetDir, uncoveredModules } = await scaffold(
|
|
44
|
+
tempDir,
|
|
45
|
+
answers,
|
|
46
|
+
options.skipInstall,
|
|
47
|
+
options.directory,
|
|
48
|
+
);
|
|
100
49
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
50
|
+
// Step 4: Print summary
|
|
51
|
+
printSummary(
|
|
52
|
+
targetDir,
|
|
53
|
+
answers.template,
|
|
54
|
+
answers.selectedBlocks.length,
|
|
55
|
+
answers.selectedIntegrations.length,
|
|
56
|
+
uncoveredModules,
|
|
57
|
+
options.skipInstall,
|
|
58
|
+
);
|
|
104
59
|
} catch (error) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
60
|
+
if (tempDir) {
|
|
61
|
+
await cleanupTempDir(tempDir);
|
|
62
|
+
}
|
|
108
63
|
|
|
109
|
-
if (error instanceof Error) {
|
|
110
|
-
|
|
64
|
+
if (error instanceof Error && error.message.includes('is required')) {
|
|
65
|
+
// User cancelled a prompt
|
|
66
|
+
console.error();
|
|
67
|
+
console.error('Setup cancelled.');
|
|
111
68
|
} else {
|
|
112
|
-
|
|
69
|
+
telemetry.sendEvent('o2s', 'create-o2s-app', 'create-project-error', {
|
|
70
|
+
phase,
|
|
71
|
+
errorMessage: error instanceof Error ? error.message : 'unknown error',
|
|
72
|
+
});
|
|
73
|
+
await telemetry.flushEvents();
|
|
74
|
+
printError('Failed to create project', error);
|
|
113
75
|
}
|
|
76
|
+
|
|
77
|
+
process.exit(1);
|
|
114
78
|
}
|
|
115
79
|
});
|
|
116
80
|
|
|
117
81
|
program.parse(process.argv);
|
|
118
82
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
for (const [key, value] of Object.entries(json.packages)) {
|
|
125
|
-
if (value && typeof value === 'object' && (value as { link: boolean }).link) {
|
|
126
|
-
delete json.packages[key];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
83
|
+
const parseTemplate = (value: unknown): TemplateType | undefined => {
|
|
84
|
+
if (!value || typeof value !== 'string') return undefined;
|
|
85
|
+
const valid: TemplateType[] = ['o2s', 'dxp', 'custom'];
|
|
86
|
+
if (valid.includes(value as TemplateType)) {
|
|
87
|
+
return value as TemplateType;
|
|
129
88
|
}
|
|
89
|
+
console.warn(`Warning: Unknown template "${value}". Valid options: o2s, dxp, custom`);
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
130
92
|
|
|
131
|
-
|
|
132
|
-
|
|
93
|
+
const parseCommaSeparated = (value: unknown): string[] | undefined => {
|
|
94
|
+
if (!value || typeof value !== 'string') return undefined;
|
|
95
|
+
return value
|
|
96
|
+
.split(',')
|
|
97
|
+
.map((s) => s.trim())
|
|
98
|
+
.filter((s) => s.length > 0);
|
|
133
99
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ALWAYS_REMOVE_DIRS, ALWAYS_REMOVE_FILES } from '../constants';
|
|
2
|
+
import * as fs from 'fs-extra';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
export const cleanupProject = async (projectDir: string): Promise<void> => {
|
|
6
|
+
console.log('Organizing project structure...');
|
|
7
|
+
|
|
8
|
+
for (const dir of ALWAYS_REMOVE_DIRS) {
|
|
9
|
+
const fullPath = path.join(projectDir, dir);
|
|
10
|
+
if (await fs.pathExists(fullPath)) {
|
|
11
|
+
await fs.remove(fullPath);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const file of ALWAYS_REMOVE_FILES) {
|
|
16
|
+
const fullPath = path.join(projectDir, file);
|
|
17
|
+
if (await fs.pathExists(fullPath)) {
|
|
18
|
+
await fs.remove(fullPath);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GITHUB_BRANCH, GITHUB_REPO_URL } from '../constants';
|
|
2
|
+
import cliProgress from 'cli-progress';
|
|
3
|
+
import * as fs from 'fs-extra';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import simpleGit from 'simple-git';
|
|
7
|
+
|
|
8
|
+
export const cloneRepository = async (): Promise<string> => {
|
|
9
|
+
const tempDir = path.join(os.tmpdir(), `openselfservice-${Date.now()}`);
|
|
10
|
+
await fs.ensureDir(tempDir);
|
|
11
|
+
|
|
12
|
+
console.log(`Cloning template from "${GITHUB_REPO_URL}" (branch: "${GITHUB_BRANCH}")...`);
|
|
13
|
+
console.log();
|
|
14
|
+
|
|
15
|
+
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
16
|
+
bar.start(100, 0);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const git = simpleGit({
|
|
20
|
+
progress({ progress }) {
|
|
21
|
+
bar.update(Math.round(progress));
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await git.clone(GITHUB_REPO_URL, tempDir, ['--branch', GITHUB_BRANCH, '--single-branch', '--depth', '1']);
|
|
26
|
+
|
|
27
|
+
bar.update(100);
|
|
28
|
+
bar.stop();
|
|
29
|
+
console.log();
|
|
30
|
+
|
|
31
|
+
return tempDir;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
bar.stop();
|
|
34
|
+
console.error('Error cloning repository:', error);
|
|
35
|
+
throw new Error('Failed to clone repository.');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const cleanupTempDir = async (tempDir: string): Promise<void> => {
|
|
40
|
+
try {
|
|
41
|
+
if (await fs.pathExists(tempDir)) {
|
|
42
|
+
await fs.remove(tempDir);
|
|
43
|
+
}
|
|
44
|
+
} catch (_error) {
|
|
45
|
+
console.error('Error cleaning up temporary directory:', _error);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { INTEGRATION_ENV_VARS } from '../constants';
|
|
2
|
+
import * as fs from 'fs-extra';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
// Updates existing .env.local by replacing KEY= placeholders with user-provided values.
|
|
6
|
+
// The base branch already contains .env.local with all required variables and defaults.
|
|
7
|
+
const updateEnvFile = async (filePath: string, envVars: Record<string, string>): Promise<void> => {
|
|
8
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
9
|
+
const lines = content.split('\n');
|
|
10
|
+
|
|
11
|
+
const updated = lines.map((line) => {
|
|
12
|
+
const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
|
|
13
|
+
if (!match || !match[1]) return line;
|
|
14
|
+
|
|
15
|
+
const key = match[1];
|
|
16
|
+
const value = envVars[key];
|
|
17
|
+
|
|
18
|
+
if (value !== undefined && value !== '') {
|
|
19
|
+
return `${key}=${value}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return line;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await fs.writeFile(filePath, updated.join('\n'), 'utf-8');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const generateEnvFiles = async (
|
|
29
|
+
projectDir: string,
|
|
30
|
+
envVars: Record<string, string>,
|
|
31
|
+
selectedIntegrations: string[],
|
|
32
|
+
): Promise<void> => {
|
|
33
|
+
const realIntegrations = selectedIntegrations.filter((integration) => !!INTEGRATION_ENV_VARS[integration]);
|
|
34
|
+
|
|
35
|
+
if (realIntegrations.length === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const apiEnvPath = path.join(projectDir, 'apps', 'api-harmonization', '.env.local');
|
|
40
|
+
|
|
41
|
+
if (await fs.pathExists(apiEnvPath)) {
|
|
42
|
+
await updateEnvFile(apiEnvPath, envVars);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WizardAnswers } from '../types';
|
|
2
|
+
import { cleanupProject } from './cleanup';
|
|
3
|
+
import { generateEnvFiles } from './generate-env';
|
|
4
|
+
import { cleanPackageLock, installDependencies } from './install';
|
|
5
|
+
import { warnUnconfiguredModules } from './transform-app-config';
|
|
6
|
+
import { transformAppModule } from './transform-app-module';
|
|
7
|
+
import { transformAppsPackageJson } from './transform-apps-package-json';
|
|
8
|
+
import { transformIntegrationConfigs } from './transform-integration-configs';
|
|
9
|
+
import { transformRootPackageJson } from './transform-package-json';
|
|
10
|
+
import { transformPageModel } from './transform-page-model';
|
|
11
|
+
import { transformRenderBlocks } from './transform-render-blocks';
|
|
12
|
+
import * as fs from 'fs-extra';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
|
|
15
|
+
export const scaffold = async (
|
|
16
|
+
tempDir: string,
|
|
17
|
+
answers: WizardAnswers,
|
|
18
|
+
skipInstall = false,
|
|
19
|
+
directory?: string,
|
|
20
|
+
): Promise<{ targetDir: string; uncoveredModules: string[] }> => {
|
|
21
|
+
const targetDir = path.resolve(directory || '.', answers.projectName);
|
|
22
|
+
|
|
23
|
+
if (await fs.pathExists(targetDir)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Directory "${answers.projectName}" already exists. Please choose a different name or remove the existing directory.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { selectedBlocks, selectedIntegrations, integrationModules, conflictResolutions, envVars } = answers;
|
|
30
|
+
|
|
31
|
+
// Step 1: Move cloned repo to target directory
|
|
32
|
+
console.log();
|
|
33
|
+
console.log(`Creating project in "${targetDir}"...`);
|
|
34
|
+
await fs.move(tempDir, targetDir);
|
|
35
|
+
|
|
36
|
+
// Step 2: Remove unneeded directories (all packages/* are removed; deps come from npm registry)
|
|
37
|
+
await cleanupProject(targetDir);
|
|
38
|
+
|
|
39
|
+
// Step 3: Remove unselected block/integration references from app source files
|
|
40
|
+
console.log('Configuring project for selected blocks...');
|
|
41
|
+
await Promise.all([
|
|
42
|
+
transformAppModule(targetDir, selectedBlocks),
|
|
43
|
+
transformRenderBlocks(targetDir, selectedBlocks),
|
|
44
|
+
transformPageModel(targetDir, selectedBlocks),
|
|
45
|
+
transformAppsPackageJson(targetDir, selectedBlocks, selectedIntegrations),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
// Step 4: Clean up root package.json (remove workspace entries for deleted dirs)
|
|
49
|
+
await transformRootPackageJson(targetDir);
|
|
50
|
+
|
|
51
|
+
// Step 5: Configure integration source files and generate environment
|
|
52
|
+
console.log('Configuring integrations...');
|
|
53
|
+
const uncoveredModules = await transformIntegrationConfigs(
|
|
54
|
+
targetDir,
|
|
55
|
+
selectedIntegrations,
|
|
56
|
+
conflictResolutions,
|
|
57
|
+
integrationModules,
|
|
58
|
+
);
|
|
59
|
+
await generateEnvFiles(targetDir, envVars, selectedIntegrations);
|
|
60
|
+
warnUnconfiguredModules(uncoveredModules);
|
|
61
|
+
|
|
62
|
+
// Step 6: Clean symlinks from package-lock.json and install dependencies
|
|
63
|
+
await cleanPackageLock(targetDir);
|
|
64
|
+
if (!skipInstall) {
|
|
65
|
+
await installDependencies(targetDir);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { targetDir, uncoveredModules };
|
|
69
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import * as fs from 'fs-extra';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Remove symlink entries ("link": true) from package-lock.json.
|
|
7
|
+
* Without this, npm install would recreate empty folders for removed packages
|
|
8
|
+
* (framework, integrations, blocks etc.) because the lock file still references them.
|
|
9
|
+
*/
|
|
10
|
+
export const cleanPackageLock = async (projectDir: string): Promise<void> => {
|
|
11
|
+
const lockFilePath = path.join(projectDir, 'package-lock.json');
|
|
12
|
+
|
|
13
|
+
if (!(await fs.pathExists(lockFilePath))) return;
|
|
14
|
+
|
|
15
|
+
const file = await fs.readFile(lockFilePath, 'utf8');
|
|
16
|
+
const json = JSON.parse(file);
|
|
17
|
+
|
|
18
|
+
if (json?.packages) {
|
|
19
|
+
for (const [key, value] of Object.entries(json.packages)) {
|
|
20
|
+
if (value && typeof value === 'object' && (value as { link?: boolean }).link) {
|
|
21
|
+
delete json.packages[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await fs.writeFile(lockFilePath, JSON.stringify(json, null, 4));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const installDependencies = async (projectDir: string): Promise<void> => {
|
|
30
|
+
await cleanPackageLock(projectDir);
|
|
31
|
+
|
|
32
|
+
console.log();
|
|
33
|
+
console.log('Installing dependencies...');
|
|
34
|
+
console.log();
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
execSync('npm install', {
|
|
38
|
+
cwd: projectDir,
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
});
|
|
41
|
+
console.log('Dependencies installed successfully.');
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error while installing dependencies.');
|
|
44
|
+
console.error('You can try running "npm install" manually in the project directory.');
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
|
|
3
|
+
// Warns about framework modules that have no integration configured.
|
|
4
|
+
// When mocked is not selected and a module has no real integration, the build
|
|
5
|
+
// will fail because the model file still imports from the deleted mocked package.
|
|
6
|
+
// Phase 3 will implement full app.config.ts transformation to remove unconfigured modules.
|
|
7
|
+
export const warnUnconfiguredModules = (uncoveredModules: string[]): void => {
|
|
8
|
+
if (uncoveredModules.length === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
console.warn();
|
|
13
|
+
console.warn(kleur.yellow().bold('Warning: The following framework modules have no integration configured:'));
|
|
14
|
+
for (const module of uncoveredModules) {
|
|
15
|
+
console.warn(kleur.yellow(` - ${module}`));
|
|
16
|
+
}
|
|
17
|
+
console.warn();
|
|
18
|
+
console.warn(
|
|
19
|
+
kleur.red('These modules still reference @o2s/integrations.mocked which was not included in your project.'),
|
|
20
|
+
);
|
|
21
|
+
console.warn(kleur.red('The project build will fail until you configure these modules manually.'));
|
|
22
|
+
console.warn('To fix: update packages/configs/integrations/src/models/<module>.ts to use your integration.');
|
|
23
|
+
console.warn();
|
|
24
|
+
};
|
|
@@ -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
|
+
};
|