Skip to content
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

Support Windows paths #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions components-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module.exports = function swingsetComponentsLoader() {
)

// add components directory as a webpack dependency
this.addContextDependency(pluginOptions.componentsRoot.split('*')[0])
this.addContextDependency(
path.resolve(pluginOptions.componentsRoot.split('*')[0])
)
const componentsWithNames = formatComponentsWithNames(usedComponents)

// Resolve docs glob
Expand Down Expand Up @@ -138,17 +140,19 @@ function formatComponentsWithNames(components) {
*/
function generateMetadataFile(components, docsFiles) {
const imports = components.reduce((memo, component) => {
memo += `import * as ${component.name}Exports from '${component.path}'\n`
memo += `import * as ${
component.name
}Exports from '${component.path.replace(/\\/g, '/')}'\n`
return memo
}, '')

const componentsData = components.reduce((acc, component) => {
// We can't just stringify here, because we need eg
// src: Button, <<< Button NOT in quotes
acc += ` '${component.name}': {
path: '${component.path}',
docsPath: '${path.join(component.path, 'docs.mdx')}',
propsPath: '${path.join(component.path, 'props.js')}',
path: '${component.path.replace(/\\/g, '/')}',
docsPath: '${path.join(component.path, 'docs.mdx').replace(/\\/g, '/')}',
propsPath: '${path.join(component.path, 'props.js').replace(/\\/g, '/')}',
slug: '${component.slug}',
exports: ${component.name}Exports,
data: ${JSON.stringify(component.data, null, 2)}
Expand Down
24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ function withSwingset(pluginOptions = {}) {
*/
webpack(config, options) {
// normalize componentsRoot path
pluginOptions.componentsRoot = path.resolve(
config.context,
pluginOptions.componentsRoot
? pluginOptions.componentsRoot
: 'components/*'
)
pluginOptions.componentsRoot = path
.resolve(
config.context,
pluginOptions.componentsRoot
? pluginOptions.componentsRoot
: 'components/*'
)
.replace(/\\/g, '/')
// normalize docsRoot path
pluginOptions.docsRoot = path.resolve(
config.context,
pluginOptions.docsRoot ? pluginOptions.docsRoot : 'docs/*'
)
pluginOptions.docsRoot = path
.resolve(
config.context,
pluginOptions.docsRoot ? pluginOptions.docsRoot : 'docs/*'
)
.replace(/\\/g, '/')
//
config.module.rules.push({
test: /__swingset_data/,
Expand Down