UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

80 lines 3.19 kB
import { globalOptionsZod } from '../../../../Command.js'; import { powerPlatform } from '../../../../utils/powerPlatform.js'; import { validation } from '../../../../utils/validation.js'; import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js'; import commands from '../../commands.js'; import { z } from 'zod'; import request from '../../../../request.js'; import { cli } from '../../../../cli/cli.js'; export const options = z.strictObject({ ...globalOptionsZod.shape, url: z.string().optional() .refine(url => url === undefined || validation.isValidPowerPagesUrl(url) === true, { error: e => `'${e.input}' is not a valid Power Pages URL.` }) .alias('u'), id: z.uuid().optional().alias('i'), name: z.string().optional().alias('n'), environmentName: z.string().alias('e'), force: z.boolean().optional().alias('f') }); class PpWebSiteRemoveCommand extends PowerPlatformCommand { get name() { return commands.WEBSITE_REMOVE; } get description() { return 'Removes the specified Power Pages website from the list of active sites.'; } get schema() { return options; } getRefinedSchema(schema) { return schema .refine(options => [options.url, options.id, options.name].filter(x => x !== undefined).length === 1, { error: `Specify either url, id or name, but not multiple.` }); } async commandAction(logger, args) { if (args.options.verbose) { await logger.logToStderr(`Removing website '${args.options.id || args.options.name || args.options.url}'...`); } if (args.options.force) { await this.deleteWebsite(args); } else { const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove website '${args.options.id || args.options.name || args.options.url}'?` }); if (result) { await this.deleteWebsite(args); } } } async getWebsiteId(args) { if (args.options.id) { return args.options.id; } if (args.options.name) { const website = await powerPlatform.getWebsiteByName(args.options.environmentName, args.options.name); return website.id; } const website = await powerPlatform.getWebsiteByUrl(args.options.environmentName, args.options.url); return website.id; } async deleteWebsite(args) { try { const websiteId = await this.getWebsiteId(args); const requestOptions = { url: `https://api.powerplatform.com/powerpages/environments/${args.options.environmentName}/websites/${websiteId}?api-version=2022-03-01-preview`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json' }; await request.delete(requestOptions); } catch (err) { this.handleRejectedODataJsonPromise(err); } } } export default new PpWebSiteRemoveCommand(); //# sourceMappingURL=website-remove.js.map