Skip to content

Commit

Permalink
Add docs, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxattax97 committed Mar 13, 2019
1 parent 506c4fd commit 7d20803
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# openscad-format
An opinionated formatter for the OpenSCAD language.
A source code formatter for the OpenSCAD language.

Currently it's opinionated, but there may be improvements in the future which
allow you to alter the code style it enforces.

## Install
The utility is available on [npm](), you can install it like so:
```
$ npm install -g openscad-format
```
It packages `clang-format` with it for most platforms, so you don't need to
worry about installing it.

## Use
`openscad-format` is designed to be simple and flexible to use:
```
$ openscad-format --help
Usage: openscad-format [options]
Options:
--version Show version number [boolean]
-i, --input Input file to read, file globs allowed (quotes recommended)
-o, --output Output file to write
-h, --help Show help [boolean]
Examples:
openscad-format -i input.scad -o output.scad Formats input.scad and saves it as
output.scad
openscad-format < input.scad > output.scad Formats input.scad and saves it as
output.scad
openscad-format < input.scad Formats input.scad and writes to stdout
cat input.scad | openscad-format | less Formats input.scad and displays in less
openscad-format -i './**/*.scad' Formats all *.scad files recursively
and writes them to their respective
files
This utility requires clang-format, but this is automatically installed for most
platforms.
```

## Contribute
Make sure your PR's pass the unit tests, are free of ESLint errors. To check,
run `npm run all` and it will guide you through what needs to be done.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const { argv } = require('yargs')
.example('$0 -i \'./**/*.scad\'', 'Formats all *.scad files recursively and writes them to their respective files')
.alias('i', 'input')
.nargs('i', 1)
.describe('i', 'Input file to read, file globs allowed (qoutes recommended)')
.describe('i', 'Input file to read, file globs allowed (quotes recommended)')
.alias('o', 'output')
.nargs('o', 1)
.describe('o', 'Output file to write')
.help('h')
.alias('h', 'help')
.epilog('This utility requies clang-format, but this is automatically installed for most platforms.');
.epilog('This utility requires clang-format, but this is automatically installed for most platforms.');

tmp.setGracefulCleanup();

Expand Down Expand Up @@ -141,6 +141,7 @@ async function format(str, tmpDir) {
return result;
} catch (err) {
console.error('Failure while formatting with Clang', err);
throw err;
}
}

Expand All @@ -156,7 +157,8 @@ async function feed(input, output, tmpDir) {
str = str.toString();

if (!str) {
console.warn(`Contents of ${input} is empty; skipping ...`);
// Do not write to output since we sometimes use stdout.
// console.warn(`Contents of ${input} is empty; skipping ...`);
return '';
}

Expand All @@ -178,6 +180,7 @@ async function feed(input, output, tmpDir) {
throw new Error('Failed to format content string');
} catch (err) {
console.error('Failed to feed to formatter and write output', err);
throw err;
}
}

Expand Down Expand Up @@ -247,9 +250,11 @@ async function main(input, output) {
return resultList;
} catch (err) {
console.error(err);
throw err;
}
} catch (err) {
console.error(err);
throw err;
}
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"scripts": {
"lint": "eslint .",
"fix": "eslint . --fix",
"cmd": "node index.js",
"test": "mocha",
"demo": "node index.js -i source.scad"
"all": "eslint . --fix && mocha"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 7d20803

Please sign in to comment.