Skip to content

Commit

Permalink
Feat: Allowed users to select components to scaffold during project i…
Browse files Browse the repository at this point in the history
…nitialization
  • Loading branch information
amoskyalo committed Mar 9, 2024
1 parent eebde6b commit 4e90c2c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
28 changes: 15 additions & 13 deletions commands/projectInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { componentChoices } = require('../utils/constants')
const chalk = require('chalk');
const ComponentGenerator = require('../utils/getComponentTemplate');

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

(async () => {
const components = installAll ?
componentChoices.map(c => c.value) :
await checkbox({
message: "Which components would you like to install to your project?",
choices: componentChoices,
required: true,
pageSize: 10
});

new ComponentGenerator(components, projectName, architecture, tool, monorepoName).generateComponent();
})()
new ComponentGenerator(components, projectName, architecture, tool, monorepoName).generateComponent();

// (async () => {
// const components = installAll ?
// componentChoices.map(c => c.value) :
// await checkbox({
// message: "Which components would you like to install to your project?",
// choices: componentChoices,
// required: true,
// pageSize: 10
// });


// })()

} catch (error) {
throw new Error(error);
Expand Down
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const { exec } = require('child_process')
const { program } = require('commander');
const { logger } = require('./utils/logger');
const { select, confirm, input } = require('@inquirer/prompts');
const { select, confirm, input, checkbox } = require('@inquirer/prompts');
const { componentChoices } = require('./utils/constants');
const CLI = require('clui');
const boxen = require('boxen');
const themeInit = require('./commands/themeInit');
Expand Down Expand Up @@ -60,8 +61,15 @@ program.command('project-init')
{ name: "CRA", value: "cra" },
{ name: "Vite", value: "vite" },
{ name: "Next.js", value: "next" }
]
});
],
default: 'vite'
});

const components = await checkbox({
message: "Which components would you like to scafold to your project? You can also install them later via the CLI.",
choices: componentChoices,
pageSize: 10
});

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

function runMonorepo() {
return monorepoInit(monorepoName, () => projectInit(projectName, options.all || false, architecture, tool, monorepoName));
return monorepoInit(monorepoName, () => projectInit(projectName, components, architecture, tool, monorepoName));
}


Expand All @@ -103,12 +111,12 @@ program.command('project-init')
runMonorepo();
})
}

} else runMonorepo();
})
}
} else {
projectInit(projectName, options.all || false, architecture, tool);
projectInit(projectName, components, architecture, tool);
}
});

Expand Down

0 comments on commit 4e90c2c

Please sign in to comment.