@tokens-studio/sdk
Version:
The official SDK for Tokens Studio
42 lines • 1.81 kB
JavaScript
import { resolveReleaseVersion } from './resolve-release-version.js';
import { getArtifactUrl, getRelease } from '../utils/queries.js';
import { fetchZIP } from './fetch-zip.js';
import { combineFunctionsConfig } from './combine-functions-config.js';
export async function fetchRelease(client, { project, org, config }) {
// fetch sets data from release
const version = await resolveReleaseVersion(config.release, {
project,
org,
client,
});
const { tokensArtifactUrl: tokensPath, configArtifactUrl: configPath } = await getRelease(client, { project, organization: org, version });
const [tokensUrl, configUrl] = await Promise.all([
tokensPath
? getArtifactUrl(client, {
project,
organization: org,
releaseVersion: version,
artifactPath: tokensPath,
})
: Promise.resolve(null),
configPath
? getArtifactUrl(client, {
project,
organization: org,
releaseVersion: version,
artifactPath: configPath,
})
: Promise.resolve(null),
]);
const [tokenFiles, configFiles] = await Promise.all([tokensUrl, configUrl].map((url) => url ? fetchZIP(url) : Promise.resolve([])));
const combine = async (name, contents) => {
const functionsAndConfig = await combineFunctionsConfig(JSON.parse(contents));
return {
name: `build-${name.split('.json')[0]}.js`,
contents: functionsAndConfig,
};
};
const combined = (await Promise.all((configFiles ?? []).map(({ name, contents }) => combine(name, contents))));
return { tokens: tokenFiles ?? [], configs: combined };
}
//# sourceMappingURL=fetch-release.js.map