Skip to content

Commit

Permalink
feat(cli): output relative destination paths (#312)
Browse files Browse the repository at this point in the history
* [cli] output relative destination paths

Currently wide output looks bad on half of the screen I use for terminal

```
src/svgs/visibility.svg -> /Users/_________________________________________/src/icons/Visibility.js
```

In this diff I suggest simply cut useless path and get this

```
src/svgs/visibility.svg -> src/icons/Visibility.js
```

* Sort output for stable test
  • Loading branch information
TrySound authored and gregberge committed May 28, 2019
1 parent e2199ca commit b78e471
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/cli/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ export default SvgFile
"
`;

exports[`cli should transform a whole directory and output relative destination paths 1`] = `
"
__fixtures__/cased/PascalCase.svg -> __fixtures_build__/whole/cased/PascalCase.js
__fixtures__/cased/camelCase.svg -> __fixtures_build__/whole/cased/CamelCase.js
__fixtures__/cased/kebab-case.svg -> __fixtures_build__/whole/cased/KebabCase.js
__fixtures__/cased/multiple---dashes.svg -> __fixtures_build__/whole/cased/MultipleDashes.js
__fixtures__/complex/skype.svg -> __fixtures_build__/whole/complex/Skype.js
__fixtures__/complex/telegram.svg -> __fixtures_build__/whole/complex/Telegram.js
__fixtures__/nesting/a/two.svg -> __fixtures_build__/whole/nesting/a/Two.js
__fixtures__/nesting/one.svg -> __fixtures_build__/whole/nesting/One.js
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/File.js
__fixtures__/withPrettierRc/file.svg -> __fixtures_build__/whole/withPrettierRc/File.js
__fixtures__/withSvgoYml/file.svg -> __fixtures_build__/whole/withSvgoYml/File.js
__fixtures__/withSvgrRc/file.svg -> __fixtures_build__/whole/withSvgrRc/File.js"
`;

exports[`cli should work with a simple file 1`] = `
"import React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/dirCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function dirCommand(
const dest = path.resolve(program.outDir, relative)
const code = await convertFile(src, options)
outputFileSync(dest, code)
process.stdout.write(`${src} -> ${dest}\n`)
process.stdout.write(`${src} -> ${path.relative(process.cwd(), dest)}\n`)
return true
}

Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ describe('cli', () => {
expect(result).toMatchSnapshot()
}, 10000)

it('should transform a whole directory', async () => {
await cli('--out-dir __fixtures_build__/whole __fixtures__')
it('should transform a whole directory and output relative destination paths', async () => {
const result = await cli('--out-dir __fixtures_build__/whole __fixtures__')
const sorted = result
.split(/\n/)
.sort()
.join('\n')
expect(sorted).toMatchSnapshot()
}, 10000)

it('should support --prettier-config as json', async () => {
Expand Down

1 comment on commit b78e471

@vercel
Copy link

@vercel vercel bot commented on b78e471 May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://svgr-ltirfjofyk.now.sh to the following alias.

Please sign in to comment.