-
Notifications
You must be signed in to change notification settings - Fork 562
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
feat(formats): add support for Microsoft's JSONC format #732
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
// some comment | ||
"source": ["test/properties/**/*.json"], | ||
"platforms": { | ||
"web": { | ||
"transformGroup": "web", | ||
"prefix": "smop", | ||
"buildPath": "test/output/web/", | ||
"files": [ | ||
{ | ||
"destination": "_icons.css", | ||
"format": "scss/icons" | ||
}, | ||
{ | ||
"destination": "_variables.css", | ||
"format": "scss/variables" | ||
}, | ||
{ | ||
"destination": "_styles.js", | ||
"format": "javascript/module" | ||
} | ||
] | ||
}, | ||
"scss": { | ||
"transformGroup": "scss", | ||
"prefix": "smop", | ||
"buildPath": "test/output/scss/", | ||
"files": [ | ||
{ | ||
"destination": "_icons.scss", | ||
"format": "scss/icons" | ||
}, | ||
{ | ||
"destination": "_variables.scss", | ||
"format": "scss/variables" | ||
} | ||
] | ||
}, | ||
"less": { | ||
"transformGroup": "less", | ||
"prefix": "smop", | ||
"buildPath": "test/output/less/", | ||
"files": [ | ||
{ | ||
"destination": "_icons.less", | ||
"format": "less/icons" | ||
}, | ||
{ | ||
"destination": "_variables.less", | ||
"format": "less/variables" | ||
} | ||
] | ||
}, | ||
"android": { | ||
"transformGroup": "android", | ||
"buildPath": "test/output/", | ||
"files": [ | ||
{ | ||
"destination": "android/colors.xml", | ||
"template": "android/colors" | ||
}, | ||
{ | ||
"destination": "android/font_dimen.xml", | ||
"template": "android/fontDimens" | ||
}, | ||
{ | ||
"destination": "android/dimens.xml", | ||
"template": "android/dimens" | ||
} | ||
], | ||
"actions": ["android/copyImages"] | ||
}, | ||
"ios": { | ||
"transformGroup": "ios", | ||
"buildPath": "test/output/ios/", | ||
"files": [ | ||
{ | ||
"destination": "style_dictionary.plist", | ||
"template": "ios/plist" | ||
}, | ||
{ | ||
"destination": "style_dictionary.h", | ||
"template": "ios/macros" | ||
} | ||
] | ||
}, | ||
"react-native": { | ||
"transformGroup": "react-native", | ||
"buildPath": "__tests__/__output/react-native/", | ||
"files": [ | ||
{ | ||
"destination": "style_dictionary.js", | ||
"format": "javascript/es6" | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"jsonCA": 5, | ||
// some comment | ||
"d": { | ||
"jsonCe": 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
*/ | ||
|
||
require('json5/lib/register'); | ||
require.extensions[".jsonc"] = require("./utils/jsonc").register; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
||
var combineJSON = require('./utils/combineJSON'), | ||
deepExtend = require('./utils/deepExtend'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fs = require("fs"); | ||
const jsonc = require("jsonc-parser"); | ||
|
||
module.exports = { | ||
register(module, filename) { | ||
const content = fs.readFileSync(filename, "utf8"); | ||
try { | ||
module.exports = jsonc.parse(content); | ||
} catch (err) { | ||
err.message = filename + ": " + err.message; | ||
throw err; | ||
} | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
], | ||
"transform": { | ||
"^.+\\.json5$": "json5-jest", | ||
"^.+\\.jsonc$": "json5-jest", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I've taken advantage of the fact that JSON5 is a superset of JSONC, so the same transform satisfies Jest. I initially writing my own JSONC transform, based on the JSON5 one—it's basically a one-liner—but for some reason I couldn't get Jest to actually run it. 🤷♂️ |
||
"^.+\\.jsx?$": "babel-jest" | ||
} | ||
}, | ||
|
@@ -141,6 +142,7 @@ | |
"jsdoc-escape-at": "^1.0.1", | ||
"jsdoc-to-markdown": "^7.0.1", | ||
"json5-jest": "^1.0.1", | ||
"jsonc-parser": "^3.0.0", | ||
"less": "^3.11.2", | ||
"lint-staged": "^10.2.7", | ||
"node-sass": "^6.0.1", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice unit tests!