|
| 1 | +import axios from 'axios'; |
| 2 | +import * as fs from 'fs-extra'; |
| 3 | +import * as path from 'path'; |
| 4 | +import { join } from 'path'; |
| 5 | +import { get } from '../src/utils/config'; |
| 6 | +import * as AdmZip from 'adm-zip'; |
| 7 | + |
| 8 | +const PATH_CONFIG = get('dir_path'); |
| 9 | +const CONTENT_CONFIG = get('content'); |
| 10 | + |
| 11 | +async function init() { |
| 12 | + try { |
| 13 | + await fs.remove(PATH_CONFIG.defaultContent); |
| 14 | + |
| 15 | + await fs.ensureDir(PATH_CONFIG.defaultContent); |
| 16 | + |
| 17 | + const { data } = await axios.get( |
| 18 | + new URL(path.join( |
| 19 | + CONTENT_CONFIG.updateUrl, |
| 20 | + CONTENT_CONFIG.zip, |
| 21 | + )).toString(), |
| 22 | + { |
| 23 | + responseType: 'arraybuffer', |
| 24 | + }, |
| 25 | + ); |
| 26 | + |
| 27 | + // extract archive to default folder |
| 28 | + const zip = new AdmZip(data); |
| 29 | + zip.extractAllTo(PATH_CONFIG.defaultContent, true); |
| 30 | + |
| 31 | + const { data: buildInfo } = await axios.get( |
| 32 | + new URL(path.join( |
| 33 | + CONTENT_CONFIG.updateUrl, |
| 34 | + CONTENT_CONFIG.buildInfo, |
| 35 | + )).toString(), |
| 36 | + { |
| 37 | + responseType: 'arraybuffer', |
| 38 | + }, |
| 39 | + ); |
| 40 | + |
| 41 | + // save build info to default folder |
| 42 | + await fs.writeFile( |
| 43 | + join(PATH_CONFIG.defaultContent, CONTENT_CONFIG.buildInfo), |
| 44 | + buildInfo, |
| 45 | + ); |
| 46 | + |
| 47 | + process.exit(0); |
| 48 | + } catch (e) { |
| 49 | + console.error('Something went wrong trying to get default commands jsons', e); |
| 50 | + process.exit(1); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +init(); |
0 commit comments