diff --git a/README.md b/README.md index 098a352..9463525 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ With Launch CLI, you can interact with the Contentstack Launch platform using th * [Launch CLI plugin](#launch-cli-plugin) -* [Usage](#usage) * [Installation steps](#installation-steps) * [Commands](#commands) @@ -38,4 +37,4 @@ $ csdx launch:functions Run cloud functions locally ``` - \ No newline at end of file + diff --git a/package-lock.json b/package-lock.json index ab35eba..8770eb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-launch", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/cli-launch", - "version": "1.4.1", + "version": "1.5.0", "license": "MIT", "dependencies": { "@apollo/client": "^3.11.8", diff --git a/package.json b/package.json index 1453970..f5d2590 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-launch", - "version": "1.4.1", + "version": "1.5.0", "description": "Launch related operations", "author": "Contentstack CLI", "bin": { diff --git a/src/adapters/file-upload.ts b/src/adapters/file-upload.ts index ba687da..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); @@ -62,7 +63,7 @@ export default class FileUpload extends BaseClass { * @memberof FileUpload */ async createNewProject(): Promise { - const { framework, projectName, buildCommand, outputDirectory, environmentName } = this.config; + const { framework, projectName, buildCommand, outputDirectory, environmentName, serverCommand } = this.config; await this.apolloClient .mutate({ mutation: importProjectMutation, @@ -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, @@ -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}`) ?? {}; @@ -171,6 +174,15 @@ export default class FileUpload extends BaseClass { message: 'Output Directory', default: (this.config.outputDirectories as Record)[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(); diff --git a/src/adapters/github.ts b/src/adapters/github.ts index 74946ac..fd44cd6 100755 --- a/src/adapters/github.ts +++ b/src/adapters/github.ts @@ -64,6 +64,7 @@ export default class GitHub extends BaseClass { outputDirectory, environmentName, provider: gitProvider, + serverCommand, } = this.config; const username = split(repository?.fullName, '/')[0]; @@ -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, }, }, }, @@ -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}`) ?? {}; @@ -182,6 +185,15 @@ export default class GitHub extends BaseClass { message: 'Output Directory', default: (this.config.outputDirectories as Record)[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(); 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 8041461..7d725f4 100755 --- a/src/commands/launch/index.ts +++ b/src/commands/launch/index.ts @@ -17,8 +17,11 @@ 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=