(name, ver)
| 129 | }; |
| 130 | |
| 131 | const downloadModule = async (name, ver) => { |
| 132 | downloading.total++; |
| 133 | |
| 134 | const path = join(downloadPath, name + '-' + ver + '.zip'); |
| 135 | const file = fs.createWriteStream(path); |
| 136 | |
| 137 | // log('Modules', 'Downloading', `${name}@${ver}`); |
| 138 | |
| 139 | let success, total, cur = 0; |
| 140 | const res = await redirs(baseUrl + '/' + name + '/' + ver + qs); |
| 141 | success = res.statusCode === 200; |
| 142 | total = parseInt(res.headers['content-length'] ?? 1, 10); |
| 143 | |
| 144 | res.pipe(file); |
| 145 | |
| 146 | res.on('data', c => { |
| 147 | cur += c.length; |
| 148 | |
| 149 | events.emit('downloading-module', { name, cur, total }); |
| 150 | }); |
| 151 | |
| 152 | await new Promise((res) => file.on('close', res)); |
| 153 | |
| 154 | if (success) commitManifest(); |
| 155 | else downloading.fail++; |
| 156 | |
| 157 | events.emit('downloaded-module', { |
| 158 | name |
| 159 | }); |
| 160 | |
| 161 | downloading.done++; |
| 162 | |
| 163 | if (downloading.done === downloading.total) { |
| 164 | events.emit('downloaded', { |
| 165 | failed: downloading.fail |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | installModule(name, ver, path); |
| 170 | }; |
| 171 | |
| 172 | const installModule = async (name, ver, path) => { |
| 173 | installing.total++; |
no test coverage detected