UNPKG

@tokens-studio/graph-engine-migration

Version:

A package to upgrade old graph engine files to the new format

21 lines 994 B
import { annotatedVersion } from '@tokens-studio/graph-engine'; import { compareVersions } from 'compare-versions'; import { sortedUpgrades } from './migrations/index.js'; export const findUpgrades = (version) => sortedUpgrades.filter(([v]) => compareVersions(v, version) === 1); export const updateGraph = async (graph, opts = { verbose: true }) => { const { verbose } = opts; //Check the version const version = graph.annotations[annotatedVersion] || '0.0.0'; //Copy the graph to prevent mutation const copiedGraph = JSON.parse(JSON.stringify(graph)); const newGraph = await findUpgrades(version).reduce(async (accP, [migrationVersion, upgrader]) => { const acc = await accP; if (verbose) { console.log(`Applying migration to version ${version} -> ${migrationVersion}`); } return await upgrader(acc); }, Promise.resolve(copiedGraph)); return newGraph; }; export * from './utils.js'; //# sourceMappingURL=index.js.map