Skip to content

Commit

Permalink
feat: add yaml interop for require
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed May 30, 2020
1 parent 1cd7905 commit f396323
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
27 changes: 3 additions & 24 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"ora": "4.0.4",
"style-dictionary": "2.10.0",
"ts-node": "8.8.2",
"typescript": "3.8.3"
"typescript": "3.8.3",
"yaml": "1.10.0"
},
"devDependencies": {
"@commitlint/cli": "8.3.5",
Expand Down
1 change: 1 addition & 0 deletions src/core-v2/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './yaml-interop'
import StyleDictionaryApi from 'style-dictionary'

import { createWhitepaperConfig } from './whitepaper-config'
Expand Down
13 changes: 13 additions & 0 deletions src/core-v2/yaml-interop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Module from 'module'
import { readFileSync } from 'fs'
import YAML from 'yaml'

Module.prototype.require = new Proxy(Module.prototype.require, {
apply(target, thisArg, args) {
if (/\.ya?ml$/.test(args[0])) {
const file = readFileSync(args[0], 'utf8')
return YAML.parse(file)
}
return Reflect.apply(target, thisArg, args)
},
})

0 comments on commit f396323

Please sign in to comment.