@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,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.fetchStrategyFile = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
10
|
-
const normalize_argv_1 = require("../../utils/normalize-argv");
|
|
11
|
-
const isRecord = (value) => {
|
|
12
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
13
|
-
};
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isUrlLike } from "../../utils/normalize-argv.js";
|
|
4
|
+
import { parseJson } from "../../utils/parse-json.js";
|
|
5
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
14
6
|
const isStrategyFile = (value) => {
|
|
15
7
|
if (!isRecord(value)) {
|
|
16
8
|
return false;
|
|
@@ -31,15 +23,15 @@ const isStrategyFile = (value) => {
|
|
|
31
23
|
return true;
|
|
32
24
|
};
|
|
33
25
|
const readTextFromPath = (p) => {
|
|
34
|
-
const full =
|
|
35
|
-
return
|
|
26
|
+
const full = path.resolve(p);
|
|
27
|
+
return fs.readFileSync(full, "utf8");
|
|
36
28
|
};
|
|
37
|
-
const fetchStrategyFile = async (input) => {
|
|
29
|
+
export const fetchStrategyFile = async (input) => {
|
|
38
30
|
const raw = input.trim();
|
|
39
31
|
if (!raw) {
|
|
40
32
|
throw new Error("strategy source is empty");
|
|
41
33
|
}
|
|
42
|
-
if (
|
|
34
|
+
if (isUrlLike(raw)) {
|
|
43
35
|
const url = new URL(raw);
|
|
44
36
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
45
37
|
throw new Error(`Unsupported strategy URL protocol: ${url.protocol}`);
|
|
@@ -49,7 +41,7 @@ const fetchStrategyFile = async (input) => {
|
|
|
49
41
|
throw new Error(`Failed to fetch strategy: ${res.status} ${res.statusText}`);
|
|
50
42
|
}
|
|
51
43
|
const text = await res.text();
|
|
52
|
-
const parsed =
|
|
44
|
+
const parsed = parseJson(text);
|
|
53
45
|
if (!parsed.ok) {
|
|
54
46
|
throw parsed.error;
|
|
55
47
|
}
|
|
@@ -59,13 +51,12 @@ const fetchStrategyFile = async (input) => {
|
|
|
59
51
|
return { strategy: parsed.value, source: { type: "url", value: url.toString() } };
|
|
60
52
|
}
|
|
61
53
|
const text = readTextFromPath(raw);
|
|
62
|
-
const parsed =
|
|
54
|
+
const parsed = parseJson(text);
|
|
63
55
|
if (!parsed.ok) {
|
|
64
56
|
throw parsed.error;
|
|
65
57
|
}
|
|
66
58
|
if (!isStrategyFile(parsed.value)) {
|
|
67
59
|
throw new Error(`Invalid strategy JSON from file: ${raw}`);
|
|
68
60
|
}
|
|
69
|
-
return { strategy: parsed.value, source: { type: "file", value:
|
|
61
|
+
return { strategy: parsed.value, source: { type: "file", value: path.resolve(raw) } };
|
|
70
62
|
};
|
|
71
|
-
exports.fetchStrategyFile = fetchStrategyFile;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeJsonAtomic = exports.readStrategyFile = exports.getStrategyPath = exports.getStrategiesDir = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
10
|
-
const isRecord = (value) => {
|
|
11
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
12
|
-
};
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseJson } from "../../utils/parse-json.js";
|
|
4
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
13
5
|
const isStrategyFile = (value) => {
|
|
14
6
|
if (!isRecord(value)) {
|
|
15
7
|
return false;
|
|
@@ -29,17 +21,11 @@ const isStrategyFile = (value) => {
|
|
|
29
21
|
}
|
|
30
22
|
return true;
|
|
31
23
|
};
|
|
32
|
-
const getStrategiesDir = (configService) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
return node_path_1.default.join((0, exports.getStrategiesDir)(configService), `${name}.json`);
|
|
38
|
-
};
|
|
39
|
-
exports.getStrategyPath = getStrategyPath;
|
|
40
|
-
const readStrategyFile = (filePath) => {
|
|
41
|
-
const text = node_fs_1.default.readFileSync(filePath, "utf8");
|
|
42
|
-
const parsed = (0, parse_json_1.parseJson)(text);
|
|
24
|
+
export const getStrategiesDir = (configService) => path.join(configService.getConfigDir(), "strategies");
|
|
25
|
+
export const getStrategyPath = (configService, name) => path.join(getStrategiesDir(configService), `${name}.json`);
|
|
26
|
+
export const readStrategyFile = (filePath) => {
|
|
27
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
28
|
+
const parsed = parseJson(text);
|
|
43
29
|
if (!parsed.ok) {
|
|
44
30
|
throw parsed.error;
|
|
45
31
|
}
|
|
@@ -48,12 +34,10 @@ const readStrategyFile = (filePath) => {
|
|
|
48
34
|
}
|
|
49
35
|
return parsed.value;
|
|
50
36
|
};
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
37
|
+
export const writeJsonAtomic = (filePath, value) => {
|
|
38
|
+
const dir = path.dirname(filePath);
|
|
39
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
55
40
|
const tmpPath = `${filePath}.tmp`;
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
fs.writeFileSync(tmpPath, `${JSON.stringify(value, undefined, 2)}\n`, "utf8");
|
|
42
|
+
fs.renameSync(tmpPath, filePath);
|
|
58
43
|
};
|
|
59
|
-
exports.writeJsonAtomic = writeJsonAtomic;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.normalizeStrategyUnits = void 0;
|
|
4
|
-
const parse_pinned_spec_1 = require("../user-packages/parse-pinned-spec");
|
|
5
|
-
const isRecord = (value) => {
|
|
6
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7
|
-
};
|
|
1
|
+
import { parsePinnedSpec } from "../user-packages/parse-pinned-spec.js";
|
|
2
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8
3
|
const isJsonValue = (value) => {
|
|
9
4
|
if (value === null) {
|
|
10
5
|
return true;
|
|
11
6
|
}
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
7
|
+
const valueType = typeof value;
|
|
8
|
+
if (valueType === "string" || valueType === "number" || valueType === "boolean") {
|
|
14
9
|
return true;
|
|
15
10
|
}
|
|
16
11
|
if (Array.isArray(value)) {
|
|
17
|
-
return value.every((
|
|
12
|
+
return value.every((item) => isJsonValue(item));
|
|
18
13
|
}
|
|
19
14
|
if (isRecord(value)) {
|
|
20
|
-
return Object.values(value).every((
|
|
15
|
+
return Object.values(value).every((entryValue) => isJsonValue(entryValue));
|
|
21
16
|
}
|
|
22
17
|
return false;
|
|
23
18
|
};
|
|
24
19
|
const normalizeUnitSpec = (spec, idx) => {
|
|
25
20
|
if (typeof spec === "string") {
|
|
26
|
-
const pinned =
|
|
21
|
+
const pinned = parsePinnedSpec(spec);
|
|
27
22
|
return { ref: pinned.spec, args: [] };
|
|
28
23
|
}
|
|
29
24
|
if (!isRecord(spec)) {
|
|
@@ -33,7 +28,7 @@ const normalizeUnitSpec = (spec, idx) => {
|
|
|
33
28
|
if (typeof ref !== "string") {
|
|
34
29
|
throw new Error(`Invalid unit ref at index ${idx}`);
|
|
35
30
|
}
|
|
36
|
-
const pinned =
|
|
31
|
+
const pinned = parsePinnedSpec(ref);
|
|
37
32
|
const argsRaw = spec.args;
|
|
38
33
|
const args = typeof argsRaw === "undefined" ? [] : argsRaw;
|
|
39
34
|
if (!Array.isArray(args)) {
|
|
@@ -44,8 +39,7 @@ const normalizeUnitSpec = (spec, idx) => {
|
|
|
44
39
|
}
|
|
45
40
|
return { ref: pinned.spec, args };
|
|
46
41
|
};
|
|
47
|
-
const normalizeStrategyUnits = (strategy) => {
|
|
42
|
+
export const normalizeStrategyUnits = (strategy) => {
|
|
48
43
|
const units = strategy.pipeline.units;
|
|
49
44
|
return units.map((spec, idx) => normalizeUnitSpec(spec, idx));
|
|
50
45
|
};
|
|
51
|
-
exports.normalizeStrategyUnits = normalizeStrategyUnits;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readStrategiesFromPackRoot = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
10
|
-
const isRecord = (value) => {
|
|
11
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
12
|
-
};
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseJson } from "../../utils/parse-json.js";
|
|
4
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
13
5
|
const isStrategyFile = (value) => {
|
|
14
6
|
if (!isRecord(value)) {
|
|
15
7
|
return false;
|
|
@@ -29,19 +21,19 @@ const isStrategyFile = (value) => {
|
|
|
29
21
|
}
|
|
30
22
|
return true;
|
|
31
23
|
};
|
|
32
|
-
const readStrategiesFromPackRoot = (packRoot) => {
|
|
33
|
-
const strategiesDir =
|
|
34
|
-
if (!
|
|
24
|
+
export const readStrategiesFromPackRoot = (packRoot) => {
|
|
25
|
+
const strategiesDir = path.join(packRoot, "strategies");
|
|
26
|
+
if (!fs.existsSync(strategiesDir)) {
|
|
35
27
|
return [];
|
|
36
28
|
}
|
|
37
|
-
const fileNames =
|
|
29
|
+
const fileNames = fs
|
|
38
30
|
.readdirSync(strategiesDir)
|
|
39
|
-
.filter((
|
|
31
|
+
.filter((fileName) => fileName.endsWith(".strategy.json"))
|
|
40
32
|
.sort((a, b) => a.localeCompare(b));
|
|
41
33
|
return fileNames.map((fileName) => {
|
|
42
|
-
const filePath =
|
|
43
|
-
const text =
|
|
44
|
-
const parsed =
|
|
34
|
+
const filePath = path.join(strategiesDir, fileName);
|
|
35
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
36
|
+
const parsed = parseJson(text);
|
|
45
37
|
if (!parsed.ok) {
|
|
46
38
|
throw parsed.error;
|
|
47
39
|
}
|
|
@@ -51,4 +43,3 @@ const readStrategiesFromPackRoot = (packRoot) => {
|
|
|
51
43
|
return parsed.value;
|
|
52
44
|
});
|
|
53
45
|
};
|
|
54
|
-
exports.readStrategiesFromPackRoot = readStrategiesFromPackRoot;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.StrategyPackStore = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const user_package_installer_1 = require("../user-packages/user-package-installer");
|
|
9
|
-
const user_package_installer_2 = require("../user-packages/user-package-installer");
|
|
10
|
-
const parse_pinned_spec_1 = require("../user-packages/parse-pinned-spec");
|
|
11
|
-
const user_package_store_1 = require("../user-packages/user-package-store");
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parsePinnedSpec } from "../user-packages/parse-pinned-spec.js";
|
|
3
|
+
import { installPinnedPackage } from "../user-packages/user-package-installer.js";
|
|
4
|
+
import { updatePackageToLatest } from "../user-packages/user-package-installer.js";
|
|
5
|
+
import { UserPackageStore } from "../user-packages/user-package-store.js";
|
|
12
6
|
const STRATEGY_PACKS_KIND = "strategy-packs";
|
|
13
7
|
const STRATEGY_PACKS_PACKAGE_JSON_NAME = "pagepocket-user-strategy-packs";
|
|
14
|
-
class StrategyPackStore {
|
|
8
|
+
export class StrategyPackStore {
|
|
9
|
+
store;
|
|
15
10
|
constructor(configService) {
|
|
16
|
-
this.store = new
|
|
11
|
+
this.store = new UserPackageStore(configService, STRATEGY_PACKS_KIND);
|
|
17
12
|
}
|
|
18
13
|
getInstallDir() {
|
|
19
14
|
return this.store.getInstallDir();
|
|
@@ -22,15 +17,15 @@ class StrategyPackStore {
|
|
|
22
17
|
return this.store.readInstalledDependencyVersions(STRATEGY_PACKS_PACKAGE_JSON_NAME);
|
|
23
18
|
}
|
|
24
19
|
installPinned(spec) {
|
|
25
|
-
const pinned =
|
|
26
|
-
|
|
20
|
+
const pinned = parsePinnedSpec(spec);
|
|
21
|
+
installPinnedPackage(this.store, {
|
|
27
22
|
packageJsonName: STRATEGY_PACKS_PACKAGE_JSON_NAME,
|
|
28
23
|
packageSpec: pinned.spec
|
|
29
24
|
});
|
|
30
25
|
return pinned;
|
|
31
26
|
}
|
|
32
27
|
updateToLatest(packageName) {
|
|
33
|
-
|
|
28
|
+
updatePackageToLatest(this.store, {
|
|
34
29
|
packageJsonName: STRATEGY_PACKS_PACKAGE_JSON_NAME,
|
|
35
30
|
packageName
|
|
36
31
|
});
|
|
@@ -39,7 +34,6 @@ class StrategyPackStore {
|
|
|
39
34
|
this.store.ensureInstallDirPackageJson(STRATEGY_PACKS_PACKAGE_JSON_NAME);
|
|
40
35
|
const req = this.store.createRequire(STRATEGY_PACKS_PACKAGE_JSON_NAME);
|
|
41
36
|
const pkgJsonPath = req.resolve(`${packageName}/package.json`);
|
|
42
|
-
return
|
|
37
|
+
return path.dirname(pkgJsonPath);
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
|
-
exports.StrategyPackStore = StrategyPackStore;
|