Skip to content

Commit 0d66d6a

Browse files
author
John Richard Chipps-Harding
authored
Overwrite support (#15)
* Overwrite support * Version bump
1 parent 2b10a50 commit 0d66d6a

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export const TopBar = styled("nav", {
291291

292292
- `--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.
293293
- `--output` The filename for the output file. Defaults to `styles.ts` which will be saved in the same directory as the CSS file.
294+
- `--overwrite` If the output file already exists, this will overwrite it. Defaults to `false`.
294295

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@phntms/css-components",
33
"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.",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"homepage": "https://github.com/phantomstudios/css-components#readme",

src/cli/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ const argv = yargs(process.argv.slice(2))
2222
describe: "filename to save alongside the css file",
2323
default: "styles.ts",
2424
},
25+
overwrite: {
26+
type: "boolean",
27+
describe: "should the output file be overwritten if it exists",
28+
default: false,
29+
},
2530
})
2631
.parseSync();
2732

2833
const cssFile = argv.css;
2934
const outputFileName = argv.output;
35+
const overwrite = argv.overwrite;
3036

3137
findFiles(cssFile).then((files) => {
3238
files.forEach((file) => {
@@ -35,6 +41,12 @@ findFiles(cssFile).then((files) => {
3541
const output = generateOutput(config, path.basename(file));
3642
const folder = path.dirname(file);
3743
const outputPath = path.join(folder, outputFileName);
44+
const exists = fs.existsSync(outputPath);
45+
46+
if (exists && !overwrite) {
47+
console.log(`File ${outputPath} already exists, skipping`);
48+
return;
49+
}
3850

3951
fs.writeFileSync(outputPath, output);
4052
console.log(

0 commit comments

Comments
 (0)