@profitlich/template-toolkit 2.21.1 → 2.22.0

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,3 +1,4 @@
1
+ .mux-player,
1
2
  mux-player {
2
3
  display: block;
3
4
  width: 100%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "2.21.1",
3
+ "version": "2.22.0",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "exports": {
package/scripts/deploy.js CHANGED
@@ -9,14 +9,21 @@ import cliProgress from 'cli-progress';
9
9
  // Helper for making sure the upload progress bars go to 100%
10
10
  const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
11
11
 
12
- async function isNewer(client, localFile, remotePath) {
12
+ function formatBytes(bytes) {
13
+ if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
14
+ if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(2)} MB`;
15
+ if (bytes >= 1024) return `${(bytes / 1024).toFixed(2)} KB`;
16
+ return `${bytes} B`;
17
+ }
18
+
19
+ async function getFileStatus(client, localFile, remotePath) {
13
20
  const localStat = await fs.stat(localFile);
14
21
  try {
15
22
  const remoteDate = await client.lastMod(remotePath);
16
- return localStat.mtimeMs > remoteDate.getTime();
23
+ return { shouldUpload: localStat.mtimeMs > remoteDate.getTime(), size: localStat.size };
17
24
  } catch {
18
25
  // File doesn't exist remotely (550) or server doesn't support MDTM — upload it
19
- return true;
26
+ return { shouldUpload: true, size: localStat.size };
20
27
  }
21
28
  }
22
29
 
@@ -71,8 +78,9 @@ export async function runDeploy(mode, uploadTasks, options = {}) {
71
78
  for (const file of files) {
72
79
  const relativeFile = path.relative(task.localBase, file);
73
80
  const remotePath = path.join(task.remoteDir, relativeFile).replace(/\\/g, '/');
74
- if (await isNewer(mainClient, file, remotePath)) {
75
- filesToUpload.push({ file, remotePath });
81
+ const { shouldUpload, size } = await getFileStatus(mainClient, file, remotePath);
82
+ if (shouldUpload) {
83
+ filesToUpload.push({ file, remotePath, size });
76
84
  }
77
85
  }
78
86
  } else {
@@ -88,8 +96,9 @@ export async function runDeploy(mode, uploadTasks, options = {}) {
88
96
  if (!file) break;
89
97
  const relativeFile = path.relative(task.localBase, file);
90
98
  const remotePath = path.join(task.remoteDir, relativeFile).replace(/\\/g, '/');
91
- if (await isNewer(workerClient, file, remotePath)) {
92
- filesToUpload.push({ file, remotePath });
99
+ const { shouldUpload, size } = await getFileStatus(workerClient, file, remotePath);
100
+ if (shouldUpload) {
101
+ filesToUpload.push({ file, remotePath, size });
93
102
  }
94
103
  }
95
104
  } finally {
@@ -105,21 +114,28 @@ export async function runDeploy(mode, uploadTasks, options = {}) {
105
114
  continue;
106
115
  }
107
116
 
117
+ const totalBytes = filesToUpload.reduce((sum, { size }) => sum + size, 0);
118
+ let uploadedBytes = 0;
119
+
108
120
  const progressBar = new cliProgress.SingleBar({
109
- format: ' Upload |{bar}| {percentage}% {value}/{total} files {duration_formatted}',
121
+ format: ' Upload |{bar}| {percentage}% {value}/{total} files {uploaded}/{totalSize} {duration_formatted}',
110
122
  barCompleteChar: '█',
111
123
  barIncompleteChar: '░',
112
124
  hideCursor: true
113
125
  });
114
126
 
115
127
  activeProgressBar = progressBar;
116
- progressBar.start(filesToUpload.length, 0);
128
+ progressBar.start(filesToUpload.length, 0, {
129
+ uploaded: formatBytes(0),
130
+ totalSize: formatBytes(totalBytes)
131
+ });
117
132
 
118
133
  if (parallel <= 1) {
119
- for (const { file, remotePath } of filesToUpload) {
134
+ for (const { file, remotePath, size } of filesToUpload) {
120
135
  await mainClient.ensureDir(path.dirname(remotePath));
121
136
  await mainClient.uploadFrom(file, remotePath);
122
- progressBar.increment();
137
+ uploadedBytes += size;
138
+ progressBar.increment(1, { uploaded: formatBytes(uploadedBytes) });
123
139
  }
124
140
  } else {
125
141
  // Pre-create all required remote directories with the main client
@@ -154,7 +170,8 @@ export async function runDeploy(mode, uploadTasks, options = {}) {
154
170
  workerClient = await createClient(accessOptions);
155
171
  }
156
172
  }
157
- progressBar.increment();
173
+ uploadedBytes += item.size;
174
+ progressBar.increment(1, { uploaded: formatBytes(uploadedBytes) });
158
175
  }
159
176
  } finally {
160
177
  workerClient.close();