Skip to content

Commit 078dc8a

Browse files
jonathantnealromainmenke
authored andcommitted
0.9.0
1 parent e163e18 commit 078dc8a

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

plugins/css-has-pseudo/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to CSS Has Pseudo
22

3+
### 0.9.0 (November 26, 2018)
4+
5+
- Improved CLI usage
6+
37
### 0.8.0 (November 26, 2018)
48

59
- Fixed an issue where attribute names were not being properly encoded

plugins/css-has-pseudo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-has-pseudo",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"description": "Style elements relative to other elements in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"license": "CC0-1.0",

plugins/css-has-pseudo/src/cli.js

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import fs from 'fs';
22
import plugin from './postcss';
33

4-
if (process.argv.length < 3) {
5-
console.log([
6-
'CSS Has Pseudo\n',
7-
' Transforms CSS with :has {}\n',
8-
'Usage:\n',
9-
' css-has-pseudo source.css transformed.css',
10-
' css-has-pseudo --in=source.css --out=transformed.css --opts={}',
11-
' echo "body:has(:focus) {}" | css-has-pseudo\n'
12-
].join('\n'));
13-
process.exit(0);
14-
}
15-
164
// get process and plugin options from the command line
175
const fileRegExp = /^[\w\/.]+$/;
186
const argRegExp = /^--(\w+)=("|')?(.+)\2$/;
@@ -41,6 +29,19 @@ const argo = process.argv.slice(2).reduce(
4129
// get css from command line arguments or stdin
4230
(argo.from === '<stdin>' ? getStdin() : readFile(argo.from))
4331
.then(css => {
32+
if (argo.from === '<stdin>' && !css) {
33+
console.log([
34+
'CSS Has Pseudo\n',
35+
' Transforms CSS with :has {}\n',
36+
'Usage:\n',
37+
' css-has-pseudo source.css transformed.css',
38+
' css-has-pseudo --from=source.css --to=transformed.css --opts={}',
39+
' echo "body:has(:focus) {}" | css-has-pseudo\n'
40+
].join('\n'));
41+
42+
process.exit(0);
43+
}
44+
4445
const pluginOpts = JSON.parse(
4546
argo.opts
4647
.replace(relaxedJsonPropRegExp, '"$2": ')
@@ -57,14 +58,26 @@ const argo = process.argv.slice(2).reduce(
5758
() => `CSS was written to "${argo.to}"`
5859
)
5960
}
60-
}).then(
61+
}).catch(
62+
error => {
63+
if (Object(error).name === 'CssSyntaxError') {
64+
throw new Error(`PostCSS had trouble reading the file (${error.reason} on line ${error.line}, column ${error.column}).`);
65+
}
66+
67+
if (Object(error).errno === -2) {
68+
throw new Error(`Sorry, "${error.path}" could not be read.`);
69+
}
70+
71+
throw error;
72+
}
73+
).then(
6174
result => {
6275
console.log(result);
6376

6477
process.exit(0);
6578
},
6679
error => {
67-
console.error(error);
80+
console.error(Object(error).message || 'Something bad happened and we don’t even know what it was.');
6881

6982
process.exit(1);
7083
}

0 commit comments

Comments
 (0)