Skip to content

Commit

Permalink
fix: allow skipping installing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Apr 3, 2024
1 parent 0551e86 commit 0a4c547
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,49 @@ export default [\n${exportContent}];`;
* @returns {void}
*/
async output() {
const packageManager = (await enquirer.prompt({
type: "select",
name: "packageManager",
message: "Which package manager do you want to use?",
initial: 0,
choices: ["npm", "yarn", "pnpm", "bun"]
})).packageManager;

installSyncSaveDev(this.result.devDependencies, packageManager);
log.info("The config that you've selected requires the following dependencies:\n");
log.info(this.result.devDependencies.join(", "));

const configPath = path.join(this.cwd, this.result.configFilename);
const installDevDeps = (await enquirer.prompt({
type: "toggle",
name: "executeInstallation",
message: "Would you like to install them now?",
enabled: "Yes",
disabled: "No",
initial: 1
})).executeInstallation;

await writeFile(configPath, this.result.configContent);
const configPath = path.join(this.cwd, this.result.configFilename);

// import("eslint") won't work in some cases.
// refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12
const eslintBin = path.join(this.packageJsonPath, "../node_modules/eslint/bin/eslint.js");
const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" });
if (installDevDeps === true) {
const packageManager = (await enquirer.prompt({
type: "select",
name: "packageManager",
message: "Which package manager do you want to use?",
initial: 0,
choices: ["npm", "yarn", "pnpm", "bun"]
})).packageManager;

log.info("☕️Installing...");
installSyncSaveDev(this.result.devDependencies, packageManager);
await writeFile(configPath, this.result.configContent);

// import("eslint") won't work in some cases.
// refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12
const eslintBin = path.join(this.packageJsonPath, "../node_modules/eslint/bin/eslint.js");
const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" });

if (result.error || result.status !== 0) {
log.error("A config file was generated, but the config file itself may not follow your linting rules.");
} else {
log.info(`Successfully created ${configPath} file.`);
}
} else {
await writeFile(configPath, this.result.configContent);

if (result.error || result.status !== 0) {
log.error("A config file was generated, but the config file itself may not follow your linting rules.");
log.info(`Successfully created ${configPath} file.`);
log.warn("You will need to install the dependencies yourself.");
}
}
}

0 comments on commit 0a4c547

Please sign in to comment.