UNPKG

blazepress

Version:

A rapid web application development platform for Node.js

90 lines (57 loc) 1.71 kB
const Default = require( './Default' ) const fs = require( '../fs' ) class Installer extends Default { constructor() { super() this.on( 'mounted', () => { this.parent.on( 'started', checkTK ) }) } } let term, tpath = fs.cwd().sub('node_modules/terminal-kit').str function checkTK() { try { require.resolve( tpath ) run() } catch( err ) { let proceed = false const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) rl.question( 'blazepress needs module "terminal-kit", install it now? [no]: ', (proceed) => { console.log( 'proceed=', proceed ) proceed = proceed.toLowerCase() proceed = ( proceed === 'y' || proceed === 'yes' ) rl.close(); }); if( proceed ) { let child = require( 'child_process' ).exec( 'npm install terminal-kit', () => setTimeout( run, 2000 ) ) child.stdout.on( 'data', (data) => { console.log( 'data:', data ) }) } console.log( 'done' ) } } function run() { term = require( tpath ).terminal ; term.fullscreen() term.bold.cyan( 'Type anything on the keyboard...\n' ) ; term.green( 'Hit CTRL-C to quit.\n\n' ) ; term.grabInput( { mouse: 'button' } ) ; term.on( 'key' , function( name ) { console.log( "'key' event:" , name ) ; if ( name === 'CTRL_C' ) { terminate() ; } } ) ; term.on( 'terminal' , function( name , data ) { console.log( "'terminal' event:" , name , data ) ; } ) ; term.on( 'mouse' , function( name , data ) { console.log( "'mouse' event:" , name , data ) ; } ) ; function terminate() { term.grabInput( false ) ; setTimeout( function() { process.exit() } , 100 ) ; } } module.exports = Installer