-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add comments to banner using formatter option (#39)
* test-cli with formatter option * use banner in banner2 project ;) * update tests, readme, changelog and .d.ts * docBlockAndGap & docBlock formatter optiond
- Loading branch information
Showing
13 changed files
with
224 additions
and
12 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
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
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,13 +1,16 @@ | ||
import pkg from './package.json' | ||
import banner2 from './src/index' | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.js', | ||
external: ['fs', 'path', ...Object.keys(pkg.dependencies || {})], | ||
external: Object.keys(pkg.dependencies || {}), | ||
output: [ | ||
{ file: pkg.main, format: 'cjs' }, | ||
{ file: pkg.module, format: 'esm' }, | ||
], | ||
plugins: [], | ||
plugins: [ | ||
banner2(() => `${pkg.name}@${pkg.version}`, { formatter: 'docBlock' }), | ||
], | ||
}, | ||
] |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const identity = (str) => str | ||
|
||
export const docBlock = (str) => { | ||
const lines = str.split('\n') | ||
const wrapped = ['/**', ...lines.map((l) => ` * ${l}`), ' */\n'].join('\n') | ||
|
||
return wrapped | ||
} | ||
|
||
export const docBlockAndGap = (str) => { | ||
return `${docBlock(str)}\n` | ||
} | ||
|
||
export const formatters = { docBlock, docBlockAndGap, identity } |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import banner2 from '../../dist/rollup-plugin-banner2.es' | ||
|
||
const input = 'test/fixture/input-multi-first.js' | ||
export default [ | ||
{ | ||
input, | ||
plugins: [banner2(() => '// banner\n')], | ||
}, | ||
{ | ||
input, | ||
plugins: [banner2(() => 'banner', { formatter: 'docBlock' })], | ||
}, | ||
] |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { docBlock, docBlockAndGap } from '../src/formatters' | ||
|
||
describe('formatters', () => { | ||
describe('docBlock', () => { | ||
it('wraps a single line', () => { | ||
const input = 'this is a banner' | ||
|
||
const actualResult = docBlock(input) | ||
|
||
expect(`\n${actualResult}`).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* this is a banner | ||
*/ | ||
" | ||
`) | ||
}) | ||
it('wraps multiple lines', () => { | ||
const input = 'this is a banner\nwith\nmore\nlines\n' | ||
|
||
const actualResult = docBlock(input) | ||
|
||
expect(`\n${actualResult}`).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* this is a banner | ||
* with | ||
* more | ||
* lines | ||
* | ||
*/ | ||
" | ||
`) | ||
}) | ||
it('does not correctly wrap comments', () => { | ||
const input = '/* comments */' | ||
|
||
const actualResult = docBlock(input) | ||
|
||
expect(`\n${actualResult}`).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* /* comments */ | ||
*/ | ||
" | ||
`) | ||
}) | ||
}) | ||
describe('docBlockAndGap', () => { | ||
it('wraps a single line', () => { | ||
const input = 'this is a banner' | ||
|
||
const actualResult = docBlockAndGap(input) | ||
|
||
expect(`\n${actualResult}`).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* this is a banner | ||
*/ | ||
" | ||
`) | ||
}) | ||
}) | ||
}) |
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