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
9 changes: 5 additions & 4 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
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
20 changes: 16 additions & 4 deletions src/commands/launch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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>',
Expand Down Expand Up @@ -58,7 +60,8 @@ export default class Launch extends BaseCommand<typeof Launch> {
}),
'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 @@ -74,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 @@ -138,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);
}
}
Loading