@@ -18,7 +18,8 @@ const DEFAULT_CONFIG_CONTENT = `/** @type {import('stylelint').Config} */
18
18
export default {
19
19
extends: ['stylelint-config-standard'],
20
20
};` ;
21
- const DEFAULT_PACKAGES = '-D stylelint stylelint-config-standard' ;
21
+
22
+ const ADD_COMMAND = 'add -D stylelint stylelint-config-standard' ;
22
23
23
24
async function getExistingConfigInDirectory ( ) {
24
25
const explorer = cosmiconfig ( 'stylelint' ) ;
@@ -36,9 +37,17 @@ function directoryHasPackageJson(dir) {
36
37
37
38
/**
38
39
* @param {string } pkgManager
40
+ * @return {string } The command
39
41
*/
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
+ }
42
51
}
43
52
44
53
/**
@@ -67,7 +76,7 @@ function cancelSetup(errorMessage = '') {
67
76
async function showPrompt ( pkgManager ) {
68
77
console . log (
69
78
stripIndent ( `
70
- This tool will create a '${ DEFAULT_CONFIG_FILE } ' file containing:
79
+ We'll create a '${ DEFAULT_CONFIG_FILE } ' file containing:
71
80
` ) ,
72
81
) ;
73
82
@@ -81,9 +90,9 @@ async function showPrompt(pkgManager) {
81
90
82
91
console . log (
83
92
stripIndent ( `
84
- And install the related dependencies using:
93
+ Then add the related dependencies using:
85
94
86
- ${ picocolors . dim ( `${ pkgManager } ${ getInstallCommand ( pkgManager ) } ${ DEFAULT_PACKAGES } ` ) }
95
+ ${ picocolors . dim ( `${ pkgManager } ${ ADD_COMMAND } ` ) }
87
96
` ) ,
88
97
) ;
89
98
@@ -144,35 +153,38 @@ async function createConfig(cwd, pkgManager) {
144
153
* @param {string } cwd
145
154
* @param {string } pkgManager
146
155
*/
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 ( ) ;
149
158
150
159
try {
151
- await execa ( pkgManager , [ ` ${ getInstallCommand ( pkgManager ) } ` , ...DEFAULT_PACKAGES . split ( ' ' ) ] , {
160
+ await execa ( pkgManager , [ ...ADD_COMMAND . split ( ' ' ) ] , {
152
161
cwd,
153
162
} ) ;
154
163
} catch ( error ) {
155
164
spinner . fail ( ) ;
156
165
cancelSetup ( error instanceof Error ? error . message : String ( error ) ) ;
157
166
}
158
167
159
- spinner . succeed ( 'Installed packages' ) ;
168
+ spinner . succeed ( 'Added packages' ) ;
160
169
}
161
170
162
- function showNextSteps ( ) {
171
+ /**
172
+ * @param {string } pkgManager
173
+ */
174
+ function showNextSteps ( pkgManager ) {
163
175
console . log (
164
176
stripIndent ( `
165
177
${ picocolors . green ( picocolors . bold ( 'Setup complete!' ) ) }
166
178
167
179
Lint your CSS files with:
168
180
169
- ${ picocolors . dim ( `npx stylelint "**/*.css"` ) }
181
+ ${ picocolors . dim ( `${ getExecuteCommand ( pkgManager ) } stylelint "**/*.css"` ) }
170
182
171
183
Next steps? Customize your config: ${ picocolors . underline (
172
184
picocolors . blue ( 'https://stylelint.io/user-guide/customize' ) ,
173
185
) }
174
186
175
- If you benefit from Stylelint, please consider sponsoring the project on :
187
+ If you benefit from Stylelint, please consider sponsoring the project at :
176
188
177
189
- ${ picocolors . underline ( picocolors . blue ( 'https://github.com/sponsors/stylelint' ) ) }
178
190
- ${ picocolors . underline ( picocolors . blue ( 'https://opencollective.com/stylelint' ) ) }
@@ -186,6 +198,6 @@ export async function main() {
186
198
187
199
await showPrompt ( pkgManager ) ;
188
200
await createConfig ( cwd , pkgManager ) ;
189
- await installPackages ( cwd , pkgManager ) ;
190
- showNextSteps ( ) ;
201
+ await addPackages ( cwd , pkgManager ) ;
202
+ showNextSteps ( pkgManager ) ;
191
203
}
0 commit comments