create-stylelint 1.0.0 → 1.0.2
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 +1 -1
- package/package.json +14 -24
- package/src/index.mjs +51 -21
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# create-stylelint
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/create-stylelint)
|
|
4
|
-
[](https://github.com/stylelint/stylelint-create/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
6
|
The [`create`](https://docs.npmjs.com/cli/commands/npm-init) script for [Stylelint](https://github.com/stylelint/stylelint).
|
|
7
7
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-stylelint",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "The npm init script for Stylelint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stylelint",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"format": "prettier . --write --cache",
|
|
33
|
-
"lint": "
|
|
33
|
+
"lint": "run-p --continue-on-error lint:*",
|
|
34
34
|
"lint:formatting": "prettier . --check --cache",
|
|
35
35
|
"lint:js": "eslint",
|
|
36
36
|
"lint:md": "remark . --quiet --frail",
|
|
37
37
|
"lint:packagejson": "npmPkgJsonLint .",
|
|
38
38
|
"lint:types": "tsc",
|
|
39
39
|
"pretest": "npm run lint",
|
|
40
|
-
"test": "
|
|
41
|
-
"watch": "
|
|
40
|
+
"test": "node --test test/integration.test.js",
|
|
41
|
+
"watch": "node --test --watch test/integration.test.js"
|
|
42
42
|
},
|
|
43
43
|
"prettier": "@stylelint/prettier-config",
|
|
44
44
|
"npmpackagejsonlint": {
|
|
@@ -50,32 +50,22 @@
|
|
|
50
50
|
]
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@clack/prompts": "^1.
|
|
54
|
-
"cosmiconfig": "^9.0.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"semver": "^7.7.4",
|
|
58
|
-
"strip-indent": "^4.1.0",
|
|
59
|
-
"which-pm-runs": "^2.0.0"
|
|
53
|
+
"@clack/prompts": "^1.8.1",
|
|
54
|
+
"cosmiconfig": "^9.0.2",
|
|
55
|
+
"semver": "^7.8.5",
|
|
56
|
+
"tinyexec": "^1.3.1"
|
|
60
57
|
},
|
|
61
58
|
"devDependencies": {
|
|
62
|
-
"@stylelint/npm-package-json-lint-config": "^
|
|
59
|
+
"@stylelint/npm-package-json-lint-config": "^6.0.0",
|
|
63
60
|
"@stylelint/prettier-config": "^4.0.0",
|
|
64
61
|
"@stylelint/remark-preset": "^5.1.1",
|
|
65
|
-
"@types/node": "^
|
|
66
|
-
"
|
|
67
|
-
"eslint": "^10.1.0",
|
|
62
|
+
"@types/node": "^26.6.3",
|
|
63
|
+
"eslint": "^10.11.0",
|
|
68
64
|
"eslint-config-stylelint": "^27.0.0",
|
|
69
|
-
"npm-run-
|
|
70
|
-
"prettier": "^3.
|
|
65
|
+
"npm-run-all2": "^9.0.3",
|
|
66
|
+
"prettier": "^3.9.9",
|
|
71
67
|
"remark-cli": "^12.0.1",
|
|
72
|
-
"typescript": "^
|
|
73
|
-
"vitest": "^4.1.1"
|
|
74
|
-
},
|
|
75
|
-
"optionalDependencies": {
|
|
76
|
-
"@rollup/rollup-darwin-x64": "*",
|
|
77
|
-
"@rollup/rollup-linux-x64-gnu": "*",
|
|
78
|
-
"@rollup/rollup-win32-x64-msvc": "*"
|
|
68
|
+
"typescript": "^7.0.2"
|
|
79
69
|
},
|
|
80
70
|
"engines": {
|
|
81
71
|
"node": ">=20.19.0"
|
package/src/index.mjs
CHANGED
|
@@ -3,33 +3,29 @@
|
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
5
|
import process from 'node:process';
|
|
6
|
+
import { styleText } from 'node:util'; // eslint-disable-line n/no-unsupported-features/node-builtins
|
|
6
7
|
|
|
7
8
|
import { cancel, confirm, intro, isCancel, log, note, outro, spinner } from '@clack/prompts';
|
|
8
9
|
import { cosmiconfig } from 'cosmiconfig';
|
|
9
|
-
import {
|
|
10
|
-
import pc from 'picocolors';
|
|
11
|
-
import stripIndent from 'strip-indent';
|
|
12
|
-
// @ts-expect-error - TS2595: 'whichPMRuns' can only be imported by using a default import.
|
|
13
|
-
// Need to wait for a `@types/which-pm-runs` new version.
|
|
14
|
-
import { whichPMRuns } from 'which-pm-runs';
|
|
10
|
+
import { x } from 'tinyexec';
|
|
15
11
|
|
|
16
12
|
const DEFAULT_CONFIG_FILE = 'stylelint.config.mjs';
|
|
17
13
|
const DEFAULT_CONFIG_CONTENT = `/** @type {import("stylelint").Config} */
|
|
18
14
|
export default {
|
|
19
|
-
|
|
15
|
+
extends: ["stylelint-config-standard"]
|
|
20
16
|
};`;
|
|
21
17
|
|
|
22
18
|
const ADD_COMMAND = 'add -D stylelint stylelint-config-standard';
|
|
23
19
|
|
|
24
20
|
export async function main() {
|
|
25
|
-
const pkgManager =
|
|
21
|
+
const pkgManager = detectPackageManager();
|
|
26
22
|
const cwd = './';
|
|
27
23
|
|
|
28
|
-
intro(
|
|
24
|
+
intro(styleText(['bgGreen', 'white'], ' create-stylelint '));
|
|
29
25
|
|
|
30
26
|
note(
|
|
31
27
|
stripIndent(`
|
|
32
|
-
Create a ${
|
|
28
|
+
Create a ${styleText('cyan', DEFAULT_CONFIG_FILE)} file containing:
|
|
33
29
|
|
|
34
30
|
${DEFAULT_CONFIG_CONTENT.split('\n').join('\n\t\t\t ')}
|
|
35
31
|
|
|
@@ -58,15 +54,15 @@ export async function main() {
|
|
|
58
54
|
const basename = path.basename(existingConfig.filepath);
|
|
59
55
|
const failureMessage =
|
|
60
56
|
basename === 'package.json'
|
|
61
|
-
? `A ${
|
|
62
|
-
: `A ${
|
|
57
|
+
? `A ${styleText('cyan', 'stylelint')} entry in ${styleText('cyan', 'package.json')} already exists.`
|
|
58
|
+
: `A ${styleText('cyan', basename)} file already exists.`;
|
|
63
59
|
|
|
64
60
|
throw new Error(`${failureMessage} Remove it and then try again.`);
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
if (!directoryHasPackageJson(cwd)) {
|
|
68
64
|
throw new Error(
|
|
69
|
-
`A ${
|
|
65
|
+
`A ${styleText('cyan', 'package.json')} was not found. Run ${styleText('cyan', `${pkgManager} init`)} and then try again.`,
|
|
70
66
|
);
|
|
71
67
|
}
|
|
72
68
|
|
|
@@ -81,7 +77,14 @@ export async function main() {
|
|
|
81
77
|
depsSpinner.start('Adding dependencies');
|
|
82
78
|
|
|
83
79
|
try {
|
|
84
|
-
await
|
|
80
|
+
const { exitCode, stderr, stdout } = await x(pkgManager, ADD_COMMAND.split(' '), {
|
|
81
|
+
nodeOptions: { cwd },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (exitCode !== 0) {
|
|
85
|
+
throw new Error(stderr || stdout);
|
|
86
|
+
}
|
|
87
|
+
|
|
85
88
|
depsSpinner.stop('Added dependencies');
|
|
86
89
|
} catch (error) {
|
|
87
90
|
handleError(depsSpinner, error);
|
|
@@ -93,25 +96,25 @@ export async function main() {
|
|
|
93
96
|
stripIndent(`
|
|
94
97
|
Lint your CSS files:
|
|
95
98
|
|
|
96
|
-
${
|
|
99
|
+
${styleText('dim', `${getExecuteCommand(pkgManager)} stylelint "**/*.css"`)}
|
|
97
100
|
|
|
98
101
|
Customize your config:
|
|
99
102
|
|
|
100
|
-
- ${
|
|
103
|
+
- ${styleText(['underline', 'cyan'], 'https://stylelint.io/user-guide/customize')}
|
|
101
104
|
`).trim(),
|
|
102
105
|
'Next steps:',
|
|
103
106
|
);
|
|
104
107
|
|
|
105
108
|
log.message(
|
|
106
109
|
stripIndent(`
|
|
107
|
-
${
|
|
110
|
+
${styleText('dim', 'Support Stylelint:')}
|
|
108
111
|
|
|
109
|
-
${
|
|
110
|
-
${
|
|
112
|
+
${styleText('dim', `- ${styleText(['underline', 'cyan'], 'https://github.com/sponsors/stylelint')}`)}
|
|
113
|
+
${styleText('dim', `- ${styleText(['underline', 'cyan'], 'https://opencollective.com/stylelint')}`)}
|
|
111
114
|
`).trim(),
|
|
112
115
|
);
|
|
113
116
|
|
|
114
|
-
outro(
|
|
117
|
+
outro(styleText('green', 'Done!'));
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
async function getExistingConfigInDirectory() {
|
|
@@ -155,6 +158,33 @@ function getExecuteCommand(pkgManager) {
|
|
|
155
158
|
case 'yarn':
|
|
156
159
|
return `${pkgManager} dlx`;
|
|
157
160
|
default:
|
|
158
|
-
throw new Error(`${
|
|
161
|
+
throw new Error(`${styleText('cyan', pkgManager)} package manager is not supported`);
|
|
159
162
|
}
|
|
160
163
|
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {string} string
|
|
167
|
+
* @return {string}
|
|
168
|
+
*/
|
|
169
|
+
function stripIndent(string) {
|
|
170
|
+
const indents = string.match(/^[ \t]*(?=\S)/gm);
|
|
171
|
+
|
|
172
|
+
if (!indents) return string;
|
|
173
|
+
|
|
174
|
+
const commonIndent = Math.min(...indents.map((indent) => indent.length));
|
|
175
|
+
|
|
176
|
+
if (commonIndent === 0) return string;
|
|
177
|
+
|
|
178
|
+
return string.replace(new RegExp(`^[ \\t]{${commonIndent}}`, 'gm'), '');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function detectPackageManager() {
|
|
182
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
183
|
+
|
|
184
|
+
if (!userAgent) return 'npm';
|
|
185
|
+
|
|
186
|
+
const [spec = ''] = userAgent.split(' ');
|
|
187
|
+
const name = spec.substring(0, spec.lastIndexOf('/'));
|
|
188
|
+
|
|
189
|
+
return name === 'npminstall' ? 'cnpm' : name;
|
|
190
|
+
}
|