Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #17 from ddbeck/make-descriptions-requirable
Browse files Browse the repository at this point in the history
Make it possible to require short-descriptions
  • Loading branch information
wbamberg committed Apr 6, 2019
2 parents a7c5934 + ce6c16c commit 922ad33
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const extend = require('extend');
const fs = require('fs');
const path = require('path');

function walk(directory, callback) {
fs.readdirSync(directory).forEach((filename) => {
const filepath = path.join(directory, filename);

if (fs.statSync(filepath).isDirectory()) {
walk(filepath, callback);
}
callback(filepath);
});
}

function collectJSON(directory) {
const filepaths = [];
walk(directory, (fp) => {
if (path.extname(fp) === '.json') {
filepaths.push(fp);
}
});
return filepaths;
}

function loadJSON() {
const jsons = collectJSON(path.resolve(__dirname, './descriptions'));
const finalObj = {};

jsons.forEach((json) => {
const nextObj = JSON.parse(fs.readFileSync(json, 'utf8'));
extend(true, finalObj, nextObj);
});
return finalObj;
}

module.exports = loadJSON();
3 changes: 1 addition & 2 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"directories": {
"test": "test"
},
"dependencies": {},
"dependencies": {
"extend": "^3.0.2"
},
"devDependencies": {
"eslint": "^5.9.0",
"eslint-config-airbnb-base": "^13.1.0",
Expand All @@ -16,7 +18,7 @@
"request": "^2.88.0"
},
"scripts": {
"test": "npm run lint-js && node test/json-format-rules.js && node test/content-rules.js && npm run lint-json",
"test": "node test/test.js && npm run lint-js && node test/json-format-rules.js && node test/content-rules.js && npm run lint-json",
"lint-js": "eslint test/*.js scripts/*.js",
"lint-json": "node test/lint-json.js",
"lint-wiki": "node test/lint-wiki.js",
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable no-underscore-dangle */
const assert = require('assert');

const descriptions = require('..');

// Make sure the data is importable and does something vaguely useful
assert(typeof descriptions.css.properties.opacity.__short_description === 'string');
assert(descriptions.css.properties.opacity.__short_description.length > 0);

0 comments on commit 922ad33

Please sign in to comment.