From 5b367f3088bbce341243eb23c5b5886eada3ba98 Mon Sep 17 00:00:00 2001 From: akameco Date: Tue, 30 Jul 2019 00:07:57 +0900 Subject: [PATCH] feat(s2s-cli): handle template when directory created --- packages/s2s-cli/src/utils/index.js | 9 ++++++--- packages/s2s-cli/src/utils/index.test.js | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/s2s-cli/src/utils/index.js b/packages/s2s-cli/src/utils/index.js index f3ca1aeb..f0a3e57b 100644 --- a/packages/s2s-cli/src/utils/index.js +++ b/packages/s2s-cli/src/utils/index.js @@ -18,9 +18,12 @@ export function getOutputPath(output: Path, input: Path): Path { return output } - return slash( - path.join(path.dirname(normalizePathSeq(input)), normalizePathSeq(output)) - ) + const inputPath = + path.extname(input) === '' + ? normalizePathSeq(input) + : path.dirname(normalizePathSeq(input)) + + return slash(path.join(inputPath, normalizePathSeq(output))) } export function writeFileSync(outputPath: Path, code: string) { diff --git a/packages/s2s-cli/src/utils/index.test.js b/packages/s2s-cli/src/utils/index.test.js index 38c7ba41..4f7c8b84 100644 --- a/packages/s2s-cli/src/utils/index.test.js +++ b/packages/s2s-cli/src/utils/index.test.js @@ -42,6 +42,11 @@ test('getOutputPath when output = relative path', () => { expect(result).toBe('/src/actions.js') }) +test('getOutputPath when input is directroy', () => { + const result = utils.getOutputPath('actions.js', './src/actions') + expect(result).toBe('src/actions/actions.js') +}) + test('getDirAndBaseName', () => { const result = utils.getDirAndBaseName('/src/fuga/hoge.js') expect(result.basename).toBe('hoge.js')