@contentstack/cli-utilities 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Chunk, PageInfo, WriteFileOptions, FsConstructorOptions, ChunkFilesGetterType } from './types';
3
3
  export default class FsUtility {
4
+ private isArray;
4
5
  private prefixKey;
5
6
  private basePath;
6
7
  private fileExt;
@@ -12,6 +12,7 @@ const helper_1 = require("./helper");
12
12
  class FsUtility {
13
13
  constructor(options = {}) {
14
14
  var _a;
15
+ this.isArray = false;
15
16
  this.prefixKey = '';
16
17
  this.currentFileName = '';
17
18
  this.keepMetadata = false;
@@ -25,8 +26,9 @@ class FsUtility {
25
26
  hasPreviousPage: false,
26
27
  pageInfoUpdated: false,
27
28
  };
28
- const { fileExt, omitKeys, basePath, moduleName, metaHandler, keepMetadata, metaPickKeys, chunkFileSize, indexFileName, defaultInitContent, useIndexer = false, createDirIfNotExist = true, } = options;
29
+ const { isArray, fileExt, omitKeys, basePath, moduleName, metaHandler, keepMetadata, metaPickKeys, chunkFileSize, indexFileName, defaultInitContent, useIndexer = false, createDirIfNotExist = true, } = options;
29
30
  this.metaHandler = metaHandler;
31
+ this.isArray = isArray;
30
32
  this.basePath = basePath || '';
31
33
  this.omitKeys = omitKeys || [];
32
34
  this.fileExt = fileExt || 'json';
@@ -36,7 +38,7 @@ class FsUtility {
36
38
  this.keepMetadata = keepMetadata || ((_a = keepMetadata === undefined) !== null && _a !== void 0 ? _a : true);
37
39
  this.indexFileName = indexFileName || 'index.json';
38
40
  this.pageInfo.hasNextPage = (0, keys_1.default)(this.indexFileContent).length > 0;
39
- this.defaultInitContent = defaultInitContent || (this.fileExt === 'json' ? '{' : '');
41
+ this.defaultInitContent = defaultInitContent || this.isArray ? '[' : this.fileExt === 'json' ? '{' : '';
40
42
  if (useIndexer) {
41
43
  this.writeIndexer = this.indexFileContent;
42
44
  }
@@ -57,7 +59,7 @@ class FsUtility {
57
59
  let indexData = {};
58
60
  const indexPath = `${this.basePath}/${this.indexFileName}`;
59
61
  if ((0, node_fs_1.existsSync)(indexPath)) {
60
- indexData = JSON.parse((0, node_fs_1.readFileSync)(indexPath, 'utf-8'));
62
+ indexData = JSON.parse((0, node_fs_1.readFileSync)(indexPath, 'utf8'));
61
63
  }
62
64
  return indexData;
63
65
  }
@@ -84,7 +86,7 @@ class FsUtility {
84
86
  filePath = (0, node_path_1.resolve)(filePath);
85
87
  parse = typeof parse === 'undefined' ? true : parse;
86
88
  if ((0, node_fs_1.existsSync)(filePath)) {
87
- data = parse ? JSON.parse((0, node_fs_1.readFileSync)(filePath, 'utf-8')) : data;
89
+ data = parse ? JSON.parse((0, node_fs_1.readFileSync)(filePath, 'utf8')) : data;
88
90
  }
89
91
  return data;
90
92
  }
@@ -180,7 +182,7 @@ class FsUtility {
180
182
  // NOTE Each chunk file size Ex. 5 (MB)
181
183
  fileSizeReachedLimit = true;
182
184
  }
183
- const suffix = fileSizeReachedLimit ? '}' : '';
185
+ const suffix = fileSizeReachedLimit ? (this.isArray ? ']' : '}') : '';
184
186
  fileContent = this.fileExt === 'json' ? `${this.prefixKey}${fileContent}${suffix}` : fileContent;
185
187
  (_a = this.writableStream) === null || _a === void 0 ? void 0 : _a.write(fileContent);
186
188
  if (!this.prefixKey)
@@ -217,7 +219,7 @@ class FsUtility {
217
219
  completeFile(closeIndexer) {
218
220
  if (this.writableStream) {
219
221
  if (this.fileExt === 'json') {
220
- this.writableStream.write('}');
222
+ this.writableStream.write(this.isArray ? ']' : '}');
221
223
  }
222
224
  }
223
225
  this.closeFile(closeIndexer);
@@ -250,7 +252,7 @@ class FsUtility {
250
252
  const path = basePath || (0, node_path_1.resolve)(this.basePath, 'metadata.json');
251
253
  if (!(0, node_fs_1.existsSync)(path))
252
254
  return {};
253
- return JSON.parse((0, node_fs_1.readFileSync)(path, { encoding: 'utf-8' }));
255
+ return JSON.parse((0, node_fs_1.readFileSync)(path, { encoding: 'utf8' }));
254
256
  }
255
257
  /**
256
258
  * @method getFileByIndex
@@ -270,7 +272,7 @@ class FsUtility {
270
272
  return;
271
273
  }
272
274
  const fileContent = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(this.basePath, this.readIndexer[index]), {
273
- encoding: 'utf-8',
275
+ encoding: 'utf8',
274
276
  });
275
277
  resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
276
278
  });
@@ -287,7 +289,7 @@ class FsUtility {
287
289
  return;
288
290
  }
289
291
  const fileContent = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(this.basePath, this.readIndexer[this.pageInfo.after]), {
290
- encoding: 'utf-8',
292
+ encoding: 'utf8',
291
293
  });
292
294
  resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
293
295
  });
@@ -305,7 +307,7 @@ class FsUtility {
305
307
  return;
306
308
  }
307
309
  const fileContent = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(this.basePath, this.readIndexer[this.pageInfo.before]), {
308
- encoding: 'utf-8',
310
+ encoding: 'utf8',
309
311
  });
310
312
  resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
311
313
  });
@@ -65,6 +65,7 @@ type FsConstructorOptions = {
65
65
  keepMetadata?: boolean;
66
66
  useIndexer?: boolean;
67
67
  metaHandler?: (array: any) => any;
68
+ isArray?: boolean;
68
69
  };
69
70
  type ChunkFilesGetterType = Promise<Record<string, unknown> | Record<string, unknown>[] | Error>;
70
71
  export { Chunk, FileType, PageInfo, WriteFileOptions, FsConstructorOptions, ChunkFilesGetterType };
@@ -1,7 +1,7 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { IHttpClient } from './client-interface';
3
3
  import { HttpResponse } from './http-response';
4
- type HttpClientOptions = {
4
+ export type HttpClientOptions = {
5
5
  disableEarlyAccessHeaders?: boolean;
6
6
  };
7
7
  export declare class HttpClient implements IHttpClient {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -32,10 +32,10 @@
32
32
  "author": "contentstack",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@contentstack/management": "~1.15.3",
35
+ "@contentstack/management": "~1.17.0",
36
36
  "@contentstack/marketplace-sdk": "^1.2.1",
37
37
  "@oclif/core": "^3.26.5",
38
- "axios": "^1.6.4",
38
+ "axios": "^1.7.4",
39
39
  "chalk": "^4.0.0",
40
40
  "cli-cursor": "^3.1.0",
41
41
  "cli-table": "^0.3.11",