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
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ fileignoreconfig:
- filecontent
- filename: src/commands/launch/index.test.ts
checksum: 9db6c02ad35a0367343cd753b916dd64db4a9efd24838201d2e1113ed19c9b62
- filename: package-lock.json
checksum: 43c0eecc2192095c8fb5bc524b7dafa33a6141ddd3923d41ffb15ec025bea9a9
- filename: src/commands/launch/rollback.test.ts
checksum: a1010882456f315a918afe2777f90472985e9966bd308c5311ac0de318b14e8c
- filename: test/unit/commands/rollback.test.ts
checksum: d1f931f2d9a397131409399ad6463653e28b5a2224e870b641d9ba57c4418f18
- filename: package-lock.json
checksum: d24dfc90fb69ded83dfe4f6839cd17801e65a1f84be04244fb917e6bef6b5cc6
version: "1.0"
1,756 changes: 552 additions & 1,204 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-launch",
"version": "1.9.9",
"version": "1.10.0",
"description": "Launch related operations",
"author": "Contentstack CLI",
"bin": {
Expand Down Expand Up @@ -115,7 +115,7 @@
"@eslint/eslintrc": {
"ajv": "^6.12.6"
},
"qs": "^6.14.2",
"qs": "^6.15.2",
"tmp": "^0.2.4"
},
"engines": {
Expand Down
235 changes: 235 additions & 0 deletions src/adapters/file-upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,241 @@ describe('FileUpload Adapter', () => {
);
expect(serverCommandCalls.length).toBe(0);
});

it('should prompt Enable Streaming Responses after server command when response-mode omitted for OTHER preset',
async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./dist');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm start');
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'server-command': undefined,
'response-mode': undefined,
},
framework: 'OTHER',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { OTHER: './dist' },
},
log: logMock,
exit: exitMock,
} as any);

await fileUploadInstance.prepareAndUploadNewProjectFile();

expect(cliux.inquire).toHaveBeenCalledWith({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
});
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
});

it('should not prompt Enable Streaming Response when response-mode flag is streaming', async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./dist');

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'server-command': 'npm start',
'response-mode': 'streaming',
},
framework: 'OTHER',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { OTHER: './dist' },
},
log: logMock,
exit: exitMock,
} as any);

await fileUploadInstance.prepareAndUploadNewProjectFile();

const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'enableStreamingResponse',
);
expect(enableStreamingCalls.length).toBe(0);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
});

it('should not prompt Enable Streaming Response when response-mode flag is buffered', async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./dist');

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'server-command': 'npm start',
'response-mode': 'buffered',
},
framework: 'OTHER',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { OTHER: './dist' },
},
log: logMock,
exit: exitMock,
} as any);

await fileUploadInstance.prepareAndUploadNewProjectFile();

const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'enableStreamingResponse',
);
expect(enableStreamingCalls.length).toBe(0);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
});

it('should prompt Enable Streaming Responses for Gatsby when flag is not provided', async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'response-mode': undefined,
},
framework: 'GATSBY',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { GATSBY: './public' },
},
log: logMock,
exit: exitMock,
} as any);

const handleEnvImportFlowMock = jest
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
.mockResolvedValue(undefined);

await fileUploadInstance.prepareAndUploadNewProjectFile();

const serverCommandCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'serverCommand',
);
expect(serverCommandCalls.length).toBe(0);
expect(cliux.inquire).toHaveBeenCalledWith({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
});
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
handleEnvImportFlowMock.mockRestore();
});

it('should apply response-mode flag for Gatsby without prompt', async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'response-mode': 'buffered',
},
framework: 'GATSBY',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { GATSBY: './public' },
},
log: logMock,
exit: exitMock,
} as any);

const handleEnvImportFlowMock = jest
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
.mockResolvedValue(undefined);

await fileUploadInstance.prepareAndUploadNewProjectFile();

const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'enableStreamingResponse',
);
expect(enableStreamingCalls.length).toBe(0);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
handleEnvImportFlowMock.mockRestore();
});
});
});

22 changes: 21 additions & 1 deletion src/adapters/file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ export default class FileUpload extends BaseClass {
* @memberof FileUpload
*/
async createNewProject(uploadUid: string): Promise<void> {
const { framework, projectName, buildCommand, outputDirectory, environmentName, serverCommand } = this.config;
const {
framework,
projectName,
buildCommand,
outputDirectory,
environmentName,
serverCommand,
isStreamingEnabled
} = this.config;
await this.apolloClient
.mutate({
mutation: importProjectMutation,
Expand All @@ -130,6 +138,7 @@ export default class FileUpload extends BaseClass {
environmentVariables: map(this.envVariables, ({ key, value }) => ({ key, value })),
buildCommand: buildCommand === undefined || buildCommand === null ? 'npm run build' : buildCommand,
...(serverCommand && serverCommand.trim() !== '' ? { serverCommand } : {}),
isStreamingEnabled: isStreamingEnabled ?? false,
},
},
skipGitData: true,
Expand Down Expand Up @@ -167,6 +176,7 @@ export default class FileUpload extends BaseClass {
'variable-type': variableType,
'env-variables': envVariables,
'server-command': serverCommand,
'response-mode': responseMode,
alias,
} = this.config.flags;
const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {};
Expand Down Expand Up @@ -239,6 +249,16 @@ export default class FileUpload extends BaseClass {
this.config.serverCommand = serverCommand;
}
}
if (!responseMode) {
this.config.isStreamingEnabled = (await cliux.inquire({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
})) as boolean;
} else {
this.config.isStreamingEnabled = responseMode === 'streaming';
}
this.config.variableType = variableType as unknown as string;
this.config.envVariables = envVariables;
await this.handleEnvImportFlow();
Expand Down
Loading
Loading