Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fetchRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ConverterRepo {
repo: string
}

export async function fetchRepo(url: string): Promise<ConverterRepo> {
export async function fetchRepo (url: string): Promise<ConverterRepo> {
const tmpRootDir = await createTempDir()
const tmpRepoDir = path.join(tmpRootDir, 'repo')

Expand Down
12 changes: 9 additions & 3 deletions src/idea/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ export async function convertToIdea (
})
return Promise.all(promises)
} catch (error) {
console.trace(chalk.red(error))
if(error.includes('checkout')
console.log(chalk.red('You may need to add the branch name explicitly to the end of your URL (eg "#main")'))
const message = error instanceof Error ? error.message : String(error)
console.trace(chalk.red(message))
if (message.includes('checkout')) {
console.log(
chalk.red(
'You may need to add the branch name explicitly to the end of your URL (e.g. "#main")'
)
)
}
}
}
12 changes: 9 additions & 3 deletions src/sublime/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ export async function convertToSublime (
})
return Promise.all(promises)
} catch (error) {
console.log(chalk.red(error))
if(error.includes('checkout')
console.log(chalk.red('You may need to add the branch name explicitly to the end of your URL (eg "#main")'))
const message = error instanceof Error ? error.message : String(error)
console.log(chalk.red(message))
if (message.includes('checkout')) {
console.log(
chalk.red(
'You may need to add the branch name explicitly to the end of your URL (e.g. "#main")'
)
)
}
}
}
4 changes: 4 additions & 0 deletions src/util/__tests__/sublime.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os from 'os'
import fs from 'fs'
import { getSublimeTextPackageDir } from '../sublime'

describe('util/sublime', () => {
Expand Down Expand Up @@ -29,9 +30,12 @@ describe('util/sublime', () => {
shell: ''
}))

const dirSpy = jest.spyOn(fs, 'existsSync').mockReturnValueOnce(true)

expect(getSublimeTextPackageDir()).toEqual(result)
expect(osSpy).toHaveBeenCalled()
expect(usernameSpy).toHaveBeenCalled()
expect(dirSpy).toHaveBeenCalled()
}
)
})
Expand Down
39 changes: 27 additions & 12 deletions src/util/sublime.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import os from 'os'
import fs from 'fs'
import chalk from 'chalk'

function getUsername (): string {
return os.userInfo().username
}

export function getSublimeTextPackageDir (): string {
const username = getUsername()
const testPaths: string[] = []
switch (os.platform()) {
case 'win32':
if(fs.existsSync('%APPDATA%/Roaming/Sublime Text 3/Packages/'))
return '%APPDATA%/Roaming/Sublime Text 3/Packages/'
else
return '%APPDATA%/Roaming/Sublime Text/Packages/'
testPaths.push(
'%APPDATA%/Roaming/Sublime Text 3/Packages/',
'%APPDATA%/Roaming/Sublime Text/Packages/'
)
break
case 'darwin':
if(fs.existsSync(`/Users/${username}/Library/Application Support/Sublime Text 3/Packages/`))
return `/Users/${username}/Library/Application Support/Sublime Text 3/Packages/`
else
return `/Users/${username}/Library/Application Support/Sublime Text/Packages/`
testPaths.push(
`/Users/${username}/Library/Application Support/Sublime Text 3/Packages/`,
`/Users/${username}/Library/Application Support/Sublime Text/Packages/`
)
break
default:
if(fs.existsSync(`/${username}/.config/sublime-text-3/Packages/`))
return `/${username}/.config/sublime-text-3/Packages/`
else
return `/${username}/.config/sublime-text/Packages/`
testPaths.push(
`/${username}/.config/sublime-text-3/Packages/`,
`/${username}/.config/sublime-text/Packages/`
)
}

for (const testPath of testPaths) {
if (fs.existsSync(testPath)) return testPath
}

console.log(
chalk.yellow(
'Could not find Sublime theme dir, falling back to current working dir'
)
)
return process.cwd()
}