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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Create an environment in a Launch project and follow its first deployment
```
USAGE
$ csdx launch:env:create [--config <value>] [-d <value>] [--org <value>] [--project <value>] [--name <value>]
[--description <value>] [--branch <value>] [--framework <value>] [--build-cmd <value>] [--server-cmd <value>]
[--branch <value>] [--framework <value>] [--build-cmd <value>] [--server-cmd <value>]
[--output-dir <value>] [--res-mode <value>] [--auto-deploy <value>] [--cs-auth <value>] [--var <value>...] [--dotenv
<value>...] [--from-stack] [-a <value>]

Expand All @@ -330,7 +330,6 @@ FLAGS
--build-cmd=<value> Build command
--config=<value> Path to the local '.cs-launch.json' file
--cs-auth=<value> Contentstack Authentication (enable | disable)
--description=<value> Environment description (255 characters or fewer)
--dotenv=<value>... Path to a dotenv file, repeatable. Use - to read dotenv content from standard input
--framework=<value> Framework preset (Gatsby | NextJs | CRA | CSR | Analog | Angular | Nuxt | Astro | VueJs |
Remix | Other)
Expand Down Expand Up @@ -440,7 +439,7 @@ Update an environment of a Launch project
```
USAGE
$ csdx launch:env:update [--config <value>] [-d <value>] [--org <value>] [--project <value>] [--env <value>] [--name
<value>] [--description <value>] [--branch <value>] [--framework <value>] [--build-cmd <value>] [--server-cmd
<value>] [--branch <value>] [--framework <value>] [--build-cmd <value>] [--server-cmd
<value>] [--output-dir <value>] [--res-mode <value>] [--auto-deploy <value>] [--cs-auth <value>] [--cache-priming
<value>] [--password-protection <value>] [-u <value>] [-p] [--yes]

Expand All @@ -455,7 +454,6 @@ FLAGS
--cache-priming=<value> Cache priming (enable | disable)
--config=<value> Path to the local '.cs-launch.json' file
--cs-auth=<value> Contentstack Authentication (enable | disable)
--description=<value> Environment description (255 characters or fewer)
--env=<value> Environment name or UID
--framework=<value> Framework preset (Gatsby | NextJs | CRA | CSR | Analog | Angular | Nuxt | Astro |
VueJs | Remix | Other)
Expand Down
20 changes: 3 additions & 17 deletions src/commands/launch/env/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { UsageError } from '../../../core/errors';
import {
ENVIRONMENT_DESCRIPTION_MAX_LENGTH,
ENVIRONMENT_NAME_MAX_LENGTH,
} from '../../../environments/environment.inputs';
import { ENVIRONMENT_NAME_MAX_LENGTH } from '../../../environments/environment.inputs';
import { catalog, resolution } from '../../../resources';
import { DEPLOYMENT_WAIT_TIMEOUT_MS } from '../../../deployments/deployment.watcher';
import { EnvironmentCreator } from '../../../environments/environment.create';
Expand Down Expand Up @@ -37,7 +34,6 @@ describe('launch:env:create', () => {

await commandUnderTest({
name: 'staging',
description: 'pre-release',
branch: 'develop',
framework: 'NEXTJS',
'build-cmd': 'npm run build',
Expand All @@ -59,7 +55,6 @@ describe('launch:env:create', () => {
dataDir: '/tmp/site',
configPath: '/tmp/site/.cs-launch.json',
name: 'staging',
description: 'pre-release',
branch: 'develop',
framework: 'NEXTJS',
buildCmd: 'npm run build',
Expand Down Expand Up @@ -89,7 +84,6 @@ describe('launch:env:create', () => {
org: { required: true },
project: { required: true },
name: {},
description: {},
branch: {},
framework: {},
'build-cmd': {},
Expand All @@ -107,28 +101,20 @@ describe('launch:env:create', () => {
expect(EnvironmentsCreate.rules).toEqual([serverCommandFrameworkGate, aliasRequiresFromStack]);
});

it('describes --name and --description as the environment its own, leaving the project wording alone', () => {
it('describes --name as the environment its own, leaving the project wording alone', () => {
expect(EnvironmentsCreate.flags.name.description).toBe('Environment name (200 characters or fewer)');
expect(EnvironmentsCreate.flags.description.description).toBe('Environment description (255 characters or fewer)');
expect(catalog.name.description).toBe('Project name (200 characters or fewer)');
expect(catalog.description.description).toBe('Project description (255 characters or fewer)');
expect(EnvironmentsCreate.flags.org).toBe(catalog.org);
});

it('states in --help the same limits the shared --name and --description specs enforce', async () => {
it('states in --help the same limit the shared --name spec enforces', async () => {
const nameSpec = resolution.name as { normalize(value: string): Promise<string> };
const descriptionSpec = resolution.description as { normalize(value: string): Promise<string> };

await expect(nameSpec.normalize('n'.repeat(ENVIRONMENT_NAME_MAX_LENGTH))).resolves.toHaveLength(
ENVIRONMENT_NAME_MAX_LENGTH,
);
await expect(nameSpec.normalize('n'.repeat(ENVIRONMENT_NAME_MAX_LENGTH + 1))).rejects.toThrow(UsageError);
await expect(descriptionSpec.normalize('d'.repeat(ENVIRONMENT_DESCRIPTION_MAX_LENGTH))).resolves.toHaveLength(
ENVIRONMENT_DESCRIPTION_MAX_LENGTH,
);
await expect(descriptionSpec.normalize('d'.repeat(ENVIRONMENT_DESCRIPTION_MAX_LENGTH + 1))).rejects.toThrow(
UsageError,
);
});
});

2 changes: 0 additions & 2 deletions src/commands/launch/env/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const createInputs = inputs({
org: { required: true },
project: { required: true },
name: {},
description: {},
branch: {},
framework: {},
'build-cmd': {},
Expand Down Expand Up @@ -49,7 +48,6 @@ export default class EnvironmentsCreate extends LaunchCommand<typeof createInput
dataDir: this.dataDir,
configPath: this.configPath,
name: resolved.name,
description: resolved.description,
branch: resolved.branch,
framework: resolved.framework,
buildCmd: resolved['build-cmd'],
Expand Down
5 changes: 3 additions & 2 deletions src/commands/launch/env/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('launch:env:get', () => {
expect(lines[1]).toBe('│ FIELD │ VALUE │');
expect(lines[3]).toBe('│ ENVIRONMENT UID │ env1 │');
expect(lines[5]).toBe('│ NAME │ production │');
expect(lines).toHaveLength(39);
expect(lines).toHaveLength(37);
expect(lines.join('\n')).not.toContain('DESCRIPTION');
});

it('leaves the branch row out for an environment of a file-upload project', async () => {
Expand All @@ -53,7 +54,7 @@ describe('launch:env:get', () => {
await command.run();

expect(lines.some((line) => line.includes('BRANCH'))).toBe(false);
expect(lines).toHaveLength(37);
expect(lines).toHaveLength(35);
});

it('propagates a failed lookup', async () => {
Expand Down
6 changes: 1 addition & 5 deletions src/commands/launch/env/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const RESOLVED = {
project: 'proj1',
env: 'env1',
name: 'renamed',
description: 'the live site',
branch: 'release',
framework: 'NUXT',
'build-cmd': 'npm run build',
Expand Down Expand Up @@ -56,7 +55,6 @@ describe('launch:env:update', () => {
project: 'proj1',
environment: 'env1',
name: 'renamed',
description: 'the live site',
branch: 'release',
framework: 'NUXT',
buildCmd: 'npm run build',
Expand Down Expand Up @@ -102,7 +100,6 @@ describe('launch:env:update', () => {
'project',
'env',
'name',
'description',
'branch',
'framework',
'build-cmd',
Expand All @@ -125,9 +122,8 @@ describe('launch:env:update', () => {
expect(EnvironmentsUpdate.rules).toEqual([serverCommandFrameworkGate]);
});

it('describes --name and --description as the environment its own, leaving the project wording alone', () => {
it('describes --name as the environment its own, leaving the project wording alone', () => {
expect(EnvironmentsUpdate.flags.name.description).toBe('Environment name (200 characters or fewer)');
expect(EnvironmentsUpdate.flags.description.description).toBe('Environment description (255 characters or fewer)');
expect(catalog.name.description).toBe('Project name (200 characters or fewer)');
expect(catalog.description.description).toBe('Project description (255 characters or fewer)');
expect(EnvironmentsUpdate.flags.org).toBe(catalog.org);
Expand Down
2 changes: 0 additions & 2 deletions src/commands/launch/env/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const updateInputs = inputs({
project: { required: true },
env: { required: true },
name: {},
description: {},
branch: {},
framework: {},
'build-cmd': {},
Expand Down Expand Up @@ -53,7 +52,6 @@ export default class EnvironmentsUpdate extends LaunchCommand<typeof updateInput
project: resolved.project,
environment: resolved.env,
name: resolved.name,
description: resolved.description,
branch: resolved.branch,
framework: resolved.framework,
buildCmd: resolved['build-cmd'],
Expand Down
11 changes: 10 additions & 1 deletion src/core/failure.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Errors } from '@oclif/core';
import { Errors, Parser } from '@oclif/core';

import { handleStandaloneFailure, reportFailure } from './failure';

Expand Down Expand Up @@ -37,6 +37,15 @@ describe('reportFailure', () => {
expect(lines).toEqual(['\u001b[31merror: Nonexistent flag: --json\u001b[39m']);
});

it('words an oclif parse error as a sentence with the --help hint on its own line, keeping its exit code', async () => {
const refusal = (await Parser.parse(['--description', 'x'], { flags: {} }).catch((error: unknown) => error)) as Error;
const { lines, outcome } = report(refusal);
const thrown = await outcome;

expect(lines).toEqual(['error: Nonexistent flag: --description.\nRun the command with --help to see its flags.']);
expect(thrown.oclif.exit).toBe(2);
});

it('prints an unexpected failure the same way and exits 1', async () => {
const { lines, fallback, outcome } = report(new Error('boom'));
const thrown = await outcome;
Expand Down
15 changes: 14 additions & 1 deletion src/core/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Errors, settings } from '@oclif/core';

import { EXIT_RUNTIME } from './constants';
import { styled } from './style';
import { asSentence } from './values';

export interface FailureOutput {
print: (line: string) => void;
Expand Down Expand Up @@ -36,6 +37,18 @@ export function failureOutputOf(fallback: (err: Error) => Promise<unknown>): Fai
};
}

const OCLIF_HELP_HINT = '\nSee more help with --help';

const HELP_SENTENCE = 'Run the command with --help to see its flags.';

function withHelpSentence(message: string): string {
if (!message.endsWith(OCLIF_HELP_HINT)) {
return message;
}

return `${asSentence(message.slice(0, -OCLIF_HELP_HINT.length))}\n${HELP_SENTENCE}`;
}

function alreadyReported(err: Error): boolean {
return (err as Error & { skipOclifErrorHandling?: boolean }).skipOclifErrorHandling === true;
}
Expand All @@ -56,7 +69,7 @@ export async function reportFailure(err: Error, output: FailureOutput): Promise<
}

if (isOclifError(err)) {
return failWith(err.message, err.oclif.exit, output);
return failWith(withHelpSentence(err.message), err.oclif.exit, output);
}

if (output.debug) {
Expand Down
3 changes: 1 addition & 2 deletions src/environments/environment.create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('EnvironmentCreator', () => {
it('creates a GitHub environment and follows its first deployment, ending on the live announcement', async () => {
const { creator, calls, lines, created } = creatorUnderTest();

await creator.create(request({ description: 'pre-release', csAuth: 'disable' }));
await creator.create(request({ csAuth: 'disable' }));

expect(calls).toEqual([
'project {"org":"org1","project":"proj1"}',
Expand All @@ -169,7 +169,6 @@ describe('EnvironmentCreator', () => {
project: 'proj1',
input: {
name: 'staging',
description: 'pre-release',
gitBranch: 'develop',
buildCommand: 'npm run build',
outputDirectory: './.next',
Expand Down
5 changes: 0 additions & 5 deletions src/environments/environment.create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface EnvironmentCreateRequest extends EnvironmentRequest {
dataDir: string;
configPath: string;
name?: string;
description?: string;
branch?: string;
autoDeploy?: ToggleValue;
}
Expand Down Expand Up @@ -79,10 +78,6 @@ export class EnvironmentCreator {

const input = await new EnvironmentBuilder(this.services).build(request, name, source, request.autoDeploy);

if (request.description !== undefined) {
input.description = request.description;
}

const environment = await this.services.api.environments.create({ org, project, input });

this.services.ux.print(environmentCreatedLine(this.services.outputIsTTY === true));
Expand Down
3 changes: 0 additions & 3 deletions src/environments/environment.inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import { FRAMEWORK_CHOICES, FRAMEWORK_PRESET_BY_LABEL, SERVER_COMMAND_FRAMEWORKS

export const ENVIRONMENT_NAME_MAX_LENGTH = 200;

export const ENVIRONMENT_DESCRIPTION_MAX_LENGTH = 255;

const ENVIRONMENT_WORDING: Record<string, string> = {
name: `Environment name (${ENVIRONMENT_NAME_MAX_LENGTH} characters or fewer)`,
description: `Environment description (${ENVIRONMENT_DESCRIPTION_MAX_LENGTH} characters or fewer)`,
};

export function withEnvironmentWording<F extends Record<string, object>>(flags: F): F {
Expand Down
3 changes: 0 additions & 3 deletions src/environments/environment.presenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
const FULL = {
uid: 'e1',
name: 'production',
description: 'the live site',
domains: [{ url: 'https://a.io' }, {}, { url: ' ' }, { url: 'https://b.io' }],
gitBranch: 'main',
frameworkPreset: 'NEXTJS',
Expand Down Expand Up @@ -77,7 +76,6 @@ describe('environmentDetailRows', () => {
expect(environmentDetailRows(FULL)).toEqual([
{ field: 'ENVIRONMENT UID', value: 'e1' },
{ field: 'NAME', value: 'production' },
{ field: 'DESCRIPTION', value: 'the live site' },
{ field: 'BRANCH', value: 'main' },
{ field: 'FRAMEWORK', value: 'NEXTJS' },
{ field: 'BUILD COMMAND', value: 'npm run build' },
Expand Down Expand Up @@ -106,7 +104,6 @@ describe('environmentDetailRows', () => {
'-',
'-',
'-',
'-',
'0',
'-',
'-',
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function environmentDetailRows(environment: Environment, showBranch = tru
const rows: DetailRow[] = [
{ field: 'ENVIRONMENT UID', value: text(environment.uid) },
{ field: 'NAME', value: text(environment.name) },
{ field: 'DESCRIPTION', value: text(environment.description) },
{ field: 'BRANCH', value: text(environment.gitBranch) },
{ field: 'FRAMEWORK', value: text(environment.frameworkPreset) },
{ field: 'BUILD COMMAND', value: text(environment.buildCommand) },
Expand Down
21 changes: 3 additions & 18 deletions src/environments/environment.update.prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SETTINGS_QUESTION, promptForEnvironmentUpdate } from './environment.upd
const CURRENT: Environment = {
uid: 'env1',
name: 'production',
description: 'the live site',
gitBranch: 'main',
frameworkPreset: 'NEXTJS',
buildCommand: 'npm run build',
Expand Down Expand Up @@ -64,7 +63,6 @@ describe('promptForEnvironmentUpdate', () => {
message: SETTINGS_QUESTION,
choices: [
{ name: 'Name', value: 'name' },
{ name: 'Description', value: 'description' },
{ name: 'Branch', value: 'branch' },
{ name: 'Framework preset', value: 'framework' },
{ name: 'Build command', value: 'buildCmd' },
Expand All @@ -90,7 +88,7 @@ describe('promptForEnvironmentUpdate', () => {
const offered = (asked[0].choices as { value: string }[]).map((choice) => choice.value);
expect(offered).not.toContain('branch');
expect(offered).not.toContain('autoDeploy');
expect(offered).toHaveLength(10);
expect(offered).toHaveLength(9);
});

it('asks nothing more and changes nothing when no setting is ticked', async () => {
Expand All @@ -102,21 +100,18 @@ describe('promptForEnvironmentUpdate', () => {

it('asks only the ticked settings, each offering its current value, and keeps only what changed', async () => {
const { services, asked } = servicesAnswering({
[SETTINGS_QUESTION]: ['cachePriming', 'name', 'buildCmd', 'description'],
[SETTINGS_QUESTION]: ['cachePriming', 'name', 'buildCmd'],
Name: 'production',
Description: ' pre-release ',
'Build command': 'npm run build:prod',
'Cache priming': 'enable',
});

await expect(promptForEnvironmentUpdate(services, githubContext())).resolves.toEqual({
description: 'pre-release',
buildCmd: 'npm run build:prod',
cachePriming: 'enable',
});
expect(asked.slice(1).map((question) => [question.message, question.default])).toEqual([
['Name', 'production'],
['Description', 'the live site'],
['Build command', 'npm run build'],
['Cache priming', 'disable'],
]);
Expand Down Expand Up @@ -190,7 +185,7 @@ describe('promptForEnvironmentUpdate', () => {
});

it('leaves out a blank answer to an optional text setting', async () => {
const { services } = servicesAnswering({ [SETTINGS_QUESTION]: ['description', 'buildCmd'], Description: ' ' });
const { services } = servicesAnswering({ [SETTINGS_QUESTION]: ['buildCmd'], 'Build command': ' ' });

await expect(promptForEnvironmentUpdate(services, githubContext())).resolves.toEqual({});
});
Expand Down Expand Up @@ -233,14 +228,4 @@ describe('promptForEnvironmentUpdate', () => {
).resolves.toEqual({ passwordProtection: 'disable' });
expect(asked[1].default).toBeUndefined();
});

it('refuses a description over 255 characters at the prompt, so it is asked again rather than sent', async () => {
const { services, asked } = servicesAnswering({ [SETTINGS_QUESTION]: ['description'], Description: 'short' });

await promptForEnvironmentUpdate(services, githubContext());

const validate = asked[1].validate as (value: string) => true | string;
expect(validate('d'.repeat(255))).toBe(true);
expect(validate('d'.repeat(256))).toBe('Description must be 255 characters or fewer; that value is 256 characters.');
});
});
Loading
Loading