Skip to content

Commit d43896f

Browse files
Merge pull request #20 from mahirshah/mdn-at-buildtime
Make mdn-data a pure build time dependency.
2 parents b5329d6 + 0c79ee5 commit d43896f

10 files changed

+48
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
node_modules
33
.DS_STORE
4+
.vscode
45

56
# ignore generated grammars
67
formatted-data

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"prepublish": "npm start",
1212
"test": "./node_modules/.bin/mocha --reporter spec --recursive",
13-
"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",
13+
"start": "./updateCSSData.sh",
1414
"clean": "rm -rf src/grammars/generated",
1515
"benchmark": "node test/benchmark.js",
1616
"doctoc": "node ./node_modules/doctoc/doctoc.js README.md",
@@ -42,11 +42,11 @@
4242
"mocha": "^3.5.0",
4343
"pre-commit": "^1.2.2",
4444
"postcss-value-parser": "^3.3.0",
45-
"sinon": "^2.4.1"
45+
"sinon": "^2.4.1",
46+
"mdn-data": "1.0.0"
4647
},
4748
"dependencies": {
4849
"fs-extra": "^3.0.1",
49-
"mdn-data": "1.0.0",
5050
"moo": "^0.4.1",
5151
"nearley": "^2.11.0"
5252
}

src/expandShorthandProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const nearley = require('nearley');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const isShorthandProperty = require('./isShorthandProperty');
44
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
55
const shorthandProperties = require('../formatted-data/shorthand-properties.json');

src/getShorthandComputedProperties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { css: { properties } } = require('mdn-data');
1+
const properties = require('../formatted-data/properties.json');
22

33
/**
44
* Given a shorthand property, returns an array of the computed properties for that shorthand property. If given

src/getShorthandsForProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const shortHandProperties = require('../formatted-data/shorthand-properties.json');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33

44
/**
55
* @type {Object}

src/initialValueMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { css: { properties } } = require('mdn-data');
1+
const properties = require('../formatted-data/properties.json');
22
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
33
const isShorthandProperty = require('./isShorthandProperty');
44

src/isValidDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const nearley = require('nearley');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const { CSS } = require('./constants');
44

55
/**

src/scripts/extractProperties.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Takes raw data from MDN, filters out the shorthand properties, and decorates the data with additional properties.
3+
* Writes the formatted data to FORMATTED_DATA_PATH.
4+
*/
5+
const fs = require('fs-extra');
6+
const { css: { properties } } = require('mdn-data');
7+
const PATHS = require('../constants/paths');
8+
9+
const ALL_PROPERTIES_DATA_FILE_NAME = 'properties.json';
10+
const OUTPUT_FILE = `${PATHS.FORMATTED_DATA_PATH}${ALL_PROPERTIES_DATA_FILE_NAME}`;
11+
fs.writeJson(OUTPUT_FILE, properties, { spaces: 2 })
12+
.then(() => (
13+
console.log(`Successfully extracted properties to ${OUTPUT_FILE}`)
14+
));

test/InitialValuesTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { assert } = require('chai');
2-
const { css: { properties: cssProperties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const {
44
initialValue,
55
initialValues,
@@ -31,7 +31,7 @@ describe('Initial values', function () {
3131
'position',
3232
'transform-box',
3333
]);
34-
Object.keys(cssProperties).forEach((prop) => {
34+
Object.keys(properties).forEach((prop) => {
3535
if (prop.startsWith('-') || buggyValues.has(prop)) return; // bug in grammar data
3636
let initial = initialValue(prop);
3737
assert(isValidDeclaration(prop, initial), `${prop}: ${initial} is not a legal initial value`);

updateCSSData.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
function realpath()
3+
{
4+
f=$@
5+
if [ -d "$f" ]; then
6+
base=""
7+
dir="$f"
8+
else
9+
base="/$(basename "$f")"
10+
dir=$(dirname "$f")
11+
fi
12+
dir=$(cd "$dir" && /bin/pwd)
13+
echo "$dir$base"
14+
}
15+
cd "$(dirname "$(realpath "$0")")";
16+
rm -rf formatted-data src/grammars/generated/json
17+
mkdir -p formatted-data src/grammars/generated/json
18+
node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax.ne > ./src/grammars/js/formalSyntax.js || exit 1
19+
node ./src/scripts/updateBasicDataUnits.js || exit 1
20+
node ./src/scripts/formatData.js || exit 1
21+
node ./src/scripts/formatFormalSyntaxes.js || exit 1
22+
node ./src/scripts/formatGrammars.js || exit 1
23+
node ./src/scripts/extractProperties.js || exit 1

0 commit comments

Comments
 (0)