refactor: ts3.7

This commit is contained in:
iCrawl 2019-11-01 18:10:59 +01:00
parent 0be9fbdf5e
commit 685d10eb3b
No known key found for this signature in database
GPG key ID: E41A6DB922EC2CFE
6 changed files with 973 additions and 194 deletions

View file

@ -185,7 +185,6 @@
"bufferutil": "^4.0.1", "bufferutil": "^4.0.1",
"clipboardy": "^2.1.0", "clipboardy": "^2.1.0",
"discord-rpc": "discordjs/RPC", "discord-rpc": "discordjs/RPC",
"register-scheme": "devsnek/node-register-scheme",
"utf-8-validate": "^5.0.2", "utf-8-validate": "^5.0.2",
"vsls": "^0.3.1291" "vsls": "^0.3.1291"
}, },
@ -199,10 +198,10 @@
"eslint-config-marine": "^5.3.2", "eslint-config-marine": "^5.3.2",
"eslint-config-prettier": "^6.5.0", "eslint-config-prettier": "^6.5.0",
"eslint-plugin-prettier": "^3.1.1", "eslint-plugin-prettier": "^3.1.1",
"prettier": "^1.18.2", "prettier": "prettier/prettier",
"terser-webpack-plugin": "^2.2.1", "terser-webpack-plugin": "^2.2.1",
"ts-loader": "^6.2.1", "ts-loader": "^6.2.1",
"typescript": "^3.6.4", "typescript": "^3.7.1-rc",
"webpack": "^4.41.2", "webpack": "^4.41.2",
"webpack-cli": "^3.3.10" "webpack-cli": "^3.3.10"
}, },

View file

@ -4,7 +4,7 @@ import * as vsls from 'vsls';
import Activity from '../structures/Activity'; import Activity from '../structures/Activity';
import Logger from '../structures/Logger'; import Logger from '../structures/Logger';
import { API } from '../git'; import { API } from '../git';
const clipboardy = require('clipboardy'); // eslint-disable-line import * as clipboardy from 'clipboardy';
let activityTimer: NodeJS.Timer; let activityTimer: NodeJS.Timer;
@ -73,7 +73,6 @@ export default class RPCClient implements Disposable {
this.statusBarIcon.text = '$(globe) Connected to Discord'; this.statusBarIcon.text = '$(globe) Connected to Discord';
this.statusBarIcon.tooltip = 'Connected to Discord'; this.statusBarIcon.tooltip = 'Connected to Discord';
// @ts-ignore
setTimeout(() => (this.statusBarIcon.text = '$(globe)'), 5000); setTimeout(() => (this.statusBarIcon.text = '$(globe)'), 5000);
if (activityTimer) clearInterval(activityTimer); if (activityTimer) clearInterval(activityTimer);

View file

@ -1,16 +1,7 @@
import { import { commands, ExtensionContext, StatusBarAlignment, StatusBarItem, window, workspace, extensions } from 'vscode';
commands,
ExtensionContext,
StatusBarAlignment,
StatusBarItem,
window,
workspace,
extensions
} from 'vscode';
import RPCClient from './client/RPCClient'; import RPCClient from './client/RPCClient';
import Logger from './structures/Logger'; import Logger from './structures/Logger';
import { GitExtension } from './git'; import { GitExtension } from './git';
const { register } = require('discord-rpc'); // eslint-disable-line
const sleep = (wait: number) => new Promise(resolve => setTimeout(resolve, wait)); const sleep = (wait: number) => new Promise(resolve => setTimeout(resolve, wait));
let loginTimeout: NodeJS.Timer; let loginTimeout: NodeJS.Timer;
@ -19,7 +10,6 @@ const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignme
statusBarIcon.text = '$(pulse) Connecting to Discord...'; statusBarIcon.text = '$(pulse) Connecting to Discord...';
const config = workspace.getConfiguration('discord'); const config = workspace.getConfiguration('discord');
register(config.get<string>('clientID'));
const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon); const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon);
export async function activate(context: ExtensionContext) { export async function activate(context: ExtensionContext) {
@ -39,7 +29,7 @@ export async function activate(context: ExtensionContext) {
let isWorkspaceExcluded = false; let isWorkspaceExcluded = false;
const excludePatterns = config.get<string[]>('workspaceExcludePatterns'); const excludePatterns = config.get<string[]>('workspaceExcludePatterns');
if (excludePatterns && excludePatterns.length > 0) { if (excludePatterns?.length) {
for (const pattern of excludePatterns) { for (const pattern of excludePatterns) {
const regex = new RegExp(pattern); const regex = new RegExp(pattern);
const folders = workspace.workspaceFolders; const folders = workspace.workspaceFolders;

16
src/git.d.ts vendored
View file

@ -1,9 +1,9 @@
/*--------------------------------------------------------------------------------------------- /*
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ */
import { Uri, SourceControlInputBox, Event, CancellationToken } from 'vscode'; import { Uri, Event } from 'vscode';
export interface Git { export interface Git {
readonly path: string; readonly path: string;
@ -16,7 +16,7 @@ export interface InputBox {
export const enum RefType { export const enum RefType {
Head, Head,
RemoteHead, RemoteHead,
Tag Tag,
} }
export interface Ref { export interface Ref {
@ -74,7 +74,7 @@ export const enum Status {
DELETED_BY_THEM, DELETED_BY_THEM,
BOTH_ADDED, BOTH_ADDED,
BOTH_DELETED, BOTH_DELETED,
BOTH_MODIFIED BOTH_MODIFIED,
} }
export interface Change { export interface Change {
@ -114,12 +114,12 @@ export interface Repository {
readonly state: RepositoryState; readonly state: RepositoryState;
readonly ui: RepositoryUIState; readonly ui: RepositoryUIState;
getConfigs(): Promise<{ key: string; value: string; }[]>; getConfigs(): Promise<{ key: string; value: string }[]>;
getConfig(key: string): Promise<string>; getConfig(key: string): Promise<string>;
setConfig(key: string, value: string): Promise<string>; setConfig(key: string, value: string): Promise<string>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>; getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>;
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>; detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }>;
buffer(ref: string, path: string): Promise<Buffer>; buffer(ref: string, path: string): Promise<Buffer>;
show(ref: string, path: string): Promise<string>; show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>; getCommit(ref: string): Promise<Commit>;

View file

@ -39,8 +39,9 @@ interface FileDetail {
export default class Activity implements Disposable { export default class Activity implements Disposable {
private _state: State | null = null; private _state: State | null = null;
private _lastKnownFile: string = ''; private _lastKnownFile = '';
// eslint-disable-next-line no-useless-constructor
public constructor(public client: RPCClient) {} public constructor(public client: RPCClient) {}
public get state() { public get state() {
@ -91,7 +92,7 @@ export default class Activity implements Disposable {
} }
let previousTimestamp = null; let previousTimestamp = null;
if (this._state && this._state.startTimestamp) previousTimestamp = this._state.startTimestamp; if (this._state?.startTimestamp) previousTimestamp = this._state.startTimestamp;
this._state = { this._state = {
...this._state, ...this._state,
@ -214,7 +215,7 @@ export default class Activity implements Disposable {
public increasePartySize(size?: number) { public increasePartySize(size?: number) {
if (!this._state) return; if (!this._state) return;
if (this.state && this._state.partySize === 5) return; if (this._state.partySize === 5) return;
this._state = { this._state = {
...this._state, ...this._state,
partySize: this._state.partySize ? this._state.partySize + 1 : size, partySize: this._state.partySize ? this._state.partySize + 1 : size,
@ -225,7 +226,7 @@ export default class Activity implements Disposable {
public decreasePartySize(size?: number) { public decreasePartySize(size?: number) {
if (!this._state) return; if (!this._state) return;
if (this.state && this._state.partySize === 1) return; if (this._state.partySize === 1) return;
this._state = { this._state = {
...this._state, ...this._state,
partySize: this._state.partySize ? this._state.partySize - 1 : size, partySize: this._state.partySize ? this._state.partySize - 1 : size,
@ -240,7 +241,7 @@ export default class Activity implements Disposable {
} }
private async _generateDetails(debugging: string, editing: string, idling: string, largeImageKey: any) { private async _generateDetails(debugging: string, editing: string, idling: string, largeImageKey: any) {
let raw: string = this.client.config.get<string>(idling)!.replace('{null}', empty); let raw = this.client.config.get<string>(idling)!.replace('{null}', empty);
let filename = null; let filename = null;
let dirname = null; let dirname = null;
let checkState = false; let checkState = false;
@ -270,7 +271,9 @@ export default class Activity implements Disposable {
raw = this.client.config.get<string>(editing)!; raw = this.client.config.get<string>(editing)!;
} }
const { totalLines, size, currentLine, currentColumn, gitbranch, gitreponame } = await this._generateFileDetails(raw); const { totalLines, size, currentLine, currentColumn, gitbranch, gitreponame } = await this._generateFileDetails(
raw,
);
raw = raw raw = raw
.replace('{null}', empty) .replace('{null}', empty)
.replace('{filename}', filename) .replace('{filename}', filename)
@ -335,7 +338,7 @@ export default class Activity implements Disposable {
if (str.includes('{gitbranch}')) { if (str.includes('{gitbranch}')) {
if (this.client.git.repositories.length) { if (this.client.git.repositories.length) {
fileDetail.gitbranch = this.client.git.repositories.find((repo) => repo.ui.selected)!.state.HEAD!.name; fileDetail.gitbranch = this.client.git.repositories.find(repo => repo.ui.selected)!.state.HEAD!.name;
} else { } else {
fileDetail.gitbranch = 'Unknown'; fileDetail.gitbranch = 'Unknown';
} }
@ -343,7 +346,10 @@ export default class Activity implements Disposable {
if (str.includes('{gitreponame}')) { if (str.includes('{gitreponame}')) {
if (this.client.git.repositories.length) { if (this.client.git.repositories.length) {
fileDetail.gitreponame = this.client.git.repositories.find((repo) => repo.ui.selected)!.state.remotes[0].fetchUrl!.split('/')[1].replace('.git', ''); fileDetail.gitreponame = this.client.git.repositories
.find(repo => repo.ui.selected)!
.state.remotes[0].fetchUrl!.split('/')[1]
.replace('.git', '');
} else { } else {
fileDetail.gitreponame = 'Unknown'; fileDetail.gitreponame = 'Unknown';
} }

1107
yarn.lock

File diff suppressed because it is too large Load diff