Files
jhonny-editor/code/scripts/generate-adobe-beta-tick-time-drift.mjs
T
João Henrique b541f502ba feat: initial commit - Jhonny Editor
- Adicionado estrutura completa do projeto
- Configurado MCP server para Premiere Pro
- Adicionado documentação e skills
- Configurado Gitignore para o projeto
2026-09-08 09:59:31 -04:00

32 lines
7.3 KiB
JavaScript
Executable File

import { createHash } from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import { dirname, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import ts from "typescript";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const stablePath = process.env.PREMIERE_BETA_TICK_TIME_STABLE_DECLARATIONS_PATH ? resolve(process.env.PREMIERE_BETA_TICK_TIME_STABLE_DECLARATIONS_PATH) : resolve(root, "node_modules/@adobe/premierepro/src/premierepro.d.ts");
const betaPath = process.env.PREMIERE_BETA_TICK_TIME_BETA_DECLARATIONS_PATH ? resolve(process.env.PREMIERE_BETA_TICK_TIME_BETA_DECLARATIONS_PATH) : resolve(root, "node_modules/@adobe/premierepro-beta/src/premierepro.d.ts");
const outputPath = resolve(root, "src/resources/adobe-beta-tick-time-drift.json");
const normalize = (text) => text.replaceAll("\r\n", "\n").replace(/\s+/g, " ").trim();
const compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;
const parse = (text, path) => { const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true); if (source.parseDiagnostics.length) throw new Error(`Adobe TickTime declaration parse failed: ${source.parseDiagnostics.map((item) => ts.flattenDiagnosticMessageText(item.messageText, " ")).join("; ")}`); return source; };
const literal = (source, name) => { const declaration = source.statements.find((item) => ts.isTypeAliasDeclaration(item) && item.name.text === name); if (!declaration || !ts.isTypeLiteralNode(declaration.type)) throw new Error(`Adobe declarations must expose ${name} as a type literal.`); return declaration; };
const binding = (rootDeclaration, source) => { const member = rootDeclaration.type.members.find((item) => ts.isPropertySignature(item) && item.name && ts.isIdentifier(item.name) && item.name.text === "TickTime"); if (!member?.type) throw new Error("Adobe declarations must expose premierepro.TickTime as a typed property."); return { symbol: "premierepro.TickTime", kind: "property", signature: normalize(member.type.getText(source)) }; };
const factories = (declaration, source, owner) => declaration.type.members.filter((item) => ts.isConstructSignatureDeclaration(item) || ts.isCallSignatureDeclaration(item)).map((item) => { if (!item.type) throw new Error(`Adobe ${owner} factory signature is missing a return type.`); return { symbol: `${owner}.${ts.isConstructSignatureDeclaration(item) ? "new" : "call"}`, kind: ts.isConstructSignatureDeclaration(item) ? "construct_signature" : "call_signature", signature: `(${item.parameters.map((parameter) => normalize(parameter.getText(source))).join(", ")}) => ${normalize(item.type.getText(source))}` }; }).sort((left, right) => compare(left.symbol, right.symbol));
const nonFactories = (declaration, source) => declaration.type.members.filter((item) => !ts.isConstructSignatureDeclaration(item) && !ts.isCallSignatureDeclaration(item)).map((item) => normalize(item.getText(source))).sort(compare);
const [stablePackageText, betaPackageText, stableText, betaText] = await Promise.all([readFile(resolve(root, "node_modules/@adobe/premierepro/package.json"), "utf8"), readFile(resolve(root, "node_modules/@adobe/premierepro-beta/package.json"), "utf8"), readFile(stablePath, "utf8"), readFile(betaPath, "utf8")]);
const stable = parse(stableText, stablePath), beta = parse(betaText, betaPath), stableRoot = literal(stable, "premierepro"), betaRoot = literal(beta, "premierepro"), stableTickTime = literal(stable, "TickTime"), betaTickTime = literal(beta, "TickTime"), stableStatic = literal(stable, "TickTimeStatic"), betaStatic = literal(beta, "TickTimeStatic"), stableBinding = binding(stableRoot, stable), betaBinding = binding(betaRoot, beta), stableFactories = factories(stableTickTime, stable, "TickTime"), betaFactories = factories(betaStatic, beta, "TickTimeStatic");
if (stableBinding.signature !== "TickTimeStatic" || betaBinding.signature !== "TickTimeStatic") throw new Error("Adobe beta declarations must retain premierepro.TickTime as TickTimeStatic.");
if (factories(stableStatic, stable, "TickTimeStatic").length || factories(betaTickTime, beta, "TickTime").length) throw new Error("Adobe beta TickTime factory signatures must move only from stable TickTime to beta TickTimeStatic.");
const stableShapes = stableFactories.map(({ kind, signature }) => ({ kind, signature })), betaShapes = betaFactories.map(({ kind, signature }) => ({ kind, signature }));
if (stableFactories.length !== 2 || betaFactories.length !== 2 || JSON.stringify(stableShapes) !== JSON.stringify(betaShapes)) throw new Error("Adobe beta TickTimeStatic factory signatures must match stable TickTime.");
if (JSON.stringify(nonFactories(stableTickTime, stable)) !== JSON.stringify(nonFactories(betaTickTime, beta))) throw new Error("Adobe beta TickTime non-factory members must match stable TickTime.");
if (JSON.stringify(nonFactories(stableStatic, stable)) !== JSON.stringify(nonFactories(betaStatic, beta))) throw new Error("Adobe beta TickTimeStatic non-factory members must match stable TickTimeStatic.");
const hash = (declaration, source) => createHash("sha256").update(normalize(declaration.getText(source))).digest("hex");
const inventory = { schemaVersion: 1, scope: { declarations: ["premierepro.TickTime", "TickTime", "TickTimeStatic"], semantics: "This records the beta TickTime factory-placement migration against the pinned stable package. It is static declaration-drift accounting, not beta API support or a complete package diff.", doesNotEstablish: "It does not prove a beta host exposes TickTimeStatic factory calls, that a TickTime can be constructed or accepted by another API, that TickTime arithmetic or frame alignment behavior is preserved, or that any MCP action is supported or licensed-host validated." }, sources: { stable: { package: "@adobe/premierepro", version: JSON.parse(stablePackageText).version, declarations: relative(root, stablePath).replaceAll("\\", "/"), tickTimeDeclarationSha256: hash(stableTickTime, stable), tickTimeStaticDeclarationSha256: hash(stableStatic, stable), rootBinding: stableBinding.signature }, beta: { package: "@adobe/premierepro-beta", version: JSON.parse(betaPackageText).version, declarations: relative(root, betaPath).replaceAll("\\", "/"), tickTimeDeclarationSha256: hash(betaTickTime, beta), tickTimeStaticDeclarationSha256: hash(betaStatic, beta), rootBinding: betaBinding.signature } }, diff: { betaOnly: betaFactories, stableOnly: stableFactories, changed: [{ symbol: "TickTime.factorySignaturePlacement", stable: { owner: "TickTime", entries: stableShapes }, beta: { owner: "TickTimeStatic", entries: betaShapes } }] } };
const rendered = `${JSON.stringify(inventory, null, 2)}\n`;
if (process.argv.includes("--validate-only")) console.log("Validated Adobe beta TickTime declaration drift.");
else if (process.argv.includes("--check")) { let current = ""; try { current = await readFile(outputPath, "utf8"); } catch {} if (current.replaceAll("\r\n", "\n") !== rendered) { console.error("Adobe beta TickTime declaration drift inventory is stale. Run npm run adobe:beta-tick-time-drift."); process.exitCode = 1; } else console.log("Adobe beta TickTime declaration drift inventory is current: 2 beta-only, 2 stable-only, and 1 changed symbol."); }
else { await writeFile(outputPath, rendered); console.log("Wrote Adobe beta TickTime declaration drift inventory: 2 beta-only, 2 stable-only, and 1 changed symbol."); }