Skip to content

Commit 5da7734

Browse files
committed
feat: add init command where preset can directly be passed
1 parent 2d97d08 commit 5da7734

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ You will be prompted to choose a preset which will be copied to your templates d
2222

2323
A config file and `.create-frontend-component` directory will be created aswell.
2424

25+
It is also possible to avoid the prompting and directly initialize a certain preset:
26+
27+
```bash
28+
npx create-frontend-component init:vue3
29+
```
30+
2531
### Configuration
2632

2733
The `init` command creates the `.create-frontend-component/config.json` configuration file.

cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ program
5757
return
5858
}
5959

60+
if (componentName.toLowerCase().startsWith('init:')) {
61+
const nameParts = componentName.toLowerCase().split(':')
62+
const presetArgument = nameParts[1]
63+
await processInitCommand(PRESET_PATH, CONFIG_DIRECTORY, CONFIG_FILE_NAME, configDefaults, presetArgument)
64+
return
65+
}
66+
6067
const { types, templatePath, componentPath, nameStyle } = loadConfig()
6168
const allowedComponentTypes = types || []
6269
const fullTemplatePath = path.join(process.cwd(), templatePath)

src/commands.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ export function processCreateComponentCommand(env, allowedComponentTypes, fullTe
9898
* @param {string} configDirectory
9999
* @param {string} configFileName
100100
* @param {string} configDefaults
101+
* @param {string} [presetArgument]
101102
* @return {Promise<void>}
102103
*/
103-
export async function processInitCommand(presetPath, configDirectory, configFileName, configDefaults) {
104+
export async function processInitCommand(presetPath, configDirectory, configFileName, configDefaults, presetArgument) {
104105
const availablePresets = getDirectories(presetPath)
105-
const presetName = await promptSingleSelect('Choose a preset', availablePresets)
106+
let presetName
107+
if (presetArgument) {
108+
presetName = presetArgument
109+
} else {
110+
presetName = await promptSingleSelect('Choose a preset', availablePresets)
111+
}
106112
return initProjectInWorkingDirectory(path.join(presetPath, presetName), configDirectory, configFileName, configDefaults)
107113
}
108114

0 commit comments

Comments
 (0)