Skip to content

Commit

Permalink
add better error handling and add colors to output
Browse files Browse the repository at this point in the history
  • Loading branch information
fpetrakov committed Aug 30, 2022
1 parent be086a5 commit 8bc5a16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-to-oklch",
"version": "1.0.8",
"version": "1.0.9",
"description": "CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files.",
"main": "./src/index.js",
"bin": {
Expand Down Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"colorjs.io": "^0.4.0",
"commander": "^9.4.0",
"picocolors": "^1.0.0",
"postcss": "^8.4.16"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { program } = require("commander");
const packageVersion = require("../package.json").version;
const postcss = require("postcss");
const fs = require("fs");
const pc = require("picocolors")
const plugin = require("./plugin");

program
Expand All @@ -13,16 +14,21 @@ program
.version(packageVersion);

program.argument("<path>", "path to css files").action(async (path) => {
if (!fs.existsSync(path)) {
console.error(pc.bgRed("File doesn't exist"));
process.exit(1);
}

const css = fs.readFileSync(path, "utf-8");

const result = await postcss([plugin])
.process(css, { from: path })
.toString();

await fs.writeFile(path, result, (err) => {
if (err) console.error(err);
if (err) console.error(pc.bgRed(err));

console.log("Done!");
console.log(pc.bgGreen("Done!"));
});
});

Expand Down

0 comments on commit 8bc5a16

Please sign in to comment.