create-o2s-app 2.0.0 → 4.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.
@@ -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;AAIxC,eAAO,MAAM,YAAY,GACrB,WAAW,MAAM,EACjB,UAAU,YAAY,EACtB,YAAY,MAAM,EAClB,kBAAkB,MAAM,EACxB,mBAAkB,MAAM,EAAO,EAC/B,qBAAmB,KACpB,IA+CF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,KAAG,IAS7D,CAAC"}
@@ -33,7 +33,9 @@ const printSummary = (targetDir, template, blockCount, integrationCount, uncover
33
33
  console.log(` cd ${targetDir}`);
34
34
  console.log(kleur_1.default.dim(' # 1. Configure the modules listed above'));
35
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'));
36
+ console.log(kleur_1.default.dim(' # 3. Start development (in two separate terminals):'));
37
+ console.log(kleur_1.default.dim(' # npm run watch:deps'));
38
+ console.log(kleur_1.default.dim(' # npm run watch:apps'));
37
39
  }
38
40
  else {
39
41
  console.log(kleur_1.default.bold('Next steps:'));
@@ -43,7 +45,8 @@ const printSummary = (targetDir, template, blockCount, integrationCount, uncover
43
45
  console.log(kleur_1.default.dim(' # Install dependencies (npm install was skipped)'));
44
46
  console.log(' npm install');
45
47
  }
46
- console.log(' npm run dev');
48
+ console.log(' npm run watch:deps ' + kleur_1.default.dim('# Terminal 1: watch & build packages'));
49
+ console.log(' npm run watch:apps ' + kleur_1.default.dim('# Terminal 2: run frontend + API'));
47
50
  }
48
51
  console.log();
49
52
  console.log(kleur_1.default.bold('Documentation:'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-o2s-app",
3
- "version": "2.0.0",
3
+ "version": "4.0.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.",
package/src/constants.ts CHANGED
@@ -15,7 +15,9 @@ export const ALWAYS_REMOVE_DIRS: string[] = [
15
15
  '.github',
16
16
  '.changeset',
17
17
  'apps/docs',
18
+ 'packages/blocks',
18
19
  'packages/framework',
20
+ 'packages/integrations',
19
21
  'packages/modules',
20
22
  'packages/utils',
21
23
  'packages/cli',
@@ -1,20 +1,10 @@
1
- import { ALWAYS_REMOVE_DIRS, ALWAYS_REMOVE_FILES, BLOCKS_PATH, INTEGRATIONS_PATH } from '../constants';
1
+ import { ALWAYS_REMOVE_DIRS, ALWAYS_REMOVE_FILES } from '../constants';
2
2
  import * as fs from 'fs-extra';
3
3
  import * as path from 'path';
4
4
 
5
- export const cleanupProject = async (
6
- projectDir: string,
7
- selectedBlockNames: string[],
8
- selectedIntegrationNames: string[],
9
- ): Promise<void> => {
5
+ export const cleanupProject = async (projectDir: string): Promise<void> => {
10
6
  console.log('Organizing project structure...');
11
7
 
12
- await removeAlwaysRemovedPaths(projectDir);
13
- await removeUnselectedBlocks(projectDir, selectedBlockNames);
14
- await removeUnselectedIntegrations(projectDir, selectedIntegrationNames);
15
- };
16
-
17
- const removeAlwaysRemovedPaths = async (projectDir: string): Promise<void> => {
18
8
  for (const dir of ALWAYS_REMOVE_DIRS) {
19
9
  const fullPath = path.join(projectDir, dir);
20
10
  if (await fs.pathExists(fullPath)) {
@@ -29,35 +19,3 @@ const removeAlwaysRemovedPaths = async (projectDir: string): Promise<void> => {
29
19
  }
30
20
  }
31
21
  };
32
-
33
- const removeUnselectedBlocks = async (projectDir: string, selectedBlockNames: string[]): Promise<void> => {
34
- const blocksDir = path.join(projectDir, BLOCKS_PATH);
35
-
36
- if (!(await fs.pathExists(blocksDir))) return;
37
-
38
- const entries = await fs.readdir(blocksDir, { withFileTypes: true });
39
-
40
- for (const entry of entries) {
41
- if (!entry.isDirectory()) continue;
42
-
43
- if (!selectedBlockNames.includes(entry.name)) {
44
- await fs.remove(path.join(blocksDir, entry.name));
45
- }
46
- }
47
- };
48
-
49
- const removeUnselectedIntegrations = async (projectDir: string, selectedIntegrationNames: string[]): Promise<void> => {
50
- const integrationsDir = path.join(projectDir, INTEGRATIONS_PATH);
51
-
52
- if (!(await fs.pathExists(integrationsDir))) return;
53
-
54
- const entries = await fs.readdir(integrationsDir, { withFileTypes: true });
55
-
56
- for (const entry of entries) {
57
- if (!entry.isDirectory()) continue;
58
-
59
- if (!selectedIntegrationNames.includes(entry.name)) {
60
- await fs.remove(path.join(integrationsDir, entry.name));
61
- }
62
- }
63
- };
@@ -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
37
- await cleanupProject(targetDir, selectedBlocks, selectedIntegrations);
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)
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...');
@@ -3,6 +3,16 @@ import * as path from 'path';
3
3
 
4
4
  const APP_PACKAGE_JSON_PATHS = ['apps/api-harmonization/package.json', 'apps/frontend/package.json'];
5
5
 
6
+ // Private workspace-only packages that are not published to npm and should be
7
+ // removed from scaffolded projects (they are part of the monorepo dev setup).
8
+ const PRIVATE_PACKAGES = [
9
+ '@o2s/eslint-config',
10
+ '@o2s/lint-staged-config',
11
+ '@o2s/prettier-config',
12
+ '@o2s/typescript-config',
13
+ '@o2s/vitest-config',
14
+ ];
15
+
6
16
  export const transformAppsPackageJson = async (
7
17
  projectDir: string,
8
18
  selectedBlockNames: string[],
@@ -15,21 +25,31 @@ export const transformAppsPackageJson = async (
15
25
 
16
26
  const packageJson = await fs.readJson(filePath);
17
27
 
18
- if (packageJson.dependencies) {
19
- for (const depName of Object.keys(packageJson.dependencies)) {
28
+ for (const section of ['dependencies', 'devDependencies'] as const) {
29
+ if (!packageJson[section]) continue;
30
+
31
+ for (const depName of Object.keys(packageJson[section])) {
32
+ // Remove private workspace-only packages
33
+ if (PRIVATE_PACKAGES.includes(depName)) {
34
+ delete packageJson[section][depName];
35
+ continue;
36
+ }
37
+
38
+ // Remove unselected blocks
20
39
  const blockMatch = depName.match(/^@o2s\/blocks\.(.+)$/);
21
40
  if (blockMatch && blockMatch[1] && !selectedBlockNames.includes(blockMatch[1])) {
22
- delete packageJson.dependencies[depName];
41
+ delete packageJson[section][depName];
23
42
  continue;
24
43
  }
25
44
 
45
+ // Remove unselected integrations
26
46
  const integrationMatch = depName.match(/^@o2s\/integrations\.(.+)$/);
27
47
  if (
28
48
  integrationMatch &&
29
49
  integrationMatch[1] &&
30
50
  !selectedIntegrationNames.includes(integrationMatch[1])
31
51
  ) {
32
- delete packageJson.dependencies[depName];
52
+ delete packageJson[section][depName];
33
53
  }
34
54
  }
35
55
  }
@@ -34,7 +34,7 @@ const buildModuleIntegrationMap = (
34
34
  const updateConfigsPackageJson = async (
35
35
  projectDir: string,
36
36
  selectedIntegrations: string[],
37
- integrationModules: Record<string, string[]>,
37
+ integrationVersions: Record<string, string>,
38
38
  ): Promise<void> => {
39
39
  const pkgPath = path.join(projectDir, CONFIGS_PACKAGE_JSON_PATH);
40
40
 
@@ -42,8 +42,12 @@ const updateConfigsPackageJson = async (
42
42
 
43
43
  const pkg = await fs.readJson(pkgPath);
44
44
 
45
+ if (!pkg.dependencies) {
46
+ pkg.dependencies = {};
47
+ }
48
+
45
49
  // Remove integration deps that were not selected
46
- 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>)) {
47
51
  if (key.startsWith('@o2s/integrations.')) {
48
52
  const name = key.replace('@o2s/integrations.', '');
49
53
  if (!selectedIntegrations.includes(name)) {
@@ -52,10 +56,14 @@ const updateConfigsPackageJson = async (
52
56
  }
53
57
  }
54
58
 
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
+ // 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
+ }
59
67
  }
60
68
  }
61
69
 
@@ -67,12 +75,10 @@ export const transformIntegrationConfigs = async (
67
75
  selectedIntegrations: string[],
68
76
  conflictResolutions: ConflictResolution[],
69
77
  integrationModules: Record<string, string[]>,
78
+ integrationVersions: Record<string, string>,
70
79
  ): Promise<string[]> => {
71
- const moduleMap = buildModuleIntegrationMap(selectedIntegrations, conflictResolutions, integrationModules);
72
-
73
- if (moduleMap.size === 0) {
74
- return [];
75
- }
80
+ // Always update configs package.json to add/remove integration dependencies
81
+ await updateConfigsPackageJson(projectDir, selectedIntegrations, integrationVersions);
76
82
 
77
83
  const modelsDir = path.join(projectDir, CONFIGS_MODELS_PATH);
78
84
 
@@ -80,6 +86,9 @@ export const transformIntegrationConfigs = async (
80
86
  return [];
81
87
  }
82
88
 
89
+ // Replace mocked imports with selected integration imports
90
+ const moduleMap = buildModuleIntegrationMap(selectedIntegrations, conflictResolutions, integrationModules);
91
+
83
92
  for (const [module, integration] of moduleMap.entries()) {
84
93
  const filePath = path.join(modelsDir, `${module}.ts`);
85
94
 
@@ -91,8 +100,6 @@ export const transformIntegrationConfigs = async (
91
100
  await fs.writeFile(filePath, updatedContent, 'utf-8');
92
101
  }
93
102
 
94
- await updateConfigsPackageJson(projectDir, selectedIntegrations, integrationModules);
95
-
96
103
  // Detect model files that still import mocked but mocked is not selected.
97
104
  // Skip only when 'mocked' (full) is selected — it covers all modules.
98
105
  // 'mocked-dxp' covers only cms/articles/search, so uncovered detection runs normally.
@@ -38,7 +38,9 @@ export const printSummary = (
38
38
  console.log(` cd ${targetDir}`);
39
39
  console.log(kleur.dim(' # 1. Configure the modules listed above'));
40
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'));
41
+ console.log(kleur.dim(' # 3. Start development (in two separate terminals):'));
42
+ console.log(kleur.dim(' # npm run watch:deps'));
43
+ console.log(kleur.dim(' # npm run watch:apps'));
42
44
  } else {
43
45
  console.log(kleur.bold('Next steps:'));
44
46
  console.log();
@@ -47,7 +49,8 @@ export const printSummary = (
47
49
  console.log(kleur.dim(' # Install dependencies (npm install was skipped)'));
48
50
  console.log(' npm install');
49
51
  }
50
- console.log(' npm run dev');
52
+ console.log(' npm run watch:deps ' + kleur.dim('# Terminal 1: watch & build packages'));
53
+ console.log(' npm run watch:apps ' + kleur.dim('# Terminal 2: run frontend + API'));
51
54
  }
52
55
 
53
56
  console.log();