UNPKG

@google/clasp

Version:

Develop Apps Script Projects locally

32 lines (31 loc) 1.45 kB
import { Command } from 'commander'; import { intl } from '../intl.js'; import { assertGcpProjectConfigured, maybePromptForProjectId, withSpinner } from './utils.js'; export const command = new Command('enable-api') .description('Enable a service for the current project.') .argument('<api>', 'Service to enable') .action(async function (serviceName) { var _a; const clasp = this.opts().clasp; await maybePromptForProjectId(clasp); assertGcpProjectConfigured(clasp); try { const spinnerMsg = intl.formatMessage({ id: "UqhzFn", defaultMessage: [{ type: 0, value: "Enabling service..." }] }); await withSpinner(spinnerMsg, async () => { await clasp.services.enableService(serviceName); }); } catch (error) { if (((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'NOT_AUTHORIZED') { const msg = intl.formatMessage({ id: "+y0rAf", defaultMessage: [{ type: 0, value: "Not authorized to enable " }, { type: 1, value: "name" }, { type: 0, value: " or it does not exist." }] }, { name: serviceName, }); this.error(msg); } throw error; } const successMessage = intl.formatMessage({ id: "6lXgOl", defaultMessage: [{ type: 0, value: "Enabled " }, { type: 1, value: "name" }, { type: 0, value: " API." }] }, { name: serviceName, }); console.log(successMessage); });