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,120 +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.writeFileTree = exports.render = exports.generate = exports.filters = void 0;
|
|
7
|
-
const minimatch_1 = __importDefault(require("minimatch"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
// @ts-expect-error
|
|
11
|
-
const globby_1 = __importDefault(require("globby"));
|
|
12
|
-
const ejs_1 = __importDefault(require("ejs"));
|
|
13
|
-
/**
|
|
14
|
-
* Generate template files to destination files.
|
|
15
|
-
* @param {PicGo} ctx
|
|
16
|
-
* @param {IOptions} options
|
|
17
|
-
*/
|
|
18
|
-
const generate = async (ctx, options) => {
|
|
19
|
-
try {
|
|
20
|
-
const opts = getOptions(options.tmp);
|
|
21
|
-
const source = path_1.default.join(options.tmp, 'template');
|
|
22
|
-
let answers = {};
|
|
23
|
-
if (opts.prompts && opts.prompts.length > 0) {
|
|
24
|
-
answers = await ctx.cmd.inquirer.prompt(opts.prompts);
|
|
25
|
-
}
|
|
26
|
-
let _files = await globby_1.default(['**/*'], { cwd: source, dot: true }); // get files' name array
|
|
27
|
-
_files = _files.filter((item) => {
|
|
28
|
-
let glob = '';
|
|
29
|
-
Object.keys(opts.filters).forEach((key) => {
|
|
30
|
-
if (minimatch_1.default(item, key, { dot: true })) {
|
|
31
|
-
glob = item;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
if (glob) { // find a filter expression
|
|
35
|
-
return filters(ctx, opts.filters[glob], answers);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (_files.length === 0) {
|
|
42
|
-
return ctx.log.warn('Template files not found!');
|
|
43
|
-
}
|
|
44
|
-
const files = render(_files, source, answers);
|
|
45
|
-
writeFileTree(options.dest, files);
|
|
46
|
-
if (typeof opts.complete === 'function') {
|
|
47
|
-
opts.complete({ answers, options, files: _files, ctx });
|
|
48
|
-
}
|
|
49
|
-
if (opts.completeMessage) {
|
|
50
|
-
ctx.log.success(opts.completeMessage);
|
|
51
|
-
}
|
|
52
|
-
ctx.log.success('Done!');
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
return ctx.log.error(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
exports.generate = generate;
|
|
59
|
-
/**
|
|
60
|
-
* Return the filters' result
|
|
61
|
-
* @param ctx PicGo
|
|
62
|
-
* @param exp condition expression
|
|
63
|
-
* @param data options data
|
|
64
|
-
*/
|
|
65
|
-
const filters = (ctx, exp, data) => {
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands, no-new-func, @typescript-eslint/no-implied-eval
|
|
67
|
-
const fn = new Function('data', 'with (data) { return ' + exp + '}');
|
|
68
|
-
try {
|
|
69
|
-
return fn(data);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
ctx.log.error(`Error when evaluating filter condition: ${JSON.stringify(exp)}`);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
exports.filters = filters;
|
|
77
|
-
/**
|
|
78
|
-
* Get template options
|
|
79
|
-
* @param {string} templatePath
|
|
80
|
-
*/
|
|
81
|
-
const getOptions = (templatePath) => {
|
|
82
|
-
const optionsPath = path_1.default.join(templatePath, 'index.js');
|
|
83
|
-
if (fs_extra_1.default.existsSync(optionsPath)) {
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
85
|
-
const options = require(optionsPath);
|
|
86
|
-
return options;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return {};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Render files to a virtual tree object
|
|
94
|
-
* @param {arry} files
|
|
95
|
-
*/
|
|
96
|
-
const render = (files, source, options) => {
|
|
97
|
-
const fileTree = {};
|
|
98
|
-
files.forEach((filePath) => {
|
|
99
|
-
const file = fs_extra_1.default.readFileSync(path_1.default.join(source, filePath), 'utf8');
|
|
100
|
-
const content = ejs_1.default.render(file, options);
|
|
101
|
-
if (Buffer.isBuffer(content) || /[^\s]/.test(content)) {
|
|
102
|
-
fileTree[filePath] = content;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return fileTree;
|
|
106
|
-
};
|
|
107
|
-
exports.render = render;
|
|
108
|
-
/**
|
|
109
|
-
* Write rendered files' content to real file
|
|
110
|
-
* @param {string} dir
|
|
111
|
-
* @param {object} files
|
|
112
|
-
*/
|
|
113
|
-
const writeFileTree = (dir, files) => {
|
|
114
|
-
Object.keys(files).forEach((name) => {
|
|
115
|
-
const filePath = path_1.default.join(dir, name);
|
|
116
|
-
fs_extra_1.default.ensureDirSync(path_1.default.dirname(filePath));
|
|
117
|
-
fs_extra_1.default.writeFileSync(filePath, files[name]);
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
exports.writeFileTree = writeFileTree;
|