UNPKG

angular-ide

Version:

Provides a seamless integration with the Angular IDE from the command-line for developers looking for an enhanced development experience with Angular.

61 lines (51 loc) 1.81 kB
const path = require('path'); const Rx = require('rxjs'); const extract = require('./extract'); const registerInstallation = require('./utils').registerInstallation; const downloadIDE = require('../lib/downloadIDE'); const Messages = require('./messages'); const ProgressBar = require('./progress-bar'); const os = require('os'); const fs = require('fs'); const rxUnlink = Rx.Observable.bindNodeCallback(fs.unlink); module.exports = function (installPath) { const osType = os.type(); const arch = os.arch(); const $downloaded = downloadIDE(osType, arch); $downloaded.subscribe(downloadedFile => { const extractedProgress = new ProgressBar('Extracting....:bar :completed%'); const compressedFilePath$ = Rx.Observable.of(downloadedFile); const destinationPath$ = Rx.Observable.of(path.resolve(installPath)); const extract$ = extract(compressedFilePath$, destinationPath$, osType); const extracted$ = Rx.Observable.create((observer) => { extract$.subscribe( progress => { extractedProgress.update(progress.current, progress.total); }, null, c => { extractedProgress.complete(); observer.next(null) }); }); extracted$ .withLatestFrom(destinationPath$) .flatMap(([extracted, destinationPath]) => { return registerInstallation(destinationPath, osType); }) .flatMap(() => { return rxUnlink(path.resolve('./angular_ide')); }) .subscribe(x => { console.log(Messages.ANGULAR_IDE_HAS_BEEN_INSTALLED); process.exit(); }); }, e => { rxUnlink(path.resolve('./angular_ide.mtd')).catch().subscribe(x => { console.log(Messages.ANGULAR_IDE_DOWNLOAD_NOT_AVAILABLE, e.message); process.exit(); }); } ); };