Skip to content

Commit

Permalink
Support config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Nov 24, 2014
1 parent cb20755 commit a3942c6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
config.json
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ Creates a comprehensive JSON file of selected [WebPlatform Docs](https://docs.we
```
[sudo] node update-wpd-docs --output <path to output json> [--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:
```
[sudo] node update-wpd-docs <alias>
```
[Example `config.json`](https://github.com/MarcelGerber/update-wpd-docs/blob/brackets-config/config.json)
4 changes: 4 additions & 0 deletions defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"vendor-prefixes": true,
"paths": "css/properties"
}
39 changes: 32 additions & 7 deletions update-wpd-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,45 @@ var fs = require("fs"),
path = require("path"),
program = require("commander");

var defaults = JSON.parse(fs.readFileSync("defaults.json")),
config;
try {
config = JSON.parse(fs.readFileSync("config.json"));
} catch (e) {
config = {};
}

instaview.conf.paths.articles = "https://docs.webplatform.org/wiki/"; // base URL for every link
instaview.conf.locale.image = "__Image__"; // disable <img> tags

var url, rawUrl = {};
rawUrl.page = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%20%5B%5BPath%3A%3A~{{1}}%2F*%5D%5D%7C%3FSummary%7Cprettyprint%3Dno%7Climit%3D1000000"; // #ask: [[Path::~{{1}}/*]]|?Summary|prettyprint=no|limit=1000000
rawUrl.properties = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%5B%5BValue%20for%20property%3A%3A~{{1}}%2F*%5D%5D%7C%3FProperty%20value%7C%3FProperty%20value%20description%7C%3FValue%20for%20property%7Cprettyprint%3Dno%7Climit%3D1000000"; // #ask: [[Value for property::~{{1}}/*]]|?Property value|?Property value description|?Value for property|prettyprint=no|limit=1000000

function getConfig(alias) {
var conf = {};
conf = defaults;
Object.keys(config).forEach(function (key) {
conf[key] = config[key];
});
var aliasConfig = config.aliases && config.aliases[alias];
if (alias && aliasConfig) {
Object.keys(aliasConfig).forEach(function (key) {
conf[key] = aliasConfig[key];
});
}
return conf;
}

// Parse arguments
program.parse(process.argv);
config = getConfig(program.args[0]);

program
.version("0.0.1")
.option("-o, --output <s>", "The output css.json")
.option("--paths, --path <s>", "Comma-separated list of path(s) to include", "css/properties")
.option("--nv, --exclude-vendor-prefixed", "Exclude vendor prefixed properties")
.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)
.parse(process.argv);

var result = {},
Expand All @@ -30,8 +56,7 @@ var result = {},
if (outputFile) {
outputFile = path.normalize(path.resolve(__dirname, outputFile));
} else {
console.error("Usage: update-docs --output <path to output json> [--exclude-vendor-prefixed] [[--path <comma-separated list of paths>]]\nExample: update-docs --output ..\\brackets\\src\\extensions\\default\\WebPlatformDocs\\css.json");
process.exit();
program.help();
}

var message = "Updated data will be written to \"" + outputFile + "\"" + (path.extname(outputFile) === ".json" ? "" : ", which is not a .json file") + ".";
Expand All @@ -55,7 +80,7 @@ function createURLs(url, path) {
}

var response, currentPath, oldResultsLength,
paths = program.path.split(",");
paths = program.paths.split(",");

function get(pathIndex) {
currentPath = paths[pathIndex];
Expand Down Expand Up @@ -135,4 +160,4 @@ function get(pathIndex) {
});
}

get(0);
get(0);

0 comments on commit a3942c6

Please sign in to comment.