(root)
| 204 | * @returns {Object} |
| 205 | */ |
| 206 | function detectProjectVersion(sourcePath, versionHint) { |
| 207 | const normalizedSourcePath = path.resolve(sourcePath); |
| 208 | const sourceBasename = path.basename(normalizedSourcePath); |
| 209 | const candidateRoots = [normalizedSourcePath]; |
| 210 | |
| 211 | // 兼容用户直接传入 assets/res 目录的场景 |
| 212 | if (sourceBasename === 'assets' || sourceBasename === 'res') { |
| 213 | candidateRoots.push(path.dirname(normalizedSourcePath)); |
| 214 | } |
| 215 | |
| 216 | const uniqueCandidateRoots = [...new Set(candidateRoots)]; |
| 217 | |
| 218 | /** |
| 219 | * Find first existing path, or first match of a basename regex under a dir. |
| 220 | * Used for MD5 Cache builds: main.<hash>.js / settings.<hash>.js / project.<hash>.js |
| 221 | */ |
| 222 | function findExistingPath(pathArray) { |
| 223 | for (const filePath of pathArray) { |
| 224 | if (fs.existsSync(filePath)) { |
| 225 | return filePath; |
| 226 | } |
| 227 | } |
| 228 | return null; |
| 229 | } |
| 230 | |
| 231 | function findHashedFile(dir, pattern) { |
| 232 | if (!fs.existsSync(dir)) return null; |
| 233 | let entries; |
no outgoing calls
no test coverage detected