Skip to content

Commit 4321d3b

Browse files
authored
Merge pull request #15 from contentstack/development
DX | 27-01-2025 | Release
2 parents 6e4ddb7 + e498d47 commit 4321d3b

File tree

8 files changed

+88
-53
lines changed

8 files changed

+88
-53
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ With Launch CLI, you can interact with the Contentstack Launch platform using th
66

77
<!-- toc -->
88
* [Launch CLI plugin](#launch-cli-plugin)
9-
* [Usage](#usage)
109
* [Installation steps](#installation-steps)
1110
* [Commands](#commands)
1211
<!-- tocstop -->
@@ -38,4 +37,4 @@ $ csdx launch:functions
3837
Run cloud functions locally
3938
```
4039

41-
<!-- commandsstop -->
40+
<!-- commandsstop -->

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-launch",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"description": "Launch related operations",
55
"author": "Contentstack CLI",
66
"bin": {

src/adapters/file-upload.ts

Lines changed: 17 additions & 5 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);
@@ -62,7 +63,7 @@ export default class FileUpload extends BaseClass {
6263
* @memberof FileUpload
6364
*/
6465
async createNewProject(): Promise<void> {
65-
const { framework, projectName, buildCommand, outputDirectory, environmentName } = this.config;
66+
const { framework, projectName, buildCommand, outputDirectory, environmentName, serverCommand } = this.config;
6667
await this.apolloClient
6768
.mutate({
6869
mutation: importProjectMutation,
@@ -77,6 +78,7 @@ export default class FileUpload extends BaseClass {
7778
name: environmentName || 'Default',
7879
environmentVariables: map(this.envVariables, ({ key, value }) => ({ key, value })),
7980
buildCommand: buildCommand === undefined || buildCommand === null ? 'npm run build' : buildCommand,
81+
serverCommand: serverCommand === undefined || serverCommand === null ? 'npm run start' : serverCommand,
8082
},
8183
},
8284
skipGitData: true,
@@ -113,6 +115,7 @@ export default class FileUpload extends BaseClass {
113115
'out-dir': outputDirectory,
114116
'variable-type': variableType,
115117
'env-variables': envVariables,
118+
'server-command': serverCommand,
116119
alias,
117120
} = this.config.flags;
118121
const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {};
@@ -171,6 +174,15 @@ export default class FileUpload extends BaseClass {
171174
message: 'Output Directory',
172175
default: (this.config.outputDirectories as Record<string, string>)[this.config?.framework || 'OTHER'],
173176
}));
177+
if (this.config.framework && this.config.supportedFrameworksForServerCommands.includes(this.config.framework)) {
178+
this.config.serverCommand =
179+
serverCommand ||
180+
(await cliux.inquire({
181+
type: 'input',
182+
name: 'serverCommand',
183+
message: 'Server Command',
184+
}));
185+
}
174186
this.config.variableType = variableType as unknown as string;
175187
this.config.envVariables = envVariables;
176188
await this.handleEnvImportFlow();

src/adapters/github.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default class GitHub extends BaseClass {
6464
outputDirectory,
6565
environmentName,
6666
provider: gitProvider,
67+
serverCommand,
6768
} = this.config;
6869
const username = split(repository?.fullName, '/')[0];
6970

@@ -87,6 +88,7 @@ export default class GitHub extends BaseClass {
8788
name: environmentName || 'Default',
8889
environmentVariables: map(this.envVariables, ({ key, value }) => ({ key, value })),
8990
buildCommand: buildCommand === undefined || buildCommand === null ? 'npm run build' : buildCommand,
91+
serverCommand: serverCommand === undefined || serverCommand === null ? 'npm run start' : serverCommand,
9092
},
9193
},
9294
},
@@ -122,6 +124,7 @@ export default class GitHub extends BaseClass {
122124
'out-dir': outputDirectory,
123125
'variable-type': variableType,
124126
'env-variables': envVariables,
127+
'server-command': serverCommand,
125128
alias,
126129
} = this.config.flags;
127130
const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {};
@@ -182,6 +185,15 @@ export default class GitHub extends BaseClass {
182185
message: 'Output Directory',
183186
default: (this.config.outputDirectories as Record<string, string>)[this.config?.framework || 'OTHER'],
184187
}));
188+
if (this.config.framework && this.config.supportedFrameworksForServerCommands.includes(this.config.framework)) {
189+
this.config.serverCommand =
190+
serverCommand ||
191+
(await ux.inquire({
192+
type: 'input',
193+
name: 'serverCommand',
194+
message: 'Server Command',
195+
}));
196+
}
185197
this.config.variableType = variableType as unknown as string;
186198
this.config.envVariables = envVariables;
187199
await this.handleEnvImportFlow();

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: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ 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>',
24+
'<%= 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>',
2225
'<%= 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> --variable-type="Import variables from a stack" --alias=<value>',
2326
'<%= 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> --variable-type="Manually add custom variables to the list" --env-variables="APP_ENV:prod, TEST_ENV:testVal"',
2427
];
@@ -52,9 +55,13 @@ export default class Launch extends BaseCommand<typeof Launch> {
5255
'out-dir': Flags.string({
5356
description: '[optional] Output Directory.',
5457
}),
58+
'server-command': Flags.string({
59+
description: '[optional] Server Command.',
60+
}),
5561
'variable-type': Flags.string({
5662
options: [...config.variablePreparationTypeOptions],
57-
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>',
5865
}),
5966
'show-variables': Flags.boolean({
6067
hidden: true,
@@ -70,9 +77,18 @@ export default class Launch extends BaseCommand<typeof Launch> {
7077
description: '[optional] Alias (name) for the delivery token.',
7178
}),
7279
'env-variables': Flags.string({
73-
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.',
82+
}),
83+
'redeploy-latest': Flags.boolean({
84+
description: '[optional] Redeploy latest commit/code',
85+
default: false,
7486
}),
75-
};
87+
'redeploy-last-upload': Flags.boolean({
88+
description: '[optional] Redeploy with last file upload',
89+
default: false,
90+
}),
91+
};
7692

7793
async run(): Promise<void> {
7894
if (!this.flags.init) {
@@ -134,7 +150,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
134150
managementSdk: this.managementSdk,
135151
analyticsInfo: this.context.analyticsInfo,
136152
});
137-
153+
138154
await this.preCheck.run(!this.flags.type);
139155
}
140156
}

src/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const config = {
4040
'Import variables from the local env file',
4141
],
4242
variableType: '',
43+
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX']
4344
};
4445

4546
export default config;

0 commit comments

Comments
 (0)