From 59a70c73b401731bf3307e4bb9e9cc4d577112da Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 22 Jan 2025 13:19:14 +0530 Subject: [PATCH 1/2] feat: add server command flag in launch --- README.md | 3 +-- package-lock.json | 4 ++-- package.json | 2 +- src/adapters/file-upload.ts | 13 ++++++++++++- src/adapters/github.ts | 12 ++++++++++++ src/commands/launch/index.ts | 4 ++++ src/config/index.ts | 1 + 7 files changed, 33 insertions(+), 6 deletions(-) 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..04ded7d 100755 --- a/src/adapters/file-upload.ts +++ b/src/adapters/file-upload.ts @@ -62,7 +62,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 +77,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 +114,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 +173,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/commands/launch/index.ts b/src/commands/launch/index.ts index 8041461..f9c4f83 100755 --- a/src/commands/launch/index.ts +++ b/src/commands/launch/index.ts @@ -19,6 +19,7 @@ export default class Launch extends BaseCommand { '<%= config.bin %> <%= command.id %> --data-dir --type ', '<%= config.bin %> <%= command.id %> --config --type ', '<%= config.bin %> <%= command.id %> --config --type --name= --environment= --branch= --build-command= --framework=