any2orca 0.0.1 → 0.1.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/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +96 -3
- package/dist/archive/adaptModelSettings.d.ts +1 -0
- package/dist/archive/adaptModelSettings.js +50 -0
- package/dist/archive/filamentColorNames.d.ts +8 -0
- package/dist/archive/filamentColorNames.js +760 -0
- package/dist/archive/fmtNum.d.ts +14 -0
- package/dist/archive/fmtNum.js +21 -0
- package/dist/archive/internal/escapeRegExp.d.ts +2 -0
- package/dist/archive/internal/escapeRegExp.js +5 -0
- package/dist/archive/lookupFilamentColorName.d.ts +45 -0
- package/dist/archive/lookupFilamentColorName.js +57 -0
- package/dist/archive/objectWorldBboxXY.d.ts +2 -0
- package/dist/archive/objectWorldBboxXY.js +123 -0
- package/dist/archive/parseItemPositions.d.ts +6 -0
- package/dist/archive/parseItemPositions.js +17 -0
- package/dist/archive/parseObjectMetadata.d.ts +10 -0
- package/dist/archive/parseObjectMetadata.js +97 -0
- package/dist/archive/parsePlateAssignments.d.ts +6 -0
- package/dist/archive/parsePlateAssignments.js +18 -0
- package/dist/archive/parseVertices.d.ts +7 -0
- package/dist/archive/parseVertices.js +12 -0
- package/dist/archive/paths.d.ts +5 -0
- package/dist/archive/paths.js +6 -0
- package/dist/archive/recenterAssembleItems.d.ts +9 -0
- package/dist/archive/recenterAssembleItems.js +53 -0
- package/dist/archive/recenterBuildItems.d.ts +15 -0
- package/dist/archive/recenterBuildItems.js +51 -0
- package/dist/archive/safeUnzip.d.ts +26 -0
- package/dist/archive/safeUnzip.js +126 -0
- package/dist/archive/setApplicationMetadata.d.ts +13 -0
- package/dist/archive/setApplicationMetadata.js +18 -0
- package/dist/archive/shouldDropFromBambu.d.ts +29 -0
- package/dist/archive/shouldDropFromBambu.js +39 -0
- package/dist/archive/streamObjectVertices.d.ts +19 -0
- package/dist/archive/streamObjectVertices.js +57 -0
- package/dist/archive/tolerantJsonParse.d.ts +20 -0
- package/dist/archive/tolerantJsonParse.js +71 -0
- package/dist/archive/transform.d.ts +21 -0
- package/dist/archive/transform.js +39 -0
- package/dist/archive/unwrapBundle.d.ts +24 -0
- package/dist/archive/unwrapBundle.js +41 -0
- package/dist/archive/xmlBlocks.d.ts +10 -0
- package/dist/archive/xmlBlocks.js +31 -0
- package/dist/archive/zip.d.ts +29 -0
- package/dist/archive/zip.js +141 -0
- package/dist/cli/archiveMove.d.ts +15 -0
- package/dist/cli/archiveMove.js +41 -0
- package/dist/cli/commands/convert.d.ts +89 -0
- package/dist/cli/commands/convert.js +311 -0
- package/dist/cli/commands/diff.d.ts +21 -0
- package/dist/cli/commands/diff.js +112 -0
- package/dist/cli/commands/presets.d.ts +51 -0
- package/dist/cli/commands/presets.js +280 -0
- package/dist/cli/commands/profiles.d.ts +5 -0
- package/dist/cli/commands/profiles.js +26 -0
- package/dist/cli/commands/telemetry.d.ts +6 -0
- package/dist/cli/commands/telemetry.js +45 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +50 -0
- package/dist/cli/expandWildcards.d.ts +17 -0
- package/dist/cli/expandWildcards.js +81 -0
- package/dist/cli/logger.d.ts +17 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/sameFile.d.ts +9 -0
- package/dist/cli/sameFile.js +40 -0
- package/dist/cli/stats.d.ts +34 -0
- package/dist/cli/stats.js +137 -0
- package/dist/cli/table.d.ts +8 -0
- package/dist/cli/table.js +18 -0
- package/dist/cli/terminalText.d.ts +7 -0
- package/dist/cli/terminalText.js +22 -0
- package/dist/cli/updateCheck.d.ts +14 -0
- package/dist/cli/updateCheck.js +78 -0
- package/dist/cli/watchState.d.ts +18 -0
- package/dist/cli/watchState.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +10 -0
- package/dist/diff/diffSettings.d.ts +81 -0
- package/dist/diff/diffSettings.js +259 -0
- package/dist/diff/reference.d.ts +14 -0
- package/dist/diff/reference.js +22 -0
- package/dist/diff/settingsCatalog.d.ts +28 -0
- package/dist/diff/settingsCatalog.js +605 -0
- package/dist/diff/valueLayout.d.ts +20 -0
- package/dist/diff/valueLayout.js +65 -0
- package/dist/engine/aboveStock.d.ts +20 -0
- package/dist/engine/aboveStock.js +89 -0
- package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
- package/dist/engine/applyFilamentComplianceMode.js +68 -0
- package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
- package/dist/engine/applyFilamentFlowVariants.js +109 -0
- package/dist/engine/applyHighFlowHotends.d.ts +52 -0
- package/dist/engine/applyHighFlowHotends.js +115 -0
- package/dist/engine/applyPresetChanges.d.ts +12 -0
- package/dist/engine/applyPresetChanges.js +23 -0
- package/dist/engine/bedCenter.d.ts +19 -0
- package/dist/engine/bedCenter.js +34 -0
- package/dist/engine/buildFilamentConfigs.d.ts +18 -0
- package/dist/engine/buildFilamentConfigs.js +49 -0
- package/dist/engine/buildProjectSettings.d.ts +24 -0
- package/dist/engine/buildProjectSettings.js +164 -0
- package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
- package/dist/engine/carrySourceLayerHeight.js +41 -0
- package/dist/engine/clampColorPenetration.d.ts +12 -0
- package/dist/engine/clampColorPenetration.js +28 -0
- package/dist/engine/clampToMachineLimits.d.ts +21 -0
- package/dist/engine/clampToMachineLimits.js +84 -0
- package/dist/engine/coerceValue.d.ts +15 -0
- package/dist/engine/coerceValue.js +56 -0
- package/dist/engine/collapseNozzleVariants.d.ts +31 -0
- package/dist/engine/collapseNozzleVariants.js +63 -0
- package/dist/engine/computeShifts.d.ts +12 -0
- package/dist/engine/computeShifts.js +339 -0
- package/dist/engine/constants.d.ts +11 -0
- package/dist/engine/constants.js +12 -0
- package/dist/engine/detectNozzleDiameter.d.ts +15 -0
- package/dist/engine/detectNozzleDiameter.js +29 -0
- package/dist/engine/detectVariantIndex.d.ts +39 -0
- package/dist/engine/detectVariantIndex.js +80 -0
- package/dist/engine/extractFilamentSlots.d.ts +18 -0
- package/dist/engine/extractFilamentSlots.js +88 -0
- package/dist/engine/filamentComplianceNames.d.ts +84 -0
- package/dist/engine/filamentComplianceNames.js +87 -0
- package/dist/engine/filamentVariantLayout.d.ts +29 -0
- package/dist/engine/filamentVariantLayout.js +38 -0
- package/dist/engine/fillFilamentSlots.d.ts +16 -0
- package/dist/engine/fillFilamentSlots.js +26 -0
- package/dist/engine/internal/jsonEqual.d.ts +2 -0
- package/dist/engine/internal/jsonEqual.js +5 -0
- package/dist/engine/parseTierName.d.ts +15 -0
- package/dist/engine/parseTierName.js +21 -0
- package/dist/engine/pickNearestProfile.d.ts +21 -0
- package/dist/engine/pickNearestProfile.js +24 -0
- package/dist/engine/pickProfile.d.ts +49 -0
- package/dist/engine/pickProfile.js +67 -0
- package/dist/engine/policy.d.ts +14 -0
- package/dist/engine/policy.js +266 -0
- package/dist/engine/remapBrimType.d.ts +30 -0
- package/dist/engine/remapBrimType.js +34 -0
- package/dist/engine/reshapeToCount.d.ts +15 -0
- package/dist/engine/reshapeToCount.js +27 -0
- package/dist/engine/resizeFlushVolumes.d.ts +27 -0
- package/dist/engine/resizeFlushVolumes.js +57 -0
- package/dist/engine/resolveMinIfLower.d.ts +21 -0
- package/dist/engine/resolveMinIfLower.js +59 -0
- package/dist/engine/runConvertPipeline.d.ts +79 -0
- package/dist/engine/runConvertPipeline.js +281 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/types.js +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +9 -0
- package/dist/explain/whatChanged.d.ts +102 -0
- package/dist/explain/whatChanged.js +197 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +33 -0
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.js +103 -0
- package/dist/node.d.ts +11 -0
- package/dist/node.js +50 -0
- package/dist/plainText.d.ts +10 -0
- package/dist/plainText.js +14 -0
- package/dist/presets/extractPreset.d.ts +13 -0
- package/dist/presets/extractPreset.js +87 -0
- package/dist/presets/preset.d.ts +124 -0
- package/dist/presets/preset.js +289 -0
- package/dist/presets/presetKeys.d.ts +5 -0
- package/dist/presets/presetKeys.js +42 -0
- package/dist/profiles.d.ts +184 -0
- package/dist/profiles.js +314 -0
- package/dist/project.d.ts +146 -0
- package/dist/project.js +342 -0
- package/dist/schema.d.ts +103 -0
- package/dist/schema.js +87 -0
- package/dist/stamp.d.ts +45 -0
- package/dist/stamp.js +111 -0
- package/dist/telemetry.d.ts +101 -0
- package/dist/telemetry.js +94 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +142 -0
- package/dist/worker.d.ts +86 -0
- package/dist/worker.js +97 -0
- package/dist/workerProtocol.d.ts +91 -0
- package/dist/workerProtocol.js +1 -0
- package/package.json +78 -12
- package/index.js +0 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Inspection } from "../inspect.js";
|
|
2
|
+
import type { ConvertReport } from "../project.js";
|
|
3
|
+
import { type StatsEvent } from "../telemetry.js";
|
|
4
|
+
import { type Env } from "./config.js";
|
|
5
|
+
import type { Logger } from "./logger.js";
|
|
6
|
+
export type StatsStatus = {
|
|
7
|
+
enabled: true;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
} | {
|
|
11
|
+
enabled: false;
|
|
12
|
+
endpoint: string | null;
|
|
13
|
+
reason: string;
|
|
14
|
+
};
|
|
15
|
+
/** Accepts https URLs, plus http on localhost for testing a collector. */
|
|
16
|
+
export declare function validateEndpoint(raw: string): string;
|
|
17
|
+
export declare function resolveStatsStatus(env: Env, flagEndpoint?: string): StatsStatus;
|
|
18
|
+
export declare function readSentLog(env: Env): Array<{
|
|
19
|
+
sentAt: string;
|
|
20
|
+
endpoint: string;
|
|
21
|
+
event: StatsEvent;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function clearSentLog(env: Env): void;
|
|
24
|
+
export interface StatsReporter {
|
|
25
|
+
/** Never throws. */
|
|
26
|
+
afterConversion(report: ConvertReport, inspection: Inspection): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare function createStatsReporter(options: {
|
|
29
|
+
env: Env;
|
|
30
|
+
logger: Logger;
|
|
31
|
+
dryRun: boolean;
|
|
32
|
+
endpoint?: string;
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
}): StatsReporter;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Opt-in usage stats for the CLI. Off unless the user turns it on
|
|
4
|
+
* (`any2orca telemetry on` or ANY2ORCA_TELEMETRY=1), and even then nothing
|
|
5
|
+
* is sent without a collector address. DO_NOT_TRACK=1 and
|
|
6
|
+
* ANY2ORCA_TELEMETRY=0 always win.
|
|
7
|
+
*
|
|
8
|
+
* Each event actually sent is appended to a local log
|
|
9
|
+
* (`any2orca telemetry show` prints it). `--dry-run-telemetry` prints the
|
|
10
|
+
* event instead of sending it. A failed send never affects a conversion.
|
|
11
|
+
*/
|
|
12
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { buildStatsEvent } from "../telemetry.js";
|
|
15
|
+
import { configDir, readCliConfig } from "./config.js";
|
|
16
|
+
const SEND_TIMEOUT_MS = 3000;
|
|
17
|
+
const SENT_LOG_LIMIT = 100;
|
|
18
|
+
function isTruthy(value) {
|
|
19
|
+
return value !== undefined && /^(1|true|yes|on)$/i.test(value.trim());
|
|
20
|
+
}
|
|
21
|
+
function isFalsy(value) {
|
|
22
|
+
return value !== undefined && /^(0|false|no|off)$/i.test(value.trim());
|
|
23
|
+
}
|
|
24
|
+
/** Accepts https URLs, plus http on localhost for testing a collector. */
|
|
25
|
+
export function validateEndpoint(raw) {
|
|
26
|
+
let url;
|
|
27
|
+
try {
|
|
28
|
+
url = new URL(raw);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error(`ANY2ORCA_STATS_ENDPOINT isn't a valid URL: ${JSON.stringify(raw.slice(0, 200))}`);
|
|
32
|
+
}
|
|
33
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
34
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
|
|
35
|
+
throw new Error("ANY2ORCA_STATS_ENDPOINT must be an https:// URL (http:// is allowed only for localhost).");
|
|
36
|
+
}
|
|
37
|
+
if (url.username || url.password)
|
|
38
|
+
throw new Error("ANY2ORCA_STATS_ENDPOINT must not contain credentials.");
|
|
39
|
+
return url.href;
|
|
40
|
+
}
|
|
41
|
+
export function resolveStatsStatus(env, flagEndpoint) {
|
|
42
|
+
// There's no default collector: with no ANY2ORCA_STATS_ENDPOINT, turning stats on sends nothing.
|
|
43
|
+
// The environment variable is checked only when stats would send, so an unrelated
|
|
44
|
+
// ANY2ORCA_STATS_ENDPOINT doesn't stop a conversion; the --stats-endpoint flag is always checked.
|
|
45
|
+
if (flagEndpoint !== undefined)
|
|
46
|
+
validateEndpoint(flagEndpoint);
|
|
47
|
+
const rawEndpoint = flagEndpoint ?? env.ANY2ORCA_STATS_ENDPOINT ?? null;
|
|
48
|
+
let endpoint = null;
|
|
49
|
+
let invalid = null;
|
|
50
|
+
try {
|
|
51
|
+
endpoint = rawEndpoint ? validateEndpoint(rawEndpoint) : null;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
invalid = err;
|
|
55
|
+
}
|
|
56
|
+
if (isTruthy(env.DO_NOT_TRACK))
|
|
57
|
+
return { enabled: false, endpoint, reason: "DO_NOT_TRACK is set" };
|
|
58
|
+
if (isFalsy(env.ANY2ORCA_TELEMETRY))
|
|
59
|
+
return { enabled: false, endpoint, reason: "ANY2ORCA_TELEMETRY is off" };
|
|
60
|
+
const choice = readCliConfig(env).stats?.choice;
|
|
61
|
+
const on = isTruthy(env.ANY2ORCA_TELEMETRY) || choice === "on";
|
|
62
|
+
if (!on)
|
|
63
|
+
return { enabled: false, endpoint, reason: choice === "off" ? "turned off" : "off unless you turn it on" };
|
|
64
|
+
if (invalid)
|
|
65
|
+
throw invalid;
|
|
66
|
+
if (!endpoint)
|
|
67
|
+
return { enabled: false, endpoint, reason: "turned on, but there's no collector to send to yet (set ANY2ORCA_STATS_ENDPOINT)" };
|
|
68
|
+
return { enabled: true, endpoint, reason: isTruthy(env.ANY2ORCA_TELEMETRY) ? "ANY2ORCA_TELEMETRY is on" : "turned on" };
|
|
69
|
+
}
|
|
70
|
+
function sentLogPath(env) {
|
|
71
|
+
return join(configDir(env), "stats-sent.jsonl");
|
|
72
|
+
}
|
|
73
|
+
export function readSentLog(env) {
|
|
74
|
+
const path = sentLogPath(env);
|
|
75
|
+
if (!existsSync(path))
|
|
76
|
+
return [];
|
|
77
|
+
return readFileSync(path, "utf-8")
|
|
78
|
+
.split("\n")
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.flatMap((line) => {
|
|
81
|
+
try {
|
|
82
|
+
return [JSON.parse(line)];
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export function clearSentLog(env) {
|
|
90
|
+
const path = sentLogPath(env);
|
|
91
|
+
if (existsSync(path))
|
|
92
|
+
writeFileSync(path, "");
|
|
93
|
+
}
|
|
94
|
+
function appendSentLog(env, entry) {
|
|
95
|
+
mkdirSync(configDir(env), { recursive: true, mode: 0o700 });
|
|
96
|
+
const path = sentLogPath(env);
|
|
97
|
+
appendFileSync(path, `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
98
|
+
const lines = readFileSync(path, "utf-8").split("\n").filter(Boolean);
|
|
99
|
+
if (lines.length > SENT_LOG_LIMIT)
|
|
100
|
+
writeFileSync(path, `${lines.slice(-SENT_LOG_LIMIT).join("\n")}\n`);
|
|
101
|
+
}
|
|
102
|
+
export function createStatsReporter(options) {
|
|
103
|
+
const { env, logger } = options;
|
|
104
|
+
const doFetch = options.fetch ?? fetch;
|
|
105
|
+
return {
|
|
106
|
+
async afterConversion(report, inspection) {
|
|
107
|
+
try {
|
|
108
|
+
const event = buildStatsEvent({
|
|
109
|
+
profileId: report.profile.id,
|
|
110
|
+
...(report.profileMatch ? { profileMatch: report.profileMatch } : {}),
|
|
111
|
+
plates: report.plates,
|
|
112
|
+
objects: report.objects,
|
|
113
|
+
filamentSlots: report.filamentSlots,
|
|
114
|
+
sourceVendor: inspection.sourceVendor,
|
|
115
|
+
});
|
|
116
|
+
if (options.dryRun) {
|
|
117
|
+
logger.log(` usage stats event (--dry-run-telemetry, not sent):\n${JSON.stringify(event, null, 2).replace(/^/gm, " ")}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const status = resolveStatsStatus(env, options.endpoint);
|
|
121
|
+
if (!status.enabled)
|
|
122
|
+
return;
|
|
123
|
+
const response = await doFetch(status.endpoint, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: { "content-type": "application/json" },
|
|
126
|
+
body: JSON.stringify(event),
|
|
127
|
+
signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
|
|
128
|
+
});
|
|
129
|
+
if (response.ok)
|
|
130
|
+
appendSentLog(env, { sentAt: new Date().toISOString(), endpoint: status.endpoint, event });
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Stats are best effort and never affect a conversion.
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats rows of strings into a left-justified, space-aligned table --
|
|
3
|
+
* plain tab characters (`\t`) don't align reliably across rows since
|
|
4
|
+
* terminal tab stops are fixed-width and don't adapt to the longest
|
|
5
|
+
* value in a column. The last column is left unpadded (padding it only
|
|
6
|
+
* adds invisible trailing whitespace, no visual benefit).
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatTable(rows: string[][], columnGap?: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Formats rows of strings into a left-justified, space-aligned table --
|
|
4
|
+
* plain tab characters (`\t`) don't align reliably across rows since
|
|
5
|
+
* terminal tab stops are fixed-width and don't adapt to the longest
|
|
6
|
+
* value in a column. The last column is left unpadded (padding it only
|
|
7
|
+
* adds invisible trailing whitespace, no visual benefit).
|
|
8
|
+
*/
|
|
9
|
+
export function formatTable(rows, columnGap = 2) {
|
|
10
|
+
if (rows.length === 0)
|
|
11
|
+
return "";
|
|
12
|
+
const columnCount = rows[0].length;
|
|
13
|
+
const widths = Array.from({ length: columnCount }, (_, col) => Math.max(...rows.map((row) => row[col].length)));
|
|
14
|
+
const gap = " ".repeat(columnGap);
|
|
15
|
+
return rows
|
|
16
|
+
.map((row) => row.map((cell, col) => (col === columnCount - 1 ? cell : cell.padEnd(widths[col]))).join(gap))
|
|
17
|
+
.join("\n");
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function safeTerminalText(text: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* A line of JSON output made safe to print without changing the data:
|
|
4
|
+
* JSON.stringify already escapes the C0 controls, and these characters only
|
|
5
|
+
* appear inside strings, so writing them as \u escapes keeps the value.
|
|
6
|
+
*/
|
|
7
|
+
export declare function escapeUnsafeForJson(line: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Text bound for the terminal, made safe to print. Much of what the CLI
|
|
4
|
+
* prints comes from files: setting values and object names in a 3MF, names in
|
|
5
|
+
* a shared presets file. The CLI uses no control codes of its own, so every
|
|
6
|
+
* one is replaced (see plainText); newlines and tabs stay.
|
|
7
|
+
*/
|
|
8
|
+
import { plainText } from "../plainText.js";
|
|
9
|
+
/** Zero-width and invisible characters: harmless to a terminal, but they make two values look alike. */
|
|
10
|
+
const INVISIBLE = /[\u00ad\u061c\u200b-\u200f\u2028\u2029\u2060\ufeff]/g;
|
|
11
|
+
export function safeTerminalText(text) {
|
|
12
|
+
return plainText(text).replace(INVISIBLE, "\ufffd");
|
|
13
|
+
}
|
|
14
|
+
const JSON_UNSAFE = /[\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028-\u202e\u2060\u2066-\u2069\ufeff]/g;
|
|
15
|
+
/**
|
|
16
|
+
* A line of JSON output made safe to print without changing the data:
|
|
17
|
+
* JSON.stringify already escapes the C0 controls, and these characters only
|
|
18
|
+
* appear inside strings, so writing them as \u escapes keeps the value.
|
|
19
|
+
*/
|
|
20
|
+
export function escapeUnsafeForJson(line) {
|
|
21
|
+
return line.replace(JSON_UNSAFE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Env } from "./config.js";
|
|
2
|
+
export declare const REGISTRY_LATEST_URL = "https://registry.npmjs.org/any2orca/latest";
|
|
3
|
+
export interface UpdateCheckContext {
|
|
4
|
+
env: Env;
|
|
5
|
+
isTTY: boolean;
|
|
6
|
+
flagDisabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function updateCheckDisabledReason(ctx: UpdateCheckContext): string | null;
|
|
9
|
+
/** Compares dotted numeric versions; prerelease suffixes are ignored, so a prerelease never triggers a notice. */
|
|
10
|
+
export declare function isNewer(candidate: string, current: string): boolean;
|
|
11
|
+
/** The notice to print for a cached newer version, or null. */
|
|
12
|
+
export declare function updateNotice(env: Env): string | null;
|
|
13
|
+
/** Refreshes the cache if it's more than a day old. Resolves quickly and never throws. */
|
|
14
|
+
export declare function refreshUpdateCache(env: Env, doFetch?: typeof fetch): Promise<void>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The CLI's update notice. At most once a day it asks the npm registry for
|
|
4
|
+
* the latest any2orca version (sending only the package name), caches the
|
|
5
|
+
* answer, and the next run prints the update command if there's a newer
|
|
6
|
+
* one. It never blocks a conversion for long, never runs in CI or when
|
|
7
|
+
* output isn't a terminal, and is off with NO_UPDATE_NOTIFIER=1,
|
|
8
|
+
* --no-update-notifier, or `any2orca telemetry update-check off`.
|
|
9
|
+
*
|
|
10
|
+
* The npm registry is the only host this contacts.
|
|
11
|
+
*/
|
|
12
|
+
import { VERSION } from "../version.js";
|
|
13
|
+
import { readCliConfig, updateCliConfig } from "./config.js";
|
|
14
|
+
export const REGISTRY_LATEST_URL = "https://registry.npmjs.org/any2orca/latest";
|
|
15
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
16
|
+
const FETCH_TIMEOUT_MS = 1500;
|
|
17
|
+
export function updateCheckDisabledReason(ctx) {
|
|
18
|
+
if (ctx.flagDisabled)
|
|
19
|
+
return "--no-update-notifier";
|
|
20
|
+
if (ctx.env.NO_UPDATE_NOTIFIER)
|
|
21
|
+
return "NO_UPDATE_NOTIFIER is set";
|
|
22
|
+
if (ctx.env.CI)
|
|
23
|
+
return "running in CI";
|
|
24
|
+
if (readCliConfig(ctx.env).updateCheck?.enabled === false)
|
|
25
|
+
return "turned off";
|
|
26
|
+
if (!ctx.isTTY)
|
|
27
|
+
return "output isn't a terminal";
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** Compares dotted numeric versions; prerelease suffixes are ignored, so a prerelease never triggers a notice. */
|
|
31
|
+
export function isNewer(candidate, current) {
|
|
32
|
+
if (/-/.test(candidate))
|
|
33
|
+
return false;
|
|
34
|
+
const a = candidate.split(".").map((n) => Number.parseInt(n, 10));
|
|
35
|
+
const b = current.split("-")[0].split(".").map((n) => Number.parseInt(n, 10));
|
|
36
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
37
|
+
const x = a[i] ?? 0;
|
|
38
|
+
const y = b[i] ?? 0;
|
|
39
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
40
|
+
return false;
|
|
41
|
+
if (x !== y)
|
|
42
|
+
return x > y;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/** The notice to print for a cached newer version, or null. */
|
|
47
|
+
export function updateNotice(env) {
|
|
48
|
+
const cached = readCliConfig(env).updateCheck;
|
|
49
|
+
if (!cached?.latest || !isNewer(cached.latest, VERSION))
|
|
50
|
+
return null;
|
|
51
|
+
const why = cached.outputAffecting ? `\n Why: ${cached.outputAffecting} Re-convert affected files after updating.` : "";
|
|
52
|
+
return `any2orca ${cached.latest} is available (you have ${VERSION}). Update: npm install -g any2orca@latest${why}`;
|
|
53
|
+
}
|
|
54
|
+
/** Refreshes the cache if it's more than a day old. Resolves quickly and never throws. */
|
|
55
|
+
export async function refreshUpdateCache(env, doFetch = fetch) {
|
|
56
|
+
try {
|
|
57
|
+
const last = readCliConfig(env).updateCheck?.lastCheckedAt ?? 0;
|
|
58
|
+
if (Date.now() - last < CHECK_INTERVAL_MS)
|
|
59
|
+
return;
|
|
60
|
+
// Record the attempt first, so an offline machine doesn't retry on every run.
|
|
61
|
+
updateCliConfig((c) => ({ ...c, updateCheck: { ...c.updateCheck, lastCheckedAt: Date.now() } }), env);
|
|
62
|
+
const response = await doFetch(REGISTRY_LATEST_URL, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
63
|
+
if (!response.ok)
|
|
64
|
+
return;
|
|
65
|
+
const text = await response.text();
|
|
66
|
+
if (text.length > 256 * 1024)
|
|
67
|
+
return;
|
|
68
|
+
const body = JSON.parse(text);
|
|
69
|
+
if (typeof body.version !== "string" || !/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(body.version))
|
|
70
|
+
return;
|
|
71
|
+
const outputAffecting = typeof body.outputAffecting === "string" ? body.outputAffecting.replace(/[\u0000-\u001f\u007f]/g, " ").slice(0, 300) : undefined;
|
|
72
|
+
// outputAffecting is always overwritten, so a reason from an older release never sticks to a newer one.
|
|
73
|
+
updateCliConfig((c) => ({ ...c, updateCheck: { ...c.updateCheck, latest: body.version, outputAffecting } }), env);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Offline, blocked, or a bad answer: try again tomorrow.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ConvertOutcome = "succeeded" | "failed-once" | "permanently-failed";
|
|
2
|
+
export interface StateRecord {
|
|
3
|
+
fingerprint: string;
|
|
4
|
+
outcome: ConvertOutcome;
|
|
5
|
+
}
|
|
6
|
+
export type StateFile = Record<string, StateRecord>;
|
|
7
|
+
/**
|
|
8
|
+
* `size:mtimeMs` -- identifies a specific version of a file's content, not
|
|
9
|
+
* just its name. Deliberately more than just size: two versions of a file
|
|
10
|
+
* can be exactly the same number of bytes (e.g. a plate renamed "Core
|
|
11
|
+
* pieces" -> "Core Pieces") while genuinely differing in content, and
|
|
12
|
+
* mtime is what catches that. Cheap to compute -- one stat() call, already
|
|
13
|
+
* needed elsewhere for the same file.
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeFingerprint(path: string): string;
|
|
16
|
+
/** Missing or corrupt state file both resolve to "nothing recorded yet" -- a long-running watch session shouldn't crash over a hand-edited or truncated bookkeeping file. */
|
|
17
|
+
export declare function loadStateFile(dir: string): StateFile;
|
|
18
|
+
export declare function saveStateFile(dir: string, state: StateFile): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* `size:mtimeMs` -- identifies a specific version of a file's content, not
|
|
6
|
+
* just its name. Deliberately more than just size: two versions of a file
|
|
7
|
+
* can be exactly the same number of bytes (e.g. a plate renamed "Core
|
|
8
|
+
* pieces" -> "Core Pieces") while genuinely differing in content, and
|
|
9
|
+
* mtime is what catches that. Cheap to compute -- one stat() call, already
|
|
10
|
+
* needed elsewhere for the same file.
|
|
11
|
+
*/
|
|
12
|
+
export function computeFingerprint(path) {
|
|
13
|
+
const stat = statSync(path);
|
|
14
|
+
return `${stat.size}:${stat.mtimeMs}`;
|
|
15
|
+
}
|
|
16
|
+
function stateFilePath(dir) {
|
|
17
|
+
return join(dir, ".any2orca-state.json");
|
|
18
|
+
}
|
|
19
|
+
/** Missing or corrupt state file both resolve to "nothing recorded yet" -- a long-running watch session shouldn't crash over a hand-edited or truncated bookkeeping file. */
|
|
20
|
+
export function loadStateFile(dir) {
|
|
21
|
+
const path = stateFilePath(dir);
|
|
22
|
+
if (!existsSync(path))
|
|
23
|
+
return {};
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function saveStateFile(dir, state) {
|
|
32
|
+
writeFileSync(stateFilePath(dir), JSON.stringify(state, null, 2));
|
|
33
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// The `any2orca` command. The shebang is added at build time by scripts/build.mjs.
|
|
4
|
+
import { runCli } from "./cli/main.js";
|
|
5
|
+
process.exitCode = await runCli(process.argv.slice(2), {
|
|
6
|
+
env: process.env,
|
|
7
|
+
isTTY: Boolean(process.stdout.isTTY),
|
|
8
|
+
out: (line) => console.log(line),
|
|
9
|
+
err: (line) => console.error(line),
|
|
10
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type SettingGroup } from "./settingsCatalog.js";
|
|
2
|
+
import { type ValueLayout } from "./valueLayout.js";
|
|
3
|
+
export type DiffGroupName = SettingGroup | "other";
|
|
4
|
+
export type DiffStatus = "same" | "changed" | "only-a" | "only-b" | "unmatched";
|
|
5
|
+
/**
|
|
6
|
+
* A value worth a look, when the diff was given a reference profile: a speed
|
|
7
|
+
* or acceleration above the printer's machine limits (it will be capped), or
|
|
8
|
+
* a speed, acceleration or filament max volumetric speed above Snapmaker's
|
|
9
|
+
* stock value (22/40 mm³/s for max volumetric speed).
|
|
10
|
+
*/
|
|
11
|
+
export type DiffAttention = "above-limit" | "above-stock";
|
|
12
|
+
export interface DiffRow {
|
|
13
|
+
key: string;
|
|
14
|
+
/** Where Snapmaker Orca shows the setting, for example "Speed > Acceleration > Outer wall", or the key itself. */
|
|
15
|
+
label: string;
|
|
16
|
+
/** The value on each side as text (list entries joined with ", "), or null where that side doesn't have the setting. */
|
|
17
|
+
a: string | null;
|
|
18
|
+
b: string | null;
|
|
19
|
+
status: DiffStatus;
|
|
20
|
+
/** The settings page and section Snapmaker Orca shows the setting on (for example "Speed" and "Acceleration"), for grouping rows; absent where it shows it on none. */
|
|
21
|
+
page?: string;
|
|
22
|
+
section?: string;
|
|
23
|
+
/** Set when either side's value is above the reference profile's stock value or its machine limits (needs `DiffOptions.reference`). */
|
|
24
|
+
attention?: DiffAttention;
|
|
25
|
+
/** What each side's several values are, where they're a pair or per-nozzle list (see {@link ValueLayout}); absent for single values. */
|
|
26
|
+
layout?: {
|
|
27
|
+
a?: ValueLayout;
|
|
28
|
+
b?: ValueLayout;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface DiffGroup {
|
|
32
|
+
group: DiffGroupName;
|
|
33
|
+
/** For filament settings: the filament slot, 1 first. */
|
|
34
|
+
slot?: number;
|
|
35
|
+
rows: DiffRow[];
|
|
36
|
+
}
|
|
37
|
+
export interface SettingsDiff {
|
|
38
|
+
format: "any2orca-diff";
|
|
39
|
+
version: 1;
|
|
40
|
+
aLabel: string;
|
|
41
|
+
bLabel: string;
|
|
42
|
+
/** The Snapmaker Orca release whose settings, labels and groups the diff uses. */
|
|
43
|
+
catalog: {
|
|
44
|
+
tag: string;
|
|
45
|
+
commit: string;
|
|
46
|
+
};
|
|
47
|
+
groups: DiffGroup[];
|
|
48
|
+
/** True when no row differs (in the groups compared). */
|
|
49
|
+
identical: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface SettingsSide {
|
|
52
|
+
/** Shown as the side's name, for example a file name or `Snapmaker's stock 0.20mm Standard @Snapmaker U1 (0.4 nozzle) profile`. */
|
|
53
|
+
label: string;
|
|
54
|
+
settings: Readonly<Record<string, unknown>>;
|
|
55
|
+
}
|
|
56
|
+
export interface DiffOptions {
|
|
57
|
+
/** Which groups to compare. Default: all. */
|
|
58
|
+
groups?: readonly DiffGroupName[];
|
|
59
|
+
/** Also list settings that are the same on both sides (status "same"). Default false. */
|
|
60
|
+
includeUnchanged?: boolean;
|
|
61
|
+
/** Also compare bookkeeping entries (preset inheritance, the changed-settings list, version stamps). Default false. */
|
|
62
|
+
includeBookkeeping?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* A profile to measure values against, for each row's `attention`: its
|
|
65
|
+
* stock project settings and its printer's machine settings. Usually the
|
|
66
|
+
* stock side of the comparison, or the profile a file would convert with.
|
|
67
|
+
*/
|
|
68
|
+
reference?: {
|
|
69
|
+
stock: Readonly<Record<string, unknown>>;
|
|
70
|
+
machine: Readonly<Record<string, unknown>>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Entries that describe how a file was saved rather than how it prints. */
|
|
74
|
+
export declare const BOOKKEEPING_KEYS: ReadonlySet<string>;
|
|
75
|
+
/** A project has a few hundred settings; this bounds the work for a crafted file. */
|
|
76
|
+
export declare const MAX_DIFF_KEYS = 10000;
|
|
77
|
+
/** Whether two values of one setting are equal as Snapmaker Orca treats them (the comparison the diff uses). */
|
|
78
|
+
export declare function sameSetting(a: unknown, b: unknown): boolean;
|
|
79
|
+
export declare function labelOf(key: string): string;
|
|
80
|
+
/** Compares two sets of settings. */
|
|
81
|
+
export declare function diffSettings(a: SettingsSide, b: SettingsSide, options?: DiffOptions): SettingsDiff;
|