Skip to content

Commit b78e471

Browse files
TrySoundgregberge
authored andcommitted
feat(cli): output relative destination paths (#312)
* [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
1 parent e2199ca commit b78e471

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/cli/src/__snapshots__/index.test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,22 @@ export default SvgFile
330330
"
331331
`;
332332

333+
exports[`cli should transform a whole directory and output relative destination paths 1`] = `
334+
"
335+
__fixtures__/cased/PascalCase.svg -> __fixtures_build__/whole/cased/PascalCase.js
336+
__fixtures__/cased/camelCase.svg -> __fixtures_build__/whole/cased/CamelCase.js
337+
__fixtures__/cased/kebab-case.svg -> __fixtures_build__/whole/cased/KebabCase.js
338+
__fixtures__/cased/multiple---dashes.svg -> __fixtures_build__/whole/cased/MultipleDashes.js
339+
__fixtures__/complex/skype.svg -> __fixtures_build__/whole/complex/Skype.js
340+
__fixtures__/complex/telegram.svg -> __fixtures_build__/whole/complex/Telegram.js
341+
__fixtures__/nesting/a/two.svg -> __fixtures_build__/whole/nesting/a/Two.js
342+
__fixtures__/nesting/one.svg -> __fixtures_build__/whole/nesting/One.js
343+
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/File.js
344+
__fixtures__/withPrettierRc/file.svg -> __fixtures_build__/whole/withPrettierRc/File.js
345+
__fixtures__/withSvgoYml/file.svg -> __fixtures_build__/whole/withSvgoYml/File.js
346+
__fixtures__/withSvgrRc/file.svg -> __fixtures_build__/whole/withSvgrRc/File.js"
347+
`;
348+
333349
exports[`cli should work with a simple file 1`] = `
334350
"import React from 'react'
335351

packages/cli/src/dirCommand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function dirCommand(
3232
const dest = path.resolve(program.outDir, relative)
3333
const code = await convertFile(src, options)
3434
outputFileSync(dest, code)
35-
process.stdout.write(`${src} -> ${dest}\n`)
35+
process.stdout.write(`${src} -> ${path.relative(process.cwd(), dest)}\n`)
3636
return true
3737
}
3838

packages/cli/src/index.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ describe('cli', () => {
4848
expect(result).toMatchSnapshot()
4949
}, 10000)
5050

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

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

0 commit comments

Comments
 (0)