Skip to content

Commit 7aea546

Browse files
authored
Merge pull request #38 from amoskyalo/issue_#37_components_scaffold
Feat: Allowed users to select components to scaffold during project initialization.
2 parents 0a5d84e + 4e90c2c commit 7aea546

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

commands/projectInit.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { componentChoices } = require('../utils/constants')
44
const chalk = require('chalk');
55
const ComponentGenerator = require('../utils/getComponentTemplate');
66

7-
async function projectInit(projectName, installAll, architecture, tool, monorepoName) {
7+
async function projectInit(projectName, components, architecture, tool, monorepoName) {
88
function getTemplateUrl() {
99
switch (tool) {
1010
case 'cra': return "https://github.com/amoskyalo/mui-cra-template";
@@ -27,18 +27,20 @@ async function projectInit(projectName, installAll, architecture, tool, monorepo
2727
try {
2828
process.chdir(projectName);
2929

30-
(async () => {
31-
const components = installAll ?
32-
componentChoices.map(c => c.value) :
33-
await checkbox({
34-
message: "Which components would you like to install to your project?",
35-
choices: componentChoices,
36-
required: true,
37-
pageSize: 10
38-
});
39-
40-
new ComponentGenerator(components, projectName, architecture, tool, monorepoName).generateComponent();
41-
})()
30+
new ComponentGenerator(components, projectName, architecture, tool, monorepoName).generateComponent();
31+
32+
// (async () => {
33+
// const components = installAll ?
34+
// componentChoices.map(c => c.value) :
35+
// await checkbox({
36+
// message: "Which components would you like to install to your project?",
37+
// choices: componentChoices,
38+
// required: true,
39+
// pageSize: 10
40+
// });
41+
42+
43+
// })()
4244

4345
} catch (error) {
4446
throw new Error(error);

index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const { exec } = require('child_process')
44
const { program } = require('commander');
55
const { logger } = require('./utils/logger');
6-
const { select, confirm, input } = require('@inquirer/prompts');
6+
const { select, confirm, input, checkbox } = require('@inquirer/prompts');
7+
const { componentChoices } = require('./utils/constants');
78
const CLI = require('clui');
89
const boxen = require('boxen');
910
const themeInit = require('./commands/themeInit');
@@ -60,8 +61,15 @@ program.command('project-init')
6061
{ name: "CRA", value: "cra" },
6162
{ name: "Vite", value: "vite" },
6263
{ name: "Next.js", value: "next" }
63-
]
64-
});
64+
],
65+
default: 'vite'
66+
});
67+
68+
const components = await checkbox({
69+
message: "Which components would you like to scafold to your project? You can also install them later via the CLI.",
70+
choices: componentChoices,
71+
pageSize: 10
72+
});
6573

6674
const architecture = await select({
6775
message: "Choose your preferred project architecture:",
@@ -79,7 +87,7 @@ program.command('project-init')
7987
const useWorkspaces = await confirm({ message: "Would you like to integrate Yarn Workspaces with Lerna for better dependency management?" });
8088

8189
function runMonorepo() {
82-
return monorepoInit(monorepoName, () => projectInit(projectName, options.all || false, architecture, tool, monorepoName));
90+
return monorepoInit(monorepoName, () => projectInit(projectName, components, architecture, tool, monorepoName));
8391
}
8492

8593

@@ -103,12 +111,12 @@ program.command('project-init')
103111
runMonorepo();
104112
})
105113
}
106-
114+
107115
} else runMonorepo();
108116
})
109117
}
110118
} else {
111-
projectInit(projectName, options.all || false, architecture, tool);
119+
projectInit(projectName, components, architecture, tool);
112120
}
113121
});
114122

0 commit comments

Comments
 (0)