picgo 1.4.26 → 1.5.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/.eslintignore +2 -0
  2. package/.github/workflows/alpha.yml +22 -0
  3. package/CHANGELOG.md +43 -0
  4. package/README.md +14 -1
  5. package/bin/picgo +1 -1
  6. package/dist/{src/core → core}/Lifecycle.d.ts +15 -15
  7. package/dist/{src/core → core}/PicGo.d.ts +44 -44
  8. package/dist/i18n/en.d.ts +2 -0
  9. package/dist/i18n/index.d.ts +16 -0
  10. package/dist/i18n/zh-CN.d.ts +65 -0
  11. package/dist/index.cjs.js +2 -0
  12. package/dist/index.d.ts +9 -0
  13. package/dist/index.esm.js +2 -0
  14. package/dist/{src/lib → lib}/Commander.d.ts +16 -16
  15. package/dist/{src/lib → lib}/LifecyclePlugins.d.ts +16 -16
  16. package/dist/{src/lib → lib}/Logger.d.ts +16 -16
  17. package/dist/{src/lib → lib}/PluginHandler.d.ts +10 -10
  18. package/dist/{src/lib → lib}/PluginLoader.d.ts +27 -27
  19. package/dist/{src/lib → lib}/Request.d.ts +11 -11
  20. package/dist/{src/plugins → plugins}/commander/config.d.ts +3 -3
  21. package/dist/plugins/commander/i18n.d.ts +3 -0
  22. package/dist/{src/plugins → plugins}/commander/index.d.ts +3 -3
  23. package/dist/{src/plugins → plugins}/commander/init.d.ts +3 -3
  24. package/dist/{src/plugins → plugins}/commander/pluginHandler.d.ts +3 -3
  25. package/dist/{src/plugins → plugins}/commander/proxy.d.ts +3 -3
  26. package/dist/{src/plugins → plugins}/commander/setting.d.ts +5 -5
  27. package/dist/{src/plugins → plugins}/commander/upload.d.ts +3 -3
  28. package/dist/{src/plugins → plugins}/commander/use.d.ts +3 -3
  29. package/dist/{src/plugins → plugins}/transformer/base64.d.ts +5 -5
  30. package/dist/{src/plugins → plugins}/transformer/index.d.ts +3 -3
  31. package/dist/{src/plugins → plugins}/transformer/path.d.ts +5 -5
  32. package/dist/plugins/uploader/aliyun.d.ts +2 -0
  33. package/dist/plugins/uploader/github.d.ts +2 -0
  34. package/dist/plugins/uploader/imgur.d.ts +2 -0
  35. package/dist/{src/plugins → plugins}/uploader/index.d.ts +3 -3
  36. package/dist/plugins/uploader/qiniu.d.ts +2 -0
  37. package/dist/plugins/uploader/smms.d.ts +2 -0
  38. package/dist/plugins/uploader/tcyun.d.ts +8 -0
  39. package/dist/plugins/uploader/upyun.d.ts +2 -0
  40. package/dist/types/index.d.ts +468 -0
  41. package/dist/{src/utils → utils}/common.d.ts +102 -101
  42. package/dist/{src/utils → utils}/createContext.d.ts +6 -6
  43. package/dist/{src/utils → utils}/db.d.ts +15 -15
  44. package/dist/{src/utils → utils}/enum.d.ts +27 -27
  45. package/dist/{src/utils → utils}/eventBus.d.ts +4 -4
  46. package/dist/{src/utils → utils}/getClipboardImage.d.ts +4 -3
  47. package/dist/{src/utils → utils}/initUtils.d.ts +26 -26
  48. package/dist/{src/utils → utils}/interfaces.d.ts +203 -203
  49. package/package.json +27 -22
  50. package/rollup.config.js +82 -0
  51. package/dist/package.json +0 -127
  52. package/dist/src/core/Lifecycle.js +0 -123
  53. package/dist/src/core/PicGo.js +0 -210
  54. package/dist/src/index.d.ts +0 -2
  55. package/dist/src/index.js +0 -6
  56. package/dist/src/lib/Commander.js +0 -56
  57. package/dist/src/lib/LifecyclePlugins.js +0 -52
  58. package/dist/src/lib/Logger.js +0 -82
  59. package/dist/src/lib/PluginHandler.js +0 -260
  60. package/dist/src/lib/PluginLoader.js +0 -145
  61. package/dist/src/lib/Request.js +0 -42
  62. package/dist/src/plugins/commander/config.js +0 -11
  63. package/dist/src/plugins/commander/index.js +0 -21
  64. package/dist/src/plugins/commander/init.js +0 -122
  65. package/dist/src/plugins/commander/pluginHandler.js +0 -43
  66. package/dist/src/plugins/commander/proxy.js +0 -14
  67. package/dist/src/plugins/commander/setting.js +0 -102
  68. package/dist/src/plugins/commander/upload.js +0 -35
  69. package/dist/src/plugins/commander/use.js +0 -87
  70. package/dist/src/plugins/transformer/base64.js +0 -9
  71. package/dist/src/plugins/transformer/index.js +0 -16
  72. package/dist/src/plugins/transformer/path.js +0 -42
  73. package/dist/src/plugins/uploader/aliyun.d.ts +0 -7
  74. package/dist/src/plugins/uploader/aliyun.js +0 -129
  75. package/dist/src/plugins/uploader/github.d.ts +0 -7
  76. package/dist/src/plugins/uploader/github.js +0 -101
  77. package/dist/src/plugins/uploader/imgur.d.ts +0 -7
  78. package/dist/src/plugins/uploader/imgur.js +0 -81
  79. package/dist/src/plugins/uploader/index.js +0 -26
  80. package/dist/src/plugins/uploader/qiniu.d.ts +0 -7
  81. package/dist/src/plugins/uploader/qiniu.js +0 -132
  82. package/dist/src/plugins/uploader/smms.d.ts +0 -7
  83. package/dist/src/plugins/uploader/smms.js +0 -74
  84. package/dist/src/plugins/uploader/tcyun.d.ts +0 -13
  85. package/dist/src/plugins/uploader/tcyun.js +0 -218
  86. package/dist/src/plugins/uploader/upyun.d.ts +0 -7
  87. package/dist/src/plugins/uploader/upyun.js +0 -128
  88. package/dist/src/types/index.d.ts +0 -471
  89. package/dist/src/utils/clipboard/linux.sh +0 -18
  90. package/dist/src/utils/clipboard/mac.applescript +0 -0
  91. package/dist/src/utils/clipboard/windows.ps1 +0 -26
  92. package/dist/src/utils/clipboard/windows10.ps1 +0 -47
  93. package/dist/src/utils/clipboard/wsl.sh +0 -18
  94. package/dist/src/utils/common.js +0 -353
  95. package/dist/src/utils/createContext.js +0 -45
  96. package/dist/src/utils/db.js +0 -85
  97. package/dist/src/utils/enum.js +0 -33
  98. package/dist/src/utils/eventBus.js +0 -6
  99. package/dist/src/utils/getClipboardImage.js +0 -101
  100. package/dist/src/utils/initUtils.js +0 -120
  101. package/dist/src/utils/interfaces.js +0 -3
@@ -1,353 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isInputConfigValid = exports.isConfigKeyInBlackList = exports.configBlackList = exports.removePluginVersion = exports.handleUnixStylePath = exports.getNormalPluginName = exports.getProcessPluginName = exports.handleCompletePluginName = exports.handleStreamlinePluginName = exports.isSimpleName = exports.getPluginNameType = exports.getURLFile = exports.getFSFile = exports.getImageSize = exports.handleUrlEncode = exports.isUrlEncode = exports.isUrl = void 0;
7
- const request_promise_native_1 = __importDefault(require("request-promise-native"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const image_size_1 = require("image-size");
11
- const url_1 = require("url");
12
- exports.isUrl = (url) => (url.startsWith('http://') || url.startsWith('https://'));
13
- exports.isUrlEncode = (url) => {
14
- url = url || '';
15
- try {
16
- return url !== decodeURI(url);
17
- }
18
- catch (e) {
19
- // if some error caught, try to let it go
20
- return true;
21
- }
22
- };
23
- exports.handleUrlEncode = (url) => {
24
- if (!exports.isUrlEncode(url)) {
25
- url = encodeURI(url);
26
- }
27
- return url;
28
- };
29
- exports.getImageSize = (file) => {
30
- try {
31
- const { width = 0, height = 0 } = image_size_1.imageSize(file);
32
- return {
33
- real: true,
34
- width,
35
- height
36
- };
37
- }
38
- catch (e) {
39
- // fallback to 200 * 200
40
- return {
41
- real: false,
42
- width: 200,
43
- height: 200
44
- };
45
- }
46
- };
47
- exports.getFSFile = async (filePath) => {
48
- try {
49
- return {
50
- extname: path_1.default.extname(filePath),
51
- fileName: path_1.default.basename(filePath),
52
- buffer: await fs_extra_1.default.readFile(filePath),
53
- success: true
54
- };
55
- }
56
- catch (_a) {
57
- return {
58
- reason: `read file ${filePath} error`,
59
- success: false
60
- };
61
- }
62
- };
63
- exports.getURLFile = async (url) => {
64
- const requestOptions = {
65
- method: 'GET',
66
- url: exports.handleUrlEncode(url),
67
- encoding: null
68
- };
69
- let isImage = false;
70
- let extname = '';
71
- let timeoutId;
72
- // tslint:disable-next-line: typedef
73
- const requestFn = new Promise((resolve, reject) => {
74
- (async () => {
75
- try {
76
- const res = await request_promise_native_1.default(requestOptions)
77
- .on('response', (response) => {
78
- const contentType = response.headers['content-type'];
79
- if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('image')) {
80
- isImage = true;
81
- extname = `.${contentType.split('image/')[1]}`;
82
- }
83
- });
84
- clearTimeout(timeoutId);
85
- if (isImage) {
86
- const urlPath = new url_1.URL(requestOptions.url).pathname;
87
- resolve({
88
- buffer: res,
89
- fileName: path_1.default.basename(urlPath),
90
- extname,
91
- success: true
92
- });
93
- }
94
- else {
95
- resolve({
96
- success: false,
97
- reason: `${url} is not image`
98
- });
99
- }
100
- }
101
- catch (_a) {
102
- clearTimeout(timeoutId);
103
- resolve({
104
- success: false,
105
- reason: `request ${url} error`
106
- });
107
- }
108
- })().catch(reject);
109
- });
110
- // tslint:disable-next-line: typedef
111
- const timeoutPromise = new Promise((resolve) => {
112
- timeoutId = setTimeout(() => {
113
- resolve({
114
- success: false,
115
- reason: `request ${url} timeout`
116
- });
117
- }, 10000);
118
- });
119
- return Promise.race([requestFn, timeoutPromise]);
120
- };
121
- /**
122
- * detect the input string's type
123
- * for example
124
- * 1. @xxx/picgo-plugin-xxx -> scope
125
- * 2. picgo-plugin-xxx -> normal
126
- * 3. xxx -> simple
127
- * 4. not exists or is a path -> unknown
128
- * @param name
129
- */
130
- exports.getPluginNameType = (name) => {
131
- if (/^@[^/]+\/picgo-plugin-/.test(name)) {
132
- return 'scope';
133
- }
134
- else if (name.startsWith('picgo-plugin-')) {
135
- return 'normal';
136
- }
137
- else if (exports.isSimpleName(name)) {
138
- return 'simple';
139
- }
140
- return 'unknown';
141
- };
142
- /**
143
- * detect the input string is a simple plugin name or not
144
- * for example
145
- * 1. xxx -> true
146
- * 2. /Usr/xx/xxxx/picgo-plugin-xxx -> false
147
- * @param name pluginNameOrPath
148
- */
149
- exports.isSimpleName = (nameOrPath) => {
150
- if (path_1.default.isAbsolute(nameOrPath)) {
151
- return false;
152
- }
153
- const pluginPath = path_1.default.join(process.cwd(), nameOrPath);
154
- if (fs_extra_1.default.existsSync(pluginPath)) {
155
- return false;
156
- }
157
- if (nameOrPath.includes('/') || nameOrPath.includes('\\')) {
158
- return false;
159
- }
160
- return true;
161
- };
162
- /**
163
- * streamline the full plugin name to a simple one
164
- * for example:
165
- * 1. picgo-plugin-xxx -> xxx
166
- * 2. @xxx/picgo-plugin-yyy -> yyy
167
- * @param name pluginFullName
168
- */
169
- exports.handleStreamlinePluginName = (name) => {
170
- if (/^@[^/]+\/picgo-plugin-/.test(name)) {
171
- return name.replace(/^@[^/]+\/picgo-plugin-/, '');
172
- }
173
- else {
174
- return name.replace(/picgo-plugin-/, '');
175
- }
176
- };
177
- /**
178
- * complete plugin name to full name
179
- * for example:
180
- * 1. xxx -> picgo-plugin-xxx
181
- * 2. picgo-plugin-xxx -> picgo-plugin-xxx
182
- * @param name pluginSimpleName
183
- * @param scope pluginScope
184
- */
185
- exports.handleCompletePluginName = (name, scope = '') => {
186
- if (scope) {
187
- return `@${scope}/picgo-plugin-${name}`;
188
- }
189
- else {
190
- return `picgo-plugin-${name}`;
191
- }
192
- };
193
- /**
194
- * handle install/uninstall/update plugin name or path
195
- * for example
196
- * 1. picgo-plugin-xxx -> picgo-plugin-xxx
197
- * 2. @xxx/picgo-plugin-xxx -> @xxx/picgo-plugin-xxx
198
- * 3. xxx -> picgo-plugin-xxx
199
- * 4. ./xxxx/picgo-plugin-xxx -> /absolutePath/.../xxxx/picgo-plugin-xxx
200
- * 5. /absolutePath/.../picgo-plugin-xxx -> /absolutePath/.../picgo-plugin-xxx
201
- * @param nameOrPath pluginName or pluginPath
202
- */
203
- exports.getProcessPluginName = (nameOrPath, logger = console) => {
204
- const pluginNameType = exports.getPluginNameType(nameOrPath);
205
- switch (pluginNameType) {
206
- case 'normal':
207
- case 'scope':
208
- return nameOrPath;
209
- case 'simple':
210
- return exports.handleCompletePluginName(nameOrPath);
211
- default: {
212
- // now, the pluginNameType is unknow here
213
- // 1. check if is an absolute path
214
- let pluginPath = nameOrPath;
215
- if (path_1.default.isAbsolute(nameOrPath) && fs_extra_1.default.existsSync(nameOrPath)) {
216
- return exports.handleUnixStylePath(pluginPath);
217
- }
218
- // 2. check if is a relative path
219
- pluginPath = path_1.default.join(process.cwd(), nameOrPath);
220
- if (fs_extra_1.default.existsSync(pluginPath)) {
221
- return exports.handleUnixStylePath(pluginPath);
222
- }
223
- // 3. invalid nameOrPath
224
- logger.warn(`Can't find plugin ${nameOrPath}`);
225
- return '';
226
- }
227
- }
228
- };
229
- /**
230
- * get the normal plugin name
231
- * for example:
232
- * 1. picgo-plugin-xxx -> picgo-plugin-xxx
233
- * 2. @xxx/picgo-plugin-xxx -> @xxx/picgo-plugin-xxx
234
- * 3. ./xxxx/picgo-plugin-xxx -> picgo-plugin-xxx
235
- * 4. /absolutePath/.../picgo-plugin-xxx -> picgo-plugin-xxx
236
- * 5. an exception: [package.json's name] !== [folder name]
237
- * then use [package.json's name], usually match the scope package.
238
- * 6. if plugin name has version: picgo-plugin-xxx@x.x.x then remove the version
239
- * @param nameOrPath
240
- */
241
- exports.getNormalPluginName = (nameOrPath, logger = console) => {
242
- var _a;
243
- const pluginNameType = exports.getPluginNameType(nameOrPath);
244
- switch (pluginNameType) {
245
- case 'normal':
246
- return exports.removePluginVersion(nameOrPath);
247
- case 'scope':
248
- return exports.removePluginVersion(nameOrPath, true);
249
- case 'simple':
250
- return exports.removePluginVersion(exports.handleCompletePluginName(nameOrPath));
251
- default: {
252
- // now, the nameOrPath must be path
253
- // the nameOrPath here will be ensured with unix style
254
- // we need to find the package.json's name cause npm using the name in package.json's name filed
255
- if (!fs_extra_1.default.existsSync(nameOrPath)) {
256
- logger.warn(`Can't find plugin: ${nameOrPath}`);
257
- return '';
258
- }
259
- const packageJSONPath = path_1.default.posix.join(nameOrPath, 'package.json');
260
- if (!fs_extra_1.default.existsSync(packageJSONPath)) {
261
- logger.warn(`Can't find plugin: ${nameOrPath}`);
262
- return '';
263
- }
264
- else {
265
- const pkg = fs_extra_1.default.readJSONSync(packageJSONPath) || {};
266
- if (!((_a = pkg.name) === null || _a === void 0 ? void 0 : _a.includes('picgo-plugin-'))) {
267
- logger.warn(`The plugin package.json's name filed is ${pkg.name || 'empty'}, need to include the prefix: picgo-plugin-`);
268
- return '';
269
- }
270
- return pkg.name;
271
- }
272
- }
273
- }
274
- };
275
- /**
276
- * handle transform the path to unix style
277
- * for example
278
- * 1. C:\\xxx\\xxx -> C:/xxx/xxx
279
- * 2. /xxx/xxx -> /xxx/xxx
280
- * @param path
281
- */
282
- exports.handleUnixStylePath = (pathStr) => {
283
- const pathArr = pathStr.split(path_1.default.sep);
284
- return pathArr.join('/');
285
- };
286
- /**
287
- * remove plugin version when register plugin name
288
- * 1. picgo-plugin-xxx@1.0.0 -> picgo-plugin-xxx
289
- * 2. @xxx/picgo-plugin-xxx@1.0.0 -> @xxx/picgo-plugin-xxx
290
- * @param nameOrPath
291
- * @param scope
292
- */
293
- exports.removePluginVersion = (nameOrPath, scope = false) => {
294
- if (!nameOrPath.includes('@')) {
295
- return nameOrPath;
296
- }
297
- else {
298
- let reg = /(.+\/)?(picgo-plugin-\w+)(@.+)*/;
299
- // if is a scope pkg
300
- if (scope) {
301
- reg = /(.+\/)?(^@[^/]+\/picgo-plugin-\w+)(@.+)*/;
302
- }
303
- const matchArr = nameOrPath.match(reg);
304
- if (!matchArr) {
305
- console.warn('can not remove plugin version');
306
- return nameOrPath;
307
- }
308
- else {
309
- return matchArr[2];
310
- }
311
- }
312
- };
313
- /**
314
- * the config black item list which won't be setted
315
- * only can be got
316
- */
317
- exports.configBlackList = [];
318
- /**
319
- * check some config key is in blackList
320
- * @param key
321
- */
322
- exports.isConfigKeyInBlackList = (key) => {
323
- return exports.configBlackList.some(blackItem => key.startsWith(blackItem));
324
- };
325
- /**
326
- * check the input config is valid
327
- * config must be object such as { xxx: 'xxx' }
328
- * && can't be array
329
- * @param config
330
- * @returns
331
- */
332
- exports.isInputConfigValid = (config) => {
333
- if (typeof config === 'object' &&
334
- !Array.isArray(config) &&
335
- Object.keys(config).length > 0) {
336
- return true;
337
- }
338
- return false;
339
- };
340
- // hold...
341
- // export const configWhiteList: RegExp[] = [
342
- // /^picBed/,
343
- // /^picgoPlugins/,
344
- // /^@[^/]+\/picgo-plugin-/,
345
- // /debug/,
346
- // /silent/,
347
- // /configPath/,
348
- // /^settings/,
349
- // /PICGO_ENV/
350
- // ]
351
- // export const isConfigKeyInWhiteList = (key: string): boolean => {
352
- // return configWhiteList.some(whiteItem => whiteItem.test(key))
353
- // }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createContext = void 0;
4
- /**
5
- * create an unique context for each upload process
6
- * @param ctx
7
- */
8
- exports.createContext = (ctx) => {
9
- return {
10
- configPath: ctx.configPath,
11
- baseDir: ctx.baseDir,
12
- log: ctx.log,
13
- cmd: ctx.cmd,
14
- output: [],
15
- input: [],
16
- pluginLoader: ctx.pluginLoader,
17
- pluginHandler: ctx.pluginHandler,
18
- Request: ctx.Request,
19
- helper: ctx.helper,
20
- VERSION: ctx.VERSION,
21
- GUI_VERSION: ctx.GUI_VERSION,
22
- request: ctx.request,
23
- getConfig: ctx.getConfig.bind(ctx),
24
- saveConfig: ctx.saveConfig.bind(ctx),
25
- removeConfig: ctx.removeConfig.bind(ctx),
26
- setConfig: ctx.setConfig.bind(ctx),
27
- unsetConfig: ctx.unsetConfig.bind(ctx),
28
- upload: ctx.upload.bind(ctx),
29
- addListener: ctx.addListener.bind(ctx),
30
- on: ctx.on.bind(ctx),
31
- once: ctx.once.bind(ctx),
32
- removeListener: ctx.removeListener.bind(ctx),
33
- off: ctx.off.bind(ctx),
34
- removeAllListeners: ctx.removeAllListeners.bind(ctx),
35
- setMaxListeners: ctx.setMaxListeners.bind(ctx),
36
- getMaxListeners: ctx.getMaxListeners.bind(ctx),
37
- listeners: ctx.listeners.bind(ctx),
38
- rawListeners: ctx.rawListeners.bind(ctx),
39
- emit: ctx.emit.bind(ctx),
40
- listenerCount: ctx.listenerCount.bind(ctx),
41
- prependListener: ctx.prependListener.bind(ctx),
42
- prependOnceListener: ctx.prependOnceListener.bind(ctx),
43
- eventNames: ctx.eventNames.bind(ctx)
44
- };
45
- };
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const lowdb_1 = __importDefault(require("lowdb"));
7
- // @ts-expect-error
8
- const lodash_id_1 = __importDefault(require("lodash-id"));
9
- const FileSync_1 = __importDefault(require("lowdb/adapters/FileSync"));
10
- const comment_json_1 = __importDefault(require("comment-json"));
11
- class DB {
12
- constructor(ctx) {
13
- this.ctx = ctx;
14
- const adapter = new FileSync_1.default(this.ctx.configPath, {
15
- serialize(obj) {
16
- return comment_json_1.default.stringify(obj, null, 2);
17
- },
18
- deserialize: comment_json_1.default.parse
19
- });
20
- this.db = lowdb_1.default(adapter);
21
- this.db._.mixin(lodash_id_1.default);
22
- if (!this.db.has('picBed').value()) {
23
- try {
24
- this.db.set('picBed', {
25
- uploader: 'smms',
26
- current: 'smms'
27
- }).write();
28
- }
29
- catch (e) {
30
- this.ctx.log.error(e);
31
- throw e;
32
- }
33
- }
34
- if (!this.db.has('picgoPlugins').value()) {
35
- try {
36
- this.db.set('picgoPlugins', {}).write();
37
- }
38
- catch (e) {
39
- this.ctx.log.error(e);
40
- throw e;
41
- }
42
- }
43
- }
44
- read() {
45
- return this.db.read();
46
- }
47
- get(key = '') {
48
- return this.read().get(key).value();
49
- }
50
- set(key, value) {
51
- return this.read().set(key, value).write();
52
- }
53
- has(key) {
54
- return this.read().has(key).value();
55
- }
56
- insert(key, value) {
57
- return this.read().get(key).insert(value).write();
58
- }
59
- unset(key, value) {
60
- return this.read().get(key).unset(value).write();
61
- }
62
- saveConfig(config) {
63
- Object.keys(config).forEach((name) => {
64
- this.set(name, config[name]);
65
- });
66
- }
67
- removeConfig(config) {
68
- Object.keys(config).forEach((name) => {
69
- this.unset(name, config[name]);
70
- });
71
- }
72
- }
73
- exports.default = DB;
74
- // const initConfig = (configPath: string): lowdb.LowdbSync<any> => {
75
- // }
76
- // const saveConfig = (configPath: string, config: any): void => {
77
- // const db = initConfig(configPath)
78
- // Object.keys(config).forEach((name: string) => {
79
- // db.read().set(name, config[name]).write()
80
- // })
81
- // }
82
- // export {
83
- // initConfig,
84
- // saveConfig
85
- // }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IBusEvent = exports.IBuildInEvent = exports.ILogType = void 0;
4
- var ILogType;
5
- (function (ILogType) {
6
- ILogType["success"] = "success";
7
- ILogType["info"] = "info";
8
- ILogType["warn"] = "warn";
9
- ILogType["error"] = "error";
10
- })(ILogType = exports.ILogType || (exports.ILogType = {}));
11
- /**
12
- * these events will be catched by users
13
- */
14
- var IBuildInEvent;
15
- (function (IBuildInEvent) {
16
- IBuildInEvent["UPLOAD_PROGRESS"] = "uploadProgress";
17
- IBuildInEvent["FAILED"] = "failed";
18
- IBuildInEvent["BEFORE_TRANSFORM"] = "beforeTransform";
19
- IBuildInEvent["BEFORE_UPLOAD"] = "beforeUpload";
20
- IBuildInEvent["AFTER_UPLOAD"] = "afterUpload";
21
- IBuildInEvent["FINISHED"] = "finished";
22
- IBuildInEvent["INSTALL"] = "install";
23
- IBuildInEvent["UNINSTALL"] = "uninstall";
24
- IBuildInEvent["UPDATE"] = "update";
25
- IBuildInEvent["NOTIFICATION"] = "notification";
26
- })(IBuildInEvent = exports.IBuildInEvent || (exports.IBuildInEvent = {}));
27
- /**
28
- * these events will be catched only by picgo
29
- */
30
- var IBusEvent;
31
- (function (IBusEvent) {
32
- IBusEvent["CONFIG_CHANGE"] = "CONFIG_CHANGE";
33
- })(IBusEvent = exports.IBusEvent || (exports.IBusEvent = {}));
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventBus = void 0;
4
- const events_1 = require("events");
5
- const eventBus = new events_1.EventEmitter();
6
- exports.eventBus = eventBus;
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = __importDefault(require("path"));
7
- const child_process_1 = require("child_process");
8
- const dayjs_1 = __importDefault(require("dayjs"));
9
- const os_1 = __importDefault(require("os"));
10
- const fs_extra_1 = __importDefault(require("fs-extra"));
11
- const is_wsl_1 = __importDefault(require("is-wsl"));
12
- const enum_1 = require("./enum");
13
- const getCurrentPlatform = () => {
14
- const platform = process.platform;
15
- if (is_wsl_1.default) {
16
- return 'wsl';
17
- }
18
- if (platform !== 'win32') {
19
- return platform;
20
- }
21
- else {
22
- const currentOS = os_1.default.release().split('.')[0];
23
- if (currentOS === '10') {
24
- return 'win10';
25
- }
26
- else {
27
- return 'win32';
28
- }
29
- }
30
- };
31
- // Thanks to vs-picgo: https://github.com/Spades-S/vs-picgo/blob/master/src/extension.ts
32
- const getClipboardImage = async (ctx) => {
33
- const imagePath = path_1.default.join(ctx.baseDir, `${dayjs_1.default().format('YYYYMMDDHHmmss')}.png`);
34
- return await new Promise((resolve, reject) => {
35
- const platform = getCurrentPlatform();
36
- let execution;
37
- // for PicGo GUI
38
- const env = ctx.getConfig('PICGO_ENV') === 'GUI';
39
- const platformPaths = {
40
- darwin: env ? path_1.default.join(ctx.baseDir, 'mac.applescript') : './clipboard/mac.applescript',
41
- win32: env ? path_1.default.join(ctx.baseDir, 'windows.ps1') : './clipboard/windows.ps1',
42
- win10: env ? path_1.default.join(ctx.baseDir, 'windows10.ps1') : './clipboard/windows10.ps1',
43
- linux: env ? path_1.default.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh',
44
- wsl: env ? path_1.default.join(ctx.baseDir, 'wsl.sh') : './clipboard/wsl.sh'
45
- };
46
- const scriptPath = env ? platformPaths[platform] : path_1.default.join(__dirname, platformPaths[platform]);
47
- if (platform === 'darwin') {
48
- execution = child_process_1.spawn('osascript', [scriptPath, imagePath]);
49
- }
50
- else if (platform === 'win32' || platform === 'win10') {
51
- execution = child_process_1.spawn('powershell', [
52
- '-noprofile',
53
- '-noninteractive',
54
- '-nologo',
55
- '-sta',
56
- '-executionpolicy', 'unrestricted',
57
- // fix windows 10 native cmd crash bug when "picgo upload"
58
- // https://github.com/PicGo/PicGo-Core/issues/32
59
- // '-windowstyle','hidden',
60
- // '-noexit',
61
- '-file', scriptPath,
62
- imagePath
63
- ]);
64
- }
65
- else {
66
- execution = child_process_1.spawn('sh', [scriptPath, imagePath]);
67
- }
68
- execution.stdout.on('data', (data) => {
69
- if (platform === 'linux') {
70
- if (data.toString().trim() === 'no xclip') {
71
- ctx.emit(enum_1.IBuildInEvent.NOTIFICATION, {
72
- title: 'xclip not found',
73
- body: 'Please install xclip before run picgo'
74
- });
75
- return reject(new Error('Please install xclip before run picgo'));
76
- }
77
- }
78
- const imgPath = data.toString().trim();
79
- // if the filePath is the real file in system
80
- // we should keep it instead of removing
81
- let shouldKeepAfterUploading = false;
82
- // in macOS if your copy the file in system, it's basename will not equal to our default basename
83
- if (path_1.default.basename(imgPath) !== path_1.default.basename(imagePath)) {
84
- // if the path is not generate by picgo
85
- // but the path exists, we should keep it
86
- if (fs_extra_1.default.existsSync(imgPath)) {
87
- shouldKeepAfterUploading = true;
88
- }
89
- }
90
- // if the imgPath is invalid
91
- if (imgPath !== 'no image' && !fs_extra_1.default.existsSync(imgPath)) {
92
- return reject(new Error(`Can't find ${imgPath}`));
93
- }
94
- resolve({
95
- imgPath,
96
- shouldKeepAfterUploading
97
- });
98
- });
99
- });
100
- };
101
- exports.default = getClipboardImage;