From b78e4712f1ccb69113bdd96bbaa8624324917c85 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 28 May 2019 10:30:36 +0300 Subject: [PATCH] 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 --- .../cli/src/__snapshots__/index.test.js.snap | 16 ++++++++++++++++ packages/cli/src/dirCommand.js | 2 +- packages/cli/src/index.test.js | 9 +++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap index d6f2ee71..c7aeeeaa 100644 --- a/packages/cli/src/__snapshots__/index.test.js.snap +++ b/packages/cli/src/__snapshots__/index.test.js.snap @@ -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' diff --git a/packages/cli/src/dirCommand.js b/packages/cli/src/dirCommand.js index cdcd83b5..d9298419 100644 --- a/packages/cli/src/dirCommand.js +++ b/packages/cli/src/dirCommand.js @@ -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 } diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js index 263f38b8..d17808ba 100644 --- a/packages/cli/src/index.test.js +++ b/packages/cli/src/index.test.js @@ -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 () => {