Skip to content

Commit

Permalink
Overwrite support (#15)
Browse files Browse the repository at this point in the history
* Overwrite support

* Version bump
  • Loading branch information
John Richard Chipps-Harding committed Nov 16, 2022
1 parent 2b10a50 commit 0d66d6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export const TopBar = styled("nav", {

- `--css` The path to the CSS file you want to generate a component from. This can also be a recursive glob pattern allowing you to scan your entire components directory.
- `--output` The filename for the output file. Defaults to `styles.ts` which will be saved in the same directory as the CSS file.
- `--overwrite` If the output file already exists, this will overwrite it. Defaults to `false`.

Example to generate components from all CSS files in the components directory:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@phntms/css-components",
"description": "At its core, css-components is a simple wrapper around standard CSS. It allows you to write your CSS how you wish then compose them into a component ready to be used in React.",
"version": "0.1.0",
"version": "0.1.1",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"homepage": "https://github.com/phantomstudios/css-components#readme",
Expand Down
12 changes: 12 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const argv = yargs(process.argv.slice(2))
describe: "filename to save alongside the css file",
default: "styles.ts",
},
overwrite: {
type: "boolean",
describe: "should the output file be overwritten if it exists",
default: false,
},
})
.parseSync();

const cssFile = argv.css;
const outputFileName = argv.output;
const overwrite = argv.overwrite;

findFiles(cssFile).then((files) => {
files.forEach((file) => {
Expand All @@ -35,6 +41,12 @@ findFiles(cssFile).then((files) => {
const output = generateOutput(config, path.basename(file));
const folder = path.dirname(file);
const outputPath = path.join(folder, outputFileName);
const exists = fs.existsSync(outputPath);

if (exists && !overwrite) {
console.log(`File ${outputPath} already exists, skipping`);
return;
}

fs.writeFileSync(outputPath, output);
console.log(
Expand Down

0 comments on commit 0d66d6a

Please sign in to comment.