create-o2s-app 4.1.1 → 4.1.2

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/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type TemplateType = 'o2s' | 'dxp' | 'custom';
2
2
  export interface BlockInfo {
3
3
  name: string;
4
+ domain?: string;
4
5
  packageName: string;
5
6
  description: string;
6
7
  category: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"block-discovery.d.ts","sourceRoot":"","sources":["../../src/utils/block-discovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAUrC,eAAO,MAAM,cAAc,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,SAAS,EAAE,CA2BzE,CAAC"}
1
+ {"version":3,"file":"block-discovery.d.ts","sourceRoot":"","sources":["../../src/utils/block-discovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAUrC,eAAO,MAAM,cAAc,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,SAAS,EAAE,CAoCzE,CAAC"}
@@ -37,26 +37,34 @@ exports.discoverBlocks = void 0;
37
37
  const constants_1 = require("../constants");
38
38
  const templates_1 = require("../wizard/templates");
39
39
  const fs = __importStar(require("fs-extra"));
40
- const path = __importStar(require("path"));
40
+ const path = __importStar(require("node:path"));
41
41
  const discoverBlocks = async (repoDir) => {
42
42
  try {
43
43
  const blocksDir = path.join(repoDir, constants_1.BLOCKS_PATH);
44
- const entries = await fs.readdir(blocksDir, { withFileTypes: true });
44
+ const domainEntries = await fs.readdir(blocksDir, { withFileTypes: true });
45
45
  const blocks = [];
46
- for (const entry of entries) {
47
- if (!entry.isDirectory())
46
+ for (const domainEntry of domainEntries) {
47
+ if (!domainEntry.isDirectory())
48
48
  continue;
49
- const blockName = entry.name;
50
- const packageJson = await readBlockPackageJson(repoDir, blockName);
51
- blocks.push({
52
- name: blockName,
53
- packageName: `@o2s/blocks.${blockName}`,
54
- description: packageJson.description || `Block: ${blockName}`,
55
- // Fallback to all templates when o2sTemplate is not declared
56
- category: packageJson.o2sTemplate ?? (0, templates_1.getAllTemplateCategories)(),
57
- });
49
+ const domainDirPath = path.join(blocksDir, domainEntry.name);
50
+ const blockEntries = await fs.readdir(domainDirPath, { withFileTypes: true });
51
+ for (const blockEntry of blockEntries) {
52
+ if (!blockEntry.isDirectory())
53
+ continue;
54
+ const blockName = blockEntry.name;
55
+ const blockPath = path.join(domainEntry.name, blockName);
56
+ const packageJson = await readBlockPackageJson(repoDir, blockPath);
57
+ blocks.push({
58
+ name: blockName,
59
+ domain: domainEntry.name,
60
+ packageName: `@o2s/blocks.${blockName}`,
61
+ description: packageJson.description || `Block: ${blockName}`,
62
+ // Fallback to all templates when o2sTemplate is not declared
63
+ category: packageJson.o2sTemplate ?? (0, templates_1.getAllTemplateCategories)(),
64
+ });
65
+ }
58
66
  }
59
- return blocks.sort((a, b) => a.name.localeCompare(b.name));
67
+ return blocks.sort((a, b) => `${a.domain ?? ''}/${a.name}`.localeCompare(`${b.domain ?? ''}/${b.name}`));
60
68
  }
61
69
  catch (error) {
62
70
  console.error('Error fetching the block list:', error);
@@ -64,16 +72,16 @@ const discoverBlocks = async (repoDir) => {
64
72
  }
65
73
  };
66
74
  exports.discoverBlocks = discoverBlocks;
67
- const readBlockPackageJson = async (repoDir, blockName) => {
75
+ const readBlockPackageJson = async (repoDir, blockPath) => {
68
76
  try {
69
- const packageJsonPath = path.join(repoDir, constants_1.BLOCKS_PATH, blockName, 'package.json');
77
+ const packageJsonPath = path.join(repoDir, constants_1.BLOCKS_PATH, blockPath, 'package.json');
70
78
  if (await fs.pathExists(packageJsonPath)) {
71
79
  return await fs.readJson(packageJsonPath);
72
80
  }
73
81
  return {};
74
82
  }
75
83
  catch (error) {
76
- console.warn(`Warning: Could not read package.json for block "${blockName}":`, error);
84
+ console.warn(`Warning: Could not read package.json for block "${blockPath}":`, error);
77
85
  return {};
78
86
  }
79
87
  };
@@ -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,CAiDnD,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;AA+JnF,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,CA8ChH,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"}
@@ -8,6 +8,120 @@ const constants_1 = require("../constants");
8
8
  const templates_1 = require("./templates");
9
9
  const kleur_1 = __importDefault(require("kleur"));
10
10
  const prompts_1 = __importDefault(require("prompts"));
11
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
12
+ const LibMultiselectPrompt = require('prompts/lib/elements/multiselect');
13
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
14
+ const DistMultiselectPrompt = require('prompts/dist/elements/multiselect');
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
16
+ const LibFigures = require('prompts/lib/util/figures');
17
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
18
+ const DistFigures = require('prompts/dist/util/figures');
19
+ const DOMAIN_CHOICE_PREFIX = '__domain__:';
20
+ const BLOCK_CHOICE_PREFIX = '__block__:';
21
+ let isDomainTogglePatchApplied = false;
22
+ let isMultiselectVisualPatchApplied = false;
23
+ const parseDomainFromBlockValue = (value) => {
24
+ if (!value.startsWith(BLOCK_CHOICE_PREFIX))
25
+ return undefined;
26
+ const encoded = value.slice(BLOCK_CHOICE_PREFIX.length);
27
+ const separatorIndex = encoded.indexOf(':');
28
+ if (separatorIndex < 0)
29
+ return undefined;
30
+ return encoded.slice(0, separatorIndex);
31
+ };
32
+ const buildBlockValue = (domain, blockName) => `${BLOCK_CHOICE_PREFIX}${domain}:${blockName}`;
33
+ const parseBlockNameFromValue = (value) => {
34
+ const encoded = value.slice(BLOCK_CHOICE_PREFIX.length);
35
+ const separatorIndex = encoded.indexOf(':');
36
+ return separatorIndex < 0 ? encoded : encoded.slice(separatorIndex + 1);
37
+ };
38
+ const syncDomainSelectionState = (ctx, domainName) => {
39
+ const domainChoice = ctx.value.find((choice) => choice.value === `${DOMAIN_CHOICE_PREFIX}${domainName}`);
40
+ if (!domainChoice)
41
+ return;
42
+ const blocksInDomain = ctx.value.filter((choice) => choice.value.startsWith(`${BLOCK_CHOICE_PREFIX}${domainName}:`) && !choice.disabled);
43
+ domainChoice.selected = blocksInDomain.length > 0 && blocksInDomain.every((choice) => choice.selected);
44
+ };
45
+ const patchMultiselectDomainToggle = () => {
46
+ if (isDomainTogglePatchApplied)
47
+ return;
48
+ const patchOne = (PromptClass) => {
49
+ const originalHandleSpaceToggle = PromptClass.prototype.handleSpaceToggle;
50
+ PromptClass.prototype.handleSpaceToggle = function patchedHandleSpaceToggle() {
51
+ const currentChoice = this.value[this.cursor];
52
+ if (!currentChoice)
53
+ return;
54
+ if (currentChoice.value.startsWith(DOMAIN_CHOICE_PREFIX)) {
55
+ const domainName = currentChoice.value.slice(DOMAIN_CHOICE_PREFIX.length);
56
+ const blockChoices = this.value.filter((choice) => choice.value.startsWith(`${BLOCK_CHOICE_PREFIX}${domainName}:`) && !choice.disabled);
57
+ const shouldSelectAll = !currentChoice.selected;
58
+ if (shouldSelectAll && Number.isFinite(this.maxChoices)) {
59
+ const currentSelectedCount = this.value.filter((choice) => choice.selected).length;
60
+ const selectedInDomainCount = blockChoices.filter((choice) => choice.selected).length;
61
+ const additionalSelectionsNeeded = blockChoices.length - selectedInDomainCount;
62
+ if (currentSelectedCount + additionalSelectionsNeeded > this.maxChoices) {
63
+ this.bell();
64
+ return;
65
+ }
66
+ }
67
+ for (const blockChoice of blockChoices) {
68
+ blockChoice.selected = shouldSelectAll;
69
+ }
70
+ currentChoice.selected = shouldSelectAll;
71
+ this.render();
72
+ return;
73
+ }
74
+ originalHandleSpaceToggle.call(this);
75
+ const currentDomain = parseDomainFromBlockValue(currentChoice.value);
76
+ if (currentDomain) {
77
+ syncDomainSelectionState(this, currentDomain);
78
+ this.render();
79
+ }
80
+ };
81
+ };
82
+ patchOne(LibMultiselectPrompt);
83
+ patchOne(DistMultiselectPrompt);
84
+ isDomainTogglePatchApplied = true;
85
+ };
86
+ const patchMultiselectVisuals = () => {
87
+ if (isMultiselectVisualPatchApplied)
88
+ return;
89
+ // Force circle-like selectors for better visual grouping across Windows terminals.
90
+ LibFigures.radioOn = '●';
91
+ LibFigures.radioOff = '○';
92
+ DistFigures.radioOn = '●';
93
+ DistFigures.radioOff = '○';
94
+ isMultiselectVisualPatchApplied = true;
95
+ };
96
+ const buildGroupedBlockChoices = (availableBlocks, preselected) => {
97
+ const choices = [];
98
+ const domainToBlocks = new Map();
99
+ for (const block of availableBlocks) {
100
+ const domain = block.domain ?? 'other';
101
+ const blocks = domainToBlocks.get(domain) ?? [];
102
+ blocks.push(block.name);
103
+ domainToBlocks.set(domain, blocks);
104
+ }
105
+ for (const [domain, domainBlockNames] of domainToBlocks.entries()) {
106
+ choices.push({
107
+ title: kleur_1.default.cyan().bold(`${domain} (${domainBlockNames.length})`),
108
+ value: `${DOMAIN_CHOICE_PREFIX}${domain}`,
109
+ selected: domainBlockNames.every((blockName) => preselected.includes(blockName)),
110
+ description: 'Space: select/deselect all blocks in this domain',
111
+ });
112
+ for (const block of availableBlocks) {
113
+ if ((block.domain ?? 'other') !== domain)
114
+ continue;
115
+ choices.push({
116
+ title: ` ${block.name}`,
117
+ description: block.description,
118
+ value: buildBlockValue(domain, block.name),
119
+ selected: preselected.includes(block.name),
120
+ });
121
+ }
122
+ }
123
+ return { choices, domainToBlocks };
124
+ };
11
125
  const promptProjectName = async (defaultName) => {
12
126
  const { name } = await (0, prompts_1.default)({
13
127
  type: 'text',
@@ -39,24 +153,47 @@ const promptTemplate = async () => {
39
153
  };
40
154
  exports.promptTemplate = promptTemplate;
41
155
  const promptBlockSelection = async (availableBlocks, preselected) => {
156
+ patchMultiselectDomainToggle();
157
+ patchMultiselectVisuals();
158
+ const { choices, domainToBlocks } = buildGroupedBlockChoices(availableBlocks, preselected);
42
159
  const { selectedBlocks } = await (0, prompts_1.default)({
43
160
  type: 'multiselect',
44
161
  name: 'selectedBlocks',
45
162
  message: 'Select blocks to include:',
46
- choices: availableBlocks.map((block) => ({
47
- title: block.name,
48
- description: block.description,
49
- value: block.name,
50
- selected: preselected.includes(block.name),
51
- })),
163
+ choices,
52
164
  min: 1,
53
165
  instructions: false,
54
- hint: '- Space to select. Return to submit',
166
+ hint: '- Space to select. Selecting domain includes all blocks',
55
167
  });
56
168
  if (!selectedBlocks || selectedBlocks.length === 0) {
57
169
  throw new Error('At least one block must be selected');
58
170
  }
59
- return selectedBlocks;
171
+ const availableBlockNames = new Set(availableBlocks.map((block) => block.name));
172
+ const normalizedSelection = new Set();
173
+ for (const selectedValue of selectedBlocks) {
174
+ if (selectedValue.startsWith(DOMAIN_CHOICE_PREFIX)) {
175
+ const domain = selectedValue.slice(DOMAIN_CHOICE_PREFIX.length);
176
+ const domainBlocks = domainToBlocks.get(domain) ?? [];
177
+ for (const blockName of domainBlocks) {
178
+ normalizedSelection.add(blockName);
179
+ }
180
+ continue;
181
+ }
182
+ if (selectedValue.startsWith(BLOCK_CHOICE_PREFIX)) {
183
+ const blockName = parseBlockNameFromValue(selectedValue);
184
+ if (availableBlockNames.has(blockName)) {
185
+ normalizedSelection.add(blockName);
186
+ }
187
+ continue;
188
+ }
189
+ if (availableBlockNames.has(selectedValue)) {
190
+ normalizedSelection.add(selectedValue);
191
+ }
192
+ }
193
+ if (normalizedSelection.size === 0) {
194
+ throw new Error('At least one block must be selected');
195
+ }
196
+ return [...normalizedSelection];
60
197
  };
61
198
  exports.promptBlockSelection = promptBlockSelection;
62
199
  const promptIntegrationSelection = async (availableIntegrations, preselected) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-o2s-app",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
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/types.ts CHANGED
@@ -2,6 +2,7 @@ export type TemplateType = 'o2s' | 'dxp' | 'custom';
2
2
 
3
3
  export interface BlockInfo {
4
4
  name: string;
5
+ domain?: string;
5
6
  packageName: string;
6
7
  description: string;
7
8
  category: string[];
@@ -2,7 +2,7 @@ import { BLOCKS_PATH } from '../constants';
2
2
  import { BlockInfo } from '../types';
3
3
  import { getAllTemplateCategories } from '../wizard/templates';
4
4
  import * as fs from 'fs-extra';
5
- import * as path from 'path';
5
+ import * as path from 'node:path';
6
6
 
7
7
  interface BlockPackageJson {
8
8
  description?: string;
@@ -12,35 +12,44 @@ interface BlockPackageJson {
12
12
  export const discoverBlocks = async (repoDir: string): Promise<BlockInfo[]> => {
13
13
  try {
14
14
  const blocksDir = path.join(repoDir, BLOCKS_PATH);
15
- const entries = await fs.readdir(blocksDir, { withFileTypes: true });
15
+ const domainEntries = await fs.readdir(blocksDir, { withFileTypes: true });
16
16
 
17
17
  const blocks: BlockInfo[] = [];
18
18
 
19
- for (const entry of entries) {
20
- if (!entry.isDirectory()) continue;
19
+ for (const domainEntry of domainEntries) {
20
+ if (!domainEntry.isDirectory()) continue;
21
21
 
22
- const blockName = entry.name;
23
- const packageJson = await readBlockPackageJson(repoDir, blockName);
22
+ const domainDirPath = path.join(blocksDir, domainEntry.name);
23
+ const blockEntries = await fs.readdir(domainDirPath, { withFileTypes: true });
24
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
- });
25
+ for (const blockEntry of blockEntries) {
26
+ if (!blockEntry.isDirectory()) continue;
27
+
28
+ const blockName = blockEntry.name;
29
+ const blockPath = path.join(domainEntry.name, blockName);
30
+ const packageJson = await readBlockPackageJson(repoDir, blockPath);
31
+
32
+ blocks.push({
33
+ name: blockName,
34
+ domain: domainEntry.name,
35
+ packageName: `@o2s/blocks.${blockName}`,
36
+ description: packageJson.description || `Block: ${blockName}`,
37
+ // Fallback to all templates when o2sTemplate is not declared
38
+ category: packageJson.o2sTemplate ?? getAllTemplateCategories(),
39
+ });
40
+ }
32
41
  }
33
42
 
34
- return blocks.sort((a, b) => a.name.localeCompare(b.name));
43
+ return blocks.sort((a, b) => `${a.domain ?? ''}/${a.name}`.localeCompare(`${b.domain ?? ''}/${b.name}`));
35
44
  } catch (error) {
36
45
  console.error('Error fetching the block list:', error);
37
46
  throw new Error('Failed to fetch the block list.');
38
47
  }
39
48
  };
40
49
 
41
- const readBlockPackageJson = async (repoDir: string, blockName: string): Promise<BlockPackageJson> => {
50
+ const readBlockPackageJson = async (repoDir: string, blockPath: string): Promise<BlockPackageJson> => {
42
51
  try {
43
- const packageJsonPath = path.join(repoDir, BLOCKS_PATH, blockName, 'package.json');
52
+ const packageJsonPath = path.join(repoDir, BLOCKS_PATH, blockPath, 'package.json');
44
53
 
45
54
  if (await fs.pathExists(packageJsonPath)) {
46
55
  return await fs.readJson(packageJsonPath);
@@ -48,7 +57,7 @@ const readBlockPackageJson = async (repoDir: string, blockName: string): Promise
48
57
 
49
58
  return {};
50
59
  } catch (error) {
51
- console.warn(`Warning: Could not read package.json for block "${blockName}":`, error);
60
+ console.warn(`Warning: Could not read package.json for block "${blockPath}":`, error);
52
61
  return {};
53
62
  }
54
63
  };
@@ -4,6 +4,160 @@ import { TEMPLATES, filterBlocksByTemplate, filterIntegrationsByTemplate } from
4
4
  import kleur from 'kleur';
5
5
  import prompts from 'prompts';
6
6
 
7
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
8
+ const LibMultiselectPrompt = require('prompts/lib/elements/multiselect');
9
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
10
+ const DistMultiselectPrompt = require('prompts/dist/elements/multiselect');
11
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
12
+ const LibFigures = require('prompts/lib/util/figures');
13
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
14
+ const DistFigures = require('prompts/dist/util/figures');
15
+
16
+ const DOMAIN_CHOICE_PREFIX = '__domain__:';
17
+ const BLOCK_CHOICE_PREFIX = '__block__:';
18
+ let isDomainTogglePatchApplied = false;
19
+ let isMultiselectVisualPatchApplied = false;
20
+
21
+ interface BlockChoice {
22
+ title: string;
23
+ value: string;
24
+ description?: string;
25
+ selected?: boolean;
26
+ }
27
+
28
+ interface MultiselectContext {
29
+ value: Array<{
30
+ value: string;
31
+ selected: boolean;
32
+ disabled?: boolean;
33
+ }>;
34
+ cursor: number;
35
+ maxChoices: number;
36
+ bell: () => void;
37
+ render: () => void;
38
+ }
39
+
40
+ const parseDomainFromBlockValue = (value: string): string | undefined => {
41
+ if (!value.startsWith(BLOCK_CHOICE_PREFIX)) return undefined;
42
+ const encoded = value.slice(BLOCK_CHOICE_PREFIX.length);
43
+ const separatorIndex = encoded.indexOf(':');
44
+ if (separatorIndex < 0) return undefined;
45
+ return encoded.slice(0, separatorIndex);
46
+ };
47
+
48
+ const buildBlockValue = (domain: string, blockName: string): string => `${BLOCK_CHOICE_PREFIX}${domain}:${blockName}`;
49
+
50
+ const parseBlockNameFromValue = (value: string): string => {
51
+ const encoded = value.slice(BLOCK_CHOICE_PREFIX.length);
52
+ const separatorIndex = encoded.indexOf(':');
53
+ return separatorIndex < 0 ? encoded : encoded.slice(separatorIndex + 1);
54
+ };
55
+
56
+ const syncDomainSelectionState = (ctx: MultiselectContext, domainName: string): void => {
57
+ const domainChoice = ctx.value.find((choice) => choice.value === `${DOMAIN_CHOICE_PREFIX}${domainName}`);
58
+ if (!domainChoice) return;
59
+
60
+ const blocksInDomain = ctx.value.filter(
61
+ (choice) => choice.value.startsWith(`${BLOCK_CHOICE_PREFIX}${domainName}:`) && !choice.disabled,
62
+ );
63
+ domainChoice.selected = blocksInDomain.length > 0 && blocksInDomain.every((choice) => choice.selected);
64
+ };
65
+
66
+ const patchMultiselectDomainToggle = (): void => {
67
+ if (isDomainTogglePatchApplied) return;
68
+
69
+ const patchOne = (PromptClass: { prototype: { handleSpaceToggle: () => void } }) => {
70
+ const originalHandleSpaceToggle = PromptClass.prototype.handleSpaceToggle;
71
+ PromptClass.prototype.handleSpaceToggle = function patchedHandleSpaceToggle(this: MultiselectContext) {
72
+ const currentChoice = this.value[this.cursor];
73
+ if (!currentChoice) return;
74
+
75
+ if (currentChoice.value.startsWith(DOMAIN_CHOICE_PREFIX)) {
76
+ const domainName = currentChoice.value.slice(DOMAIN_CHOICE_PREFIX.length);
77
+ const blockChoices = this.value.filter(
78
+ (choice) => choice.value.startsWith(`${BLOCK_CHOICE_PREFIX}${domainName}:`) && !choice.disabled,
79
+ );
80
+ const shouldSelectAll = !currentChoice.selected;
81
+
82
+ if (shouldSelectAll && Number.isFinite(this.maxChoices)) {
83
+ const currentSelectedCount = this.value.filter((choice) => choice.selected).length;
84
+ const selectedInDomainCount = blockChoices.filter((choice) => choice.selected).length;
85
+ const additionalSelectionsNeeded = blockChoices.length - selectedInDomainCount;
86
+ if (currentSelectedCount + additionalSelectionsNeeded > this.maxChoices) {
87
+ this.bell();
88
+ return;
89
+ }
90
+ }
91
+
92
+ for (const blockChoice of blockChoices) {
93
+ blockChoice.selected = shouldSelectAll;
94
+ }
95
+ currentChoice.selected = shouldSelectAll;
96
+ this.render();
97
+ return;
98
+ }
99
+
100
+ originalHandleSpaceToggle.call(this);
101
+
102
+ const currentDomain = parseDomainFromBlockValue(currentChoice.value);
103
+ if (currentDomain) {
104
+ syncDomainSelectionState(this, currentDomain);
105
+ this.render();
106
+ }
107
+ };
108
+ };
109
+
110
+ patchOne(LibMultiselectPrompt);
111
+ patchOne(DistMultiselectPrompt);
112
+
113
+ isDomainTogglePatchApplied = true;
114
+ };
115
+
116
+ const patchMultiselectVisuals = (): void => {
117
+ if (isMultiselectVisualPatchApplied) return;
118
+
119
+ // Force circle-like selectors for better visual grouping across Windows terminals.
120
+ LibFigures.radioOn = '●';
121
+ LibFigures.radioOff = '○';
122
+ DistFigures.radioOn = '●';
123
+ DistFigures.radioOff = '○';
124
+
125
+ isMultiselectVisualPatchApplied = true;
126
+ };
127
+
128
+ const buildGroupedBlockChoices = (availableBlocks: BlockInfo[], preselected: string[]) => {
129
+ const choices: BlockChoice[] = [];
130
+ const domainToBlocks = new Map<string, string[]>();
131
+
132
+ for (const block of availableBlocks) {
133
+ const domain = block.domain ?? 'other';
134
+ const blocks = domainToBlocks.get(domain) ?? [];
135
+ blocks.push(block.name);
136
+ domainToBlocks.set(domain, blocks);
137
+ }
138
+
139
+ for (const [domain, domainBlockNames] of domainToBlocks.entries()) {
140
+ choices.push({
141
+ title: kleur.cyan().bold(`${domain} (${domainBlockNames.length})`),
142
+ value: `${DOMAIN_CHOICE_PREFIX}${domain}`,
143
+ selected: domainBlockNames.every((blockName) => preselected.includes(blockName)),
144
+ description: 'Space: select/deselect all blocks in this domain',
145
+ });
146
+
147
+ for (const block of availableBlocks) {
148
+ if ((block.domain ?? 'other') !== domain) continue;
149
+ choices.push({
150
+ title: ` ${block.name}`,
151
+ description: block.description,
152
+ value: buildBlockValue(domain, block.name),
153
+ selected: preselected.includes(block.name),
154
+ });
155
+ }
156
+ }
157
+
158
+ return { choices, domainToBlocks };
159
+ };
160
+
7
161
  export const promptProjectName = async (defaultName: string): Promise<string> => {
8
162
  const { name } = await prompts({
9
163
  type: 'text',
@@ -39,26 +193,51 @@ export const promptTemplate = async (): Promise<TemplateType> => {
39
193
  };
40
194
 
41
195
  export const promptBlockSelection = async (availableBlocks: BlockInfo[], preselected: string[]): Promise<string[]> => {
196
+ patchMultiselectDomainToggle();
197
+ patchMultiselectVisuals();
198
+ const { choices, domainToBlocks } = buildGroupedBlockChoices(availableBlocks, preselected);
42
199
  const { selectedBlocks } = await prompts({
43
200
  type: 'multiselect',
44
201
  name: 'selectedBlocks',
45
202
  message: 'Select blocks to include:',
46
- choices: availableBlocks.map((block) => ({
47
- title: block.name,
48
- description: block.description,
49
- value: block.name,
50
- selected: preselected.includes(block.name),
51
- })),
203
+ choices,
52
204
  min: 1,
53
205
  instructions: false,
54
- hint: '- Space to select. Return to submit',
206
+ hint: '- Space to select. Selecting domain includes all blocks',
55
207
  });
56
208
 
57
209
  if (!selectedBlocks || selectedBlocks.length === 0) {
58
210
  throw new Error('At least one block must be selected');
59
211
  }
60
212
 
61
- return selectedBlocks;
213
+ const availableBlockNames = new Set(availableBlocks.map((block) => block.name));
214
+ const normalizedSelection = new Set<string>();
215
+ for (const selectedValue of selectedBlocks as string[]) {
216
+ if (selectedValue.startsWith(DOMAIN_CHOICE_PREFIX)) {
217
+ const domain = selectedValue.slice(DOMAIN_CHOICE_PREFIX.length);
218
+ const domainBlocks = domainToBlocks.get(domain) ?? [];
219
+ for (const blockName of domainBlocks) {
220
+ normalizedSelection.add(blockName);
221
+ }
222
+ continue;
223
+ }
224
+ if (selectedValue.startsWith(BLOCK_CHOICE_PREFIX)) {
225
+ const blockName = parseBlockNameFromValue(selectedValue);
226
+ if (availableBlockNames.has(blockName)) {
227
+ normalizedSelection.add(blockName);
228
+ }
229
+ continue;
230
+ }
231
+ if (availableBlockNames.has(selectedValue)) {
232
+ normalizedSelection.add(selectedValue);
233
+ }
234
+ }
235
+
236
+ if (normalizedSelection.size === 0) {
237
+ throw new Error('At least one block must be selected');
238
+ }
239
+
240
+ return [...normalizedSelection];
62
241
  };
63
242
 
64
243
  export const promptIntegrationSelection = async (