Skip to content

Commit c0838f1

Browse files
committed
Fix add and execute commands
1 parent a1f93e7 commit c0838f1

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/index.mjs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const DEFAULT_CONFIG_CONTENT = `/** @type {import('stylelint').Config} */
1818
export default {
1919
extends: ['stylelint-config-standard'],
2020
};`;
21-
const DEFAULT_PACKAGES = '-D stylelint stylelint-config-standard';
21+
22+
const ADD_COMMAND = 'add -D stylelint stylelint-config-standard';
2223

2324
async function getExistingConfigInDirectory() {
2425
const explorer = cosmiconfig('stylelint');
@@ -36,9 +37,17 @@ function directoryHasPackageJson(dir) {
3637

3738
/**
3839
* @param {string} pkgManager
40+
* @return {string} The command
3941
*/
40-
function getInstallCommand(pkgManager) {
41-
return pkgManager === 'npm' ? 'install' : 'add';
42+
function getExecuteCommand(pkgManager) {
43+
switch (pkgManager) {
44+
case 'npm':
45+
return 'npx';
46+
case 'bun':
47+
return 'bunx';
48+
default:
49+
return `${pkgManager} dlx`;
50+
}
4251
}
4352

4453
/**
@@ -67,7 +76,7 @@ function cancelSetup(errorMessage = '') {
6776
async function showPrompt(pkgManager) {
6877
console.log(
6978
stripIndent(`
70-
This tool will create a '${DEFAULT_CONFIG_FILE}' file containing:
79+
We'll create a '${DEFAULT_CONFIG_FILE}' file containing:
7180
`),
7281
);
7382

@@ -81,9 +90,9 @@ async function showPrompt(pkgManager) {
8190

8291
console.log(
8392
stripIndent(`
84-
And install the related dependencies using:
93+
Then add the related dependencies using:
8594
86-
${picocolors.dim(`${pkgManager} ${getInstallCommand(pkgManager)} ${DEFAULT_PACKAGES}`)}
95+
${picocolors.dim(`${pkgManager} ${ADD_COMMAND}`)}
8796
`),
8897
);
8998

@@ -144,35 +153,38 @@ async function createConfig(cwd, pkgManager) {
144153
* @param {string} cwd
145154
* @param {string} pkgManager
146155
*/
147-
async function installPackages(cwd, pkgManager) {
148-
const spinner = ora('Installing packages...').start();
156+
async function addPackages(cwd, pkgManager) {
157+
const spinner = ora('Adding packages...').start();
149158

150159
try {
151-
await execa(pkgManager, [`${getInstallCommand(pkgManager)}`, ...DEFAULT_PACKAGES.split(' ')], {
160+
await execa(pkgManager, [...ADD_COMMAND.split(' ')], {
152161
cwd,
153162
});
154163
} catch (error) {
155164
spinner.fail();
156165
cancelSetup(error instanceof Error ? error.message : String(error));
157166
}
158167

159-
spinner.succeed('Installed packages');
168+
spinner.succeed('Added packages');
160169
}
161170

162-
function showNextSteps() {
171+
/**
172+
* @param {string} pkgManager
173+
*/
174+
function showNextSteps(pkgManager) {
163175
console.log(
164176
stripIndent(`
165177
${picocolors.green(picocolors.bold('Setup complete!'))}
166178
167179
Lint your CSS files with:
168180
169-
${picocolors.dim(`npx stylelint "**/*.css"`)}
181+
${picocolors.dim(`${getExecuteCommand(pkgManager)} stylelint "**/*.css"`)}
170182
171183
Next steps? Customize your config: ${picocolors.underline(
172184
picocolors.blue('https://stylelint.io/user-guide/customize'),
173185
)}
174186
175-
If you benefit from Stylelint, please consider sponsoring the project on:
187+
If you benefit from Stylelint, please consider sponsoring the project at:
176188
177189
- ${picocolors.underline(picocolors.blue('https://github.com/sponsors/stylelint'))}
178190
- ${picocolors.underline(picocolors.blue('https://opencollective.com/stylelint'))}
@@ -186,6 +198,6 @@ export async function main() {
186198

187199
await showPrompt(pkgManager);
188200
await createConfig(cwd, pkgManager);
189-
await installPackages(cwd, pkgManager);
190-
showNextSteps();
201+
await addPackages(cwd, pkgManager);
202+
showNextSteps(pkgManager);
191203
}

0 commit comments

Comments
 (0)