Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jun 14, 2019
1 parent 82e3348 commit a5ecdeb
Show file tree
Hide file tree
Showing 62 changed files with 271 additions and 280 deletions.
4 changes: 2 additions & 2 deletions app/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'

export function getRootModule (plugins: any[]) {
let imports = [
const imports = [
BrowserModule,
...plugins,
NgbModule.forRoot(),
Expand All @@ -15,7 +15,7 @@ export function getRootModule (plugins: any[]) {
extendedTimeOut: 5000,
}),
]
let bootstrap = [
const bootstrap = [
...(plugins.filter(x => x.bootstrap).map(x => x.bootstrap)),
]

Expand Down
4 changes: 2 additions & 2 deletions app/src/entry.preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Raven.config(
{
release: require('electron').remote.app.getVersion(),
dataCallback: (data: any) => {
const normalize = (filename) => {
let splitArray = filename.split('/')
const normalize = (filename: string) => {
const splitArray = filename.split('/')
return splitArray[splitArray.length - 1]
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ async function bootstrap (plugins: IPluginInfo[], safeMode = false): Promise<NgM
if (safeMode) {
plugins = plugins.filter(x => x.isBuiltin)
}
let pluginsModules = await loadPlugins(plugins, (current, total) => {
const pluginsModules = await loadPlugins(plugins, (current, total) => {
(document.querySelector('.progress .bar') as HTMLElement).style.width = 100 * current / total + '%'
})
let module = getRootModule(pluginsModules)
const module = getRootModule(pluginsModules)
window['rootModule'] = module
return platformBrowserDynamic().bootstrapModule(module)
}
Expand Down
32 changes: 16 additions & 16 deletions app/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function normalizePath (path: string): string {
return path
}

nodeRequire.main.paths.map(x => nodeModule.globalPaths.push(normalizePath(x)))
nodeRequire.main.paths.map((x: string) => nodeModule.globalPaths.push(normalizePath(x)))

if (process.env.TERMINUS_DEV) {
nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath()))
Expand All @@ -38,7 +38,7 @@ if (process.env.TERMINUS_PLUGINS) {
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.push(normalizePath(x)))
}

export declare type ProgressCallback = (current, total) => void
export declare type ProgressCallback = (current: number, total: number) => void

export interface IPluginInfo {
name: string
Expand Down Expand Up @@ -80,54 +80,54 @@ builtinModules.forEach(m => {
})

const originalRequire = (global as any).require
;(global as any).require = function (query) {
;(global as any).require = function (query: string) {
if (cachedBuiltinModules[query]) {
return cachedBuiltinModules[query]
}
return originalRequire.apply(this, arguments)
}

export async function findPlugins (): Promise<IPluginInfo[]> {
let paths = nodeModule.globalPaths
const paths = nodeModule.globalPaths
let foundPlugins: IPluginInfo[] = []
let candidateLocations: { pluginDir: string, packageName: string }[] = []
const candidateLocations: { pluginDir: string, packageName: string }[] = []
const PREFIX = 'terminus-'

for (let pluginDir of paths) {
pluginDir = normalizePath(pluginDir)
if (!await fs.exists(pluginDir)) {
continue
}
let pluginNames = await fs.readdir(pluginDir)
const pluginNames = await fs.readdir(pluginDir)
if (await fs.exists(path.join(pluginDir, 'package.json'))) {
candidateLocations.push({
pluginDir: path.dirname(pluginDir),
packageName: path.basename(pluginDir)
})
}
for (let packageName of pluginNames) {
for (const packageName of pluginNames) {
if (packageName.startsWith(PREFIX)) {
candidateLocations.push({ pluginDir, packageName })
}
}
}

for (let { pluginDir, packageName } of candidateLocations) {
let pluginPath = path.join(pluginDir, packageName)
let infoPath = path.join(pluginPath, 'package.json')
for (const { pluginDir, packageName } of candidateLocations) {
const pluginPath = path.join(pluginDir, packageName)
const infoPath = path.join(pluginPath, 'package.json')
if (!await fs.exists(infoPath)) {
continue
}

let name = packageName.substring(PREFIX.length)
const name = packageName.substring(PREFIX.length)

if (foundPlugins.some(x => x.name === name)) {
console.info(`Plugin ${packageName} already exists, overriding`)
foundPlugins = foundPlugins.filter(x => x.name !== name)
}

try {
let info = JSON.parse(await fs.readFile(infoPath, { encoding: 'utf-8' }))
const info = JSON.parse(await fs.readFile(infoPath, { encoding: 'utf-8' }))
if (!info.keywords || !(info.keywords.includes('terminus-plugin') || info.keywords.includes('terminus-builtin-plugin'))) {
continue
}
Expand All @@ -153,17 +153,17 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
}

export async function loadPlugins (foundPlugins: IPluginInfo[], progress: ProgressCallback): Promise<any[]> {
let plugins: any[] = []
const plugins: any[] = []
progress(0, 1)
let index = 0
for (let foundPlugin of foundPlugins) {
for (const foundPlugin of foundPlugins) {
console.info(`Loading ${foundPlugin.name}: ${nodeRequire.resolve(foundPlugin.path)}`)
progress(index, foundPlugins.length)
try {
const label = 'Loading ' + foundPlugin.name
console.time(label)
let packageModule = nodeRequire(foundPlugin.path)
let pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
const packageModule = nodeRequire(foundPlugin.path)
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule['pluginName'] = foundPlugin.name
pluginModule['bootstrap'] = packageModule.bootstrap
plugins.push(pluginModule)
Expand Down
10 changes: 5 additions & 5 deletions terminus-community-color-schemes/src/colorSchemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const schemeContents = require.context('../schemes/', true, /.*/)
@Injectable()
export class ColorSchemes extends TerminalColorSchemeProvider {
async getSchemes (): Promise<ITerminalColorScheme[]> {
let schemes: ITerminalColorScheme[] = []
const schemes: ITerminalColorScheme[] = []

schemeContents.keys().forEach(schemeFile => {
let lines = (schemeContents(schemeFile).default as string).split('\n')
const lines = (schemeContents(schemeFile).default as string).split('\n')

// process #define variables
let variables: any = {}
const variables: any = {}
lines
.filter(x => x.startsWith('#define'))
.map(x => x.split(' ').map(v => v.trim()))
.forEach(([ignore, variableName, variableValue]) => {
variables[variableName] = variableValue
})

let values: any = {}
const values: any = {}
lines
.filter(x => x.startsWith('*.'))
.map(x => x.substring(2))
Expand All @@ -29,7 +29,7 @@ export class ColorSchemes extends TerminalColorSchemeProvider {
values[key] = variables[value] ? variables[value] : value
})

let colors: string[] = []
const colors: string[] = []
let colorIndex = 0
while (values[`color${colorIndex}`]) {
colors.push(values[`color${colorIndex}`])
Expand Down
2 changes: 1 addition & 1 deletion terminus-core/src/components/appRoot.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class AppRootComponent {

this.hotkeys.matchedHotkey.subscribe((hotkey) => {
if (hotkey.startsWith('tab-')) {
let index = parseInt(hotkey.split('-')[1])
const index = parseInt(hotkey.split('-')[1])
if (index <= this.app.tabs.length) {
this.app.selectTab(this.app.tabs[index - 1])
}
Expand Down
2 changes: 1 addition & 1 deletion terminus-core/src/components/checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CheckboxComponent implements ControlValueAccessor {
}

this.model = !this.model
for (let fx of this.changed) {
for (const fx of this.changed) {
fx(this.model)
}
}
Expand Down
58 changes: 29 additions & 29 deletions terminus-core/src/components/splitTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class SplitContainer {
*/
getAllTabs () {
let r = []
for (let child of this.children) {
for (const child of this.children) {
if (child instanceof SplitContainer) {
r = r.concat(child.getAllTabs())
} else {
Expand All @@ -50,7 +50,7 @@ export class SplitContainer {
*/
normalize () {
for (let i = 0; i < this.children.length; i++) {
let child = this.children[i]
const child = this.children[i]

if (child instanceof SplitContainer) {
child.normalize()
Expand All @@ -63,7 +63,7 @@ export class SplitContainer {
} else if (child.children.length === 1) {
this.children[i] = child.children[0]
} else if (child.orientation === this.orientation) {
let ratio = this.ratios[i]
const ratio = this.ratios[i]
this.children.splice(i, 1)
this.ratios.splice(i, 1)
for (let j = 0; j < child.children.length; j++) {
Expand All @@ -76,7 +76,7 @@ export class SplitContainer {
}

let s = 0
for (let x of this.ratios) {
for (const x of this.ratios) {
s += x
}
this.ratios = this.ratios.map(x => x / s)
Expand All @@ -94,8 +94,8 @@ export class SplitContainer {
}

async serialize () {
let children = []
for (let child of this.children) {
const children = []
for (const child of this.children) {
if (child instanceof SplitContainer) {
children.push(await child.serialize())
} else {
Expand Down Expand Up @@ -257,7 +257,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes

focus (tab: BaseTabComponent) {
this.focusedTab = tab
for (let x of this.getAllTabs()) {
for (const x of this.getAllTabs()) {
if (x !== tab) {
x.emitBlurred()
}
Expand Down Expand Up @@ -294,7 +294,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
(target.orientation === 'v' && ['l', 'r'].includes(side)) ||
(target.orientation === 'h' && ['t', 'b'].includes(side))
) {
let newContainer = new SplitContainer()
const newContainer = new SplitContainer()
newContainer.orientation = (target.orientation === 'v') ? 'h' : 'v'
newContainer.children = [relative]
newContainer.ratios = [1]
Expand Down Expand Up @@ -326,8 +326,8 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

removeTab (tab: BaseTabComponent) {
let parent = this.getParentOf(tab)
let index = parent.children.indexOf(tab)
const parent = this.getParentOf(tab)
const index = parent.children.indexOf(tab)
parent.ratios.splice(index, 1)
parent.children.splice(index, 1)

Expand All @@ -350,7 +350,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
navigate (dir: SplitDirection) {
let rel: BaseTabComponent | SplitContainer = this.focusedTab
let parent = this.getParentOf(rel)
let orientation = ['l', 'r'].includes(dir) ? 'h' : 'v'
const orientation = ['l', 'r'].includes(dir) ? 'h' : 'v'

while (parent !== this.root && parent.orientation !== orientation) {
rel = parent
Expand All @@ -361,7 +361,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
return
}

let index = parent.children.indexOf(rel)
const index = parent.children.indexOf(rel)
if (['l', 't'].includes(dir)) {
if (index > 0) {
this.focusAnyIn(parent.children[index - 1])
Expand All @@ -374,7 +374,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

async splitTab (tab: BaseTabComponent, dir: SplitDirection) {
let newTab = await this.tabsService.duplicate(tab)
const newTab = await this.tabsService.duplicate(tab)
this.addTab(newTab, tab, dir)
}

Expand All @@ -383,9 +383,9 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
*/
getParentOf (tab: BaseTabComponent | SplitContainer, root?: SplitContainer): SplitContainer {
root = root || this.root
for (let child of root.children) {
for (const child of root.children) {
if (child instanceof SplitContainer) {
let r = this.getParentOf(tab, child)
const r = this.getParentOf(tab, child)
if (r) {
return r
}
Expand Down Expand Up @@ -419,7 +419,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

private attachTabView (tab: BaseTabComponent) {
let ref = this.viewContainer.insert(tab.hostView) as EmbeddedViewRef<any>
const ref = this.viewContainer.insert(tab.hostView) as EmbeddedViewRef<any>
this.viewRefs.set(tab, ref)

ref.rootNodes[0].addEventListener('click', () => this.focus(tab))
Expand All @@ -436,7 +436,7 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

private detachTabView (tab: BaseTabComponent) {
let ref = this.viewRefs.get(tab)
const ref = this.viewRefs.get(tab)
this.viewRefs.delete(tab)
this.viewContainer.remove(this.viewContainer.indexOf(ref))
}
Expand All @@ -448,8 +448,8 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

private layoutInternal (root: SplitContainer, x: number, y: number, w: number, h: number) {
let size = (root.orientation === 'v') ? h : w
let sizes = root.ratios.map(x => x * size)
const size = (root.orientation === 'v') ? h : w
const sizes = root.ratios.map(x => x * size)

root.x = x
root.y = y
Expand All @@ -458,14 +458,14 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes

let offset = 0
root.children.forEach((child, i) => {
let childX = (root.orientation === 'v') ? x : (x + offset)
let childY = (root.orientation === 'v') ? (y + offset) : y
let childW = (root.orientation === 'v') ? w : sizes[i]
let childH = (root.orientation === 'v') ? sizes[i] : h
const childX = (root.orientation === 'v') ? x : (x + offset)
const childY = (root.orientation === 'v') ? (y + offset) : y
const childW = (root.orientation === 'v') ? w : sizes[i]
const childH = (root.orientation === 'v') ? sizes[i] : h
if (child instanceof SplitContainer) {
this.layoutInternal(child, childX, childY, childW, childH)
} else {
let element = this.viewRefs.get(child).rootNodes[0]
const element = this.viewRefs.get(child).rootNodes[0]
element.style.position = 'absolute'
element.style.left = `${childX}%`
element.style.top = `${childY}%`
Expand All @@ -486,19 +486,19 @@ export class SplitTabComponent extends BaseTabComponent implements OnInit, OnDes
}

private async recoverContainer (root: SplitContainer, state: any) {
let children: (SplitContainer | BaseTabComponent)[] = []
const children: (SplitContainer | BaseTabComponent)[] = []
root.orientation = state.orientation
root.ratios = state.ratios
root.children = children
for (let childState of state.children) {
for (const childState of state.children) {
if (childState.type === 'app:split-tab') {
let child = new SplitContainer()
const child = new SplitContainer()
await this.recoverContainer(child, childState)
children.push(child)
} else {
let recovered = await this.tabRecovery.recoverTab(childState)
const recovered = await this.tabRecovery.recoverTab(childState)
if (recovered) {
let tab = this.tabsService.create(recovered.type, recovered.options)
const tab = this.tabsService.create(recovered.type, recovered.options)
children.push(tab)
this.attachTabView(tab)
} else {
Expand Down
Loading

0 comments on commit a5ecdeb

Please sign in to comment.