Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ With Launch CLI, you can interact with the Contentstack Launch platform using th

<!-- toc -->
* [Launch CLI plugin](#launch-cli-plugin)
* [Usage](#usage)
* [Installation steps](#installation-steps)
* [Commands](#commands)
<!-- tocstop -->
Expand Down Expand Up @@ -38,4 +37,4 @@ $ csdx launch:functions
Run cloud functions locally
```

<!-- commandsstop -->
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-launch",
"version": "1.4.1",
"version": "1.5.0",
"description": "Launch related operations",
"author": "Contentstack CLI",
"bin": {
Expand Down
22 changes: 17 additions & 5 deletions src/adapters/file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export default class FileUpload extends BaseClass {
async run(): Promise<void> {
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);
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class FileUpload extends BaseClass {
* @memberof FileUpload
*/
async createNewProject(): Promise<void> {
const { framework, projectName, buildCommand, outputDirectory, environmentName } = this.config;
const { framework, projectName, buildCommand, outputDirectory, environmentName, serverCommand } = this.config;
await this.apolloClient
.mutate({
mutation: importProjectMutation,
Expand All @@ -77,6 +78,7 @@ export default class FileUpload extends BaseClass {
name: environmentName || 'Default',
environmentVariables: map(this.envVariables, ({ key, value }) => ({ key, value })),
buildCommand: buildCommand === undefined || buildCommand === null ? 'npm run build' : buildCommand,
serverCommand: serverCommand === undefined || serverCommand === null ? 'npm run start' : serverCommand,
},
},
skipGitData: true,
Expand Down Expand Up @@ -113,6 +115,7 @@ export default class FileUpload extends BaseClass {
'out-dir': outputDirectory,
'variable-type': variableType,
'env-variables': envVariables,
'server-command': serverCommand,
alias,
} = this.config.flags;
const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {};
Expand Down Expand Up @@ -171,6 +174,15 @@ export default class FileUpload extends BaseClass {
message: 'Output Directory',
default: (this.config.outputDirectories as Record<string, string>)[this.config?.framework || 'OTHER'],
}));
if (this.config.framework && this.config.supportedFrameworksForServerCommands.includes(this.config.framework)) {
this.config.serverCommand =
serverCommand ||
(await cliux.inquire({
type: 'input',
name: 'serverCommand',
message: 'Server Command',
}));
}
this.config.variableType = variableType as unknown as string;
this.config.envVariables = envVariables;
await this.handleEnvImportFlow();
Expand Down
12 changes: 12 additions & 0 deletions src/adapters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class GitHub extends BaseClass {
outputDirectory,
environmentName,
provider: gitProvider,
serverCommand,
} = this.config;
const username = split(repository?.fullName, '/')[0];

Expand All @@ -87,6 +88,7 @@ export default class GitHub extends BaseClass {
name: environmentName || 'Default',
environmentVariables: map(this.envVariables, ({ key, value }) => ({ key, value })),
buildCommand: buildCommand === undefined || buildCommand === null ? 'npm run build' : buildCommand,
serverCommand: serverCommand === undefined || serverCommand === null ? 'npm run start' : serverCommand,
},
},
},
Expand Down Expand Up @@ -122,6 +124,7 @@ export default class GitHub extends BaseClass {
'out-dir': outputDirectory,
'variable-type': variableType,
'env-variables': envVariables,
'server-command': serverCommand,
alias,
} = this.config.flags;
const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {};
Expand Down Expand Up @@ -182,6 +185,15 @@ export default class GitHub extends BaseClass {
message: 'Output Directory',
default: (this.config.outputDirectories as Record<string, string>)[this.config?.framework || 'OTHER'],
}));
if (this.config.framework && this.config.supportedFrameworksForServerCommands.includes(this.config.framework)) {
this.config.serverCommand =
serverCommand ||
(await ux.inquire({
type: 'input',
name: 'serverCommand',
message: 'Server Command',
}));
}
this.config.variableType = variableType as unknown as string;
this.config.envVariables = envVariables;
await this.handleEnvImportFlow();
Expand Down
73 changes: 34 additions & 39 deletions src/adapters/pre-check.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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<string, any> = {
"Project Name": name,
"Project Type":
(this.config.providerMapper as Record<string, any>)[projectType] ||
"",
'Project Name': name,
'Project Type': (this.config.providerMapper as Record<string, any>)[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: {
Expand All @@ -104,7 +101,7 @@ export default class PreCheck extends BaseClass {
Repository: {
minWidth: 7,
},
"Framework Preset": {
'Framework Preset': {
minWidth: 7,
},
});
Expand All @@ -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) {}
Expand All @@ -133,19 +130,17 @@ export default class PreCheck extends BaseClass {
* @memberof PreCheck
*/
async identifyWhatProjectItIs(): Promise<void> {
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.'):
this.config.provider = 'GitHub';
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,
});
}
Expand Down
24 changes: 20 additions & 4 deletions src/commands/launch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export default class Launch extends BaseCommand<typeof Launch> {
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file>',
'<%= config.bin %> <%= command.id %> --type <options: GitHub|FileUpload>',
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --type <options: GitHub|FileUpload>',
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-latest',
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-latest --redeploy-last-upload',
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload>',
'<%= 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>',
'<%= 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>',
'<%= 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>',
'<%= 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"',
];
Expand Down Expand Up @@ -52,9 +55,13 @@ export default class Launch extends BaseCommand<typeof Launch> {
'out-dir': Flags.string({
description: '[optional] Output Directory.',
}),
'server-command': Flags.string({
description: '[optional] Server Command.',
}),
'variable-type': Flags.string({
options: [...config.variablePreparationTypeOptions],
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>',
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>',
}),
'show-variables': Flags.boolean({
hidden: true,
Expand All @@ -70,9 +77,18 @@ export default class Launch extends BaseCommand<typeof Launch> {
description: '[optional] Alias (name) for the delivery token.',
}),
'env-variables': Flags.string({
description: '[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
description:
'[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
}),
'redeploy-latest': Flags.boolean({
description: '[optional] Redeploy latest commit/code',
default: false,
}),
};
'redeploy-last-upload': Flags.boolean({
description: '[optional] Redeploy with last file upload',
default: false,
}),
};

async run(): Promise<void> {
if (!this.flags.init) {
Expand Down Expand Up @@ -134,7 +150,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
managementSdk: this.managementSdk,
analyticsInfo: this.context.analyticsInfo,
});

await this.preCheck.run(!this.flags.type);
}
}
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const config = {
'Import variables from the local env file',
],
variableType: '',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX']
};

export default config;
Loading