@supernovaio/cli
Version:
Supernova.io Command Line Interface
100 lines (98 loc) • 5.09 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a671b2d1-a314-5e8b-86a1-0f94c800cdce")}catch(e){}}();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Flags } from "@oclif/core";
import { SentryTraced } from "@sentry/nestjs";
import { z } from "zod";
import { SentryCommand } from "../types/index.js";
import "colors";
import { FigmaTokensDataLoader } from "../utils/figma-tokens-data-loader.js";
import { getWritableVersion } from "../utils/sdk.js";
const SyncDesignTokensConfigSchema = z.object({
apiKey: z.string(),
apiUrl: z.string().url().optional(),
configFilePath: z.string(),
designSystemId: z.string(),
proxyUrl: z.string().url().optional(),
tokenDirPath: z.string().optional(),
tokenFilePath: z.string().optional(),
});
export class SyncDesignTokens extends SentryCommand {
static aliases = ["sync-tokens"];
static description = "Synchronize tokens from Figma Tokens plugin to Supernova workspaces";
static examples = [
`$ @supernovaio/cli sync-tokens --apiKey="{xxx-xxx-xxx}" --designSystemId={1234} --tokenFilePath "/path/to/tokens.json" --configFilePath "/path/to/config.json"`,
`$ @supernovaio/cli sync-tokens --apiKey="{xxx-xxx-xxx}" --designSystemId={1234} --tokenDirPath "/path/to/tokens/" --configFilePath "/path/to/config.json"`,
];
static flags = {
apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }),
apiUrl: Flags.string({
description: "API url to use for accessing Supernova instance, would ignore defaults",
hidden: true,
}),
configFilePath: Flags.string({ description: "Path to configuration JSON file", exclusive: [], required: true }),
designSystemId: Flags.string({ description: "Design System to synchronize contents with", required: true }),
proxyUrl: Flags.string({
description: "When set, CLI will use provided proxy URL for all requests",
hidden: true,
required: false,
}),
tokenDirPath: Flags.string({
description: "Path to directory of JSON files containing token definitions",
exactlyOne: ["tokenDirPath", "tokenFilePath"],
}),
tokenFilePath: Flags.string({
description: "Path to JSON file containing token definitions",
exactlyOne: ["tokenDirPath", "tokenFilePath"],
}),
};
get commandId() {
return SyncDesignTokens.id;
}
get configSchema() {
return SyncDesignTokensConfigSchema;
}
async run() {
const { flags } = await this.parse(SyncDesignTokens);
const { id, instance } = await getWritableVersion(flags);
const dataLoader = new FigmaTokensDataLoader();
const configDefinition = dataLoader.loadConfigFromPath(flags.configFilePath);
const { settings } = configDefinition;
if (flags.dry) {
settings.dryRun = true;
}
const buildData = (payload) => ({
connection: { name: "CLI" },
...dataLoader.loadConfigFromPathAsIs(flags.configFilePath),
payload,
});
if (!flags.tokenFilePath && !flags.tokenDirPath) {
throw new Error(`Either tokenFilePath or tokenDirPath must be provided`);
}
const tokenDefinition = flags.tokenDirPath
? await dataLoader.loadTokensFromDirectory(flags.tokenDirPath, flags.configFilePath)
: await dataLoader.loadTokensFromPath(flags.tokenFilePath);
const response = (await instance.versions.writeTokenStudioData(id, buildData(tokenDefinition)));
if (response?.result?.logs && response.result.logs.length > 0) {
for (const log of response.result.logs) {
this.log(log);
}
}
this.log(`\nTokens synchronized`.green);
}
}
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], SyncDesignTokens.prototype, "run", null);
//# sourceMappingURL=sync-tokens.js.map
//# debugId=a671b2d1-a314-5e8b-86a1-0f94c800cdce