From 438b442925bb416f730bf1ad8693b179c084d106 Mon Sep 17 00:00:00 2001 From: Morteza <139925612+Mortza81@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:22:06 +0330 Subject: [PATCH] refactor: get rid of detect platform (#203) --- src/commands/deploy.ts | 50 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index 148244d..812b530 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -3,7 +3,6 @@ import path from 'node:path'; import fs from 'fs-extra'; import chalk from 'chalk'; import bytes from 'bytes'; -import moment from 'moment'; import ora, { Ora } from 'ora'; import inquirer from 'inquirer'; import ProgressBar from 'progress'; @@ -31,7 +30,6 @@ import { createDebugLogger } from '../utils/output.js'; import createArchive from '../utils/create-archive.js'; import ReleaseFailed from '../errors/release-failed.js'; import prepareTmpDirectory from '../services/tmp-dir.js'; -import detectPlatform from '../utils/detect-platform.js'; import collectGitInfo from '../utils/collect-git-info.js'; import ICreatedRelease from '../types/created-release.js'; import { BundlePlanError } from '../errors/bundle-plan.js'; @@ -126,38 +124,10 @@ export default class Deploy extends Command { this.validateDeploymentConfig(config); - let isPlatformDetected = false; - if (!config.image) { - if (!config.platform) { - try { - config.platform = detectPlatform(config.path); - isPlatformDetected = true; - } catch (error) { - return this.error(error.message); - } - } - - this.validatePlatform(config.platform, config.path); - } else { - config.platform = 'docker'; - } - if (!config.app) { config.app = await this.promptProject(); } - if (!config.port) { - config.port = - getPort(config.platform) || (await promptPort(config.platform)); - } - - this.logKeyValue('App', config.app); - this.logKeyValue('Path', config.path); - isPlatformDetected - ? this.logKeyValue('Detected platform', config.platform) - : this.logKeyValue('Platform', config.platform); - this.logKeyValue('Port', String(config.port)); - if (config.disks) { this.logKeyValue('Disks'); for (const disk of config.disks) { @@ -198,7 +168,27 @@ export default class Deploy extends Command { `v1/projects/${config.app}`, ).json(); bundlePlanID = project.bundlePlanID; + if (!config.image) { + if (!config.platform) { + try { + config.platform = project.type; + } catch (error) { + return this.error(error.message); + } + } + this.validatePlatform(config.platform, config.path); + } else { + config.platform = 'docker'; + } + if (!config.port) { + config.port = + getPort(config.platform) || (await promptPort(config.platform)); + } + this.logKeyValue('App', config.app); + this.logKeyValue('Path', config.path); + this.logKeyValue('Platform', config.platform); + this.logKeyValue('Port', String(config.port)); const response = await this.deploy(config); if (flags.detach) {