Skip to content

Commit

Permalink
feat(s2s-cli): handle template when directory created
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Jul 29, 2019
1 parent 9be9edf commit 5b367f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/s2s-cli/src/utils/index.js
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions packages/s2s-cli/src/utils/index.test.js
Expand Up @@ -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')
Expand Down

0 comments on commit 5b367f3

Please sign in to comment.