create-stylelint 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/package.json +7 -11
- package/src/index.mjs +15 -23
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# create-stylelint
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/create-stylelint)
|
|
4
|
+
[](https://github.com/stylelint/create-stylelint/actions/workflows/testing.yml)
|
|
5
|
+
|
|
3
6
|
The [`npm init`](https://docs.npmjs.com/cli/v9/commands/npm-init) script for [Stylelint](https://github.com/stylelint/stylelint).
|
|
4
7
|
|
|
5
8
|
## Usage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-stylelint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The npm init script for Stylelint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stylelint",
|
|
@@ -35,11 +35,6 @@
|
|
|
35
35
|
},
|
|
36
36
|
"prettier": "@stylelint/prettier-config",
|
|
37
37
|
"eslintConfig": {
|
|
38
|
-
"settings": {
|
|
39
|
-
"jest": {
|
|
40
|
-
"version": "latest"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
38
|
"extends": [
|
|
44
39
|
"stylelint"
|
|
45
40
|
],
|
|
@@ -54,7 +49,8 @@
|
|
|
54
49
|
]
|
|
55
50
|
},
|
|
56
51
|
"dependencies": {
|
|
57
|
-
"
|
|
52
|
+
"cosmiconfig": "^8.1.0",
|
|
53
|
+
"execa": "^7.0.0",
|
|
58
54
|
"ora": "^6.1.2",
|
|
59
55
|
"picocolors": "^1.0.0",
|
|
60
56
|
"semver": "^7.3.8",
|
|
@@ -66,15 +62,15 @@
|
|
|
66
62
|
"@stylelint/prettier-config": "^2.0.0",
|
|
67
63
|
"@stylelint/remark-preset": "^4.0.0",
|
|
68
64
|
"@types/which-pm-runs": "^1.0.0",
|
|
69
|
-
"eslint": "^8.
|
|
70
|
-
"eslint-config-stylelint": "^
|
|
65
|
+
"eslint": "^8.35.0",
|
|
66
|
+
"eslint-config-stylelint": "^18.0.0",
|
|
71
67
|
"np": "^7.6.3",
|
|
72
68
|
"npm-run-all": "^4.1.5",
|
|
73
69
|
"remark-cli": "^11.0.0",
|
|
74
70
|
"typescript": "^4.9.5",
|
|
75
|
-
"vitest": "^0.
|
|
71
|
+
"vitest": "^0.29.2"
|
|
76
72
|
},
|
|
77
73
|
"engines": {
|
|
78
|
-
"node": "^14.
|
|
74
|
+
"node": "^14.18.0 || ^16.14.0 || >=18.0.0"
|
|
79
75
|
}
|
|
80
76
|
}
|
package/src/index.mjs
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
/* eslint-disable no-process-exit */
|
|
2
2
|
/* eslint no-console: 'off' */
|
|
3
3
|
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { cosmiconfigSync } from 'cosmiconfig';
|
|
4
7
|
import detectPackageManager from 'which-pm-runs';
|
|
5
8
|
import { execa } from 'execa';
|
|
6
|
-
import fs from 'fs';
|
|
7
9
|
import ora from 'ora';
|
|
8
10
|
import picocolors from 'picocolors';
|
|
9
11
|
import stripIndent from 'strip-indent';
|
|
10
12
|
|
|
11
13
|
const DEFAULT_CONFIG_FILE = '.stylelintrc.json';
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
'
|
|
15
|
-
'.stylelintrc.cjs',
|
|
16
|
-
'.stylelintrc.json',
|
|
17
|
-
'.stylelintrc.yaml',
|
|
18
|
-
'.stylelintrc.yml',
|
|
19
|
-
'.stylelintrc.js',
|
|
20
|
-
'stylelint.config.js',
|
|
21
|
-
'stylelint.config.cjs',
|
|
22
|
-
]);
|
|
15
|
+
function getExistingConfigInDirectory() {
|
|
16
|
+
const explorer = cosmiconfigSync('stylelint');
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
* @param {fs.PathLike} dir
|
|
26
|
-
*/
|
|
27
|
-
function getExistingConfigsInDirectory(dir) {
|
|
28
|
-
return fs.readdirSync(dir).filter((file) => STYLELINT_CONFIG_PATHS.has(file));
|
|
18
|
+
return explorer.search();
|
|
29
19
|
}
|
|
30
20
|
|
|
31
21
|
/**
|
|
@@ -48,14 +38,16 @@ function getInstallCommand(pkgManager) {
|
|
|
48
38
|
*/
|
|
49
39
|
function createConfig(cwd, pkgManager) {
|
|
50
40
|
const spinner = ora('Creating config...').start();
|
|
51
|
-
const
|
|
41
|
+
const existingConfig = getExistingConfigInDirectory();
|
|
52
42
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
if (existingConfig !== null) {
|
|
44
|
+
const basename = path.basename(existingConfig.filepath);
|
|
45
|
+
const failureMessage =
|
|
46
|
+
basename === 'package.json'
|
|
47
|
+
? 'The "stylelint" config in "package.json" already exists.'
|
|
48
|
+
: `The "${basename}" config already exists.`;
|
|
49
|
+
|
|
50
|
+
spinner.fail(`Failed to create config:\n${failureMessage} Remove it and then try again.`);
|
|
59
51
|
process.exit(1);
|
|
60
52
|
}
|
|
61
53
|
|