Skip to content

Commit

Permalink
Add option --lowercase-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Nov 25, 2014
1 parent a3942c6 commit 7bb24bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Creates a comprehensive JSON file of selected [WebPlatform Docs](https://docs.we

# Usage
```
[sudo] node update-wpd-docs --output <path to output json> [--exclude-vendor-prefixed] [[--path <comma-separated list of paths>]]
[sudo] node update-wpd-docs --output <path to output json> [--lowercase-keys] [--exclude-vendor-prefixed] [--path <comma-separated list of paths>]
```

# Config
You can create a `config.json` file with the keys `output`, `paths` and `vendor-prefixes`. You can also define aliases in there and use them like this:
You can create a `config.json` file with the keys `output`, `paths`, `lowercase-keys` and `vendor-prefixes`. You can also define aliases in there and use them like this:
```
[sudo] node update-wpd-docs <alias>
```
Expand Down
3 changes: 2 additions & 1 deletion defaults.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"vendor-prefixes": true,
"paths": "css/properties"
"paths": "css/properties",
"lowercase-keys": false
}
15 changes: 13 additions & 2 deletions update-wpd-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ config = getConfig(program.args[0]);
program
.version("0.0.1")
.option("-o, --output <s>", "Path to output JSON", config.output)
.option("--nv, --exclude-vendor-prefixed", "Exclude vendor prefixed properties", !config["vendor-prefixes"])
.option("--path, --paths <s>", "Comma-separated list of path(s) to include", "css/properties", config.paths)
.option("-l, --lowercase-keys", "Make object keys all-lowercase")
.option("--nv, --exclude-vendor-prefixed", "Exclude vendor prefixed properties")
.option("--path, --paths <s>", "Comma-separated list of path(s) to include", config.paths)
.parse(process.argv);

// Apply defaults
program.lowercaseKeys = program.lowercaseKeys || config["lowercase-keys"];
program.excludeVendorPrefixed = program.excludeVendorPrefixed || !config["vendor-prefixes"];

var result = {},
outputFile = program.output;

Expand Down Expand Up @@ -113,6 +118,9 @@ function get(pathIndex) {
propertyData.SUMMARY = instaview.convert(htmlEscape(data.printouts.Summary[0]));
propertyData.URL = data.fullurl;

if (program.lowercaseKeys) {
propertyName = propertyName.toLowerCase();
}
result[propertyName] = propertyData;
}
});
Expand All @@ -130,6 +138,9 @@ function get(pathIndex) {
Object.keys(response).forEach(function (valueIdentifier) {
var data = response[valueIdentifier].printouts;
var forProperty = data["Value for property"].length && data["Value for property"][0].fulltext;
if (forProperty && program.lowercaseKeys) {
forProperty = forProperty.toLowerCase();
}
var valueData = {};
var description;
if (data["Property value"].length && forProperty && result.hasOwnProperty(forProperty)) {
Expand Down

0 comments on commit 7bb24bf

Please sign in to comment.