Skip to content

Commit 233a6ca

Browse files
committed
🐛 Fix(type): some type error
1 parent 2d9271b commit 233a6ca

32 files changed

+497
-73
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
"uploaders",
2828
"upyun",
2929
"weibo"
30-
]
30+
],
31+
"typescript.tsdk": "node_modules\\typescript\\lib"
3132
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"start": "node ./bin/picgo",
15-
"lint": "eslint src/**/*.ts",
15+
"lint": "eslint src/**/*.ts && npm run build",
1616
"test": "echo \"Error: no test specified\" && exit 1",
1717
"build": "tsc -p . && npm run copy",
1818
"copy": "copyfiles -f src/utils/clipboard/* dist/src/utils/clipboard",
@@ -53,15 +53,19 @@
5353
"@commitlint/cli": "^7.5.2",
5454
"@picgo/bump-version": "^1.0.1",
5555
"@types/cross-spawn": "^6.0.0",
56+
"@types/ejs": "^3.0.5",
5657
"@types/fs-extra": "^5.0.4",
58+
"@types/globby": "^9.1.0",
5759
"@types/image-size": "^0.0.29",
5860
"@types/inquirer": "^0.0.42",
5961
"@types/lowdb": "^1.0.4",
6062
"@types/md5": "^2.1.32",
6163
"@types/mime-types": "^2.1.0",
64+
"@types/minimatch": "^3.0.3",
6265
"@types/node": "^10.5.2",
6366
"@types/request-promise-native": "^1.0.15",
6467
"@types/resolve": "^0.0.8",
68+
"@types/rimraf": "^3.0.0",
6569
"@typescript-eslint/eslint-plugin": "3",
6670
"@typescript-eslint/parser": "^3.2.0",
6771
"babel-eslint": "^10.1.0",

src/core/Lifecycle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { EventEmitter } from 'events'
22
import PicGo from './PicGo'
3-
import { IPlugin, Undefinable } from '../utils/interfaces'
3+
import { IPlugin, Undefinable } from 'src/types'
44
import { handleUrlEncode } from '../utils/common'
55
import LifecyclePlugins from '../lib/LifecyclePlugins'
66

77
class Lifecycle extends EventEmitter {
8-
configPath: string
98
ctx: PicGo
109

1110
constructor (ctx: PicGo) {

src/core/PicGo.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ import uploaders from '../plugins/uploader'
1010
import transformers from '../plugins/transformer'
1111
import PluginLoader from '../lib/PluginLoader'
1212
import { get, set, unset } from 'lodash'
13-
import { IHelper, IImgInfo, IConfig } from '../utils/interfaces'
13+
import { IHelper, IImgInfo, IConfig, IPicGo, IStringKeyMap } from 'src/types'
1414
import getClipboardImage from '../utils/getClipboardImage'
1515
import Request from '../lib/Request'
1616
import DB from '../utils/db'
1717
import PluginHandler from '../lib/PluginHandler'
1818

19-
class PicGo extends EventEmitter {
20-
private config: IConfig
21-
private lifecycle: Lifecycle
22-
private db: DB
19+
class PicGo extends EventEmitter implements IPicGo {
20+
private config!: IConfig
21+
private lifecycle!: Lifecycle
22+
private db!: DB
2323
configPath: string
24-
baseDir: string
25-
helper: IHelper
24+
baseDir!: string
25+
helper!: IHelper
2626
log: Logger
2727
cmd: Commander
2828
output: IImgInfo[]
2929
input: any[]
30-
pluginLoader: PluginLoader
30+
pluginLoader!: PluginLoader
3131
pluginHandler: PluginHandler
32-
Request: Request
32+
Request!: Request
3333

3434
constructor (configPath: string = '') {
3535
super()
@@ -127,7 +127,7 @@ class PicGo extends EventEmitter {
127127

128128
// set config for ctx but will not be saved to db
129129
// it's more lightweight
130-
setConfig (config: object): void {
130+
setConfig (config: IStringKeyMap<any>): void {
131131
Object.keys(config).forEach((name: string) => {
132132
set(this.config, name, config[name])
133133
})
@@ -139,10 +139,10 @@ class PicGo extends EventEmitter {
139139
unset(this.getConfig(key), propName)
140140
}
141141

142-
async upload (input?: any[]): Promise<string | Error> {
142+
async upload (input?: any[]): Promise<IImgInfo[] | Error> {
143143
if (this.configPath === '') {
144144
this.log.error('The configuration file only supports JSON format.')
145-
return ''
145+
return []
146146
}
147147
// upload from clipboard
148148
if (input === undefined || input.length === 0) {
@@ -163,17 +163,17 @@ class PicGo extends EventEmitter {
163163
}
164164
})
165165
await this.lifecycle.start([imgPath])
166+
return this.output
166167
}
167168
} catch (e) {
168169
this.log.error(e)
169170
this.emit('failed', e)
170171
throw e
171172
}
172-
return ''
173173
} else {
174174
// upload from path
175175
await this.lifecycle.start(input)
176-
return ''
176+
return this.output
177177
}
178178
}
179179
}

src/lib/Commander.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PicGo from '../core/PicGo'
22
import program, { CommanderStatic } from 'commander'
33
import inquirer, { Inquirer } from 'inquirer'
4-
import { IPlugin } from '../utils/interfaces'
4+
import { IPlugin } from 'src/types'
55
import commanders from '../plugins/commander'
66
import pkg from '../../package.json'
77

src/lib/LifecyclePlugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPlugin } from '../utils/interfaces'
1+
import { IPlugin } from 'src/types'
22

33
class LifecyclePlugins {
44
static currentPlugin: string | null

src/lib/Logger.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
ILogArgvType,
1010
ILogArgvTypeWithError,
1111
IConfig,
12-
Undefinable
13-
} from '../utils/interfaces'
12+
Undefinable,
13+
ILogColor
14+
} from 'src/types'
1415

1516
class Logger {
1617
private readonly level = {
@@ -21,8 +22,8 @@ class Logger {
2122
}
2223

2324
private readonly ctx: PicGo
24-
private logLevel: string
25-
private logPath: string
25+
private logLevel!: string
26+
private logPath!: string
2627
constructor (ctx: PicGo) {
2728
this.ctx = ctx
2829
}
@@ -31,7 +32,7 @@ class Logger {
3132
// if configPath is invalid then this.ctx.config === undefined
3233
// if not then check config.silent
3334
if (this.ctx.getConfig<IConfig>() === undefined || !this.ctx.getConfig<Undefinable<string>>('silent')) {
34-
const logHeader = chalk[this.level[type]](`[PicGo ${type.toUpperCase()}]:`)
35+
const logHeader = chalk[this.level[type] as ILogColor](`[PicGo ${type.toUpperCase()}]:`)
3536
console.log(logHeader, ...msg)
3637
this.logLevel = this.ctx.getConfig('settings.logLevel')
3738
const logPath = this.checkLogPathChange()

src/lib/PluginHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PicGo from '../core/PicGo'
22
import spawn from 'cross-spawn'
3-
import { IResult, IProcessEnv, Undefinable } from '../utils/interfaces'
3+
import { IResult, IProcessEnv, Undefinable } from 'src/types'
44

55
class PluginHandler {
66
// Thanks to feflow -> https://github.com/feflow/feflow/blob/master/lib/internal/install/plugin.js

src/lib/Request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import PicGo from '../core/PicGo'
22
import request, { RequestPromiseOptions, RequestPromiseAPI } from 'request-promise-native'
3-
import { Undefinable } from '../utils/interfaces'
3+
import { Undefinable } from 'src/types'
44

55
class Request {
66
ctx: PicGo
7-
request: RequestPromiseAPI
7+
request!: RequestPromiseAPI
88
constructor (ctx: PicGo) {
99
this.ctx = ctx
1010
this.init()

src/plugins/commander/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PicGo from '../../core/PicGo'
2-
import { IPlugin } from '../../utils/interfaces'
2+
import { IPlugin } from 'src/types'
33

44
const config: IPlugin = {
55
handle: (ctx: PicGo) => {

0 commit comments

Comments
 (0)