From 524ededc0d411d15abc6539d58c59bb23a4031b0 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 22 Jan 2025 15:47:42 +0530 Subject: [PATCH] feat: add redeploy-latest & redeploy-last-upload flag support in launch command --- src/adapters/file-upload.ts | 9 +++-- src/adapters/pre-check.ts | 73 +++++++++++++++++------------------- src/commands/launch/index.ts | 20 ++++++++-- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/adapters/file-upload.ts b/src/adapters/file-upload.ts index 04ded7d..eb3ccba 100755 --- a/src/adapters/file-upload.ts +++ b/src/adapters/file-upload.ts @@ -27,14 +27,15 @@ export default class FileUpload extends BaseClass { async run(): Promise { if (this.config.isExistingProject) { await this.initApolloClient(); - if ( - !(await cliux.inquire({ + const uploadLastFile = + this.config['redeploy-last-upload'] || + (await cliux.inquire({ type: 'confirm', default: false, name: 'uploadLastFile', message: 'Redeploy with last file upload?', - })) - ) { + })); + if (!uploadLastFile) { await this.createSignedUploadUrl(); const { zipName, zipPath } = await this.archive(); await this.uploadFile(zipName, zipPath); diff --git a/src/adapters/pre-check.ts b/src/adapters/pre-check.ts index bccb069..cb08d9a 100755 --- a/src/adapters/pre-check.ts +++ b/src/adapters/pre-check.ts @@ -1,12 +1,12 @@ -import find from "lodash/find"; -import { resolve } from "path"; -import { existsSync } from "fs"; -import isEmpty from "lodash/isEmpty"; -import includes from "lodash/includes"; -import { cliux as ux } from "@contentstack/cli-utilities"; +import find from 'lodash/find'; +import { resolve } from 'path'; +import { existsSync } from 'fs'; +import isEmpty from 'lodash/isEmpty'; +import includes from 'lodash/includes'; +import { cliux as ux } from '@contentstack/cli-utilities'; -import BaseClass from "./base-class"; -import { getRemoteUrls } from "../util"; +import BaseClass from './base-class'; +import { getRemoteUrls } from '../util'; export default class PreCheck extends BaseClass { public projectBasePath: string = process.cwd(); @@ -44,17 +44,17 @@ export default class PreCheck extends BaseClass { } else { this.validateLaunchConfig(); - this.log("Existing launch project identified", "info"); + this.log('Existing launch project identified', 'info'); await this.displayPreDeploymentDetails(); - - if ( - !(await ux.inquire({ - type: "confirm", - name: "deployLatestSource", - message: "Redeploy latest commit/code?", - })) - ) { + const deployLatestCode = + this.config['redeploy-latest'] || + (await ux.inquire({ + type: 'confirm', + name: 'deployLatestSource', + message: 'Redeploy latest commit/code?', + })); + if (!deployLatestCode) { this.exit(1); } } @@ -68,34 +68,31 @@ export default class PreCheck extends BaseClass { */ async displayPreDeploymentDetails() { if (this.config.config && !isEmpty(this.config.currentConfig)) { - this.log(""); // Empty line - this.log("Current Project details:", { bold: true, color: "green" }); - this.log(""); // Empty line - const { name, projectType, repository, environments } = - this.config.currentConfig; + this.log(''); // Empty line + this.log('Current Project details:', { bold: true, color: 'green' }); + this.log(''); // Empty line + const { name, projectType, repository, environments } = this.config.currentConfig; const [environment] = environments; const detail: Record = { - "Project Name": name, - "Project Type": - (this.config.providerMapper as Record)[projectType] || - "", + 'Project Name': name, + 'Project Type': (this.config.providerMapper as Record)[projectType] || '', Environment: environment.name, - "Framework Preset": + 'Framework Preset': find(this.config.listOfFrameWorks, { value: environment.frameworkPreset, - })?.name || "", + })?.name || '', }; if (repository?.repositoryName) { - detail["Repository"] = repository.repositoryName; + detail['Repository'] = repository.repositoryName; } ux.table([detail, {}], { - "Project Name": { + 'Project Name': { minWidth: 7, }, - "Project Type": { + 'Project Type': { minWidth: 7, }, Environment: { @@ -104,7 +101,7 @@ export default class PreCheck extends BaseClass { Repository: { minWidth: 7, }, - "Framework Preset": { + 'Framework Preset': { minWidth: 7, }, }); @@ -120,7 +117,7 @@ export default class PreCheck extends BaseClass { try { // NOTE Perform validations here if (isEmpty(require(this.config.config as string))) { - this.log("Invalid Launch config!", "warn"); + this.log('Invalid Launch config!', 'warn'); this.exit(1); } } catch (error) {} @@ -133,9 +130,7 @@ export default class PreCheck extends BaseClass { * @memberof PreCheck */ async identifyWhatProjectItIs(): Promise { - const localRemoteUrl = - (await getRemoteUrls(resolve(this.config.projectBasePath, ".git/config"))) - ?.origin || ""; + const localRemoteUrl = (await getRemoteUrls(resolve(this.config.projectBasePath, '.git/config')))?.origin || ''; switch (true) { case includes(localRemoteUrl, 'github.'): @@ -143,9 +138,9 @@ export default class PreCheck extends BaseClass { this.log('Git project identified', 'info'); break; default: - if (existsSync(resolve(this.config.projectBasePath, ".git"))) { - this.log("Git config found but remote URL not found in the config!", { - color: "yellow", + if (existsSync(resolve(this.config.projectBasePath, '.git'))) { + this.log('Git config found but remote URL not found in the config!', { + color: 'yellow', bold: true, }); } diff --git a/src/commands/launch/index.ts b/src/commands/launch/index.ts index f9c4f83..7d725f4 100755 --- a/src/commands/launch/index.ts +++ b/src/commands/launch/index.ts @@ -17,6 +17,8 @@ export default class Launch extends BaseCommand { '<%= config.bin %> <%= command.id %> --config ', '<%= config.bin %> <%= command.id %> --type ', '<%= config.bin %> <%= command.id %> --data-dir --type ', + '<%= config.bin %> <%= command.id %> --data-dir --redeploy-latest', + '<%= config.bin %> <%= command.id %> --data-dir --redeploy-latest --redeploy-last-upload', '<%= config.bin %> <%= command.id %> --config --type ', '<%= config.bin %> <%= command.id %> --config --type --name= --environment= --branch= --build-command= --framework=