@supernovaio/cli
Version:
Supernova.io Command Line Interface
103 lines (101 loc) ⢠5.61 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]="dda062fb-0b36-5132-9203-226cc0521c4b")}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 { analyzeComponents } from "@supernovaio/code-analyzer";
import { z } from "zod";
import { SentryCommand } from "../types/index.js";
const ImportComponentsConfigSchema = z
.object({
designSystemId: z.string(),
importFrom: z.string(),
rootDir: z.string(),
versionId: z.string(),
})
.transform(data => ({
...data,
rootDir: data.rootDir ?? process.cwd(),
}));
export default class ImportComponents extends SentryCommand {
static args = {};
static description = "Analyze react components from given package and import them into Supernova";
static examples = [
"<%= config.bin %> <%= command.id %> --importFrom components-package --rootDir ./src",
"<%= config.bin %> <%= command.id %> --importFrom @mui/material",
];
static flags = {
designSystemId: Flags.string({ description: "Import code components to design system of", required: true }),
importFrom: Flags.string({
char: "i",
description: "Package or directory path to import components from",
required: true,
}),
rootDir: Flags.string({
char: "r",
default: process.cwd(),
description: "Root directory of the package where the import should resolve from. Defaults to the current directory",
}),
versionId: Flags.string({ description: "Import code components to version of", required: true }),
};
static hidden = true;
get commandId() {
return ImportComponents.id;
}
get configSchema() {
return ImportComponentsConfigSchema;
}
async run() {
const { flags } = await this.parse(ImportComponents);
const { designSystemId, importFrom, rootDir, versionId } = flags;
this.log("š¦ Component Import Summary".green);
this.log("========================");
this.log(`Source: ${importFrom}`);
this.log(`Root Directory: ${rootDir}`);
const components = await analyzeComponents({ importFrom, rootDir });
if (components.length > 0) {
this.log("\nComponent Summary Table:");
this.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
this.log("Component Name Props.Num Required Props Names ");
this.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
for (const component of components) {
const propsCount = Object.keys(component.properties).length;
const requiredCount = Object.values(component.properties).filter(prop => prop.required).length;
const propsNames = new Set(Object.values(component.properties).map(prop => prop.name));
const name = component.exportName.padEnd(16, " ").slice(0, 16);
const propsNum = String(propsCount).padStart(5, " ");
const required = String(requiredCount).padStart(10, " ");
const props = [...propsNames].slice(0, 2).join(", ") + (propsNames.size > 2 ? ", ..." : "");
this.log(`${name} ${propsNum} ${required} ${props}`);
}
this.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
this.log("Importing to Supernova...");
const client = await this.apiClient();
const result = await client.designSystems.versions.codeComponents.import(designSystemId, versionId, {
codeComponents: components.map(c => ({
...c,
persistentId: `${designSystemId}-${versionId}${c.exportName}}`,
})),
});
this.log(`Total: ${result.created} components imported`.green);
}
else {
this.log("\nā ļø No components were imported".green);
}
}
}
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ImportComponents.prototype, "run", null);
//# sourceMappingURL=components-import.js.map
//# debugId=dda062fb-0b36-5132-9203-226cc0521c4b