/*! * Copyright (c) Microsoft. All rights reserved. * Licensed under the MIT license. See LICENSE file in the project. */ import type { Command } from 'commander' import { deployBlob } from '../steps/azure/index.mjs' enum DeployType { AzureBlobStorage = 'azure-blob-storage', } interface DeployCommandOptions { verbose: boolean type: DeployType storageAccount: string storageAccountKey: string paths: string } export default function deploy(program: Command): void { program .command('deploy') .description('deploys standard essex projects') .option('-v, --verbose', 'verbose output') .option('--storageAccount ', 'Azure Storage Account Id') .option( '--storageAccountKey ', 'Azure Storage Account Key', ) .option( '--type ', 'deployment type: (e.g. azure-blob-storage)', 'azure-blob-storage', ) .option( '--paths ', 'When using Azure-Blob-Storage deployment, the paths to upload into the blob container, comma-delimited.', 'build/,public/,/dist', ) .action(async (options: DeployCommandOptions): Promise => { await execute(options) }) } function execute(options: DeployCommandOptions): Promise { if (!options.type) { throw new Error("'type' argument not set") } switch (options.type) { case DeployType.AzureBlobStorage: { return executeAzureBlobDeploy(options) } default: throw new Error(`Unhandled deploy type: ${options.type as string}`) } } function executeAzureBlobDeploy({ storageAccount, storageAccountKey, verbose = false, paths, }: DeployCommandOptions) { if (!storageAccount) { throw new Error('storageAccount must be set') } if (!storageAccountKey) { throw new Error('storageAccountKey must be set') } const pathsToPass = paths.split(',').map((p) => p.trim()) return deployBlob(storageAccount, storageAccountKey, verbose, pathsToPass) }