This repository has been archived by the owner on Nov 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use cache instead of hardcoding path (#310)
- Loading branch information
1 parent
9263a03
commit 1f2e720
Showing
7 changed files
with
43 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
const path = require("path"); | ||
|
||
const CACHE_LOCATION = path.join(".cache", "gatsby-mdx"); | ||
const MDX_WRAPPERS_LOCATION = path.join(CACHE_LOCATION, "mdx-wrappers-dir"); | ||
const MDX_SCOPES_LOCATION = path.join(CACHE_LOCATION, "mdx-scopes-dir"); | ||
const MDX_WRAPPERS_LOCATION = "mdx-wrappers-dir"; | ||
const MDX_SCOPES_LOCATION = "mdx-scopes-dir"; | ||
|
||
module.exports = { | ||
CACHE_LOCATION, | ||
MDX_WRAPPERS_LOCATION, | ||
MDX_SCOPES_LOCATION | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const slash = require("slash"); | ||
const loaderUtils = require("loader-utils"); | ||
const { MDX_SCOPES_LOCATION } = require("../constants"); | ||
|
||
module.exports = () => { | ||
const files = fs.readdirSync("./.cache/gatsby-mdx/mdx-scopes-dir"); | ||
const abs = path.resolve("./.cache/gatsby-mdx/mdx-scopes-dir"); | ||
module.exports = function() { | ||
const { cache } = loaderUtils.getOptions(this); | ||
const abs = path.join(cache.directory, MDX_SCOPES_LOCATION); | ||
const files = fs.readdirSync(abs); | ||
return ( | ||
files | ||
.map( | ||
(file, i) => | ||
`const scope_${i} = require('${slash(path.join(abs, file))}').default;` | ||
`const scope_${i} = require('${slash( | ||
path.join(abs, file) | ||
)}').default;` | ||
) | ||
.join("\n") + | ||
`export default | ||
Object.assign({}, ${files.map((_, i) => 'scope_' + i).join(',\n')} ) | ||
`export default | ||
Object.assign({}, ${files.map((_, i) => "scope_" + i).join(",\n")} ) | ||
` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters