Skip to content

Commit

Permalink
feat: default bookshop/init to new component if a bookshop dir was found
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Jun 7, 2022
1 parent 13c5393 commit 12ad117
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions javascript-modules/init/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ const renderFile = (template, props, filename) => {
}
}

const initComponent = async (options) => {
const bookshopConfigFiles = await fastGlob(`./**/bookshop.config.js`, {
cwd,
dot: !!options.dot
});
const initComponent = async (options, bookshopConfigFiles) => {
if (!bookshopConfigFiles) {
bookshopConfigFiles = await fastGlob(`./**/bookshop.config.js`, {
cwd,
dot: !!options.dot
});
}

if (!bookshopConfigFiles.length) {
console.error(chalk.red(`Couldn't locate a ${chalk.cyan(`bookshop.config.js`)} file to anchor the component with`));
Expand Down Expand Up @@ -206,9 +208,20 @@ async function run() {
process.exit(1);
}

const bookshopConfigFiles = await fastGlob(`./**/bookshop.config.js`, {
cwd,
dot: !!options.dot
});

let action;
if (options.component) action = 'component';
if (options.new) action = 'new';

if (!options.component && !options.new && bookshopConfigFiles.length) {
options.component = true;
action = 'component';
}

if (!options.component && !options.new) {
const resp = await inquirer.prompt([{
type: 'list',
Expand Down Expand Up @@ -248,7 +261,7 @@ async function run() {
}

if (options.component) {
await initComponent(options);
await initComponent(options, bookshopConfigFiles);
console.log(chalk.bold.green(`\nAll done.`));
return;
}
Expand Down

0 comments on commit 12ad117

Please sign in to comment.