| 7 | |
| 8 | main(); |
| 9 | async function main() { |
| 10 | const lastExtensionPath = path.join(__dirname, '../dist/lastExtension/manifest.json'); |
| 11 | if (!fs.existsSync(lastExtensionPath)) { |
| 12 | console.log('Downloading'); |
| 13 | mkdirp.sync(path.join(__dirname, '../dist/lastExtension')); |
| 14 | await ex( |
| 15 | 'curl -fsSL https://github.com/MALSync/MALSync/releases/latest/download/webextension.zip -o dist/lastExtension.zip', |
| 16 | ); |
| 17 | console.log('Extracting'); |
| 18 | try { |
| 19 | await ex(`tar -xf dist/lastExtension.zip --directory dist/lastExtension`); |
| 20 | } catch (error) { |
| 21 | await ex(`unzip -o dist/lastExtension.zip -d dist/lastExtension`); |
| 22 | } |
| 23 | } else { |
| 24 | console.log('Skipping download, manifest found.'); |
| 25 | } |
| 26 | |
| 27 | const manifest = require('../dist/lastExtension/manifest.json'); |
| 28 | |
| 29 | const version = manifest.version; |
| 30 | const oldUrls = getUrls(manifest); |
| 31 | const descFile = path.join(__dirname, '../src/pages/diffUrls.json'); |
| 32 | fs.readFile(descFile, 'utf8', function(err, data) { |
| 33 | const currentData = JSON.parse(data); |
| 34 | const diffUrls = getDiff(oldUrls, currentData[version]); |
| 35 | console.log(version, diffUrls); |
| 36 | currentData[version] = diffUrls; |
| 37 | |
| 38 | if(Object.keys(currentData).length > 5) { |
| 39 | const remove = Object.keys(currentData).slice(0, Object.keys(currentData).length - 5); |
| 40 | |
| 41 | for(const item of remove) { |
| 42 | delete currentData[item]; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fs.writeFile(descFile, JSON.stringify(currentData, null, 2), 'utf8', function (err) { |
| 47 | if (err) throw err; |
| 48 | }); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | function getDiff(oldUrls, oldDiff) { |
| 53 | res = {}; |