Skip to content

Commit

Permalink
feat: CLI integration on GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
aman19K committed Nov 15, 2024
1 parent f96a4be commit 844c24c
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.7.3 darwin-arm64 node-v22.8.0
@contentstack/cli-audit/1.7.3 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.2.0 darwin-arm64 node-v22.8.0
@contentstack/cli-cm-branches/1.2.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.13.0 darwin-arm64 node-v22.8.0
@contentstack/cli-cm-clone/1.13.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.14.1 darwin-arm64 node-v22.8.0
@contentstack/cli-cm-export/1.14.1 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.19.2 darwin-arm64 node-v22.8.0
@contentstack/cli-cm-import/1.19.2 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-launch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-launch
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-launch/1.2.3 darwin-arm64 node-v22.2.0
@contentstack/cli-launch/1.3.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-launch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-launch",
"version": "1.2.3",
"version": "1.3.0",
"description": "Launch related operations",
"author": "Contentstack CLI",
"bin": {
Expand Down
22 changes: 11 additions & 11 deletions packages/contentstack-launch/src/adapters/file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import includes from 'lodash/includes';
import isEmpty from 'lodash/isEmpty';
import { basename, resolve } from 'path';
import { cliux, configHandler, HttpClient, ux } from '@contentstack/cli-utilities';
import { createReadStream, existsSync, PathLike, statSync } from 'fs';
import { createReadStream, existsSync, PathLike, statSync, readFileSync } from 'fs';

import { print } from '../util';
import BaseClass from './base-class';
Expand Down Expand Up @@ -63,7 +63,6 @@ export default class FileUpload extends BaseClass {
*/
async createNewProject(): Promise<void> {
const { framework, projectName, buildCommand, outputDirectory, environmentName } = this.config;

await this.apolloClient
.mutate({
mutation: importProjectMutation,
Expand Down Expand Up @@ -215,7 +214,7 @@ export default class FileUpload extends BaseClass {

switch (true) {
case state.isDirectory(): // NOTE folder
await zip.addLocalFolderPromise(entryPath, { zipPath: entry });
zip.addLocalFolder(entryPath, entry);
break;
case state.isFile(): // NOTE check is file
zip.addLocalFile(entryPath);
Expand Down Expand Up @@ -264,7 +263,7 @@ export default class FileUpload extends BaseClass {
* @memberof FileUpload
*/
async uploadFile(fileName: string, filePath: PathLike): Promise<void> {
const { uploadUrl, fields, headers } = this.signedUploadUrlData;
const { uploadUrl, fields, headers, method } = this.signedUploadUrlData;
const formData = new FormData();

if (!isEmpty(fields)) {
Expand All @@ -274,8 +273,8 @@ export default class FileUpload extends BaseClass {

formData.append('file', createReadStream(filePath), fileName);
await this.submitFormData(formData, uploadUrl);
} else if (!isEmpty(headers)) {
await this.uploadWithHttpClient(filePath, uploadUrl, headers, fileName);
} else if (method === 'PUT') {
await this.uploadWithHttpClient(filePath, uploadUrl, headers);
}
}

Expand Down Expand Up @@ -307,28 +306,29 @@ export default class FileUpload extends BaseClass {
filePath: PathLike,
uploadUrl: string,
headers: Array<{ key: string; value: string }>,
fileName: string,
): Promise<void> {
ux.action.start('Starting file upload...');
const httpClient = new HttpClient();
const form = new FormData();
form.append('file', createReadStream(filePath), fileName);
const file = readFileSync(filePath);

// Convert headers array to a headers object
const headerObject = headers.reduce((acc, { key, value }) => {
const headerObject = headers?.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {} as Record<string, string>);

try {
const response = await httpClient.headers(headerObject).put(uploadUrl, form);
httpClient.headers({ 'Content-Type': 'application/zip' });
if (headerObject !== undefined) httpClient.headers(headerObject);
const response = (await httpClient.put(uploadUrl, file)) as any;
const { status } = response;

if (status >= 200 && status < 300) {
ux.action.stop();
} else {
ux.action.stop('File upload failed!');
this.log('File upload failed. Please try again.', 'error');
this.log(`Error: ${status}, ${response?.statusText}`, 'error');
this.exit(1);
}
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-launch/src/graphql/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const createSignedUploadUrlMutation: DocumentNode = gql`
key
value
}
method
}
}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli/1.30.0 darwin-arm64 node-v22.8.0
@contentstack/cli/1.30.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@contentstack/cli-cm-seed": "~1.10.0",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-config": "~1.8.0",
"@contentstack/cli-launch": "~1.2.3",
"@contentstack/cli-launch": "~1.3.0",
"@contentstack/cli-migration": "~1.6.3",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/management": "~1.18.3",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 844c24c

Please sign in to comment.