@intecoag/inteco-cli 1.5.0 → 1.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intecoag/inteco-cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "CLI-Tools for Inteco",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "fast-glob": "^3.3.3",
25
25
  "fuzzysort": "^3.1.0",
26
26
  "graphql": "^16.6.0",
27
- "meow": "^14.0.0",
27
+ "meow": "^14.1.0",
28
28
  "mysql-await": "^2.1.8",
29
29
  "n-readlines": "^3.4.0",
30
30
  "node-7z": "^3.0.0",
@@ -39,8 +39,8 @@
39
39
  "inteco": "src/index.js"
40
40
  },
41
41
  "devDependencies": {
42
- "@commitlint/cli": "^20.4.1",
43
- "@commitlint/config-conventional": "^20.4.1",
42
+ "@commitlint/cli": "^20.4.2",
43
+ "@commitlint/config-conventional": "^20.4.2",
44
44
  "husky": "^9.1.7",
45
45
  "semantic-release": "^25.0.3"
46
46
  },
@@ -366,6 +366,7 @@ async function executeOperations(mode, operations) {
366
366
  const operation = operations[index];
367
367
  try {
368
368
  if (operation.type === "upload") {
369
+ const totalBytes = operation.localFile.size ?? null;
369
370
  spinner.text = `Uploading ${operation.localFile.relativePath} (${index + 1}/${operations.length})`;
370
371
  const md5Base64 = operation.localFile.md5Base64
371
372
  ?? await getLocalMd5Base64(operation.localFile.filePath);
@@ -373,15 +374,30 @@ async function executeOperations(mode, operations) {
373
374
  operation.containerClient,
374
375
  operation.localFile.blobPath,
375
376
  operation.localFile.filePath,
376
- md5Base64
377
+ md5Base64,
378
+ progress => {
379
+ if (!totalBytes) {
380
+ return;
381
+ }
382
+ const percent = ((progress.loadedBytes / totalBytes) * 100).toFixed(1);
383
+ spinner.text = `Uploading ${operation.localFile.relativePath} ${percent}% (${formatBytes(progress.loadedBytes)}/${formatBytes(totalBytes)})`;
384
+ }
377
385
  );
378
386
  } else if (operation.type === "download") {
387
+ const totalBytes = operation.localFile.size ?? null;
379
388
  spinner.text = `Downloading ${operation.localFile.relativePath} (${index + 1}/${operations.length})`;
380
389
  await ensureDirectory(path.dirname(operation.localFile.filePath));
381
390
  await operation.azure.downloadToFile(
382
391
  operation.containerClient,
383
392
  operation.localFile.blobPath,
384
- operation.localFile.filePath
393
+ operation.localFile.filePath,
394
+ progress => {
395
+ if (!totalBytes) {
396
+ return;
397
+ }
398
+ const percent = ((progress.loadedBytes / totalBytes) * 100).toFixed(1);
399
+ spinner.text = `Downloading ${operation.localFile.relativePath} ${percent}% (${formatBytes(progress.loadedBytes)}/${formatBytes(totalBytes)})`;
400
+ }
385
401
  );
386
402
  } else if (operation.type === "delete") {
387
403
  spinner.text = `Deleting ${operation.blobPath} (${index + 1}/${operations.length})`;
@@ -504,7 +520,8 @@ async function buildPullOperations(syncState, azure) {
504
520
  localFile: {
505
521
  filePath: localPath,
506
522
  relativePath: path.relative(entry.rootDir, localPath),
507
- blobPath: blob.name
523
+ blobPath: blob.name,
524
+ size: blob.properties?.contentLength ?? null
508
525
  }
509
526
  });
510
527
  }
@@ -537,4 +554,15 @@ async function listRemoteBlobNames(containerClient, includes) {
537
554
  remoteBlobs.add(blob.name);
538
555
  }
539
556
  return remoteBlobs;
557
+ }
558
+
559
+ function formatBytes(bytes) {
560
+ if (!bytes || bytes <= 0) {
561
+ return "0 B";
562
+ }
563
+
564
+ const units = ["B", "KB", "MB", "GB", "TB"];
565
+ const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
566
+ const value = bytes / Math.pow(1024, index);
567
+ return `${value.toFixed(value >= 10 || index === 0 ? 0 : 1)} ${units[index]}`;
540
568
  }
@@ -265,7 +265,7 @@ function processMultiple(responses, dryRun, sourcePaths, destPaths) {
265
265
  let deletedCount = 0;
266
266
  for(let i = 0; i < sourcePaths.length && i < destPaths.length; i++) {
267
267
  if (existsSync(destPaths[i])) {
268
- deletedCount += countAndDeleteDir(destPaths[i], dryRun);
268
+ deletedCount += countAndDeleteDir(destPaths[i], dryRun, ["wegas.properties", "path.yaml"]);
269
269
  if (!dryRun) {
270
270
  console.log(chalk.gray(`Deleted existing folder: ${destPaths[i]}`));
271
271
  }
@@ -293,27 +293,47 @@ function processMultiple(responses, dryRun, sourcePaths, destPaths) {
293
293
  }
294
294
  }
295
295
 
296
- function countAndDeleteDir(dirPath, dryRun = false) {
296
+ function countAndDeleteDir(dirPath, dryRun = false, filenameBlacklist = []) {
297
297
  let deletedCount = 0;
298
298
 
299
299
  if (existsSync(dirPath)) {
300
- if (dryRun) {
301
- console.log(chalk.red(`[DryRun] Would delete directory: ${dirPath}`));
302
- // For dry run, recursively count files/directories without deleting
303
- const entries = readdirSync(dirPath, { withFileTypes: true });
304
- for (const entry of entries) {
305
- const entryPath = path.join(dirPath, entry.name);
306
- if (entry.isDirectory()) {
307
- deletedCount += countAndDeleteDir(entryPath, dryRun);
308
- } else {
309
- deletedCount++;
300
+
301
+ let shouldKeepDirectory = false;
302
+
303
+ // For dry run, recursively count files/directories without deleting
304
+ const entries = readdirSync(dirPath, { withFileTypes: true });
305
+ for (const entry of entries) {
306
+ if(filenameBlacklist.includes(entry.name)){
307
+ shouldKeepDirectory = true; // Directory will not empty
308
+ continue;
309
+ }
310
+
311
+ const entryPath = path.join(dirPath, entry.name);
312
+ if (entry.isDirectory()) {
313
+ deletedCount += countAndDeleteDir(entryPath, dryRun, filenameBlacklist);
314
+ shouldKeepDirectory |= deletedCount != 0;
315
+ } else {
316
+ deletedCount++;
317
+ if(dryRun) {
310
318
  console.log(chalk.red(`[DryRun] Would delete file: ${entryPath}`));
311
319
  }
320
+ else {
321
+ console.log(chalk.red(`Deleting file: ${entryPath}`));
322
+ rmSync(entryPath, { recursive: false, force: true });
323
+ }
324
+ }
325
+ }
326
+
327
+ if(!shouldKeepDirectory) {
328
+ if(dryRun) {
329
+ console.log(chalk.red(`[DryRun] Would delete directory: ${dirPath}`));
330
+ }
331
+ else {
332
+ console.log(chalk.red(`Deleting directory: ${dirPath}`));
333
+ rmSync(dirPath, { recursive: true, force: true });
312
334
  }
335
+
313
336
  deletedCount++; // counting the directory itself
314
- } else {
315
- rmSync(dirPath, { recursive: true, force: true });
316
- // Can't count after delete, so you may skip or count before if desired
317
337
  }
318
338
  }
319
339
  return deletedCount;
@@ -56,18 +56,19 @@ export class AzureHelper {
56
56
  }
57
57
  }
58
58
 
59
- async uploadFile(containerClient, blobPath, filePath, md5Base64) {
59
+ async uploadFile(containerClient, blobPath, filePath, md5Base64, onProgress) {
60
60
  const blockBlobClient = containerClient.getBlockBlobClient(blobPath);
61
61
  const md5Buffer = md5Base64 ? Buffer.from(md5Base64, "base64") : undefined;
62
62
 
63
63
  await blockBlobClient.uploadFile(filePath, {
64
- blobHTTPHeaders: md5Buffer ? { blobContentMD5: md5Buffer } : undefined
64
+ blobHTTPHeaders: md5Buffer ? { blobContentMD5: md5Buffer } : undefined,
65
+ onProgress
65
66
  });
66
67
  }
67
68
 
68
- async downloadToFile(containerClient, blobPath, filePath) {
69
+ async downloadToFile(containerClient, blobPath, filePath, onProgress) {
69
70
  const blockBlobClient = containerClient.getBlockBlobClient(blobPath);
70
- await blockBlobClient.downloadToFile(filePath);
71
+ await blockBlobClient.downloadToFile(filePath, 0, 0, { onProgress });
71
72
  }
72
73
 
73
74
  async deleteBlob(containerClient, blobPath) {