From 1cb69116b7202e8939dfbe01721ac22187252f91 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Tue, 21 Nov 2017 12:24:28 -0800 Subject: [PATCH 1/3] Extract unweildy shell command in package.json to a bash script. --- package.json | 2 +- updateCSSData.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 updateCSSData.sh diff --git a/package.json b/package.json index 72554b5..bc219d6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/updateCSSData.sh b/updateCSSData.sh new file mode 100755 index 0000000..4c89d3b --- /dev/null +++ b/updateCSSData.sh @@ -0,0 +1,22 @@ +#!/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 \ No newline at end of file From 3cb3b7354e58253a7d045366e543e3dda542d0be Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Tue, 21 Nov 2017 12:25:47 -0800 Subject: [PATCH 2/3] Make mdn-data a pure build time dependency. The mdn-data package is not being released to npm on any sort of regular basis. This change is preparing for the ability to update directly from the github repo using scripts or submodules. Also, it's best if all the data is in kept in sync because the mdn-data changes are not following any sort of semver concepts in how they land schema or data changes. --- package.json | 4 ++-- src/expandShorthandProperty.js | 2 +- src/getShorthandComputedProperties.js | 2 +- src/getShorthandsForProperty.js | 2 +- src/initialValueMap.js | 2 +- src/isValidDeclaration.js | 2 +- src/scripts/extractProperties.js | 14 ++++++++++++++ test/InitialValuesTest.js | 4 ++-- updateCSSData.sh | 3 ++- 9 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 src/scripts/extractProperties.js diff --git a/package.json b/package.json index bc219d6..6bf5523 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/expandShorthandProperty.js b/src/expandShorthandProperty.js index f292efa..83fcc3d 100644 --- a/src/expandShorthandProperty.js +++ b/src/expandShorthandProperty.js @@ -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'); diff --git a/src/getShorthandComputedProperties.js b/src/getShorthandComputedProperties.js index d2571eb..3164609 100644 --- a/src/getShorthandComputedProperties.js +++ b/src/getShorthandComputedProperties.js @@ -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 diff --git a/src/getShorthandsForProperty.js b/src/getShorthandsForProperty.js index 55024ad..50ebbb4 100644 --- a/src/getShorthandsForProperty.js +++ b/src/getShorthandsForProperty.js @@ -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} diff --git a/src/initialValueMap.js b/src/initialValueMap.js index 0e1730c..c661f48 100644 --- a/src/initialValueMap.js +++ b/src/initialValueMap.js @@ -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'); diff --git a/src/isValidDeclaration.js b/src/isValidDeclaration.js index b5d554a..c9ac2b9 100644 --- a/src/isValidDeclaration.js +++ b/src/isValidDeclaration.js @@ -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'); /** diff --git a/src/scripts/extractProperties.js b/src/scripts/extractProperties.js new file mode 100644 index 0000000..79fb0f2 --- /dev/null +++ b/src/scripts/extractProperties.js @@ -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}`) + )); diff --git a/test/InitialValuesTest.js b/test/InitialValuesTest.js index 1647144..cca2d02 100644 --- a/test/InitialValuesTest.js +++ b/test/InitialValuesTest.js @@ -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, @@ -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`); diff --git a/updateCSSData.sh b/updateCSSData.sh index 4c89d3b..56867f1 100755 --- a/updateCSSData.sh +++ b/updateCSSData.sh @@ -19,4 +19,5 @@ node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax. 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 \ No newline at end of file +node ./src/scripts/formatGrammars.js || exit 1 +node ./src/scripts/extractProperties.js || exit 1 \ No newline at end of file From 0c79ee581c01e0b6c8db852092f9fa40cff81c14 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Tue, 21 Nov 2017 12:30:34 -0800 Subject: [PATCH 3/3] Ignore .vscode directory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 91b829c..bc21573 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea node_modules .DS_STORE +.vscode # ignore generated grammars formatted-data