Skip to content

Commit

Permalink
Can now specify the amount of segments
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Ingram committed Nov 28, 2018
1 parent f141ced commit 6c91791
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ $ yarn add babel-plugin-console-source -D
}
````

.babelrc (Will append the full file path and line numbers)
.babelrc (Will append the last 2 path segments and line numbers)
````json
{
"plugins": [
["console-source", {
"fullPath": true

"segments": 1
// 0 = full file path (Default)
// 1 = file name ONLY
// 2 = file name and last segment

}]
]
}
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ module.exports = () => {

let file = state.file.opts.filename;

if(!opts || !opts.fullPath) {
if(!opts || opts.segments !== 0) {
file = state.file.opts.filename.split("/");
file = file[file.length - 1];
let segs = file.slice(Math.max(file.length - opts.segments));
file = segs.join('/');
}

path.node.arguments.unshift({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-console-source",
"version": "1.0.4",
"version": "2.0.0",
"main": "index.js",
"repository": "https://github.com/peteringram0/babel-console-source",
"author": "Peter Ingram <peter.ingram0@gmail.com>",
Expand Down
12 changes: 6 additions & 6 deletions tests/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ module.exports = {
loader: 'babel-loader',
query: {

plugins: [consoleSource]
// plugins: [consoleSource]

// plugins: [
// [consoleSource, {
// "fullPath": true
// }]
// ]
plugins: [
[consoleSource, {
"segments": 2
}]
]

}
},
Expand Down

0 comments on commit 6c91791

Please sign in to comment.