Skip to content

Commit

Permalink
fix: createDir() path resolve under linux
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jan 6, 2019
1 parent 30f3862 commit c6d1274
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,23 @@ function isDirFileExists(path: string, type: 'DIR' | 'FILE'): Promise<boolean> {
: Promise.resolve(false)
}

export function createDir(path: string): Observable<string> {
export function createDir(absolutePath: string): Observable<string> {
/* istanbul ignore else */
if (! path) {
if (! absolutePath) {
throw new Error('value of path param invalid')
}
// ! normalize required for '.../.myca' under win32
const target$ = of(normalize(path))
const paths$ = target$.pipe(
const path$ = of(normalize(absolutePath))
const paths$ = path$.pipe(
mergeMap(target => ofrom(target.split(sep))),
scan((acc: string, curr: string) => {
return acc ? join(acc, curr) : curr
}, ''),
scan((acc: string, curr: string) => pathResolve(acc, curr), sep),
)
const create$ = paths$.pipe(
concatMap(_createDirObb),
last(),
)

const ret$ = target$.pipe(
const ret$ = path$.pipe(
mergeMap(dirExists),
mergeMap(p => p ? of(p) : create$),
)
Expand Down

0 comments on commit c6d1274

Please sign in to comment.