Skip to content

Commit 524eded

Browse files
committed
feat: add redeploy-latest & redeploy-last-upload flag support in launch command
1 parent 59a70c7 commit 524eded

File tree

3 files changed

+55
-47
lines changed

3 files changed

+55
-47
lines changed

src/adapters/file-upload.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export default class FileUpload extends BaseClass {
2727
async run(): Promise<void> {
2828
if (this.config.isExistingProject) {
2929
await this.initApolloClient();
30-
if (
31-
!(await cliux.inquire({
30+
const uploadLastFile =
31+
this.config['redeploy-last-upload'] ||
32+
(await cliux.inquire({
3233
type: 'confirm',
3334
default: false,
3435
name: 'uploadLastFile',
3536
message: 'Redeploy with last file upload?',
36-
}))
37-
) {
37+
}));
38+
if (!uploadLastFile) {
3839
await this.createSignedUploadUrl();
3940
const { zipName, zipPath } = await this.archive();
4041
await this.uploadFile(zipName, zipPath);

src/adapters/pre-check.ts

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import find from "lodash/find";
2-
import { resolve } from "path";
3-
import { existsSync } from "fs";
4-
import isEmpty from "lodash/isEmpty";
5-
import includes from "lodash/includes";
6-
import { cliux as ux } from "@contentstack/cli-utilities";
1+
import find from 'lodash/find';
2+
import { resolve } from 'path';
3+
import { existsSync } from 'fs';
4+
import isEmpty from 'lodash/isEmpty';
5+
import includes from 'lodash/includes';
6+
import { cliux as ux } from '@contentstack/cli-utilities';
77

8-
import BaseClass from "./base-class";
9-
import { getRemoteUrls } from "../util";
8+
import BaseClass from './base-class';
9+
import { getRemoteUrls } from '../util';
1010

1111
export default class PreCheck extends BaseClass {
1212
public projectBasePath: string = process.cwd();
@@ -44,17 +44,17 @@ export default class PreCheck extends BaseClass {
4444
} else {
4545
this.validateLaunchConfig();
4646

47-
this.log("Existing launch project identified", "info");
47+
this.log('Existing launch project identified', 'info');
4848

4949
await this.displayPreDeploymentDetails();
50-
51-
if (
52-
!(await ux.inquire({
53-
type: "confirm",
54-
name: "deployLatestSource",
55-
message: "Redeploy latest commit/code?",
56-
}))
57-
) {
50+
const deployLatestCode =
51+
this.config['redeploy-latest'] ||
52+
(await ux.inquire({
53+
type: 'confirm',
54+
name: 'deployLatestSource',
55+
message: 'Redeploy latest commit/code?',
56+
}));
57+
if (!deployLatestCode) {
5858
this.exit(1);
5959
}
6060
}
@@ -68,34 +68,31 @@ export default class PreCheck extends BaseClass {
6868
*/
6969
async displayPreDeploymentDetails() {
7070
if (this.config.config && !isEmpty(this.config.currentConfig)) {
71-
this.log(""); // Empty line
72-
this.log("Current Project details:", { bold: true, color: "green" });
73-
this.log(""); // Empty line
74-
const { name, projectType, repository, environments } =
75-
this.config.currentConfig;
71+
this.log(''); // Empty line
72+
this.log('Current Project details:', { bold: true, color: 'green' });
73+
this.log(''); // Empty line
74+
const { name, projectType, repository, environments } = this.config.currentConfig;
7675
const [environment] = environments;
7776

7877
const detail: Record<string, any> = {
79-
"Project Name": name,
80-
"Project Type":
81-
(this.config.providerMapper as Record<string, any>)[projectType] ||
82-
"",
78+
'Project Name': name,
79+
'Project Type': (this.config.providerMapper as Record<string, any>)[projectType] || '',
8380
Environment: environment.name,
84-
"Framework Preset":
81+
'Framework Preset':
8582
find(this.config.listOfFrameWorks, {
8683
value: environment.frameworkPreset,
87-
})?.name || "",
84+
})?.name || '',
8885
};
8986

9087
if (repository?.repositoryName) {
91-
detail["Repository"] = repository.repositoryName;
88+
detail['Repository'] = repository.repositoryName;
9289
}
9390

9491
ux.table([detail, {}], {
95-
"Project Name": {
92+
'Project Name': {
9693
minWidth: 7,
9794
},
98-
"Project Type": {
95+
'Project Type': {
9996
minWidth: 7,
10097
},
10198
Environment: {
@@ -104,7 +101,7 @@ export default class PreCheck extends BaseClass {
104101
Repository: {
105102
minWidth: 7,
106103
},
107-
"Framework Preset": {
104+
'Framework Preset': {
108105
minWidth: 7,
109106
},
110107
});
@@ -120,7 +117,7 @@ export default class PreCheck extends BaseClass {
120117
try {
121118
// NOTE Perform validations here
122119
if (isEmpty(require(this.config.config as string))) {
123-
this.log("Invalid Launch config!", "warn");
120+
this.log('Invalid Launch config!', 'warn');
124121
this.exit(1);
125122
}
126123
} catch (error) {}
@@ -133,19 +130,17 @@ export default class PreCheck extends BaseClass {
133130
* @memberof PreCheck
134131
*/
135132
async identifyWhatProjectItIs(): Promise<void> {
136-
const localRemoteUrl =
137-
(await getRemoteUrls(resolve(this.config.projectBasePath, ".git/config")))
138-
?.origin || "";
133+
const localRemoteUrl = (await getRemoteUrls(resolve(this.config.projectBasePath, '.git/config')))?.origin || '';
139134

140135
switch (true) {
141136
case includes(localRemoteUrl, 'github.'):
142137
this.config.provider = 'GitHub';
143138
this.log('Git project identified', 'info');
144139
break;
145140
default:
146-
if (existsSync(resolve(this.config.projectBasePath, ".git"))) {
147-
this.log("Git config found but remote URL not found in the config!", {
148-
color: "yellow",
141+
if (existsSync(resolve(this.config.projectBasePath, '.git'))) {
142+
this.log('Git config found but remote URL not found in the config!', {
143+
color: 'yellow',
149144
bold: true,
150145
});
151146
}

src/commands/launch/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default class Launch extends BaseCommand<typeof Launch> {
1717
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file>',
1818
'<%= config.bin %> <%= command.id %> --type <options: GitHub|FileUpload>',
1919
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --type <options: GitHub|FileUpload>',
20+
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-latest',
21+
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-latest --redeploy-last-upload',
2022
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload>',
2123
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value>',
2224
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --server-command=<value>',
@@ -58,7 +60,8 @@ export default class Launch extends BaseCommand<typeof Launch> {
5860
}),
5961
'variable-type': Flags.string({
6062
options: [...config.variablePreparationTypeOptions],
61-
description: '[optional] Provide a variable type. <options: Import variables from a stack|Manually add custom variables to the list|Import variables from the local env file>',
63+
description:
64+
'[optional] Provide a variable type. <options: Import variables from a stack|Manually add custom variables to the list|Import variables from the local env file>',
6265
}),
6366
'show-variables': Flags.boolean({
6467
hidden: true,
@@ -74,9 +77,18 @@ export default class Launch extends BaseCommand<typeof Launch> {
7477
description: '[optional] Alias (name) for the delivery token.',
7578
}),
7679
'env-variables': Flags.string({
77-
description: '[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
80+
description:
81+
'[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
7882
}),
79-
};
83+
'redeploy-latest': Flags.boolean({
84+
description: '[optional] Redeploy latest commit/code',
85+
default: false,
86+
}),
87+
'redeploy-last-upload': Flags.boolean({
88+
description: '[optional] Redeploy with last file upload',
89+
default: false,
90+
}),
91+
};
8092

8193
async run(): Promise<void> {
8294
if (!this.flags.init) {
@@ -138,7 +150,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
138150
managementSdk: this.managementSdk,
139151
analyticsInfo: this.context.analyticsInfo,
140152
});
141-
153+
142154
await this.preCheck.run(!this.flags.type);
143155
}
144156
}

0 commit comments

Comments
 (0)