UNPKG

@nodescript/cli

Version:
79 lines 3.27 kB
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 chalk from 'chalk'; import { dep } from 'mesh-ioc'; import { ApiManager } from '../managers/api.js'; import { BuilderManager } from '../managers/builder.js'; import { ConfigManager } from '../managers/config.js'; import { WorkdirManager } from '../managers/workdir.js'; export class PublishTask { async run() { console.info(`Publishing to `, chalk.green(this.config.options.apiUrl)); const map = await this.fetchModuleMap(); for await (const mod of this.workdir.readModuleDescriptors()) { await this.publishModule(map, mod); } } async publishModule(existingModules, mod) { const { file, sourceUrl, channel, visibility } = mod; try { const res = await this.builder.buildModuleFile(file); const { moduleSpec, computeCode } = res; const existing = existingModules.get(moduleSpec.moduleName); if (existing && existing.refs[moduleSpec.version]) { // Skipping return; } await this.api.publishEsm({ workspaceId: this.config.options.workspaceId, moduleSpec, computeCode, visibility, channel, sourceUrl: sourceUrl.replace(/\{file\}/ig, file), }); console.info(' ', chalk.yellow(file)); console.info(chalk.green(' published')); } catch (error) { if (error.status === 409) { return; } console.info(' ', chalk.yellow(file)); console.error(chalk.yellow(error.status), chalk.red(error.message)); } } async fetchModuleMap() { const map = new Map(); const { workspaceId } = this.config.options; const existingModules = await this.api.getWorkspaceModules(workspaceId); for (const module of existingModules) { map.set(module.moduleSpec.moduleName, module); } return map; } } __decorate([ dep(), __metadata("design:type", ApiManager) ], PublishTask.prototype, "api", void 0); __decorate([ dep(), __metadata("design:type", WorkdirManager) ], PublishTask.prototype, "workdir", void 0); __decorate([ dep(), __metadata("design:type", ConfigManager) ], PublishTask.prototype, "config", void 0); __decorate([ dep(), __metadata("design:type", BuilderManager) ], PublishTask.prototype, "builder", void 0); //# sourceMappingURL=publish.js.map