Skip to content

Commit

Permalink
fix: get component filename relative (fix #706)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 29, 2019
1 parent d81c568 commit 84b23ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions core/docz-core/src/states/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const getPattern = (config: Config) => {

export const mapToArray = (map: any = []) =>
Object.entries(map)
.map(entry => entry && { key: entry[0], value: entry[1] })
.map(entry => {
return entry && { key: relative(paths.root, entry[0]), value: entry[1] }
})
.filter(Boolean)

const initial = (config: Config) => async (p: Params) => {
Expand All @@ -39,9 +41,8 @@ const add = (p: Params, config: Config) => async (filepath: string) => {
}

const remove = (p: Params) => async (filepath: string) => {
const root = paths.root
const prev = get('props', p.getState())
const next = prev.filter((item: any) => relative(root, item.key) !== filepath)
const next = prev.filter((item: any) => item.key !== filepath)
p.setState('props', next)
}

Expand Down
6 changes: 5 additions & 1 deletion other-packages/babel-plugin-export-metadata/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path')
const { default: template } = require('@babel/template')
const { get } = require('lodash')

Expand All @@ -14,7 +15,10 @@ const buildFileMeta = template(`
}
`)

const getFilename = state => get(state, 'file.opts.filename')
const getFilename = state => {
const filename = get(state, 'file.opts.filename')
return filename && path.relative(process.cwd(), filename)
}

const getPathName = path =>
get(path, 'node.id.name') || get(path, 'parent.id.name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (typeof bar !== 'undefined' && bar && bar === Object(bar)) {
configurable: true,
value: {
name: \\"bar\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
filename: \\"tests/fixtures/example.js\\"
}
});
}
Expand All @@ -22,7 +22,7 @@ if (typeof bar !== 'undefined' && bar && bar === Object(bar)) {
configurable: true,
value: {
name: \\"bar\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
filename: \\"tests/fixtures/example.js\\"
}
});
}
Expand All @@ -49,7 +49,7 @@ if (typeof getOther !== 'undefined' && getOther && getOther === Object(getOther)
configurable: true,
value: {
name: \\"getOther\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
filename: \\"tests/fixtures/example.js\\"
}
});
}
Expand Down Expand Up @@ -82,7 +82,7 @@ if (typeof component !== 'undefined' && component && component === Object(compon
configurable: true,
value: {
name: \\"component\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
filename: \\"tests/fixtures/example.js\\"
}
});
}
Expand All @@ -103,7 +103,7 @@ if (typeof Abcd !== 'undefined' && Abcd && Abcd === Object(Abcd)) {
configurable: true,
value: {
name: \\"Abcd\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
filename: \\"tests/fixtures/example.js\\"
}
});
}
Expand Down

0 comments on commit 84b23ea

Please sign in to comment.