Skip to content

Commit 437b9c5

Browse files
committed
fix: ls presets
1 parent 33b03a3 commit 437b9c5

File tree

3 files changed

+9
-71
lines changed

3 files changed

+9
-71
lines changed

lib/commands/presets.commands.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const prompt = createPromptModule();
1414
* The user is guided by a series of prompts to enter a preset name.
1515
* @param {string} command - The operation to be performed:
1616
* 'create' to create a preset, 'ls' to list presets.
17-
* @param {string} [presetName] - The name of the preset for which to list.
1817
* @returns {Promise<void>} - A promise that resolves when the action is complete.
1918
* @example
2019
*
@@ -24,7 +23,7 @@ const prompt = createPromptModule();
2423
* // To list existing presets
2524
* presetsCommand('ls');
2625
*/
27-
async function presetsCommand(command, presetName) {
26+
async function presetsCommand(command) {
2827
const { presets } = await import('#utils');
2928

3029
let name;
@@ -70,17 +69,8 @@ async function presetsCommand(command, presetName) {
7069
break;
7170

7271
case 'ls':
73-
if (presetName) {
74-
const modes = presets.getModes(presetName);
75-
if (modes.length > 0) {
76-
modes.forEach((presetMode) => feedback.option(presetMode));
77-
} else {
78-
feedback.error(`No modes found for preset ${presetName}.`);
79-
}
80-
}
81-
if (!presetName) {
82-
presets.getBeautify().forEach((preset) => feedback.option(preset));
83-
}
72+
presets.getBeautify().forEach((preset) => feedback.option(preset));
73+
8474
break;
8575

8676
default:

lib/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ function startVulcanProgram() {
212212
.description(
213213
'Create <create> or list <ls> defined project presets for Edge',
214214
)
215-
.action(async (command, options) => {
215+
.action(async (command) => {
216216
const { presetsCommand } = await import('#commands');
217-
await presetsCommand(command, options.preset);
217+
await presetsCommand(command);
218218
});
219219

220220
program.parse(process.argv);

lib/utils/presets/presets.utils.js

+4-56
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ if (!isWindows) {
2424
* Unlike `getKeys`, this method returns preset names formatted
2525
* for display and includes modes like '(Deliver)' or '(Compute)'.
2626
* Each type corresponds to a folder in the 'presets' directory.
27-
* @returns {string[]} The list of presets with modes like '(Deliver)' or '(Compute)' if applicable.
27+
* @returns {string[]} The list of presets.
2828
* @example
2929
* const presetsList = getBeautify();
3030
* console.log(presetsList);
31-
* // Output might be: ['Angular (Deliver)', 'React (Compute)', 'Vue (Deliver)']
31+
* // Output might be: ['Angular', 'React', 'Vue']
3232
*/
3333
function getBeautify() {
3434
const presets = [];
@@ -37,25 +37,9 @@ function getBeautify() {
3737
const folders = fs
3838
.readdirSync(presetsDir, { withFileTypes: true })
3939
.filter((dirent) => dirent.isDirectory())
40-
.flatMap((dirent) => {
40+
.map((dirent) => {
4141
const presetName = dirent.name;
42-
const subDirs = fs
43-
.readdirSync(path.join(presetsDir, presetName), {
44-
withFileTypes: true,
45-
})
46-
.filter((subDirent) => subDirent.isDirectory());
47-
48-
if (subDirs.length === 0) {
49-
return [presetName.charAt(0).toUpperCase() + presetName.slice(1)];
50-
}
51-
52-
return subDirs.map((subDir) => {
53-
const subDirName =
54-
subDir.name.charAt(0).toUpperCase() + subDir.name.slice(1);
55-
return `${
56-
presetName.charAt(0).toUpperCase() + presetName.slice(1)
57-
} (${subDirName})`;
58-
});
42+
return presetName.charAt(0).toUpperCase() + presetName.slice(1);
5943
});
6044

6145
presets.push(...folders);
@@ -111,37 +95,6 @@ function set(name) {
11195
fs.writeFileSync(path.join(presetPath, 'prebuild.js'), '');
11296
fs.writeFileSync(path.join(presetPath, 'config.js'), '');
11397
}
114-
115-
/**
116-
* @function
117-
* @memberof Utils
118-
* @description Retrieves an array of available modes for a given preset.
119-
* Each sub-folder name in these directories is considered as a valid mode for the preset.
120-
* @param {string} presetName - The name of the preset for which modes are to be retrieved.
121-
* @returns {string[]} An array of available modes for the given preset.
122-
* @example
123-
* const availableModes = getModes('angular');
124-
* console.log(availableModes);
125-
* // Output might be: ['Deliver']
126-
* @throws {Error} Throws an error if unable to read the directory.
127-
*/
128-
function getModes(presetName) {
129-
const modes = [];
130-
131-
const presetPath = path.join(baselibPath, 'presets', presetName);
132-
133-
if (fs.existsSync(presetPath)) {
134-
const directories = fs
135-
.readdirSync(presetPath, { withFileTypes: true })
136-
.filter((dir) => dir.isDirectory())
137-
.map((dir) => dir.name.charAt(0).toUpperCase() + dir.name.slice(1));
138-
139-
modes.push(...directories);
140-
}
141-
142-
return modes;
143-
}
144-
14598
/**
14699
* @function
147100
* @memberof Utils
@@ -150,8 +103,6 @@ function getModes(presetName) {
150103
* These keys are raw and do not include any modes or formatting.
151104
* @property {Function} getBeautify - Function to retrieve a list of presets in a beautified format.
152105
* Unlike `getKeys`, the names are formatted and include modes like '(Compute)' or '(Deliver)'.
153-
* @property {Function} getModes - Function to retrieve an array of a
154-
* vailable modes for a given preset.
155106
* @property {Function} set - Function to create a new preset along with its required files.
156107
* @example
157108
* import { presets } from '#utils';
@@ -162,16 +113,13 @@ function getModes(presetName) {
162113
* // Get beautified preset names
163114
* const beautifiedNames = presets.getBeautify();
164115
*
165-
* // Get available modes for a preset
166-
* const availableModes = presets.getModes('angular');
167116
*
168117
* // Create a new preset
169118
* presets.set('MyNewPreset');
170119
*/
171120
const presets = {
172121
getKeys,
173122
getBeautify,
174-
getModes,
175123
set,
176124
};
177125

0 commit comments

Comments
 (0)