create-o2s-app 3.0.0 → 4.1.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.
@@ -1,4 +1,5 @@
1
1
  import { TemplateType } from '../types';
2
- export declare const printSummary: (targetDir: string, template: TemplateType, blockCount: number, integrationCount: number, uncoveredModules?: string[], skipInstall?: boolean) => void;
2
+ export declare const printBanner: () => void;
3
+ export declare const printSummary: (targetDir: string, template: TemplateType, selectedBlocks: string[], selectedIntegrations: string[], uncoveredModules?: string[], skipInstall?: boolean) => void;
3
4
  export declare const printError: (message: string, error?: unknown) => void;
4
5
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,eAAO,MAAM,YAAY,GACrB,WAAW,MAAM,EACjB,UAAU,YAAY,EACtB,YAAY,MAAM,EAClB,kBAAkB,MAAM,EACxB,mBAAkB,MAAM,EAAO,EAC/B,qBAAmB,KACpB,IA4CF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,KAAG,IAS7D,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAKxC,eAAO,MAAM,WAAW,QAAO,IAyB9B,CAAC;AAEF,eAAO,MAAM,YAAY,GACrB,WAAW,MAAM,EACjB,UAAU,YAAY,EACtB,gBAAgB,MAAM,EAAE,EACxB,sBAAsB,MAAM,EAAE,EAC9B,mBAAkB,MAAM,EAAO,EAC/B,qBAAmB,KACpB,IA0HF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,KAAG,IAS7D,CAAC"}
@@ -3,51 +3,104 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.printError = exports.printSummary = void 0;
6
+ exports.printError = exports.printSummary = exports.printBanner = void 0;
7
7
  const constants_1 = require("../constants");
8
8
  const templates_1 = require("../wizard/templates");
9
9
  const kleur_1 = __importDefault(require("kleur"));
10
- const printSummary = (targetDir, template, blockCount, integrationCount, uncoveredModules = [], skipInstall = false) => {
11
- const templateName = templates_1.TEMPLATES[template].name;
12
- console.log();
13
- console.log(kleur_1.default.green().bold('Project created successfully!'));
10
+ const path_1 = __importDefault(require("path"));
11
+ const printBanner = () => {
12
+ const title = 'Open Self Service CLI';
13
+ const desc = 'Scaffold your custom composable frontend';
14
+ const contentWidth = 46;
15
+ const topLine = ` ${kleur_1.default.blue('╭' + '─'.repeat(contentWidth) + '╮')}`;
16
+ const empty = ` ${kleur_1.default.blue('│')}${' '.repeat(contentWidth)}${kleur_1.default.blue('│')}`;
17
+ const bottomLine = ` ${kleur_1.default.blue('╰' + '─'.repeat(contentWidth) + '╯')}`;
18
+ const titlePad = Math.floor((contentWidth - title.length) / 2);
19
+ const titleRightPad = contentWidth - title.length - titlePad;
20
+ const titleLine = ` ${kleur_1.default.blue('│')}${' '.repeat(titlePad)}${kleur_1.default.bold().white(title)}${' '.repeat(titleRightPad)}${kleur_1.default.blue('│')}`;
21
+ const descPad = Math.floor((contentWidth - desc.length) / 2);
22
+ const descRightPad = contentWidth - desc.length - descPad;
23
+ const descLine = ` ${kleur_1.default.blue('│')}${' '.repeat(descPad)}${kleur_1.default.dim().white(desc)}${' '.repeat(descRightPad)}${kleur_1.default.blue('│')}`;
14
24
  console.log();
15
- console.log(` Location: ${kleur_1.default.cyan(targetDir)}`);
16
- console.log(` Template: ${templateName}`);
17
- console.log(` Blocks: ${blockCount} blocks`);
18
- console.log(` Integrations: ${integrationCount} integrations`);
25
+ console.log(topLine);
26
+ console.log(empty);
27
+ console.log(titleLine);
28
+ console.log(descLine);
29
+ console.log(empty);
30
+ console.log(bottomLine);
19
31
  console.log();
32
+ };
33
+ exports.printBanner = printBanner;
34
+ const printSummary = (targetDir, template, selectedBlocks, selectedIntegrations, uncoveredModules = [], skipInstall = false) => {
35
+ const templateName = templates_1.TEMPLATES[template].name;
36
+ const relativeDir = path_1.default.relative(process.cwd(), targetDir) || '.';
37
+ // Collect all content lines to measure max width
38
+ const lines = [];
39
+ const addLine = (text, plain) => {
40
+ lines.push({ text, plain });
41
+ };
42
+ const addEmpty = () => {
43
+ lines.push({ text: '', plain: '' });
44
+ };
45
+ addLine(` ${kleur_1.default.green().bold('Project created successfully!')}`, ' Project created successfully!');
46
+ addEmpty();
47
+ addLine(` Location: ${kleur_1.default.cyan(`./${relativeDir}`)}`, ` Location: ./${relativeDir}`);
48
+ addLine(` Template: ${templateName}`, ` Template: ${templateName}`);
49
+ addEmpty();
50
+ addLine(` ${kleur_1.default.bold('Blocks')} ${kleur_1.default.dim(`(${selectedBlocks.length})`)}`, ` Blocks (${selectedBlocks.length})`);
51
+ for (const block of selectedBlocks) {
52
+ addLine(` ${kleur_1.default.cyan('•')} ${block}`, ` • ${block}`);
53
+ }
54
+ addEmpty();
55
+ addLine(` ${kleur_1.default.bold('Integrations')} ${kleur_1.default.dim(`(${selectedIntegrations.length})`)}`, ` Integrations (${selectedIntegrations.length})`);
56
+ for (const integration of selectedIntegrations) {
57
+ addLine(` ${kleur_1.default.yellow('•')} ${integration}`, ` • ${integration}`);
58
+ }
20
59
  if (uncoveredModules.length > 0) {
21
- console.log(kleur_1.default.yellow().bold('⚠ Warning: the following modules have no integration assigned:'));
22
- console.log();
60
+ addEmpty();
61
+ addLine(` ${kleur_1.default.yellow().bold('⚠ Uncovered modules')}`, ' ⚠ Uncovered modules');
23
62
  for (const mod of uncoveredModules) {
24
- console.log(kleur_1.default.yellow(` - ${mod}`));
63
+ addLine(` ${kleur_1.default.red('•')} ${mod}`, ` • ${mod}`);
25
64
  }
26
- console.log();
27
- console.log(kleur_1.default.red(' The project will NOT start until these modules are configured.'));
28
- console.log(' To fix this, edit packages/configs/integrations/src/models/<module>.ts');
29
- console.log(' and replace the @o2s/integrations.mocked import with a real integration.');
30
- console.log();
31
- console.log(kleur_1.default.bold('Next steps:'));
32
- console.log();
33
- console.log(` cd ${targetDir}`);
34
- console.log(kleur_1.default.dim(' # 1. Configure the modules listed above'));
35
- console.log(kleur_1.default.dim(' # 2. Add the required env vars to apps/api-harmonization/.env.local'));
36
- console.log(kleur_1.default.dim(' # 3. npm run dev'));
65
+ addEmpty();
66
+ addLine(` ${kleur_1.default.red('The project will NOT start until these are configured.')}`, ' The project will NOT start until these are configured.');
67
+ addLine(` ${kleur_1.default.dim('Edit packages/configs/integrations/src/models/<module>.ts')}`, ' Edit packages/configs/integrations/src/models/<module>.ts');
68
+ }
69
+ addEmpty();
70
+ addLine(` ${kleur_1.default.bold('Next steps:')}`, ' Next steps:');
71
+ addEmpty();
72
+ addLine(` ${kleur_1.default.white(`cd ./${relativeDir}`)}`, ` cd ./${relativeDir}`);
73
+ if (uncoveredModules.length > 0) {
74
+ addLine(` ${kleur_1.default.dim('# 1. Configure the uncovered modules above')}`, ' # 1. Configure the uncovered modules above');
75
+ addLine(` ${kleur_1.default.dim('# 2. Add required env vars to apps/api-harmonization/.env.local')}`, ' # 2. Add required env vars to apps/api-harmonization/.env.local');
76
+ addLine(` ${kleur_1.default.dim('# 3. Start development (two terminals):')}`, ' # 3. Start development (two terminals):');
77
+ addLine(` ${kleur_1.default.dim('npm run watch:deps')}`, ' npm run watch:deps');
78
+ addLine(` ${kleur_1.default.dim('npm run watch:apps')}`, ' npm run watch:apps');
37
79
  }
38
80
  else {
39
- console.log(kleur_1.default.bold('Next steps:'));
40
- console.log();
41
- console.log(` cd ${targetDir}`);
42
81
  if (skipInstall) {
43
- console.log(kleur_1.default.dim(' # Install dependencies (npm install was skipped)'));
44
- console.log(' npm install');
82
+ addLine(` ${kleur_1.default.dim('# Install dependencies (npm install was skipped)')}`, ' # Install dependencies (npm install was skipped)');
83
+ addLine(' npm install', ' npm install');
45
84
  }
46
- console.log(' npm run dev');
85
+ addLine(` npm run watch:deps ${kleur_1.default.dim('# Terminal 1: watch & build packages')}`, ' npm run watch:deps # Terminal 1: watch & build packages');
86
+ addLine(` npm run watch:apps ${kleur_1.default.dim('# Terminal 2: run frontend + API')}`, ' npm run watch:apps # Terminal 2: run frontend + API');
47
87
  }
88
+ addEmpty();
89
+ addLine(` ${kleur_1.default.bold('Useful links:')}`, ' Useful links:');
90
+ addLine(` ${kleur_1.default.dim('Docs & installation:')} ${kleur_1.default.cyan(constants_1.DOCS_URL)}`, ` Docs & installation: ${constants_1.DOCS_URL}`);
91
+ addLine(` ${kleur_1.default.dim('Storybook (blocks):')} ${kleur_1.default.cyan(constants_1.STORYBOOK_URL)}`, ` Storybook (blocks): ${constants_1.STORYBOOK_URL}`);
92
+ addLine(` ${kleur_1.default.dim('Integrations guide:')} ${kleur_1.default.cyan(constants_1.DOCS_INTEGRATIONS_URL)}`, ` Integrations guide: ${constants_1.DOCS_INTEGRATIONS_URL}`);
93
+ // Calculate box width
94
+ const maxPlainWidth = Math.max(...lines.map((l) => l.plain.length));
95
+ const boxWidth = maxPlainWidth + 4; // 2 padding each side
96
+ // Print box
48
97
  console.log();
49
- console.log(kleur_1.default.bold('Documentation:'));
50
- console.log(kleur_1.default.cyan(` ${constants_1.DOCS_URL}`));
98
+ console.log(` ${kleur_1.default.blue('╭' + '─'.repeat(boxWidth) + '╮')}`);
99
+ for (const line of lines) {
100
+ const rightPad = boxWidth - line.plain.length;
101
+ console.log(` ${kleur_1.default.blue('│')}${line.text}${' '.repeat(rightPad)}${kleur_1.default.blue('│')}`);
102
+ }
103
+ console.log(` ${kleur_1.default.blue('╰' + '─'.repeat(boxWidth) + '╯')}`);
51
104
  console.log();
52
105
  };
53
106
  exports.printSummary = printSummary;
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/wizard/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKnF,eAAO,MAAM,iBAAiB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,MAAM,CAa3E,CAAC;AAEF,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,YAAY,CAiB3D,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,iBAAiB,SAAS,EAAE,EAAE,aAAa,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,EAAE,CAqBhH,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACnC,uBAAuB,eAAe,EAAE,EACxC,aAAa,MAAM,EAAE,KACtB,OAAO,CAAC,MAAM,EAAE,CAgBlB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GACzB,iBAAiB,SAAS,EAAE,EAC5B,uBAAuB,eAAe,EAAE,EACxC,UAAU,MAAM,EAChB,cAAc,YAAY,KAC3B,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CA6BnD,CAAC"}
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/wizard/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKnF,eAAO,MAAM,iBAAiB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,MAAM,CAa3E,CAAC;AAEF,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,YAAY,CAiB3D,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,iBAAiB,SAAS,EAAE,EAAE,aAAa,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,EAAE,CAqBhH,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACnC,uBAAuB,eAAe,EAAE,EACxC,aAAa,MAAM,EAAE,KACtB,OAAO,CAAC,MAAM,EAAE,CAgBlB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GACzB,iBAAiB,SAAS,EAAE,EAC5B,uBAAuB,eAAe,EAAE,EACxC,UAAU,MAAM,EAChB,cAAc,YAAY,KAC3B,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAiDnD,CAAC"}
@@ -82,10 +82,19 @@ const runWizardPrompts = async (availableBlocks, availableIntegrations, cliName,
82
82
  let selectedBlocks;
83
83
  let selectedIntegrations;
84
84
  if (template === 'custom') {
85
+ const tipLines = [
86
+ `${kleur_1.default.blue().bold('Tip:')} Not sure which blocks to pick?`,
87
+ `Browse our Storybook to preview all available components:`,
88
+ kleur_1.default.cyan(constants_1.STORYBOOK_URL),
89
+ ];
90
+ const tipWidth = Math.max('Tip: Not sure which blocks to pick?'.length, 'Browse our Storybook to preview all available components:'.length, constants_1.STORYBOOK_URL.length);
91
+ const boxWidth = tipWidth + 4;
85
92
  console.log();
86
- console.log(kleur_1.default.cyan().bold(' Tip:') + ' Not sure which blocks to pick?');
87
- console.log(` Browse our Storybook to preview all available components:`);
88
- console.log(kleur_1.default.cyan(` ${constants_1.STORYBOOK_URL}`));
93
+ console.log(` ${kleur_1.default.blue('╭' + '─'.repeat(boxWidth) + '╮')}`);
94
+ console.log(` ${kleur_1.default.blue('│')} ${tipLines[0]}${' '.repeat(boxWidth - 2 - 'Tip: Not sure which blocks to pick?'.length)}${kleur_1.default.blue('│')}`);
95
+ console.log(` ${kleur_1.default.blue('│')} ${tipLines[1]}${' '.repeat(boxWidth - 2 - 'Browse our Storybook to preview all available components:'.length)}${kleur_1.default.blue('│')}`);
96
+ console.log(` ${kleur_1.default.blue('│')} ${tipLines[2]}${' '.repeat(boxWidth - 2 - constants_1.STORYBOOK_URL.length)}${kleur_1.default.blue('│')}`);
97
+ console.log(` ${kleur_1.default.blue('╰' + '─'.repeat(boxWidth) + '╯')}`);
89
98
  console.log();
90
99
  selectedBlocks = await (0, exports.promptBlockSelection)(availableBlocks, []);
91
100
  selectedIntegrations = await (0, exports.promptIntegrationSelection)(availableIntegrations, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-o2s-app",
3
- "version": "3.0.0",
3
+ "version": "4.1.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "CLI tool to scaffold new O2S applications with Next.js and NestJS setup.",
@@ -32,7 +32,7 @@
32
32
  "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,json}\""
33
33
  },
34
34
  "dependencies": {
35
- "@o2s/telemetry": "^1.2.1",
35
+ "@o2s/telemetry": "^1.2.2",
36
36
  "@types/prompts": "^2.4.9",
37
37
  "cli-progress": "^3.12.0",
38
38
  "commander": "^14.0.3",
@@ -49,7 +49,7 @@
49
49
  "@o2s/typescript-config": "*",
50
50
  "@types/cli-progress": "^3.11.6",
51
51
  "@types/fs-extra": "^11.0.4",
52
- "eslint": "^9.39.3",
52
+ "eslint": "^9.39.4",
53
53
  "prettier": "^3.8.1",
54
54
  "typescript": "^5.9.3"
55
55
  }
package/src/constants.ts CHANGED
@@ -4,7 +4,8 @@ export const GITHUB_REPO_URL = 'https://github.com/o2sdev/openselfservice';
4
4
  export const GITHUB_BRANCH = 'create-o2s-app/base';
5
5
  export const PROJECT_PREFIX = 'o2s';
6
6
  export const STORYBOOK_URL = 'https://storybook-o2s.openselfservice.com/';
7
- export const DOCS_URL = 'https://docs.openselfservice.com/getting-started';
7
+ export const DOCS_URL = 'https://www.openselfservice.com/docs/getting-started/installation';
8
+ export const DOCS_INTEGRATIONS_URL = 'https://www.openselfservice.com/docs/integrations';
8
9
 
9
10
  export const BLOCKS_PATH = 'packages/blocks';
10
11
  export const INTEGRATIONS_PATH = 'packages/integrations';
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { cleanupTempDir, cloneRepository } from './scaffold/clone';
3
3
  import { scaffold } from './scaffold/index';
4
4
  import { TemplateType } from './types';
5
- import { printError, printSummary } from './utils/logger';
5
+ import { printBanner, printError, printSummary } from './utils/logger';
6
6
  import { runWizard } from './wizard/index';
7
7
  import * as telemetry from '@o2s/telemetry';
8
8
  import { Command } from 'commander';
@@ -11,7 +11,7 @@ const program = new Command();
11
11
 
12
12
  program
13
13
  .name('create-o2s-app')
14
- .description('Create a new O2S project with interactive setup wizard')
14
+ .description('Scaffold your custom frontend')
15
15
  .argument('[name]', 'Name of the new project')
16
16
  .option('--directory [directory]', 'Specify the destination directory')
17
17
  .option('--template [template]', 'Template: o2s | dxp | custom')
@@ -19,6 +19,8 @@ program
19
19
  .option('--integrations [integrations]', 'Comma-separated list of integration names (for non-interactive mode)')
20
20
  .option('--skip-install', 'Skip npm install step')
21
21
  .action(async (name, options) => {
22
+ printBanner();
23
+
22
24
  telemetry.sendEvent('o2s', 'create-o2s-app', 'create-project');
23
25
  await telemetry.flushEvents();
24
26
 
@@ -51,8 +53,8 @@ program
51
53
  printSummary(
52
54
  targetDir,
53
55
  answers.template,
54
- answers.selectedBlocks.length,
55
- answers.selectedIntegrations.length,
56
+ answers.selectedBlocks,
57
+ answers.selectedIntegrations,
56
58
  uncoveredModules,
57
59
  options.skipInstall,
58
60
  );
@@ -1,3 +1,4 @@
1
+ import { INTEGRATIONS_PATH } from '../constants';
1
2
  import { WizardAnswers } from '../types';
2
3
  import { cleanupProject } from './cleanup';
3
4
  import { generateEnvFiles } from './generate-env';
@@ -12,6 +13,33 @@ import { transformRenderBlocks } from './transform-render-blocks';
12
13
  import * as fs from 'fs-extra';
13
14
  import * as path from 'path';
14
15
 
16
+ const readIntegrationVersions = async (
17
+ projectDir: string,
18
+ selectedIntegrations: string[],
19
+ ): Promise<Record<string, string>> => {
20
+ const versions: Record<string, string> = {};
21
+
22
+ for (const name of selectedIntegrations) {
23
+ const pkgPath = path.join(projectDir, INTEGRATIONS_PATH, name, 'package.json');
24
+
25
+ if (!(await fs.pathExists(pkgPath))) {
26
+ throw new Error(
27
+ `Integration "${name}" not found at expected path: ${pkgPath}. Ensure the integration exists in the template.`,
28
+ );
29
+ }
30
+
31
+ const pkg = await fs.readJson(pkgPath);
32
+
33
+ if (!pkg.version) {
34
+ throw new Error(`Integration "${name}" has no version field in ${pkgPath}.`);
35
+ }
36
+
37
+ versions[name] = pkg.version;
38
+ }
39
+
40
+ return versions;
41
+ };
42
+
15
43
  export const scaffold = async (
16
44
  tempDir: string,
17
45
  answers: WizardAnswers,
@@ -33,10 +61,13 @@ export const scaffold = async (
33
61
  console.log(`Creating project in "${targetDir}"...`);
34
62
  await fs.move(tempDir, targetDir);
35
63
 
36
- // Step 2: Remove unneeded directories (all packages/* are removed; deps come from npm registry)
64
+ // Step 2: Read integration versions before cleanup removes the source directories
65
+ const integrationVersions = await readIntegrationVersions(targetDir, selectedIntegrations);
66
+
67
+ // Step 3: Remove unneeded directories (all packages/* are removed; deps come from npm registry)
37
68
  await cleanupProject(targetDir);
38
69
 
39
- // Step 3: Remove unselected block/integration references from app source files
70
+ // Step 4: Remove unselected block/integration references from app source files
40
71
  console.log('Configuring project for selected blocks...');
41
72
  await Promise.all([
42
73
  transformAppModule(targetDir, selectedBlocks),
@@ -45,24 +76,25 @@ export const scaffold = async (
45
76
  transformAppsPackageJson(targetDir, selectedBlocks, selectedIntegrations),
46
77
  ]);
47
78
 
48
- // Step 4: Clean up root package.json (remove workspace entries for deleted dirs)
79
+ // Step 5: Clean up root package.json (remove workspace entries for deleted dirs)
49
80
  await transformRootPackageJson(targetDir);
50
81
 
51
- // Step 5: Configure integration source files and generate environment
82
+ // Step 6: Configure integration source files and generate environment
52
83
  console.log('Configuring integrations...');
53
84
  const uncoveredModules = await transformIntegrationConfigs(
54
85
  targetDir,
55
86
  selectedIntegrations,
56
87
  conflictResolutions,
57
88
  integrationModules,
89
+ integrationVersions,
58
90
  );
59
91
  await generateEnvFiles(targetDir, envVars, selectedIntegrations);
60
92
  warnUnconfiguredModules(uncoveredModules);
61
93
 
62
- // Step 6: Clean symlinks from package-lock.json and install dependencies
63
- await cleanPackageLock(targetDir);
94
+ // Step 7: Clean symlinks from package-lock.json and install dependencies
95
+ await cleanPackageLock(targetDir, selectedIntegrations);
64
96
  if (!skipInstall) {
65
- await installDependencies(targetDir);
97
+ await installDependencies(targetDir, selectedIntegrations);
66
98
  }
67
99
 
68
100
  return { targetDir, uncoveredModules };
@@ -1,13 +1,18 @@
1
+ import { ALWAYS_REMOVE_DIRS } from '../constants';
1
2
  import { execSync } from 'child_process';
2
3
  import * as fs from 'fs-extra';
3
4
  import * as path from 'path';
4
5
 
5
6
  /**
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.
7
+ * Clean package-lock.json by removing:
8
+ * - Local workspace symlink entries ("link": true)
9
+ * - Entries for directories removed during cleanup (packages/blocks/*, packages/integrations/*, etc.)
10
+ * - References to unselected integrations in nested dependency lists
11
+ *
12
+ * Without this, npm install would either recreate empty folders for removed
13
+ * workspace packages or install unselected integrations from the registry.
9
14
  */
10
- export const cleanPackageLock = async (projectDir: string): Promise<void> => {
15
+ export const cleanPackageLock = async (projectDir: string, selectedIntegrations: string[]): Promise<void> => {
11
16
  const lockFilePath = path.join(projectDir, 'package-lock.json');
12
17
 
13
18
  if (!(await fs.pathExists(lockFilePath))) return;
@@ -15,10 +20,43 @@ export const cleanPackageLock = async (projectDir: string): Promise<void> => {
15
20
  const file = await fs.readFile(lockFilePath, 'utf8');
16
21
  const json = JSON.parse(file);
17
22
 
23
+ const isUnselectedIntegration = (name: string): boolean => {
24
+ const match = name.match(/^@o2s\/integrations\.(.+)$/);
25
+ return !!match && !!match[1] && !selectedIntegrations.includes(match[1]);
26
+ };
27
+
28
+ const isRemovedDir = (key: string): boolean => {
29
+ return ALWAYS_REMOVE_DIRS.some((dir) => key === dir || key.startsWith(`${dir}/`));
30
+ };
31
+
18
32
  if (json?.packages) {
19
33
  for (const [key, value] of Object.entries(json.packages)) {
20
- if (value && typeof value === 'object' && (value as { link?: boolean }).link) {
34
+ if (!value || typeof value !== 'object') continue;
35
+ const entry = value as Record<string, unknown>;
36
+
37
+ // Remove local workspace symlinks
38
+ if (entry.link) {
39
+ delete json.packages[key];
40
+ continue;
41
+ }
42
+
43
+ // Remove stale entries: deleted directories and workspace packages
44
+ // whose package.json was modified during scaffolding.
45
+ // npm install will regenerate correct entries from the actual files on disk.
46
+ if (isRemovedDir(key) || key.startsWith('packages/')) {
21
47
  delete json.packages[key];
48
+ continue;
49
+ }
50
+
51
+ // Remove unselected integrations from nested dependencies
52
+ for (const section of ['dependencies', 'devDependencies'] as const) {
53
+ const deps = entry[section] as Record<string, string> | undefined;
54
+ if (!deps) continue;
55
+ for (const depName of Object.keys(deps)) {
56
+ if (isUnselectedIntegration(depName)) {
57
+ delete deps[depName];
58
+ }
59
+ }
22
60
  }
23
61
  }
24
62
  }
@@ -26,8 +64,8 @@ export const cleanPackageLock = async (projectDir: string): Promise<void> => {
26
64
  await fs.writeFile(lockFilePath, JSON.stringify(json, null, 4));
27
65
  };
28
66
 
29
- export const installDependencies = async (projectDir: string): Promise<void> => {
30
- await cleanPackageLock(projectDir);
67
+ export const installDependencies = async (projectDir: string, selectedIntegrations: string[]): Promise<void> => {
68
+ await cleanPackageLock(projectDir, selectedIntegrations);
31
69
 
32
70
  console.log();
33
71
  console.log('Installing dependencies...');
@@ -31,15 +31,23 @@ const buildModuleIntegrationMap = (
31
31
  return moduleMap;
32
32
  };
33
33
 
34
- const updateConfigsPackageJson = async (projectDir: string, selectedIntegrations: string[]): Promise<void> => {
34
+ const updateConfigsPackageJson = async (
35
+ projectDir: string,
36
+ selectedIntegrations: string[],
37
+ integrationVersions: Record<string, string>,
38
+ ): Promise<void> => {
35
39
  const pkgPath = path.join(projectDir, CONFIGS_PACKAGE_JSON_PATH);
36
40
 
37
41
  if (!(await fs.pathExists(pkgPath))) return;
38
42
 
39
43
  const pkg = await fs.readJson(pkgPath);
40
44
 
45
+ if (!pkg.dependencies) {
46
+ pkg.dependencies = {};
47
+ }
48
+
41
49
  // Remove integration deps that were not selected
42
- for (const key of Object.keys((pkg.dependencies || {}) as Record<string, string>)) {
50
+ for (const key of Object.keys(pkg.dependencies as Record<string, string>)) {
43
51
  if (key.startsWith('@o2s/integrations.')) {
44
52
  const name = key.replace('@o2s/integrations.', '');
45
53
  if (!selectedIntegrations.includes(name)) {
@@ -48,6 +56,17 @@ const updateConfigsPackageJson = async (projectDir: string, selectedIntegrations
48
56
  }
49
57
  }
50
58
 
59
+ // Add selected integrations that are not yet in dependencies
60
+ for (const name of selectedIntegrations) {
61
+ const packageName = `@o2s/integrations.${name}`;
62
+ if (!pkg.dependencies[packageName]) {
63
+ const version = integrationVersions[name];
64
+ if (version) {
65
+ pkg.dependencies[packageName] = `^${version}`;
66
+ }
67
+ }
68
+ }
69
+
51
70
  await fs.writeJson(pkgPath, pkg, { spaces: 4 });
52
71
  };
53
72
 
@@ -56,12 +75,10 @@ export const transformIntegrationConfigs = async (
56
75
  selectedIntegrations: string[],
57
76
  conflictResolutions: ConflictResolution[],
58
77
  integrationModules: Record<string, string[]>,
78
+ integrationVersions: Record<string, string>,
59
79
  ): Promise<string[]> => {
60
- const moduleMap = buildModuleIntegrationMap(selectedIntegrations, conflictResolutions, integrationModules);
61
-
62
- if (moduleMap.size === 0) {
63
- return [];
64
- }
80
+ // Always update configs package.json to add/remove integration dependencies
81
+ await updateConfigsPackageJson(projectDir, selectedIntegrations, integrationVersions);
65
82
 
66
83
  const modelsDir = path.join(projectDir, CONFIGS_MODELS_PATH);
67
84
 
@@ -69,6 +86,9 @@ export const transformIntegrationConfigs = async (
69
86
  return [];
70
87
  }
71
88
 
89
+ // Replace mocked imports with selected integration imports
90
+ const moduleMap = buildModuleIntegrationMap(selectedIntegrations, conflictResolutions, integrationModules);
91
+
72
92
  for (const [module, integration] of moduleMap.entries()) {
73
93
  const filePath = path.join(modelsDir, `${module}.ts`);
74
94
 
@@ -80,8 +100,6 @@ export const transformIntegrationConfigs = async (
80
100
  await fs.writeFile(filePath, updatedContent, 'utf-8');
81
101
  }
82
102
 
83
- await updateConfigsPackageJson(projectDir, selectedIntegrations);
84
-
85
103
  // Detect model files that still import mocked but mocked is not selected.
86
104
  // Skip only when 'mocked' (full) is selected — it covers all modules.
87
105
  // 'mocked-dxp' covers only cms/articles/search, so uncovered detection runs normally.