UNPKG

sdk.do

Version:

SDK for publishing Functions, Workflows, and Databases to NPM

90 lines (89 loc) 2.71 kB
import { API } from './client.js'; export class CLI { api; configPath; constructor(options = {}) { this.api = new API({ apiKey: options.apiKey, baseUrl: options.baseUrl, }); this.configPath = options.configPath || '.ai/config.json'; } /** * Initialize a new package */ async init(options = {}) { console.log('Initializing new package...'); return Promise.resolve(); } /** * Login to sdk.do and store credentials */ async login(options = {}) { console.log('Logging in to sdk.do...'); return Promise.resolve(); } /** * Logout and remove stored credentials */ async logout() { console.log('Logging out from sdk.do...'); return Promise.resolve(); } /** * List all packages */ async listPackages() { console.log('Listing packages...'); return this.api.listPackages(); } /** * Create a new package */ async createPackage(name, options = {}) { console.log(`Creating package ${name}...`); const packageData = { name, package: { name, version: '0.0.1', description: `${name} package`, main: 'dist/index.js', types: 'dist/index.d.ts', files: ['dist', 'README.md'], license: 'MIT', }, collections: options.collections?.map((collection) => ({ collection })) || [], }; return this.api.createPackage(packageData); } /** * Add a collection to a package */ async addCollection(packageId, collection) { console.log(`Adding ${collection} to package ${packageId}...`); return this.api.addCollectionToPackage(packageId, collection); } /** * Remove a collection from a package */ async removeCollection(packageId, collection) { console.log(`Removing ${collection} from package ${packageId}...`); return this.api.removeCollectionFromPackage(packageId, collection); } /** * Update package.json for a package */ async updatePackageJson(packageId, packageJson) { console.log(`Updating package.json for package ${packageId}...`); return this.api.updatePackageJson(packageId, packageJson); } /** * Publish a package to NPM */ async publish(packageId, options = {}) { const action = options.dryRun ? 'Dry run publishing' : 'Publishing'; console.log(`${action} package ${packageId} to NPM...`); return this.api.publishPackage(packageId, options); } }