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,56 +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 commander_1 = require("commander");
7
- const inquirer_1 = __importDefault(require("inquirer"));
8
- const commander_2 = __importDefault(require("../plugins/commander"));
9
- const package_json_1 = require("../../package.json");
10
- class Commander {
11
- constructor(ctx) {
12
- this.list = {};
13
- this.program = new commander_1.Command();
14
- this.inquirer = inquirer_1.default;
15
- this.ctx = ctx;
16
- }
17
- init() {
18
- this.program
19
- .version(package_json_1.version, '-v, --version')
20
- .option('-d, --debug', 'debug mode', () => {
21
- this.ctx.setConfig({
22
- debug: true
23
- });
24
- })
25
- .option('-s, --silent', 'silent mode', () => {
26
- this.ctx.setConfig({
27
- silent: true
28
- });
29
- })
30
- .on('command:*', () => {
31
- this.ctx.log.error(`Invalid command: ${this.program.args.join(' ')}\nSee --help for a list of available commands.`);
32
- process.exit(1);
33
- });
34
- // built-in commands
35
- commander_2.default(this.ctx);
36
- }
37
- register(name, plugin) {
38
- if (!name)
39
- throw new TypeError('name is required!');
40
- if (typeof plugin.handle !== 'function')
41
- throw new TypeError('plugin.handle must be a function!');
42
- if (name in this.list)
43
- throw new TypeError('duplicate name!');
44
- this.list[name] = plugin;
45
- }
46
- loadCommands() {
47
- Object.keys(this.list).map((item) => this.list[item].handle(this.ctx));
48
- }
49
- get(name) {
50
- return this.list[name];
51
- }
52
- getList() {
53
- return Object.keys(this.list).map((item) => this.list[item]);
54
- }
55
- }
56
- exports.default = Commander;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setCurrentPluginName = void 0;
4
- class LifecyclePlugins {
5
- constructor(name) {
6
- this.name = name;
7
- this.list = new Map();
8
- this.pluginIdMap = new Map();
9
- }
10
- register(id, plugin) {
11
- var _a;
12
- if (!id)
13
- throw new TypeError('id is required!');
14
- if (typeof plugin.handle !== 'function')
15
- throw new TypeError('plugin.handle must be a function!');
16
- if (this.list.has(id))
17
- throw new TypeError(`${this.name} duplicate id: ${id}!`);
18
- this.list.set(id, plugin);
19
- if (LifecyclePlugins.currentPlugin) {
20
- if (this.pluginIdMap.has(LifecyclePlugins.currentPlugin)) {
21
- (_a = this.pluginIdMap.get(LifecyclePlugins.currentPlugin)) === null || _a === void 0 ? void 0 : _a.push(id);
22
- }
23
- else {
24
- this.pluginIdMap.set(LifecyclePlugins.currentPlugin, [id]);
25
- }
26
- }
27
- }
28
- unregister(pluginName) {
29
- if (this.pluginIdMap.has(pluginName)) {
30
- const pluginList = this.pluginIdMap.get(pluginName);
31
- pluginList === null || pluginList === void 0 ? void 0 : pluginList.forEach((plugin) => {
32
- this.list.delete(plugin);
33
- });
34
- }
35
- }
36
- getName() {
37
- return this.name;
38
- }
39
- get(id) {
40
- return this.list.get(id);
41
- }
42
- getList() {
43
- return [...this.list.values()];
44
- }
45
- getIdList() {
46
- return [...this.list.keys()];
47
- }
48
- }
49
- exports.setCurrentPluginName = (name = null) => {
50
- LifecyclePlugins.currentPlugin = name;
51
- };
52
- exports.default = LifecyclePlugins;
@@ -1,82 +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 chalk_1 = __importDefault(require("chalk"));
7
- const dayjs_1 = __importDefault(require("dayjs"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const util_1 = __importDefault(require("util"));
11
- const enum_1 = require("../utils/enum");
12
- class Logger {
13
- constructor(ctx) {
14
- this.level = {
15
- [enum_1.ILogType.success]: 'green',
16
- [enum_1.ILogType.info]: 'blue',
17
- [enum_1.ILogType.warn]: 'yellow',
18
- [enum_1.ILogType.error]: 'red'
19
- };
20
- this.ctx = ctx;
21
- }
22
- handleLog(type, ...msg) {
23
- // check config.silent
24
- if (!this.ctx.getConfig('silent')) {
25
- const logHeader = chalk_1.default[this.level[type]](`[PicGo ${type.toUpperCase()}]:`);
26
- console.log(logHeader, ...msg);
27
- this.logLevel = this.ctx.getConfig('settings.logLevel');
28
- this.logPath = this.ctx.getConfig('settings.logPath') || path_1.default.join(this.ctx.baseDir, './picgo.log');
29
- setTimeout(() => {
30
- this.handleWriteLog(this.logPath, type, ...msg);
31
- }, 0);
32
- }
33
- }
34
- handleWriteLog(logPath, type, ...msg) {
35
- try {
36
- if (this.checkLogLevel(type, this.logLevel)) {
37
- let log = `${dayjs_1.default().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `;
38
- msg.forEach((item) => {
39
- if (typeof item === 'object' && type === 'error') {
40
- log += `\n------Error Stack Begin------\n${util_1.default.format(item.stack)}\n-------Error Stack End------- `;
41
- }
42
- else {
43
- if (typeof item === 'object') {
44
- item = JSON.stringify(item);
45
- }
46
- log += `${item} `;
47
- }
48
- });
49
- log += '\n';
50
- // A synchronized approach to avoid log msg sequence errors
51
- fs_extra_1.default.appendFileSync(logPath, log);
52
- }
53
- }
54
- catch (e) {
55
- console.log(e);
56
- }
57
- }
58
- checkLogLevel(type, level) {
59
- if (level === undefined || level === 'all') {
60
- return true;
61
- }
62
- if (Array.isArray(level)) {
63
- return level.some((item) => (item === type || item === 'all'));
64
- }
65
- else {
66
- return type === level;
67
- }
68
- }
69
- success(...msg) {
70
- return this.handleLog(enum_1.ILogType.success, ...msg);
71
- }
72
- info(...msg) {
73
- return this.handleLog(enum_1.ILogType.info, ...msg);
74
- }
75
- error(...msg) {
76
- return this.handleLog(enum_1.ILogType.error, ...msg);
77
- }
78
- warn(...msg) {
79
- return this.handleLog(enum_1.ILogType.warn, ...msg);
80
- }
81
- }
82
- exports.default = Logger;
@@ -1,260 +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 cross_spawn_1 = __importDefault(require("cross-spawn"));
7
- const enum_1 = require("../utils/enum");
8
- const common_1 = require("../utils/common");
9
- class PluginHandler {
10
- constructor(ctx) {
11
- this.ctx = ctx;
12
- }
13
- async install(plugins, options = {}, env) {
14
- const installedPlugins = [];
15
- const processPlugins = plugins
16
- .map((item) => handlePluginNameProcess(this.ctx, item))
17
- .filter((item) => {
18
- // detect if has already installed
19
- // or will cause error
20
- if (this.ctx.pluginLoader.hasPlugin(item.pkgName)) {
21
- installedPlugins.push(item.pkgName);
22
- this.ctx.log.success(`PicGo has already installed ${item.pkgName}`);
23
- return false;
24
- }
25
- // if something wrong, filter it out
26
- if (!item.success) {
27
- return false;
28
- }
29
- return true;
30
- });
31
- const fullNameList = processPlugins.map(item => item.fullName);
32
- const pkgNameList = processPlugins.map(item => item.pkgName);
33
- if (fullNameList.length > 0) {
34
- // install plugins must use fullNameList:
35
- // 1. install remote pacage
36
- // 2. install local pacage
37
- const result = await this.execCommand('install', fullNameList, this.ctx.baseDir, options, env);
38
- if (!result.code) {
39
- pkgNameList.forEach((pluginName) => {
40
- this.ctx.pluginLoader.registerPlugin(pluginName);
41
- });
42
- this.ctx.log.success('插件安装成功');
43
- this.ctx.emit('installSuccess', {
44
- title: '插件安装成功',
45
- body: [...pkgNameList, ...installedPlugins]
46
- });
47
- const res = {
48
- success: true,
49
- body: [...pkgNameList, ...installedPlugins]
50
- };
51
- return res;
52
- }
53
- else {
54
- const err = `插件安装失败,失败码为${result.code},错误日志为${result.data}`;
55
- this.ctx.log.error(err);
56
- this.ctx.emit('installFailed', {
57
- title: '插件安装失败',
58
- body: err
59
- });
60
- const res = {
61
- success: false,
62
- body: err
63
- };
64
- return res;
65
- }
66
- }
67
- else if (installedPlugins.length === 0) {
68
- const err = '插件安装失败,请输入合法插件名或合法安装路径';
69
- this.ctx.log.error(err);
70
- this.ctx.emit('installFailed', {
71
- title: '插件安装失败',
72
- body: err
73
- });
74
- const res = {
75
- success: false,
76
- body: err
77
- };
78
- return res;
79
- }
80
- else {
81
- this.ctx.log.success('插件安装成功');
82
- this.ctx.emit('installSuccess', {
83
- title: '插件安装成功',
84
- body: [...pkgNameList, ...installedPlugins]
85
- });
86
- const res = {
87
- success: true,
88
- body: [...pkgNameList, ...installedPlugins]
89
- };
90
- return res;
91
- }
92
- }
93
- async uninstall(plugins) {
94
- const processPlugins = plugins.map((item) => handlePluginNameProcess(this.ctx, item)).filter(item => item.success);
95
- const pkgNameList = processPlugins.map(item => item.pkgName);
96
- if (pkgNameList.length > 0) {
97
- // uninstall plugins must use pkgNameList:
98
- // npm uninstall will use the package.json's name
99
- const result = await this.execCommand('uninstall', pkgNameList, this.ctx.baseDir);
100
- if (!result.code) {
101
- pkgNameList.forEach((pluginName) => {
102
- this.ctx.pluginLoader.unregisterPlugin(pluginName);
103
- });
104
- this.ctx.log.success('插件卸载成功');
105
- this.ctx.emit('uninstallSuccess', {
106
- title: '插件卸载成功',
107
- body: pkgNameList
108
- });
109
- const res = {
110
- success: true,
111
- body: pkgNameList
112
- };
113
- return res;
114
- }
115
- else {
116
- const err = `插件卸载失败,失败码为${result.code},错误日志为${result.data}`;
117
- this.ctx.log.error(err);
118
- this.ctx.emit('uninstallFailed', {
119
- title: '插件卸载失败',
120
- body: err
121
- });
122
- const res = {
123
- success: false,
124
- body: err
125
- };
126
- return res;
127
- }
128
- }
129
- else {
130
- const err = '插件卸载失败,请输入合法插件名';
131
- this.ctx.log.error(err);
132
- this.ctx.emit('uninstallFailed', {
133
- title: '插件卸载失败',
134
- body: err
135
- });
136
- const res = {
137
- success: false,
138
- body: err
139
- };
140
- return res;
141
- }
142
- }
143
- async update(plugins, options = {}, env) {
144
- const processPlugins = plugins.map((item) => handlePluginNameProcess(this.ctx, item)).filter(item => item.success);
145
- const pkgNameList = processPlugins.map(item => item.pkgName);
146
- if (pkgNameList.length > 0) {
147
- // update plugins must use pkgNameList:
148
- // npm update will use the package.json's name
149
- const result = await this.execCommand('update', pkgNameList, this.ctx.baseDir, options, env);
150
- if (!result.code) {
151
- this.ctx.log.success('插件更新成功');
152
- this.ctx.emit('updateSuccess', {
153
- title: '插件更新成功',
154
- body: pkgNameList
155
- });
156
- const res = {
157
- success: true,
158
- body: pkgNameList
159
- };
160
- return res;
161
- }
162
- else {
163
- const err = `插件更新失败,失败码为${result.code},错误日志为 \n ${result.data}`;
164
- this.ctx.log.error(err);
165
- this.ctx.emit('updateFailed', {
166
- title: '插件更新失败',
167
- body: err
168
- });
169
- const res = {
170
- success: false,
171
- body: err
172
- };
173
- return res;
174
- }
175
- }
176
- else {
177
- const err = '插件更新失败,请输入合法插件名';
178
- this.ctx.log.error(err);
179
- this.ctx.emit('updateFailed', {
180
- title: '插件更新失败',
181
- body: err
182
- });
183
- const res = {
184
- success: false,
185
- body: err
186
- };
187
- return res;
188
- }
189
- }
190
- async execCommand(cmd, modules, where, options = {}, env = {}) {
191
- // options first
192
- const registry = options.registry || this.ctx.getConfig('settings.registry');
193
- const proxy = options.proxy || this.ctx.getConfig('settings.proxy');
194
- return await new Promise((resolve) => {
195
- let args = [cmd].concat(modules).concat('--color=always').concat('--save');
196
- if (registry) {
197
- args = args.concat(`--registry=${registry}`);
198
- }
199
- if (proxy) {
200
- args = args.concat(`--proxy=${proxy}`);
201
- }
202
- try {
203
- const npm = cross_spawn_1.default('npm', args, { cwd: where, env: Object.assign({}, process.env, env) });
204
- let output = '';
205
- npm.stdout.on('data', (data) => {
206
- output += data;
207
- }).pipe(process.stdout);
208
- npm.stderr.on('data', (data) => {
209
- output += data;
210
- }).pipe(process.stderr);
211
- npm.on('close', (code) => {
212
- if (!code) {
213
- resolve({ code: 0, data: output });
214
- }
215
- else {
216
- resolve({ code: code, data: output });
217
- }
218
- });
219
- // for users who haven't installed node.js
220
- npm.on('error', (err) => {
221
- this.ctx.log.error(err);
222
- this.ctx.log.error('NPM is not installed');
223
- this.ctx.emit(enum_1.IBuildInEvent.FAILED, 'NPM is not installed');
224
- });
225
- }
226
- catch (e) {
227
- this.ctx.log.error(e);
228
- this.ctx.emit(enum_1.IBuildInEvent.FAILED, e);
229
- }
230
- });
231
- }
232
- }
233
- /**
234
- * transform the input plugin name or path string to valid result
235
- * @param ctx
236
- * @param nameOrPath
237
- */
238
- const handlePluginNameProcess = (ctx, nameOrPath) => {
239
- const res = {
240
- success: false,
241
- fullName: '',
242
- pkgName: ''
243
- };
244
- const result = common_1.getProcessPluginName(nameOrPath, ctx.log);
245
- if (!result) {
246
- return res;
247
- }
248
- // first get result then do this process
249
- // or some error will log twice
250
- const pkgName = common_1.getNormalPluginName(result, ctx.log);
251
- if (!pkgName) {
252
- return res;
253
- }
254
- return {
255
- success: true,
256
- fullName: result,
257
- pkgName
258
- };
259
- };
260
- exports.default = PluginHandler;
@@ -1,145 +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 fs_extra_1 = __importDefault(require("fs-extra"));
7
- const path_1 = __importDefault(require("path"));
8
- const resolve_1 = __importDefault(require("resolve"));
9
- const enum_1 = require("../utils/enum");
10
- const LifecyclePlugins_1 = require("./LifecyclePlugins");
11
- /**
12
- * Local plugin loader, file system is required
13
- */
14
- class PluginLoader {
15
- constructor(ctx) {
16
- this.list = [];
17
- this.fullList = new Set();
18
- this.pluginMap = new Map();
19
- this.ctx = ctx;
20
- this.init();
21
- }
22
- init() {
23
- const packagePath = path_1.default.join(this.ctx.baseDir, 'package.json');
24
- if (!fs_extra_1.default.existsSync(packagePath)) {
25
- const pkg = {
26
- name: 'picgo-plugins',
27
- description: 'picgo-plugins',
28
- repository: 'https://github.com/Molunerfinn/PicGo-Core',
29
- license: 'MIT'
30
- };
31
- fs_extra_1.default.writeFileSync(packagePath, JSON.stringify(pkg), 'utf8');
32
- }
33
- }
34
- // get plugin entry
35
- resolvePlugin(ctx, name) {
36
- try {
37
- return resolve_1.default.sync(name, { basedir: ctx.baseDir });
38
- }
39
- catch (err) {
40
- return path_1.default.join(ctx.baseDir, 'node_modules', name);
41
- }
42
- }
43
- // load all third party plugin
44
- load() {
45
- const packagePath = path_1.default.join(this.ctx.baseDir, 'package.json');
46
- const pluginDir = path_1.default.join(this.ctx.baseDir, 'node_modules/');
47
- // Thanks to hexo -> https://github.com/hexojs/hexo/blob/master/lib/hexo/load_plugins.js
48
- if (!fs_extra_1.default.existsSync(pluginDir)) {
49
- return false;
50
- }
51
- const json = fs_extra_1.default.readJSONSync(packagePath);
52
- const deps = Object.keys(json.dependencies || {});
53
- const devDeps = Object.keys(json.devDependencies || {});
54
- const modules = deps.concat(devDeps).filter((name) => {
55
- if (!/^picgo-plugin-|^@[^/]+\/picgo-plugin-/.test(name))
56
- return false;
57
- const path = this.resolvePlugin(this.ctx, name);
58
- return fs_extra_1.default.existsSync(path);
59
- });
60
- for (const module of modules) {
61
- this.registerPlugin(module);
62
- }
63
- return true;
64
- }
65
- registerPlugin(name, plugin) {
66
- if (!name || typeof name !== 'string') {
67
- this.ctx.log.warn('Please provide valid plugin');
68
- return;
69
- }
70
- this.fullList.add(name);
71
- try {
72
- // register local plugin
73
- if (!plugin) {
74
- if (this.ctx.getConfig(`picgoPlugins.${name}`) === true || (this.ctx.getConfig(`picgoPlugins.${name}`) === undefined)) {
75
- this.list.push(name);
76
- LifecyclePlugins_1.setCurrentPluginName(name);
77
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
78
- this.getPlugin(name).register(this.ctx);
79
- const plugin = `picgoPlugins[${name}]`;
80
- this.ctx.saveConfig({
81
- [plugin]: true
82
- });
83
- }
84
- }
85
- else {
86
- // register provided plugin
87
- // && won't write config to files
88
- this.list.push(name);
89
- LifecyclePlugins_1.setCurrentPluginName(name);
90
- const pluginInterface = plugin(this.ctx);
91
- this.pluginMap.set(name, pluginInterface);
92
- plugin(this.ctx).register(this.ctx);
93
- }
94
- }
95
- catch (e) {
96
- this.pluginMap.delete(name);
97
- this.list = this.list.filter((item) => item !== name);
98
- this.fullList.delete(name);
99
- this.ctx.log.error(e);
100
- this.ctx.emit(enum_1.IBuildInEvent.NOTIFICATION, {
101
- title: `Plugin ${name} Load Error`,
102
- body: e
103
- });
104
- }
105
- }
106
- unregisterPlugin(name) {
107
- this.list = this.list.filter((item) => item !== name);
108
- this.fullList.delete(name);
109
- this.pluginMap.delete(name);
110
- LifecyclePlugins_1.setCurrentPluginName(name);
111
- this.ctx.helper.uploader.unregister(name);
112
- this.ctx.helper.transformer.unregister(name);
113
- this.ctx.helper.beforeTransformPlugins.unregister(name);
114
- this.ctx.helper.beforeUploadPlugins.unregister(name);
115
- this.ctx.helper.afterUploadPlugins.unregister(name);
116
- this.ctx.removeConfig('picgoPlugins', name);
117
- }
118
- // get plugin by name
119
- getPlugin(name) {
120
- if (this.pluginMap.has(name)) {
121
- return this.pluginMap.get(name);
122
- }
123
- const pluginDir = path_1.default.join(this.ctx.baseDir, 'node_modules/');
124
- // eslint-disable-next-line @typescript-eslint/no-var-requires
125
- const plugin = require(pluginDir + name)(this.ctx);
126
- this.pluginMap.set(name, plugin);
127
- return plugin;
128
- }
129
- /**
130
- * Get the list of enabled plugins
131
- */
132
- getList() {
133
- return this.list;
134
- }
135
- hasPlugin(name) {
136
- return this.fullList.has(name);
137
- }
138
- /**
139
- * Get the full list of plugins, whether it is enabled or not
140
- */
141
- getFullList() {
142
- return [...this.fullList];
143
- }
144
- }
145
- exports.default = PluginLoader;
@@ -1,42 +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 request_promise_native_1 = __importDefault(require("request-promise-native"));
7
- const enum_1 = require("../utils/enum");
8
- const eventBus_1 = require("../utils/eventBus");
9
- class Request {
10
- constructor(ctx) {
11
- this.proxy = '';
12
- this.options = {};
13
- this.ctx = ctx;
14
- this.init();
15
- eventBus_1.eventBus.on(enum_1.IBusEvent.CONFIG_CHANGE, (data) => {
16
- var _a;
17
- switch (data.configName) {
18
- case 'picBed':
19
- if ((_a = data.value) === null || _a === void 0 ? void 0 : _a.proxy) {
20
- this.proxy = data.value.proxy;
21
- }
22
- break;
23
- case 'picBed.proxy':
24
- this.proxy = data.value;
25
- break;
26
- }
27
- });
28
- }
29
- init() {
30
- const proxy = this.ctx.getConfig('picBed.proxy');
31
- if (proxy) {
32
- this.proxy = proxy;
33
- }
34
- }
35
- // #64 dynamic get proxy value
36
- get request() {
37
- // remove jar because we don't need anymore
38
- this.options.proxy = this.proxy || undefined;
39
- return request_promise_native_1.default.defaults(this.options);
40
- }
41
- }
42
- exports.default = Request;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
4
- handle: (ctx) => {
5
- const cmd = ctx.cmd;
6
- cmd.program
7
- .option('-c, --config <path>', 'set config path');
8
- // will handle in `bin/picgo`
9
- }
10
- };
11
- exports.default = config;
@@ -1,21 +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 pluginHandler_1 = __importDefault(require("./pluginHandler"));
7
- const config_1 = __importDefault(require("./config"));
8
- const upload_1 = __importDefault(require("./upload"));
9
- const setting_1 = __importDefault(require("./setting"));
10
- const use_1 = __importDefault(require("./use"));
11
- const proxy_1 = __importDefault(require("./proxy"));
12
- const init_1 = __importDefault(require("./init"));
13
- exports.default = (ctx) => {
14
- ctx.cmd.register('pluginHandler', pluginHandler_1.default);
15
- ctx.cmd.register('config', config_1.default);
16
- ctx.cmd.register('setting', setting_1.default);
17
- ctx.cmd.register('upload', upload_1.default);
18
- ctx.cmd.register('use', use_1.default);
19
- ctx.cmd.register('proxy', proxy_1.default);
20
- ctx.cmd.register('init', init_1.default);
21
- };