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.
- package/.eslintignore +2 -0
- package/.github/workflows/alpha.yml +22 -0
- package/CHANGELOG.md +43 -0
- package/README.md +14 -1
- package/bin/picgo +1 -1
- package/dist/{src/core → core}/Lifecycle.d.ts +15 -15
- package/dist/{src/core → core}/PicGo.d.ts +44 -44
- package/dist/i18n/en.d.ts +2 -0
- package/dist/i18n/index.d.ts +16 -0
- package/dist/i18n/zh-CN.d.ts +65 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.esm.js +2 -0
- package/dist/{src/lib → lib}/Commander.d.ts +16 -16
- package/dist/{src/lib → lib}/LifecyclePlugins.d.ts +16 -16
- package/dist/{src/lib → lib}/Logger.d.ts +16 -16
- package/dist/{src/lib → lib}/PluginHandler.d.ts +10 -10
- package/dist/{src/lib → lib}/PluginLoader.d.ts +27 -27
- package/dist/{src/lib → lib}/Request.d.ts +11 -11
- package/dist/{src/plugins → plugins}/commander/config.d.ts +3 -3
- package/dist/plugins/commander/i18n.d.ts +3 -0
- package/dist/{src/plugins → plugins}/commander/index.d.ts +3 -3
- package/dist/{src/plugins → plugins}/commander/init.d.ts +3 -3
- package/dist/{src/plugins → plugins}/commander/pluginHandler.d.ts +3 -3
- package/dist/{src/plugins → plugins}/commander/proxy.d.ts +3 -3
- package/dist/{src/plugins → plugins}/commander/setting.d.ts +5 -5
- package/dist/{src/plugins → plugins}/commander/upload.d.ts +3 -3
- package/dist/{src/plugins → plugins}/commander/use.d.ts +3 -3
- package/dist/{src/plugins → plugins}/transformer/base64.d.ts +5 -5
- package/dist/{src/plugins → plugins}/transformer/index.d.ts +3 -3
- package/dist/{src/plugins → plugins}/transformer/path.d.ts +5 -5
- package/dist/plugins/uploader/aliyun.d.ts +2 -0
- package/dist/plugins/uploader/github.d.ts +2 -0
- package/dist/plugins/uploader/imgur.d.ts +2 -0
- package/dist/{src/plugins → plugins}/uploader/index.d.ts +3 -3
- package/dist/plugins/uploader/qiniu.d.ts +2 -0
- package/dist/plugins/uploader/smms.d.ts +2 -0
- package/dist/plugins/uploader/tcyun.d.ts +8 -0
- package/dist/plugins/uploader/upyun.d.ts +2 -0
- package/dist/types/index.d.ts +468 -0
- package/dist/{src/utils → utils}/common.d.ts +102 -101
- package/dist/{src/utils → utils}/createContext.d.ts +6 -6
- package/dist/{src/utils → utils}/db.d.ts +15 -15
- package/dist/{src/utils → utils}/enum.d.ts +27 -27
- package/dist/{src/utils → utils}/eventBus.d.ts +4 -4
- package/dist/{src/utils → utils}/getClipboardImage.d.ts +4 -3
- package/dist/{src/utils → utils}/initUtils.d.ts +26 -26
- package/dist/{src/utils → utils}/interfaces.d.ts +203 -203
- package/package.json +27 -22
- package/rollup.config.js +82 -0
- package/dist/package.json +0 -127
- package/dist/src/core/Lifecycle.js +0 -123
- package/dist/src/core/PicGo.js +0 -210
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -6
- package/dist/src/lib/Commander.js +0 -56
- package/dist/src/lib/LifecyclePlugins.js +0 -52
- package/dist/src/lib/Logger.js +0 -82
- package/dist/src/lib/PluginHandler.js +0 -260
- package/dist/src/lib/PluginLoader.js +0 -145
- package/dist/src/lib/Request.js +0 -42
- package/dist/src/plugins/commander/config.js +0 -11
- package/dist/src/plugins/commander/index.js +0 -21
- package/dist/src/plugins/commander/init.js +0 -122
- package/dist/src/plugins/commander/pluginHandler.js +0 -43
- package/dist/src/plugins/commander/proxy.js +0 -14
- package/dist/src/plugins/commander/setting.js +0 -102
- package/dist/src/plugins/commander/upload.js +0 -35
- package/dist/src/plugins/commander/use.js +0 -87
- package/dist/src/plugins/transformer/base64.js +0 -9
- package/dist/src/plugins/transformer/index.js +0 -16
- package/dist/src/plugins/transformer/path.js +0 -42
- package/dist/src/plugins/uploader/aliyun.d.ts +0 -7
- package/dist/src/plugins/uploader/aliyun.js +0 -129
- package/dist/src/plugins/uploader/github.d.ts +0 -7
- package/dist/src/plugins/uploader/github.js +0 -101
- package/dist/src/plugins/uploader/imgur.d.ts +0 -7
- package/dist/src/plugins/uploader/imgur.js +0 -81
- package/dist/src/plugins/uploader/index.js +0 -26
- package/dist/src/plugins/uploader/qiniu.d.ts +0 -7
- package/dist/src/plugins/uploader/qiniu.js +0 -132
- package/dist/src/plugins/uploader/smms.d.ts +0 -7
- package/dist/src/plugins/uploader/smms.js +0 -74
- package/dist/src/plugins/uploader/tcyun.d.ts +0 -13
- package/dist/src/plugins/uploader/tcyun.js +0 -218
- package/dist/src/plugins/uploader/upyun.d.ts +0 -7
- package/dist/src/plugins/uploader/upyun.js +0 -128
- package/dist/src/types/index.d.ts +0 -471
- package/dist/src/utils/clipboard/linux.sh +0 -18
- package/dist/src/utils/clipboard/mac.applescript +0 -0
- package/dist/src/utils/clipboard/windows.ps1 +0 -26
- package/dist/src/utils/clipboard/windows10.ps1 +0 -47
- package/dist/src/utils/clipboard/wsl.sh +0 -18
- package/dist/src/utils/common.js +0 -353
- package/dist/src/utils/createContext.js +0 -45
- package/dist/src/utils/db.js +0 -85
- package/dist/src/utils/enum.js +0 -33
- package/dist/src/utils/eventBus.js +0 -6
- package/dist/src/utils/getClipboardImage.js +0 -101
- package/dist/src/utils/initUtils.js +0 -120
- package/dist/src/utils/interfaces.js +0 -3
|
@@ -1,122 +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 path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const initUtils_1 = require("../../utils/initUtils");
|
|
10
|
-
const os_1 = require("os");
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
const download_git_repo_1 = __importDefault(require("download-git-repo"));
|
|
13
|
-
const rimraf_1 = __importDefault(require("rimraf"));
|
|
14
|
-
const run = (ctx, options) => {
|
|
15
|
-
// const name = options.inPlace ? path.relative('../', process.cwd()) : options.project
|
|
16
|
-
if (options.offline) { // offline mode
|
|
17
|
-
if (fs_extra_1.default.existsSync(options.template)) {
|
|
18
|
-
initUtils_1.generate(ctx, options).catch((e) => { ctx.log.error(e); });
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
ctx.log.error(`Local template ${options.template} not found`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else { // online mode
|
|
25
|
-
options.template = !options.hasSlash
|
|
26
|
-
? 'PicGo/picgo-template-' + options.template // official template
|
|
27
|
-
: options.template;
|
|
28
|
-
downloadAndGenerate(ctx, options);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* download template & generate
|
|
33
|
-
* @param { PicGo } ctx
|
|
34
|
-
* @param { IOptions } options
|
|
35
|
-
*/
|
|
36
|
-
const downloadAndGenerate = (ctx, options) => {
|
|
37
|
-
if (fs_extra_1.default.existsSync(options.tmp)) {
|
|
38
|
-
rimraf_1.default.sync(options.tmp);
|
|
39
|
-
}
|
|
40
|
-
ctx.log.info('Template files are downloading...');
|
|
41
|
-
download_git_repo_1.default(options.template, options.tmp, { clone: options.clone }, (err) => {
|
|
42
|
-
if (err) {
|
|
43
|
-
return ctx.log.error(err);
|
|
44
|
-
}
|
|
45
|
-
ctx.log.success('Template files are downloaded!');
|
|
46
|
-
initUtils_1.generate(ctx, options).catch((e) => { ctx.log.error(e); });
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const init = {
|
|
50
|
-
handle: async (ctx) => {
|
|
51
|
-
const cmd = ctx.cmd;
|
|
52
|
-
cmd.program
|
|
53
|
-
.command('init')
|
|
54
|
-
.arguments('<template> [project]')
|
|
55
|
-
.option('--clone', 'use git clone')
|
|
56
|
-
.option('--offline', 'use cached template')
|
|
57
|
-
.description('create picgo plugin\'s development templates')
|
|
58
|
-
.action((template, project, program) => {
|
|
59
|
-
(async () => {
|
|
60
|
-
// Thanks to vue-cli init: https://github.com/vuejs/vue-cli/blob/master/bin/vue-init
|
|
61
|
-
try {
|
|
62
|
-
const hasSlash = template.includes('/');
|
|
63
|
-
const inPlace = !project || project === '.';
|
|
64
|
-
const dest = path_1.default.resolve(project || '.');
|
|
65
|
-
const clone = program.clone || false;
|
|
66
|
-
const offline = program.offline || false;
|
|
67
|
-
const tmp = path_1.default.join(os_1.homedir(), '.picgo/templates', template.replace(/[/:]/g, '-')); // for caching template
|
|
68
|
-
if (program.offline) {
|
|
69
|
-
template = tmp;
|
|
70
|
-
}
|
|
71
|
-
const options = {
|
|
72
|
-
template,
|
|
73
|
-
project,
|
|
74
|
-
hasSlash,
|
|
75
|
-
inPlace,
|
|
76
|
-
dest,
|
|
77
|
-
clone,
|
|
78
|
-
tmp,
|
|
79
|
-
offline
|
|
80
|
-
};
|
|
81
|
-
// check if project is empty or exist
|
|
82
|
-
if (inPlace || fs_extra_1.default.existsSync(dest)) {
|
|
83
|
-
await ctx.cmd.inquirer.prompt([
|
|
84
|
-
{
|
|
85
|
-
type: 'confirm',
|
|
86
|
-
message: inPlace
|
|
87
|
-
? 'Generate project in current directory?'
|
|
88
|
-
: 'Target directory exists. Continue?',
|
|
89
|
-
name: 'ok'
|
|
90
|
-
}
|
|
91
|
-
]).then((answer) => {
|
|
92
|
-
if (answer.ok) {
|
|
93
|
-
run(ctx, options);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else { // project is given
|
|
98
|
-
run(ctx, options);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
ctx.log.error(e);
|
|
103
|
-
if (process.argv.includes('--debug')) {
|
|
104
|
-
throw e;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
})().catch((e) => { ctx.log.error(e); });
|
|
108
|
-
})
|
|
109
|
-
.on('--help', () => {
|
|
110
|
-
console.log();
|
|
111
|
-
console.log('Examples:');
|
|
112
|
-
console.log();
|
|
113
|
-
console.log(chalk_1.default.gray(' # create a new project with an official template'));
|
|
114
|
-
console.log(' $ picgo init plugin my-project');
|
|
115
|
-
console.log();
|
|
116
|
-
console.log(chalk_1.default.gray(' # create a new project straight from a github template'));
|
|
117
|
-
console.log(' $ picgo init username/repo my-project');
|
|
118
|
-
console.log();
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
exports.default = init;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const pluginHandler = {
|
|
4
|
-
handle: (ctx) => {
|
|
5
|
-
// const pluginHandler = new PluginHandler(ctx)
|
|
6
|
-
const cmd = ctx.cmd;
|
|
7
|
-
cmd.program
|
|
8
|
-
.command('install <plugins...>')
|
|
9
|
-
.description('install picgo plugin')
|
|
10
|
-
.alias('add')
|
|
11
|
-
.option('-p, --proxy <proxy>', 'Add proxy for installing')
|
|
12
|
-
.option('-r, --registry <registry>', 'Choose a registry for installing')
|
|
13
|
-
.action((plugins, program) => {
|
|
14
|
-
const { proxy, registry } = program;
|
|
15
|
-
const options = {
|
|
16
|
-
proxy,
|
|
17
|
-
registry
|
|
18
|
-
};
|
|
19
|
-
ctx.pluginHandler.install(plugins, options).catch((e) => { ctx.log.error(e); });
|
|
20
|
-
});
|
|
21
|
-
cmd.program
|
|
22
|
-
.command('uninstall <plugins...>')
|
|
23
|
-
.alias('rm')
|
|
24
|
-
.description('uninstall picgo plugin')
|
|
25
|
-
.action((plugins) => {
|
|
26
|
-
ctx.pluginHandler.uninstall(plugins).catch((e) => { ctx.log.error(e); });
|
|
27
|
-
});
|
|
28
|
-
cmd.program
|
|
29
|
-
.command('update <plugins...>')
|
|
30
|
-
.description('update picgo plugin')
|
|
31
|
-
.option('-p, --proxy <proxy>', 'Add proxy for installing')
|
|
32
|
-
.option('-r, --registry <registry>', 'Choose a registry for installing')
|
|
33
|
-
.action((plugins, program) => {
|
|
34
|
-
const { proxy, registry } = program;
|
|
35
|
-
const options = {
|
|
36
|
-
proxy,
|
|
37
|
-
registry
|
|
38
|
-
};
|
|
39
|
-
ctx.pluginHandler.update(plugins, options).catch((e) => { ctx.log.error(e); });
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.default = pluginHandler;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const proxy = {
|
|
4
|
-
handle: (ctx) => {
|
|
5
|
-
const cmd = ctx.cmd;
|
|
6
|
-
cmd.program
|
|
7
|
-
.option('-p, --proxy <url>', 'set proxy for uploading', (proxy) => {
|
|
8
|
-
ctx.setConfig({
|
|
9
|
-
'picBed.proxy': proxy
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
exports.default = proxy;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// handle modules config -> save to picgo config file
|
|
4
|
-
const handleConfig = async (ctx, prompts, module, name) => {
|
|
5
|
-
const answer = await ctx.cmd.inquirer.prompt(prompts);
|
|
6
|
-
const configName = module === 'uploader'
|
|
7
|
-
? `picBed.${name}` : module === 'transformer'
|
|
8
|
-
? `transformer.${name}` : name;
|
|
9
|
-
ctx.saveConfig({
|
|
10
|
-
[configName]: answer
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
const setting = {
|
|
14
|
-
handle: (ctx) => {
|
|
15
|
-
const cmd = ctx.cmd;
|
|
16
|
-
cmd.program
|
|
17
|
-
.command('set')
|
|
18
|
-
.alias('config')
|
|
19
|
-
.arguments('<module> [name]')
|
|
20
|
-
.description('configure config of picgo modules')
|
|
21
|
-
.action((module, name) => {
|
|
22
|
-
(async () => {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
try {
|
|
25
|
-
// // load third-party plugins
|
|
26
|
-
// await ctx.pluginLoader.load()
|
|
27
|
-
// if a module is specific, then just set this option in config
|
|
28
|
-
switch (module) {
|
|
29
|
-
case 'uploader':
|
|
30
|
-
case 'transformer':
|
|
31
|
-
if (name) {
|
|
32
|
-
const item = ctx.helper[module].get(name);
|
|
33
|
-
if (!item) {
|
|
34
|
-
return ctx.log.error(`No ${module} named ${name}`);
|
|
35
|
-
}
|
|
36
|
-
if (item.config) {
|
|
37
|
-
await handleConfig(ctx, item.config(ctx), module, name);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const prompts = [
|
|
42
|
-
{
|
|
43
|
-
type: 'list',
|
|
44
|
-
name: `${module}`,
|
|
45
|
-
choices: ctx.helper[module].getIdList(),
|
|
46
|
-
message: `Choose a(n) ${module}`,
|
|
47
|
-
default: ctx.getConfig('picBed.uploader') || ctx.getConfig('picBed.current')
|
|
48
|
-
}
|
|
49
|
-
];
|
|
50
|
-
const answer = await ctx.cmd.inquirer.prompt(prompts);
|
|
51
|
-
const item = ctx.helper[module].get(answer[module]);
|
|
52
|
-
if (item === null || item === void 0 ? void 0 : item.config) {
|
|
53
|
-
await handleConfig(ctx, item.config(ctx), module, answer[module]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
break;
|
|
57
|
-
case 'plugin':
|
|
58
|
-
if (name) {
|
|
59
|
-
if (!name.includes('picgo-plugin-')) {
|
|
60
|
-
name = `picgo-plugin-${name}`;
|
|
61
|
-
}
|
|
62
|
-
if (Object.keys(ctx.getConfig('picgoPlugins')).includes(name)) {
|
|
63
|
-
if ((_a = ctx.pluginLoader.getPlugin(name)) === null || _a === void 0 ? void 0 : _a.config) {
|
|
64
|
-
await handleConfig(ctx, ctx.pluginLoader.getPlugin(name).config(ctx), 'plugin', name);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
return ctx.log.error(`No plugin named ${name}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const prompts = [
|
|
73
|
-
{
|
|
74
|
-
type: 'list',
|
|
75
|
-
name: 'plugin',
|
|
76
|
-
choices: ctx.pluginLoader.getFullList(),
|
|
77
|
-
message: 'Choose a plugin'
|
|
78
|
-
}
|
|
79
|
-
];
|
|
80
|
-
const answer = await ctx.cmd.inquirer.prompt(prompts);
|
|
81
|
-
if ((_b = ctx.pluginLoader.getPlugin(answer.plugin)) === null || _b === void 0 ? void 0 : _b.config) {
|
|
82
|
-
await handleConfig(ctx, ctx.pluginLoader.getPlugin(answer.plugin).config(ctx), 'plugin', answer.plugin);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
ctx.log.warn(`No module named ${module}`);
|
|
88
|
-
return ctx.log.warn('Available modules are uploader|transformer|plugin');
|
|
89
|
-
}
|
|
90
|
-
ctx.log.success('Configure config successfully!');
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
ctx.log.error(e);
|
|
94
|
-
if (process.argv.includes('--debug')) {
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
})().catch((e) => { ctx.log.error(e); });
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
exports.default = setting;
|
|
@@ -1,35 +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 fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const common_1 = require("../../utils/common");
|
|
9
|
-
const upload = {
|
|
10
|
-
handle: (ctx) => {
|
|
11
|
-
const cmd = ctx.cmd;
|
|
12
|
-
cmd.program
|
|
13
|
-
.command('upload')
|
|
14
|
-
.description('upload, go go go')
|
|
15
|
-
.arguments('[input...]')
|
|
16
|
-
.alias('u')
|
|
17
|
-
.action((input) => {
|
|
18
|
-
(async () => {
|
|
19
|
-
const inputList = input
|
|
20
|
-
.map((item) => {
|
|
21
|
-
return common_1.isUrl(item) ? item : path_1.default.resolve(item);
|
|
22
|
-
})
|
|
23
|
-
.filter((item) => {
|
|
24
|
-
const exist = fs_extra_1.default.existsSync(item) || common_1.isUrl(item);
|
|
25
|
-
if (!exist) {
|
|
26
|
-
ctx.log.warn(`${item} does not exist.`);
|
|
27
|
-
}
|
|
28
|
-
return exist;
|
|
29
|
-
});
|
|
30
|
-
await ctx.upload(inputList);
|
|
31
|
-
})().catch((e) => { ctx.log.error(e); });
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
exports.default = upload;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const use = {
|
|
4
|
-
handle: async (ctx) => {
|
|
5
|
-
const cmd = ctx.cmd;
|
|
6
|
-
cmd.program
|
|
7
|
-
.command('use')
|
|
8
|
-
.arguments('[module]')
|
|
9
|
-
.description('use modules of picgo')
|
|
10
|
-
.action((module) => {
|
|
11
|
-
(async () => {
|
|
12
|
-
try {
|
|
13
|
-
// // load third-party plugins
|
|
14
|
-
// await ctx.pluginLoader.load()
|
|
15
|
-
let prompts = [];
|
|
16
|
-
const config = {
|
|
17
|
-
uploader: {
|
|
18
|
-
type: 'list',
|
|
19
|
-
name: 'uploader',
|
|
20
|
-
message: 'Use an uploader',
|
|
21
|
-
choices: ctx.helper.uploader.getIdList(),
|
|
22
|
-
default: ctx.getConfig('picBed.uploader') || ctx.getConfig('picBed.current') || 'smms'
|
|
23
|
-
},
|
|
24
|
-
transformer: {
|
|
25
|
-
type: 'list',
|
|
26
|
-
name: 'transformer',
|
|
27
|
-
message: 'Use a transformer',
|
|
28
|
-
choices: ctx.helper.transformer.getIdList(),
|
|
29
|
-
default: ctx.getConfig('picBed.transformer') || 'path'
|
|
30
|
-
},
|
|
31
|
-
plugins: {
|
|
32
|
-
type: 'checkbox',
|
|
33
|
-
name: 'plugins',
|
|
34
|
-
message: 'Use plugins',
|
|
35
|
-
choices: ctx.pluginLoader.getFullList(),
|
|
36
|
-
default: Object.keys(ctx.getConfig('picgoPlugins')).filter((item) => ctx.getConfig(`picgoPlugins.${item}`))
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
// if an option is specific, then just set this option in config
|
|
40
|
-
if (module) {
|
|
41
|
-
if (config[module]) {
|
|
42
|
-
prompts.push(config[module]);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
ctx.log.warn(`No module named ${module}`);
|
|
46
|
-
return ctx.log.warn('Available modules are uploader|transformer|plugins');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
prompts = Object.keys(config).map((item) => config[item]);
|
|
51
|
-
}
|
|
52
|
-
const answer = await cmd.inquirer.prompt(prompts);
|
|
53
|
-
// handle for plugins option from Array to object
|
|
54
|
-
if (answer.plugins) {
|
|
55
|
-
const plugins = ctx.getConfig('picgoPlugins');
|
|
56
|
-
Object.keys(plugins).map((item) => {
|
|
57
|
-
if (answer.plugins.includes(item)) {
|
|
58
|
-
plugins[item] = true;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
plugins[item] = false;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
// save config for plugins
|
|
65
|
-
ctx.saveConfig({
|
|
66
|
-
picgoPlugins: plugins
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
// save config for uploader & transformer
|
|
70
|
-
ctx.saveConfig({
|
|
71
|
-
'picBed.current': answer.uploader || ctx.getConfig('picBed.current'),
|
|
72
|
-
'picBed.uploader': answer.uploader || ctx.getConfig('picBed.current'),
|
|
73
|
-
'picBed.transformer': answer.transformer || 'path'
|
|
74
|
-
});
|
|
75
|
-
ctx.log.success('Configure config successfully!');
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
ctx.log.error(e);
|
|
79
|
-
if (process.argv.includes('--debug')) {
|
|
80
|
-
throw e;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
})().catch((e) => { ctx.log.error(e); });
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
exports.default = use;
|
|
@@ -1,16 +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 base64_1 = __importDefault(require("./base64"));
|
|
8
|
-
const buildInTransformers = () => {
|
|
9
|
-
return {
|
|
10
|
-
register(ctx) {
|
|
11
|
-
ctx.helper.transformer.register('path', path_1.default);
|
|
12
|
-
ctx.helper.transformer.register('base64', base64_1.default);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
exports.default = buildInTransformers;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("../../utils/common");
|
|
4
|
-
const handle = async (ctx) => {
|
|
5
|
-
const results = ctx.output;
|
|
6
|
-
await Promise.all(ctx.input.map(async (item, index) => {
|
|
7
|
-
let info;
|
|
8
|
-
if (common_1.isUrl(item)) {
|
|
9
|
-
info = await common_1.getURLFile(item);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
info = await common_1.getFSFile(item);
|
|
13
|
-
}
|
|
14
|
-
if (info.success && info.buffer) {
|
|
15
|
-
const imgSize = getImgSize(ctx, info.buffer, item);
|
|
16
|
-
results[index] = {
|
|
17
|
-
buffer: info.buffer,
|
|
18
|
-
fileName: info.fileName,
|
|
19
|
-
width: imgSize.width,
|
|
20
|
-
height: imgSize.height,
|
|
21
|
-
extname: info.extname
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
throw new Error(info.reason);
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
28
|
-
// remove empty item
|
|
29
|
-
ctx.output = results.filter(item => item);
|
|
30
|
-
return ctx;
|
|
31
|
-
};
|
|
32
|
-
const getImgSize = (ctx, file, path) => {
|
|
33
|
-
const imageSize = common_1.getImageSize(file);
|
|
34
|
-
if (!imageSize.real) {
|
|
35
|
-
ctx.log.warn(`can't get ${path}'s image size`);
|
|
36
|
-
ctx.log.warn('fallback to 200 * 200');
|
|
37
|
-
}
|
|
38
|
-
return imageSize;
|
|
39
|
-
};
|
|
40
|
-
exports.default = {
|
|
41
|
-
handle
|
|
42
|
-
};
|
|
@@ -1,129 +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 crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
const mime_types_1 = __importDefault(require("mime-types"));
|
|
8
|
-
const enum_1 = require("../../utils/enum");
|
|
9
|
-
// generate OSS signature
|
|
10
|
-
const generateSignature = (options, fileName) => {
|
|
11
|
-
const date = new Date().toUTCString();
|
|
12
|
-
const mimeType = mime_types_1.default.lookup(fileName);
|
|
13
|
-
if (!mimeType)
|
|
14
|
-
throw Error(`No mime type found for file ${fileName}`);
|
|
15
|
-
const signString = `PUT\n\n${mimeType}\n${date}\n/${options.bucket}/${options.path}${fileName}`;
|
|
16
|
-
const signature = crypto_1.default.createHmac('sha1', options.accessKeySecret).update(signString).digest('base64');
|
|
17
|
-
return `OSS ${options.accessKeyId}:${signature}`;
|
|
18
|
-
};
|
|
19
|
-
const postOptions = (options, fileName, signature, image) => {
|
|
20
|
-
return {
|
|
21
|
-
method: 'PUT',
|
|
22
|
-
url: `https://${options.bucket}.${options.area}.aliyuncs.com/${encodeURI(options.path)}${encodeURI(fileName)}`,
|
|
23
|
-
headers: {
|
|
24
|
-
Host: `${options.bucket}.${options.area}.aliyuncs.com`,
|
|
25
|
-
Authorization: signature,
|
|
26
|
-
Date: new Date().toUTCString(),
|
|
27
|
-
'content-type': mime_types_1.default.lookup(fileName)
|
|
28
|
-
},
|
|
29
|
-
body: image,
|
|
30
|
-
resolveWithFullResponse: true
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const handle = async (ctx) => {
|
|
34
|
-
const aliYunOptions = ctx.getConfig('picBed.aliyun');
|
|
35
|
-
if (!aliYunOptions) {
|
|
36
|
-
throw new Error('Can\'t find aliYun OSS config');
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const imgList = ctx.output;
|
|
40
|
-
const customUrl = aliYunOptions.customUrl;
|
|
41
|
-
const path = aliYunOptions.path;
|
|
42
|
-
for (const img of imgList) {
|
|
43
|
-
if (img.fileName && img.buffer) {
|
|
44
|
-
const signature = generateSignature(aliYunOptions, img.fileName);
|
|
45
|
-
let image = img.buffer;
|
|
46
|
-
if (!image && img.base64Image) {
|
|
47
|
-
image = Buffer.from(img.base64Image, 'base64');
|
|
48
|
-
}
|
|
49
|
-
const options = postOptions(aliYunOptions, img.fileName, signature, image);
|
|
50
|
-
const body = await ctx.Request.request(options);
|
|
51
|
-
if (body.statusCode === 200) {
|
|
52
|
-
delete img.base64Image;
|
|
53
|
-
delete img.buffer;
|
|
54
|
-
const optionUrl = aliYunOptions.options || '';
|
|
55
|
-
if (customUrl) {
|
|
56
|
-
img.imgUrl = `${customUrl}/${path}${img.fileName}${optionUrl}`;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
img.imgUrl = `https://${aliYunOptions.bucket}.${aliYunOptions.area}.aliyuncs.com/${path}${img.fileName}${optionUrl}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw new Error('Upload failed');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return ctx;
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
ctx.emit(enum_1.IBuildInEvent.NOTIFICATION, {
|
|
71
|
-
title: '上传失败',
|
|
72
|
-
body: '请检查你的配置项是否正确'
|
|
73
|
-
});
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const config = (ctx) => {
|
|
78
|
-
const userConfig = ctx.getConfig('picBed.aliyun') || {};
|
|
79
|
-
const config = [
|
|
80
|
-
{
|
|
81
|
-
name: 'accessKeyId',
|
|
82
|
-
type: 'input',
|
|
83
|
-
default: userConfig.accessKeyId || '',
|
|
84
|
-
required: true
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'accessKeySecret',
|
|
88
|
-
type: 'input',
|
|
89
|
-
default: userConfig.accessKeySecret || '',
|
|
90
|
-
required: true
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: 'bucket',
|
|
94
|
-
type: 'input',
|
|
95
|
-
default: userConfig.bucket || '',
|
|
96
|
-
required: true
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: 'area',
|
|
100
|
-
type: 'input',
|
|
101
|
-
default: userConfig.area || '',
|
|
102
|
-
required: true
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: 'path',
|
|
106
|
-
type: 'input',
|
|
107
|
-
default: userConfig.path || '',
|
|
108
|
-
required: false
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: 'customUrl',
|
|
112
|
-
type: 'input',
|
|
113
|
-
default: userConfig.customUrl || '',
|
|
114
|
-
required: false
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: 'options',
|
|
118
|
-
type: 'input',
|
|
119
|
-
default: userConfig.options || '',
|
|
120
|
-
required: false
|
|
121
|
-
}
|
|
122
|
-
];
|
|
123
|
-
return config;
|
|
124
|
-
};
|
|
125
|
-
exports.default = {
|
|
126
|
-
name: '阿里云OSS',
|
|
127
|
-
handle,
|
|
128
|
-
config
|
|
129
|
-
};
|