@pagepocket/cli 0.11.0 → 0.12.0
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 +80 -118
- package/dist/commands/plugin/add.js +19 -25
- package/dist/commands/plugin/doctor.js +22 -28
- package/dist/commands/plugin/ls.js +16 -22
- package/dist/commands/plugin/prune.js +13 -19
- package/dist/commands/plugin/remove.js +16 -22
- package/dist/commands/plugin/set.js +14 -22
- package/dist/commands/plugin/uninstall.js +29 -35
- package/dist/commands/plugin/update.js +22 -28
- package/dist/commands/strategy/add.js +14 -20
- package/dist/commands/strategy/doctor.js +15 -21
- package/dist/commands/strategy/ls.js +31 -17
- package/dist/commands/strategy/pin.js +10 -16
- package/dist/commands/strategy/remove.js +10 -16
- package/dist/commands/strategy/update.js +21 -27
- package/dist/commands/view.js +36 -42
- package/dist/index.js +9 -7
- package/dist/lib/filename.js +1 -5
- package/dist/services/config-service.js +30 -36
- package/dist/services/load-configured-plugins.js +8 -12
- package/dist/services/plugin-installer.js +14 -20
- package/dist/services/plugin-store.js +36 -79
- package/dist/services/strategy/builtin-strategy-registry.js +14 -32
- package/dist/services/strategy/strategy-analyze.js +14 -22
- package/dist/services/strategy/strategy-config.js +10 -17
- package/dist/services/strategy/strategy-fetch.js +12 -21
- package/dist/services/strategy/strategy-io.js +14 -30
- package/dist/services/strategy/strategy-normalize.js +9 -15
- package/dist/services/strategy/strategy-pack-read.js +12 -21
- package/dist/services/strategy/strategy-pack-store.js +12 -18
- package/dist/services/strategy/strategy-service.js +122 -117
- package/dist/services/strategy/types.js +1 -2
- package/dist/services/units/unit-store.js +16 -20
- package/dist/services/units/unit-validate.js +23 -11
- package/dist/services/user-packages/parse-pinned-spec.js +7 -17
- package/dist/services/user-packages/user-package-installer.js +8 -13
- package/dist/services/user-packages/user-package-store.js +27 -65
- package/dist/stages/prepare-output.js +6 -13
- package/dist/units/network-observer-unit.js +7 -10
- package/dist/utils/array.js +1 -7
- package/dist/utils/normalize-argv.js +3 -8
- package/dist/utils/parse-json.js +1 -5
- package/dist/utils/parse-plugin-options.js +1 -5
- package/dist/utils/parse-plugin-spec.js +5 -11
- package/dist/utils/validate-plugin-default-export.js +1 -5
- package/dist/utils/with-spinner.js +3 -10
- package/dist/view.js +14 -21
- package/package.json +16 -12
|
@@ -1,71 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.UserPackageStore = void 0;
|
|
40
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
|
-
const node_module_1 = require("node:module");
|
|
42
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
-
const node_url_1 = require("node:url");
|
|
44
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
45
|
-
const isRecord = (value) => {
|
|
46
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
47
|
-
};
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { parseJson } from "../../utils/parse-json.js";
|
|
6
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
48
7
|
const isStringRecord = (value) => {
|
|
49
8
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
50
9
|
return false;
|
|
51
10
|
}
|
|
52
|
-
return Object.values(value).every((
|
|
11
|
+
return Object.values(value).every((entryValue) => typeof entryValue === "string");
|
|
53
12
|
};
|
|
54
|
-
class UserPackageStore {
|
|
13
|
+
export class UserPackageStore {
|
|
14
|
+
configService;
|
|
15
|
+
kind;
|
|
55
16
|
constructor(configService, kind) {
|
|
56
17
|
this.configService = configService;
|
|
57
18
|
this.kind = kind;
|
|
58
19
|
}
|
|
59
20
|
getInstallDir() {
|
|
60
|
-
return
|
|
21
|
+
return path.join(this.configService.getDataDir(), this.kind);
|
|
61
22
|
}
|
|
62
23
|
ensureInstallDir() {
|
|
63
|
-
|
|
24
|
+
fs.mkdirSync(this.getInstallDir(), { recursive: true });
|
|
64
25
|
}
|
|
65
26
|
ensureInstallDirPackageJson(packageJsonName) {
|
|
66
27
|
this.ensureInstallDir();
|
|
67
|
-
const pkgJsonPath =
|
|
68
|
-
if (
|
|
28
|
+
const pkgJsonPath = path.join(this.getInstallDir(), "package.json");
|
|
29
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
69
30
|
return pkgJsonPath;
|
|
70
31
|
}
|
|
71
32
|
const pkgJson = {
|
|
@@ -73,12 +34,12 @@ class UserPackageStore {
|
|
|
73
34
|
private: true,
|
|
74
35
|
version: "0.0.0"
|
|
75
36
|
};
|
|
76
|
-
|
|
37
|
+
fs.writeFileSync(pkgJsonPath, `${JSON.stringify(pkgJson, undefined, 2)}\n`, "utf8");
|
|
77
38
|
return pkgJsonPath;
|
|
78
39
|
}
|
|
79
40
|
createRequire(packageJsonName) {
|
|
80
41
|
const pkgJsonPath = this.ensureInstallDirPackageJson(packageJsonName);
|
|
81
|
-
return
|
|
42
|
+
return createRequire(pkgJsonPath);
|
|
82
43
|
}
|
|
83
44
|
resolveInstalledPackageJsonPath(packageJsonName, packageName) {
|
|
84
45
|
const req = this.createRequire(packageJsonName);
|
|
@@ -87,16 +48,18 @@ class UserPackageStore {
|
|
|
87
48
|
readInstalledPackageMeta(packageJsonName, packageName) {
|
|
88
49
|
try {
|
|
89
50
|
const pkgJsonPath = this.resolveInstalledPackageJsonPath(packageJsonName, packageName);
|
|
90
|
-
const text =
|
|
91
|
-
const json =
|
|
51
|
+
const text = fs.readFileSync(pkgJsonPath, "utf8");
|
|
52
|
+
const json = parseJson(text);
|
|
92
53
|
if (!json.ok || !isRecord(json.value)) {
|
|
93
54
|
return { name: packageName };
|
|
94
55
|
}
|
|
95
|
-
const
|
|
56
|
+
const packageJsonRecord = json.value;
|
|
96
57
|
return {
|
|
97
|
-
name: typeof
|
|
98
|
-
description: typeof
|
|
99
|
-
|
|
58
|
+
name: typeof packageJsonRecord.name === "string" ? packageJsonRecord.name : packageName,
|
|
59
|
+
description: typeof packageJsonRecord.description === "string"
|
|
60
|
+
? packageJsonRecord.description
|
|
61
|
+
: undefined,
|
|
62
|
+
version: typeof packageJsonRecord.version === "string" ? packageJsonRecord.version : undefined
|
|
100
63
|
};
|
|
101
64
|
}
|
|
102
65
|
catch {
|
|
@@ -105,8 +68,8 @@ class UserPackageStore {
|
|
|
105
68
|
}
|
|
106
69
|
readInstalledDependencyVersions(packageJsonName) {
|
|
107
70
|
const pkgJsonPath = this.ensureInstallDirPackageJson(packageJsonName);
|
|
108
|
-
const text =
|
|
109
|
-
const parsed =
|
|
71
|
+
const text = fs.readFileSync(pkgJsonPath, "utf8");
|
|
72
|
+
const parsed = parseJson(text);
|
|
110
73
|
if (!parsed.ok || !isRecord(parsed.value)) {
|
|
111
74
|
return {};
|
|
112
75
|
}
|
|
@@ -119,8 +82,7 @@ class UserPackageStore {
|
|
|
119
82
|
async importModule(packageJsonName, packageName) {
|
|
120
83
|
const req = this.createRequire(packageJsonName);
|
|
121
84
|
const resolved = req.resolve(packageName);
|
|
122
|
-
const mod = await
|
|
85
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
123
86
|
return isRecord(mod) ? mod : {};
|
|
124
87
|
}
|
|
125
88
|
}
|
|
126
|
-
exports.UserPackageStore = UserPackageStore;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const filename_1 = require("../lib/filename");
|
|
9
|
-
const prepareOutputDir = async (title, outputFlag) => {
|
|
10
|
-
const safeTitle = (0, filename_1.safeFilename)(title || "snapshot");
|
|
11
|
-
const baseDir = outputFlag ? node_path_1.default.resolve(outputFlag) : process.cwd();
|
|
12
|
-
const outputDir = node_path_1.default.join(baseDir, safeTitle);
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { safeFilename } from "../lib/filename.js";
|
|
3
|
+
export const prepareOutputDir = async (title, outputFlag) => {
|
|
4
|
+
const safeTitle = safeFilename(title || "snapshot");
|
|
5
|
+
const baseDir = outputFlag ? path.resolve(outputFlag) : process.cwd();
|
|
6
|
+
const outputDir = path.join(baseDir, safeTitle);
|
|
13
7
|
return {
|
|
14
8
|
safeTitle,
|
|
15
9
|
outputDir
|
|
16
10
|
};
|
|
17
11
|
};
|
|
18
|
-
exports.prepareOutputDir = prepareOutputDir;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NetworkObserverUnit = void 0;
|
|
4
|
-
const contracts_1 = require("@pagepocket/contracts");
|
|
5
|
-
const lib_1 = require("@pagepocket/lib");
|
|
1
|
+
import { NETWORK } from "@pagepocket/contracts";
|
|
2
|
+
import { Unit } from "@pagepocket/lib";
|
|
6
3
|
/**
|
|
7
4
|
* Observes the network@1 channel and forwards events to user-provided callbacks.
|
|
8
5
|
*
|
|
9
6
|
* This unit is intentionally UI-agnostic (no CLI/spinner coupling).
|
|
10
7
|
*/
|
|
11
|
-
class NetworkObserverUnit extends
|
|
8
|
+
export class NetworkObserverUnit extends Unit {
|
|
9
|
+
id = "networkObserver";
|
|
10
|
+
kind = "observe.network";
|
|
11
|
+
config;
|
|
12
12
|
constructor(config = {}) {
|
|
13
13
|
super();
|
|
14
|
-
this.id = "networkObserver";
|
|
15
|
-
this.kind = "observe.network";
|
|
16
14
|
this.config = config;
|
|
17
15
|
}
|
|
18
16
|
async run(_ctx, rt) {
|
|
19
17
|
const config = this.config;
|
|
20
18
|
const task = (async () => {
|
|
21
|
-
for await (const event of rt.subscribe(
|
|
19
|
+
for await (const event of rt.subscribe(NETWORK)) {
|
|
22
20
|
await config.onEvent?.(event);
|
|
23
21
|
if (event.type === "request") {
|
|
24
22
|
await config.onRequest?.(event);
|
|
@@ -34,4 +32,3 @@ class NetworkObserverUnit extends lib_1.Unit {
|
|
|
34
32
|
rt.defer(task);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
exports.NetworkObserverUnit = NetworkObserverUnit;
|
package/dist/utils/array.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeArgv = exports.isUrlLike = void 0;
|
|
4
|
-
const isUrlLike = (value) => {
|
|
1
|
+
export const isUrlLike = (value) => {
|
|
5
2
|
try {
|
|
6
3
|
const url = new URL(value);
|
|
7
4
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
@@ -10,8 +7,7 @@ const isUrlLike = (value) => {
|
|
|
10
7
|
return false;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const normalizeArgv = (argv) => {
|
|
10
|
+
export const normalizeArgv = (argv) => {
|
|
15
11
|
// pnpm forwards args to scripts by inserting a literal `--`.
|
|
16
12
|
// oclif does not treat that as a flag; strip it if present.
|
|
17
13
|
if (argv[0] === "--") {
|
|
@@ -22,9 +18,8 @@ const normalizeArgv = (argv) => {
|
|
|
22
18
|
}
|
|
23
19
|
const first = argv[0];
|
|
24
20
|
// If the first token is a URL, treat it as implicit `archive`.
|
|
25
|
-
if (first &&
|
|
21
|
+
if (first && isUrlLike(first)) {
|
|
26
22
|
return ["archive", ...argv];
|
|
27
23
|
}
|
|
28
24
|
return argv;
|
|
29
25
|
};
|
|
30
|
-
exports.normalizeArgv = normalizeArgv;
|
package/dist/utils/parse-json.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJson = void 0;
|
|
4
1
|
const toErrorMessage = (value) => {
|
|
5
2
|
if (value instanceof Error) {
|
|
6
3
|
return value.message;
|
|
@@ -13,7 +10,7 @@ const toErrorMessage = (value) => {
|
|
|
13
10
|
}
|
|
14
11
|
return JSON.stringify(value);
|
|
15
12
|
};
|
|
16
|
-
const parseJson = (text) => {
|
|
13
|
+
export const parseJson = (text) => {
|
|
17
14
|
try {
|
|
18
15
|
return { ok: true, value: JSON.parse(text) };
|
|
19
16
|
}
|
|
@@ -21,4 +18,3 @@ const parseJson = (text) => {
|
|
|
21
18
|
return { ok: false, error: new Error(toErrorMessage(e)) };
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
exports.parseJson = parseJson;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePluginOptions = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Parse plugin options from argv tokens.
|
|
6
3
|
*
|
|
7
4
|
* Usage:
|
|
8
5
|
* const parsed = parsePluginOptions(["--option-mode", "strict"]);
|
|
9
6
|
*/
|
|
10
|
-
const parsePluginOptions = (argv) => {
|
|
7
|
+
export const parsePluginOptions = (argv) => {
|
|
11
8
|
const tokens = argv.filter(Boolean);
|
|
12
9
|
const pairs = tokens
|
|
13
10
|
.map((t, i) => ({ t, next: tokens[i + 1] }))
|
|
@@ -45,4 +42,3 @@ const parsePluginOptions = (argv) => {
|
|
|
45
42
|
}
|
|
46
43
|
return { kind: "none" };
|
|
47
44
|
};
|
|
48
|
-
exports.parsePluginOptions = parsePluginOptions;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsePluginSpec = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const node_module_1 = require("node:module");
|
|
9
|
-
const parsePluginSpec = (spec) => {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export const parsePluginSpec = (spec) => {
|
|
10
5
|
const trimmed = spec.trim();
|
|
11
6
|
if (!trimmed) {
|
|
12
7
|
throw new Error("plugin spec is empty");
|
|
13
8
|
}
|
|
14
|
-
const req = (
|
|
9
|
+
const req = createRequire(import.meta.url ? fileURLToPath(import.meta.url) : path.join(process.cwd(), "package.json"));
|
|
15
10
|
const npa = req("npm-package-arg");
|
|
16
11
|
const parsed = npa(trimmed);
|
|
17
12
|
if (!parsed || typeof parsed.name !== "string" || !parsed.name) {
|
|
@@ -19,4 +14,3 @@ const parsePluginSpec = (spec) => {
|
|
|
19
14
|
}
|
|
20
15
|
return { name: parsed.name, spec: trimmed };
|
|
21
16
|
};
|
|
22
|
-
exports.parsePluginSpec = parsePluginSpec;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validatePluginDefaultExport = void 0;
|
|
4
1
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5
2
|
const isPagePocketPlugin = (value) => {
|
|
6
3
|
if (!isRecord(value)) {
|
|
@@ -23,7 +20,7 @@ const toError = (value) => {
|
|
|
23
20
|
}
|
|
24
21
|
return new Error(typeof value === "string" ? value : JSON.stringify(value));
|
|
25
22
|
};
|
|
26
|
-
const validatePluginDefaultExport = (input) => {
|
|
23
|
+
export const validatePluginDefaultExport = (input) => {
|
|
27
24
|
const { pluginName, moduleExports, options } = input;
|
|
28
25
|
const defaultExport = moduleExports.default;
|
|
29
26
|
if (typeof defaultExport !== "function") {
|
|
@@ -51,4 +48,3 @@ const validatePluginDefaultExport = (input) => {
|
|
|
51
48
|
return { ok: false, error: toError(e) };
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
|
-
exports.validatePluginDefaultExport = validatePluginDefaultExport;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withSpinner = void 0;
|
|
7
|
-
const ora_1 = __importDefault(require("ora"));
|
|
8
|
-
const withSpinner = async (run, spinnerText) => {
|
|
9
|
-
const spinner = (0, ora_1.default)(spinnerText).start();
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
export const withSpinner = async (run, spinnerText) => {
|
|
3
|
+
const spinner = ora(spinnerText).start();
|
|
10
4
|
try {
|
|
11
5
|
const result = await run(spinner);
|
|
12
6
|
spinner.succeed(spinnerText.replace(/\.$/, "") || spinnerText);
|
|
@@ -17,4 +11,3 @@ const withSpinner = async (run, spinnerText) => {
|
|
|
17
11
|
throw error;
|
|
18
12
|
}
|
|
19
13
|
};
|
|
20
|
-
exports.withSpinner = withSpinner;
|
package/dist/view.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const koa_1 = __importDefault(require("koa"));
|
|
10
|
-
const koa_send_1 = __importDefault(require("koa-send"));
|
|
11
|
-
const koa_static_1 = __importDefault(require("koa-static"));
|
|
12
|
-
const createViewServer = async (args) => {
|
|
13
|
-
const indexPath = node_path_1.default.join(args.rootDir, "index.html");
|
|
14
|
-
const stat = await node_fs_1.default.promises.stat(args.rootDir).catch(() => undefined);
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Koa from "koa";
|
|
4
|
+
import send from "koa-send";
|
|
5
|
+
import serve from "koa-static";
|
|
6
|
+
export const createViewServer = async (args) => {
|
|
7
|
+
const indexPath = path.join(args.rootDir, "index.html");
|
|
8
|
+
const stat = await fs.promises.stat(args.rootDir).catch(() => undefined);
|
|
15
9
|
if (!stat || !stat.isDirectory()) {
|
|
16
10
|
throw new Error(`view: directory not found: ${args.rootDir}`);
|
|
17
11
|
}
|
|
18
|
-
const indexStat = await
|
|
12
|
+
const indexStat = await fs.promises.stat(indexPath).catch(() => undefined);
|
|
19
13
|
if (!indexStat || !indexStat.isFile()) {
|
|
20
14
|
throw new Error(`view: index.html not found under: ${args.rootDir}`);
|
|
21
15
|
}
|
|
22
|
-
const app = new
|
|
16
|
+
const app = new Koa();
|
|
23
17
|
// Avoid Koa's generator-function detection (and its dependency chain) by
|
|
24
18
|
// not calling `app.use()`.
|
|
25
19
|
//
|
|
@@ -27,18 +21,18 @@ const createViewServer = async (args) => {
|
|
|
27
21
|
// `is-generator-function` can break ("getGeneratorFunction is not a function")
|
|
28
22
|
// when it tries to require `generator-function`. We don't need generator
|
|
29
23
|
// middleware support here, so bypass it entirely.
|
|
30
|
-
const staticMw = (
|
|
24
|
+
const staticMw = serve(args.rootDir, { index: false });
|
|
31
25
|
app.middleware.push(staticMw);
|
|
32
26
|
app.middleware.push(async (ctx) => {
|
|
33
27
|
// SPA fallback (anything not matched by static middleware)
|
|
34
28
|
ctx.status = 200;
|
|
35
|
-
await (
|
|
29
|
+
await send(ctx, "index.html", {
|
|
36
30
|
root: args.rootDir
|
|
37
31
|
});
|
|
38
32
|
});
|
|
39
33
|
const server = await new Promise((resolve, reject) => {
|
|
40
|
-
const
|
|
41
|
-
|
|
34
|
+
const httpServer = app.listen(args.port, args.host, () => resolve(httpServer));
|
|
35
|
+
httpServer.on("error", reject);
|
|
42
36
|
});
|
|
43
37
|
const address = server.address();
|
|
44
38
|
const port = typeof address === "object" && address ? address.port : args.port;
|
|
@@ -53,4 +47,3 @@ const createViewServer = async (args) => {
|
|
|
53
47
|
}
|
|
54
48
|
};
|
|
55
49
|
};
|
|
56
|
-
exports.createViewServer = createViewServer;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "CLI for capturing offline snapshots of web pages.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"pp": "dist/index.js"
|
|
@@ -21,22 +22,25 @@
|
|
|
21
22
|
"koa-static": "^5.0.0",
|
|
22
23
|
"npm-package-arg": "^13.0.2",
|
|
23
24
|
"ora": "^9.0.0",
|
|
24
|
-
"@pagepocket/
|
|
25
|
-
"@pagepocket/
|
|
26
|
-
"@pagepocket/capture-http-cdp-unit": "0.
|
|
27
|
-
"@pagepocket/capture-http-
|
|
28
|
-
"@pagepocket/
|
|
29
|
-
"@pagepocket/
|
|
30
|
-
"@pagepocket/builtin-strategy": "0.
|
|
31
|
-
"@pagepocket/
|
|
32
|
-
"@pagepocket/
|
|
33
|
-
"@pagepocket/
|
|
25
|
+
"@pagepocket/main-content-unit": "0.12.0",
|
|
26
|
+
"@pagepocket/build-snapshot-unit": "0.12.0",
|
|
27
|
+
"@pagepocket/capture-http-cdp-unit": "0.12.0",
|
|
28
|
+
"@pagepocket/capture-http-lighterceptor-unit": "0.12.0",
|
|
29
|
+
"@pagepocket/capture-http-puppeteer-unit": "0.12.0",
|
|
30
|
+
"@pagepocket/contracts": "0.12.0",
|
|
31
|
+
"@pagepocket/builtin-strategy": "0.12.0",
|
|
32
|
+
"@pagepocket/lib": "0.12.0",
|
|
33
|
+
"@pagepocket/plugin-yt-dlp": "0.12.0",
|
|
34
|
+
"@pagepocket/shared": "0.12.0",
|
|
35
|
+
"@pagepocket/single-file-unit": "0.12.0",
|
|
36
|
+
"@pagepocket/write-down-unit": "0.12.0"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
39
|
"@types/koa": "^2.15.0",
|
|
37
40
|
"@types/koa-send": "^4.1.5",
|
|
38
41
|
"@types/koa-static": "^4.0.4",
|
|
39
42
|
"@types/node": "^20.11.30",
|
|
43
|
+
"rimraf": "^6.0.1",
|
|
40
44
|
"tsx": "^4.19.3",
|
|
41
45
|
"typescript": "^5.4.5"
|
|
42
46
|
},
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
}
|
|
50
54
|
},
|
|
51
55
|
"scripts": {
|
|
52
|
-
"build": "
|
|
56
|
+
"build": "rimraf dist && tsc",
|
|
53
57
|
"start": "node dist/index.js",
|
|
54
58
|
"test": "pnpm build && tsx --test specs/*.spec.ts"
|
|
55
59
|
}
|