(item, options)
| 151 | |
| 152 | // Core: Process file item (handles checking and downloading) |
| 153 | const processFileItem = async (item, options) => { |
| 154 | const { |
| 155 | filePath, |
| 156 | remoteHash, |
| 157 | downloadUrl, |
| 158 | cdnPattern, |
| 159 | itemName, |
| 160 | downloadDir |
| 161 | } = options; |
| 162 | |
| 163 | const fileExists = fsSync.existsSync(filePath); |
| 164 | |
| 165 | if (fileExists) { |
| 166 | const localHash = getLocalHash(filePath); |
| 167 | |
| 168 | if (config.verbose) { |
| 169 | console.log(`${LOG_TAG} \t\tremote ${itemName} hash ${remoteHash}`); |
| 170 | } |
| 171 | |
| 172 | if (localHash !== remoteHash) { |
| 173 | console.log(`${LOG_TAG} \t\t${itemName} is different on the remote, downloading...`); |
| 174 | |
| 175 | if (config.dryRun) { |
| 176 | console.log(`${LOG_TAG} \t\tDRY_RUN is set, not downloading ${itemName} but we should`); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | const url = getCDNUrl(downloadUrl, cdnPattern); |
| 181 | if (config.verbose) { |
| 182 | console.log(`${LOG_TAG} \t\tDownloading ${url} to ${filePath}`); |
| 183 | } |
| 184 | await downloadFile(filePath, url); |
| 185 | return true; |
| 186 | } else { |
| 187 | console.log(`${LOG_TAG} \t\t${itemName} is already up to date. Skipping.`); |
| 188 | return false; |
| 189 | } |
| 190 | } else { |
| 191 | console.log(`${LOG_TAG} \t\t${itemName} is missing, downloading...`); |
| 192 | ensureDirectory(downloadDir); |
| 193 | |
| 194 | if (config.dryRun) { |
| 195 | console.log(`${LOG_TAG} \t\tDRY_RUN is set, not downloading ${itemName} but we should`); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | const url = getCDNUrl(downloadUrl, cdnPattern); |
| 200 | if (config.verbose) { |
| 201 | console.log(`${LOG_TAG} \t\tDownloading ${url} to ${filePath}`); |
| 202 | } |
| 203 | await downloadFile(filePath, url); |
| 204 | return true; |
| 205 | } |
| 206 | }; |
| 207 | |
| 208 | // Core: Fetch GitHub directory contents |
| 209 | const fetchGitHubContents = async (repoPath, useAuth = false) => { |
no test coverage detected