Skip to content

Make mdn-data a pure build time dependency. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
node_modules
.DS_STORE
.vscode

# ignore generated grammars
formatted-data
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"prepublish": "npm start",
"test": "./node_modules/.bin/mocha --reporter spec --recursive",
"start": "mkdir -p formatted-data src/grammars/generated/json && node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax.ne > ./src/grammars/js/formalSyntax.js && node ./src/scripts/updateBasicDataUnits.js && node ./src/scripts/formatData.js && node ./src/scripts/formatFormalSyntaxes.js && node ./src/scripts/formatGrammars.js",
"start": "./updateCSSData.sh",
"clean": "rm -rf src/grammars/generated",
"benchmark": "node test/benchmark.js",
"doctoc": "node ./node_modules/doctoc/doctoc.js README.md",
Expand Down Expand Up @@ -42,11 +42,11 @@
"mocha": "^3.5.0",
"pre-commit": "^1.2.2",
"postcss-value-parser": "^3.3.0",
"sinon": "^2.4.1"
"sinon": "^2.4.1",
"mdn-data": "1.0.0"
},
"dependencies": {
"fs-extra": "^3.0.1",
"mdn-data": "1.0.0",
"moo": "^0.4.1",
"nearley": "^2.11.0"
}
Expand Down
2 changes: 1 addition & 1 deletion src/expandShorthandProperty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const nearley = require('nearley');
const { css: { properties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');
const isShorthandProperty = require('./isShorthandProperty');
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
const shorthandProperties = require('../formatted-data/shorthand-properties.json');
Expand Down
2 changes: 1 addition & 1 deletion src/getShorthandComputedProperties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { css: { properties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');

/**
* Given a shorthand property, returns an array of the computed properties for that shorthand property. If given
Expand Down
2 changes: 1 addition & 1 deletion src/getShorthandsForProperty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const shortHandProperties = require('../formatted-data/shorthand-properties.json');
const { css: { properties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');

/**
* @type {Object}
Expand Down
2 changes: 1 addition & 1 deletion src/initialValueMap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { css: { properties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
const isShorthandProperty = require('./isShorthandProperty');

Expand Down
2 changes: 1 addition & 1 deletion src/isValidDeclaration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const nearley = require('nearley');
const { css: { properties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');
const { CSS } = require('./constants');

/**
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/extractProperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Takes raw data from MDN, filters out the shorthand properties, and decorates the data with additional properties.
* Writes the formatted data to FORMATTED_DATA_PATH.
*/
const fs = require('fs-extra');
const { css: { properties } } = require('mdn-data');
const PATHS = require('../constants/paths');

const ALL_PROPERTIES_DATA_FILE_NAME = 'properties.json';
const OUTPUT_FILE = `${PATHS.FORMATTED_DATA_PATH}${ALL_PROPERTIES_DATA_FILE_NAME}`;
fs.writeJson(OUTPUT_FILE, properties, { spaces: 2 })
.then(() => (
console.log(`Successfully extracted properties to ${OUTPUT_FILE}`)
));
4 changes: 2 additions & 2 deletions test/InitialValuesTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { assert } = require('chai');
const { css: { properties: cssProperties } } = require('mdn-data');
const properties = require('../formatted-data/properties.json');
const {
initialValue,
initialValues,
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('Initial values', function () {
'position',
'transform-box',
]);
Object.keys(cssProperties).forEach((prop) => {
Object.keys(properties).forEach((prop) => {
if (prop.startsWith('-') || buggyValues.has(prop)) return; // bug in grammar data
let initial = initialValue(prop);
assert(isValidDeclaration(prop, initial), `${prop}: ${initial} is not a legal initial value`);
Expand Down
23 changes: 23 additions & 0 deletions updateCSSData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
function realpath()
{
f=$@
if [ -d "$f" ]; then
base=""
dir="$f"
else
base="/$(basename "$f")"
dir=$(dirname "$f")
fi
dir=$(cd "$dir" && /bin/pwd)
echo "$dir$base"
}
cd "$(dirname "$(realpath "$0")")";
rm -rf formatted-data src/grammars/generated/json
mkdir -p formatted-data src/grammars/generated/json
node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax.ne > ./src/grammars/js/formalSyntax.js || exit 1
node ./src/scripts/updateBasicDataUnits.js || exit 1
node ./src/scripts/formatData.js || exit 1
node ./src/scripts/formatFormalSyntaxes.js || exit 1
node ./src/scripts/formatGrammars.js || exit 1
node ./src/scripts/extractProperties.js || exit 1