Skip to content

Commit

Permalink
refactor: get rid of detect platform (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortza81 authored Dec 17, 2024
1 parent 03c4784 commit 438b442
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -198,7 +168,27 @@ export default class Deploy extends Command {
`v1/projects/${config.app}`,
).json<IProjectDetailsResponse>();
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) {
Expand Down

0 comments on commit 438b442

Please sign in to comment.