@supernovaio/cli
Version:
Supernova.io Command Line Interface
197 lines (195 loc) • 9.83 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]="62dab586-d9bd-5ff3-b08f-4517a9feeadb")}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 { runSetupFlow } from "../../utils/ui/flow/run-setup-flow.js";
import { clearPersistedSetupSession, persistSetupSession, resolveInitialSetupContext, resolveInitialSetupState, } from "../../utils/ui/flow/session.js";
import { createDependencyService } from "../../utils/ui/services/dependency-service.js";
import { createPrototypeService } from "../../utils/ui/services/prototype-service.js";
import { createScanService } from "../../utils/ui/services/scan-service.js";
import { createTemplateService } from "../../utils/ui/services/template-service.js";
import { createValidationServices } from "../../utils/ui/services/validation-service.js";
import { renderTemplateReady } from "../../utils/ui/steps/container/screens.js";
import { renderSetupComplete } from "../../utils/ui/steps/prototype/screens.js";
import { renderStepHeader, success } from "../../utils/ui/ui.js";
export { discoverPackagesUnderPath } from "../../utils/ui/helpers.js";
const SetupConfigSchema = z.object({
debug: z.boolean().optional(),
restart: z.boolean().optional(),
});
export default class Setup extends SentryCommand {
static description = "Supernova Create Setup";
static examples = ["<%= config.bin %> <%= command.id %>", "<%= config.bin %> <%= command.id %> --restart"];
static hidden = true;
static flags = {
debug: Flags.boolean({
description: "Enable setup debug shortcuts like skipping scan or upload steps",
default: false,
hidden: true,
}),
restart: Flags.boolean({
description: "Restart setup from the beginning and ignore unfinished setup state",
default: false,
}),
};
get commandId() {
return Setup.id;
}
get configSchema() {
return SetupConfigSchema;
}
async run() {
const { flags } = await this.parse(Setup);
if (flags.debug && this.env !== "development") {
flags.debug = false;
}
await this.ensureAuthenticated();
this.log("");
const config = this.configService.get();
const initialState = await resolveInitialSetupState({
restart: flags.restart ?? false,
});
const initialContext = resolveInitialSetupContext(config);
persistSetupSession({
context: initialContext,
state: initialState,
status: "InProgress",
});
await runSetupFlow({
initialContext,
initialState,
log: message => this.log(message),
onStateTransition(state, context) {
const status = state === "DONE" ? "Completed" : "InProgress";
persistSetupSession({
context,
state,
status,
});
},
services: {
ui: {
error: message => this.error(message),
log: message => this.log(message),
renderSetupCompleteCard: input => this.log(renderSetupComplete(input)),
renderStep: title => {
this.log("");
for (const line of renderStepHeader(title))
this.log(line);
},
renderTemplateReadyCard: templateDestinationPath => this.log(renderTemplateReady(templateDestinationPath)),
},
validation: createValidationServices(),
container: {
...createTemplateService({
env: this.env,
error: message => this.error(message),
log: message => this.log(message),
runTemplateUploadCommand: async (cwd, args) => {
const previousCwd = process.cwd();
try {
process.chdir(cwd);
await this.config.runCommand("template-upload", args);
}
finally {
process.chdir(previousCwd);
}
},
}),
},
dependencies: {
...createDependencyService({
error: message => this.error(message),
log: message => this.log(message),
}),
},
designSystems: {
ensureSandboxTemplateAccess: workspaceId => this.ensureSandboxTemplateAccess(workspaceId),
ensureWorkspaceSetupEligibility: workspaceId => this.ensureWorkspaceSetupEligibility(workspaceId),
promptDesignSystemId: () => this.promptDesignSystemId(),
resolveDesignSystemName: designSystemId => this.resolveDesignSystemName(designSystemId),
resolveWorkspaceIdForDesignSystem: designSystemId => this.resolveWorkspaceIdForDesignSystem(designSystemId),
updateSelectedDesignSystem: designSystemId => this.configService.update({ designSystemId }),
},
debug: flags.debug ?? false,
env: this.env,
prototype: createPrototypeService({
env: this.env,
error: message => this.error(message),
openBrowser: url => this.openBrowser(url),
}),
scan: createScanService({
configService: this.configService,
env: this.env,
error: message => this.error(message),
log: message => this.log(message),
runAnalyzeCommand: async (cwd, args) => {
const previousCwd = process.cwd();
try {
process.chdir(cwd);
await this.config.runCommand("code:analyze", args);
}
finally {
process.chdir(previousCwd);
}
},
}),
},
});
clearPersistedSetupSession();
this.log(success("All done."));
}
async resolveWorkspaceIdForDesignSystem(designSystemId) {
const apiClient = await this.apiClient();
const { designSystems } = await apiClient.designSystems.listUserDesignSystems();
const selectedDesignSystem = designSystems.find(designSystem => designSystem.id === designSystemId);
if (selectedDesignSystem?.workspaceId) {
return selectedDesignSystem.workspaceId;
}
return this.getWorkspaceId();
}
async resolveDesignSystemName(designSystemId) {
const apiClient = await this.apiClient();
const { designSystem } = await apiClient.designSystems.get(designSystemId);
return designSystem.meta.name;
}
async ensureWorkspaceSetupEligibility(workspaceId) {
const apiClient = await this.apiClient();
const { membership } = await apiClient.workspaces.list();
const workspaceMembership = membership.find(item => item.workspace.id === workspaceId);
if (!workspaceMembership) {
this.error("You do not have access to the workspace for the selected design system.");
}
const effectiveRole = workspaceMembership.effectiveRole ?? workspaceMembership.role;
if (effectiveRole !== "Owner" && effectiveRole !== "Admin") {
this.error("Supernova setup requires workspace admin access. Ask a workspace admin to continue.");
}
}
async ensureSandboxTemplateAccess(workspaceId) {
const apiClient = await this.apiClient();
const subscriptionResponse = await apiClient.workspaces.subscription.get(workspaceId);
const sandboxTemplatesFeature = subscriptionResponse.subscription?.featuresSummary?.sandboxTemplates;
if (!sandboxTemplatesFeature?.enabled) {
this.error(sandboxTemplatesFeature?.errorMessage ??
"Sandbox templates require an enterprise workspace plan. Upgrade this workspace to enterprise to continue with setup.");
}
}
}
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], Setup.prototype, "run", null);
//# sourceMappingURL=setup.js.map
//# debugId=62dab586-d9bd-5ff3-b08f-4517a9feeadb