@pagepocket/cli 0.8.0 → 0.8.1
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/dist/commands/archive.js
CHANGED
|
@@ -12,9 +12,9 @@ const lib_1 = require("@pagepocket/lib");
|
|
|
12
12
|
const single_file_unit_1 = require("@pagepocket/single-file-unit");
|
|
13
13
|
const write_down_unit_1 = require("@pagepocket/write-down-unit");
|
|
14
14
|
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
+
const load_configured_plugins_1 = require("../services/load-configured-plugins");
|
|
15
16
|
const network_observer_unit_1 = require("../units/network-observer-unit");
|
|
16
17
|
const with_spinner_1 = require("../utils/with-spinner");
|
|
17
|
-
const load_configured_plugins_1 = require("../services/load-configured-plugins");
|
|
18
18
|
const MAX_STATUS_URL_LENGTH = 80;
|
|
19
19
|
const formatStatusUrl = (url) => {
|
|
20
20
|
if (url.length <= MAX_STATUS_URL_LENGTH) {
|
|
@@ -8,6 +8,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const config_service_1 = require("../../services/config-service");
|
|
9
9
|
const plugin_installer_1 = require("../../services/plugin-installer");
|
|
10
10
|
const plugin_store_1 = require("../../services/plugin-store");
|
|
11
|
+
const validate_plugin_default_export_1 = require("../../utils/validate-plugin-default-export");
|
|
11
12
|
const parseDynamicOptions = (argv) => {
|
|
12
13
|
const tokens = argv.filter(Boolean);
|
|
13
14
|
const pairs = tokens
|
|
@@ -72,8 +73,13 @@ class PluginAddCommand extends core_1.Command {
|
|
|
72
73
|
: { name, options: parsed.value };
|
|
73
74
|
(0, plugin_installer_1.installPluginPackage)(store, { packageName: name });
|
|
74
75
|
const mod = await store.importPluginModule(name);
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
const validation = (0, validate_plugin_default_export_1.validatePluginDefaultExport)({
|
|
77
|
+
pluginName: name,
|
|
78
|
+
moduleExports: mod,
|
|
79
|
+
options: parsed.kind === "none" ? undefined : parsed.value
|
|
80
|
+
});
|
|
81
|
+
if (!validation.ok) {
|
|
82
|
+
throw validation.error;
|
|
77
83
|
}
|
|
78
84
|
const nextConfig = store.addPluginToConfig(config, entry);
|
|
79
85
|
configService.writeConfig(nextConfig);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loadConfiguredPlugins = void 0;
|
|
4
4
|
const config_service_1 = require("./config-service");
|
|
5
5
|
const plugin_store_1 = require("./plugin-store");
|
|
6
|
+
const validate_plugin_default_export_1 = require("../utils/validate-plugin-default-export");
|
|
6
7
|
const loadConfiguredPlugins = async () => {
|
|
7
8
|
const configService = new config_service_1.ConfigService();
|
|
8
9
|
const store = new plugin_store_1.PluginStore(configService);
|
|
@@ -11,12 +12,17 @@ const loadConfiguredPlugins = async () => {
|
|
|
11
12
|
const specs = config.plugins.map(plugin_store_1.normalizePluginConfigEntry);
|
|
12
13
|
const loaded = await Promise.all(specs.map(async (spec) => {
|
|
13
14
|
try {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const mod = await store.importPluginModule(spec.name);
|
|
16
|
+
const v = (0, validate_plugin_default_export_1.validatePluginDefaultExport)({
|
|
17
|
+
pluginName: spec.name,
|
|
18
|
+
moduleExports: mod,
|
|
19
|
+
options: spec.options
|
|
20
|
+
});
|
|
21
|
+
if (!v.ok) {
|
|
22
|
+
console.error(`Skipping plugin ${spec.name}: ${v.error.message}`);
|
|
17
23
|
return null;
|
|
18
24
|
}
|
|
19
|
-
return
|
|
25
|
+
return v.plugin;
|
|
20
26
|
}
|
|
21
27
|
catch (e) {
|
|
22
28
|
const msg = e && typeof e.message === "string"
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PluginStore = exports.getPluginNameFromSpec = exports.normalizePluginConfigEntry = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
8
|
const node_module_1 = require("node:module");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const node_url_1 = require("node:url");
|
|
11
11
|
const normalizePluginConfigEntry = (entry) => {
|
|
12
12
|
if (typeof entry === "string") {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePluginDefaultExport = void 0;
|
|
4
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
const toError = (value) => {
|
|
6
|
+
if (value instanceof Error) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
return new Error(typeof value === "string" ? value : JSON.stringify(value));
|
|
10
|
+
};
|
|
11
|
+
const validatePluginDefaultExport = (input) => {
|
|
12
|
+
const { pluginName, moduleExports, options } = input;
|
|
13
|
+
const defaultExport = moduleExports.default;
|
|
14
|
+
if (typeof defaultExport !== "function") {
|
|
15
|
+
return {
|
|
16
|
+
ok: false,
|
|
17
|
+
error: new Error(`Plugin ${pluginName} must default export a class/constructor.`)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const ctor = defaultExport;
|
|
21
|
+
try {
|
|
22
|
+
const instance = typeof options === "undefined"
|
|
23
|
+
? new ctor()
|
|
24
|
+
: Array.isArray(options)
|
|
25
|
+
? new ctor(...options)
|
|
26
|
+
: new ctor(options);
|
|
27
|
+
if (!isRecord(instance)) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
error: new Error(`Plugin ${pluginName} default export did not construct an object.`)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const name = instance.name;
|
|
34
|
+
if (typeof name !== "string" || name.trim().length === 0) {
|
|
35
|
+
return {
|
|
36
|
+
ok: false,
|
|
37
|
+
error: new Error(`Plugin ${pluginName} instance must have a non-empty string 'name'.`)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const setup = instance.setup;
|
|
41
|
+
if (typeof setup !== "function") {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
error: new Error(`Plugin ${pluginName} instance must implement setup(host).`)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const contribute = instance.contribute;
|
|
48
|
+
if (typeof contribute !== "undefined" && typeof contribute !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
error: new Error(`Plugin ${pluginName} contribute must be a function if provided.`)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { ok: true, plugin: instance };
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return { ok: false, error: toError(e) };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.validatePluginDefaultExport = validatePluginDefaultExport;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "CLI for capturing offline snapshots of web pages.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"koa-static": "^5.0.0",
|
|
21
21
|
"ora": "^9.0.0",
|
|
22
22
|
"env-paths": "^2.2.1",
|
|
23
|
-
"@pagepocket/lib": "0.8.
|
|
24
|
-
"@pagepocket/capture-http-cdp-unit": "0.8.
|
|
25
|
-
"@pagepocket/capture-http-
|
|
26
|
-
"@pagepocket/
|
|
27
|
-
"@pagepocket/
|
|
28
|
-
"@pagepocket/plugin-yt-dlp": "0.8.
|
|
29
|
-
"@pagepocket/single-file-unit": "0.8.
|
|
30
|
-
"@pagepocket/write-down-unit": "0.8.
|
|
31
|
-
"@pagepocket/contracts": "0.8.
|
|
23
|
+
"@pagepocket/lib": "0.8.1",
|
|
24
|
+
"@pagepocket/capture-http-cdp-unit": "0.8.1",
|
|
25
|
+
"@pagepocket/capture-http-lighterceptor-unit": "0.8.1",
|
|
26
|
+
"@pagepocket/capture-http-puppeteer-unit": "0.8.1",
|
|
27
|
+
"@pagepocket/build-snapshot-unit": "0.8.1",
|
|
28
|
+
"@pagepocket/plugin-yt-dlp": "0.8.1",
|
|
29
|
+
"@pagepocket/single-file-unit": "0.8.1",
|
|
30
|
+
"@pagepocket/write-down-unit": "0.8.1",
|
|
31
|
+
"@pagepocket/contracts": "0.8.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^20.11.30",
|