Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a progress task list #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 47 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,61 @@
var program = require('commander')
var childProcess = require('child_process')
var fs = require('fs')
var Listr = require('listr')
var port = process.env.port || 3000

function startCommand(command, callback) {
var child = childProcess.exec(command, callback)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
return child
}

function init() {

console.log('Creating new bot...')

fs.readFile(__dirname + '/templates/index.js', function(err, data) {
if (err) throw err

console.log('Copying index.js...')

fs.writeFile('index.js', data, function(err) {
if (err) throw err

console.log('Copied index.js...')
function copyFile(src, dest) {
return new Promise((resolve, reject) => {
fs.readFile(src, function(err1, data) {
if (err1) {
reject()
return
}

fs.writeFile(dest, data, function(err2) {
if (err2) {
reject()
return
}

resolve();
})
})
})
}

fs.readFile(__dirname + '/templates/package.json', function(err, data) {
if (err) throw err

console.log('Copying Package.json...')

fs.writeFile('package.json', data, function(err) {
if (err) throw err

console.log('Copied Package.json...')
console.log('Installing Dependencies...')

startCommand('npm install')
})
})
function init() {
var tasks = new Listr([
{
title: 'Copy index.js',
task: () => copyFile(
__dirname + '/templates/index.js',
'index.js'
),
},
{
title: 'Copy package.json',
task: () => copyFile(
__dirname + '/templates/package.json',
'package.json'
),
},
{
title: 'Installing dependencies',
task: () => new Promise((resolve, reject) => {
var child = childProcess.exec('npm install')
child.on('close', () => {
resolve();
});
}),
},
]);

tasks.run();
}

function startServer() {
return startCommand('node .', function (error, stdout, stderr) {
childProcess.exec('node .', (err, stdout, stderr) => {
process.exit(1)
})
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"dependencies": {
"commander": "^2.9.0",
"eslint": "^3.7.1"
"eslint": "^3.7.1",
"listr": "^0.6.1"
},
"devDependencies": {},
"scripts": {
Expand Down