-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
95 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.yml | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"useTabs": true, | ||
"tabWidth": 4, | ||
"arrowParens": "avoid", | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Sync object | ||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
const config = { | ||
verbose: true, | ||
export default { | ||
verbose: true, | ||
transform: {}, | ||
}; | ||
|
||
module.exports = config; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
#!/usr/bin/env node | ||
const { program, Option } = require('commander') | ||
const packageVersion = require('../package.json').version | ||
const postcss = require('postcss') | ||
const fs = require('fs') | ||
const pc = require('picocolors') | ||
const plugin = require('./plugin') | ||
const { logError } = require('./utils') | ||
import { Command, Option } from "commander"; | ||
import postcss from "postcss"; | ||
import fs from "fs"; | ||
import pc from "picocolors"; | ||
|
||
const PRECISION_VALUES = Array.from(Array(21), (_, index) => String(index + 1)) | ||
import plugin from "./plugin.js"; | ||
import { logError } from "./utils.js"; | ||
|
||
|
||
const program = new Command(); | ||
|
||
const PRECISION_VALUES = Array.from(Array(21), (_, index) => String(index + 1)); | ||
|
||
const precisionOption = new Option( | ||
'-p, --precision <number>', | ||
'precision of color conversion', | ||
'5', | ||
).choices(PRECISION_VALUES) | ||
"-p, --precision <number>", | ||
"precision of color conversion", | ||
"5", | ||
).choices(PRECISION_VALUES); | ||
|
||
program | ||
.name('convert-to-oklch') | ||
.name("convert-to-oklch") | ||
.description( | ||
'CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files.', | ||
"CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files.", | ||
) | ||
.version(packageVersion) | ||
.argument('<path>', 'path to css files') | ||
.version("1.2.4") | ||
.argument("<path>", "path to css files") | ||
.addOption(precisionOption) | ||
.parse() | ||
.parse(); | ||
|
||
const { args: cssFilePaths } = program | ||
const { precision } = program.opts() | ||
const { args: cssFilePaths } = program; | ||
const { precision } = program.opts(); | ||
|
||
const processCssFile = async path => { | ||
if (!fs.existsSync(path)) { | ||
logError("File doesn't exist: " + path) | ||
return | ||
logError("File doesn't exist: " + path); | ||
return; | ||
} | ||
|
||
const css = fs.readFileSync(path, 'utf-8') | ||
const css = fs.readFileSync(path, "utf-8"); | ||
|
||
const convertedCss = await postcss([plugin(precision)]) | ||
.process(css, { from: path }) | ||
.toString() | ||
.toString(); | ||
|
||
fs.writeFile(path, convertedCss, err => { | ||
if (err) { | ||
logError(err) | ||
fs.writeFileSync(path, css) | ||
logError(err); | ||
fs.writeFileSync(path, css); | ||
} | ||
}) | ||
} | ||
}); | ||
}; | ||
|
||
const processFiles = async () => { | ||
cssFilePaths.map(file => processCssFile(file)) | ||
await Promise.allSettled(cssFilePaths) | ||
console.log(pc.bgGreen(pc.black('Done!'))) | ||
} | ||
cssFilePaths.map(file => processCssFile(file)); | ||
await Promise.allSettled(cssFilePaths); | ||
console.log(pc.bgGreen(pc.black("Done!"))); | ||
}; | ||
|
||
processFiles() | ||
processFiles(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
const pc = require("picocolors"); | ||
import pc from "picocolors"; | ||
|
||
function logError(errorMessage) { | ||
export function logError(errorMessage) { | ||
console.error(pc.bgRed(errorMessage)); | ||
} | ||
|
||
module.exports = { | ||
logError, | ||
}; |