forked from actionhero/actionhero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb20b8b
commit 065daf6
Showing
24 changed files
with
324 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use strict' | ||
|
||
exports.createChatRoom = { | ||
name: 'createChatRoom', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,76 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
'use strict' | ||
|
||
const cluster = require('cluster'); | ||
const fs = require('fs'); | ||
const winston = require('winston'); | ||
const path = require('path'); | ||
const optimist = require('optimist'); | ||
const spawn = require('child_process').spawn; | ||
const path = require('path') | ||
const optimist = require('optimist') | ||
const spawn = require('child_process').spawn | ||
|
||
const actionheroRoot = path.normalize(__dirname + '/..'); | ||
let projectRoot; | ||
const actionheroRoot = path.normalize(path.join(__dirname, '..')) | ||
let projectRoot | ||
|
||
if(process.env.projectRoot){ | ||
projectRoot = process.env.projectRoot; | ||
}else if(process.env.project_root){ | ||
projectRoot = process.env.project_root; | ||
}else if(process.env.PROJECT_ROOT){ | ||
projectRoot = process.env.PROJECT_ROOT; | ||
}else{ | ||
projectRoot = path.normalize(process.cwd()); | ||
if (process.env.projectRoot) { | ||
projectRoot = process.env.projectRoot | ||
} else if (process.env.project_root) { | ||
projectRoot = process.env.project_root | ||
} else if (process.env.PROJECT_ROOT) { | ||
projectRoot = process.env.PROJECT_ROOT | ||
} else { | ||
projectRoot = path.normalize(process.cwd()) | ||
} | ||
|
||
const ActionheroPrototype = require(actionheroRoot + '/actionhero.js'); | ||
const actionhero = new ActionheroPrototype(); | ||
const configChanges = {}; | ||
|
||
let commands = []; | ||
if(!optimist.argv._ || optimist.argv._.length === 0){ commands.push('start'); } | ||
optimist.argv._.forEach(function(arg){ commands.push(arg); }); | ||
if(commands.length === 1 && ['generate', 'help', 'version'].indexOf(commands[0]) >= 0){ | ||
const ActionheroPrototype = require(actionheroRoot + '/actionhero.js') | ||
const actionhero = new ActionheroPrototype() | ||
const configChanges = {} | ||
|
||
let commands = [] | ||
if (!optimist.argv._ || optimist.argv._.length === 0) { commands.push('start') } | ||
optimist.argv._.forEach(function (arg) { commands.push(arg) }) | ||
if (commands.length === 1 && ['generate', 'help', 'version'].indexOf(commands[0]) >= 0) { | ||
// when generating the project from scratch, we cannot rely on the normal initilizers | ||
const runner = require(__dirname + path.sep + 'methods' + path.sep + commands.join(path.sep) + '.js'); | ||
runner({projectRoot: projectRoot}, function(error){ | ||
if(error){ throw error; } | ||
setTimeout(process.exit, 500, 0); | ||
}); | ||
|
||
}else{ | ||
|
||
actionhero.initialize({configChanges: configChanges}, function(error, api){ | ||
if(error){ throw error; } | ||
api._context = actionhero; | ||
const runner = require(path.join(__dirname, 'methods', commands.join(path.sep) + '.js')) | ||
runner({projectRoot: projectRoot}, function (error) { | ||
if (error) { throw error } | ||
setTimeout(process.exit, 500, 0) | ||
}) | ||
} else { | ||
actionhero.initialize({configChanges: configChanges}, function (error, api) { | ||
if (error) { throw error } | ||
api._context = actionhero | ||
|
||
try{ | ||
const runner = require(__dirname + path.sep + 'methods' + path.sep + commands.join(path.sep) + '.js'); | ||
try { | ||
const runner = require(path.join(__dirname, 'methods', commands.join(path.sep) + '.js')) | ||
|
||
api.log('--------------------------------------'); | ||
api.log(['ACTIONHERO COMMAND >> %s', commands.join(' ')]); | ||
api.log(['projectRoot: %s', path.normalize(projectRoot)], 'debug'); | ||
api.log(['actionheroRoot: %s', path.normalize(actionheroRoot)], 'debug'); | ||
api.log('--------------------------------------'); | ||
api.log('--------------------------------------') | ||
api.log(['ACTIONHERO COMMAND >> %s', commands.join(' ')]) | ||
api.log(['projectRoot: %s', path.normalize(projectRoot)], 'debug') | ||
api.log(['actionheroRoot: %s', path.normalize(actionheroRoot)], 'debug') | ||
api.log('--------------------------------------') | ||
|
||
if(optimist.argv.daemon){ | ||
let newArgs = process.argv.splice(2); | ||
for(let i in newArgs){ | ||
if(newArgs[i].indexOf('--daemon') >= 0){ newArgs.splice(i, 1); } | ||
if (optimist.argv.daemon) { | ||
let newArgs = process.argv.splice(2) | ||
for (let i in newArgs) { | ||
if (newArgs[i].indexOf('--daemon') >= 0) { newArgs.splice(i, 1) } | ||
} | ||
newArgs.push('--isDaemon=true'); | ||
const command = path.normalize(actionheroRoot + '/bin/actionhero'); | ||
const child = spawn(command, newArgs, {detached: true, cwd: process.cwd(), env: process.env, stdio: 'ignore'}); | ||
api.log(['%s %s', command, newArgs.join(' ')], 'debug'); | ||
api.log(['spawned child process with pid %s', child.pid], 'notice'); | ||
process.nextTick(process.exit); | ||
}else{ | ||
runner(api, function(error, toStop){ | ||
if(error){ throw error; } | ||
if(toStop){ setTimeout(process.exit, 500, 0); } | ||
}); | ||
newArgs.push('--isDaemon=true') | ||
const command = path.normalize(actionheroRoot + '/bin/actionhero') | ||
const child = spawn(command, newArgs, {detached: true, cwd: process.cwd(), env: process.env, stdio: 'ignore'}) | ||
api.log(['%s %s', command, newArgs.join(' ')], 'debug') | ||
api.log(['spawned child process with pid %s', child.pid], 'notice') | ||
process.nextTick(process.exit) | ||
} else { | ||
runner(api, function (error, toStop) { | ||
if (error) { throw error } | ||
if (toStop) { setTimeout(process.exit, 500, 0) } | ||
}) | ||
} | ||
}catch(e){ | ||
if(!e.message.match(/Cannot find module/)){ | ||
throw(e); | ||
}else{ | ||
api.log(['Error: `%s` is not a method I can perform', commands.join(' ')], 'error'); | ||
api.log('run `actionhero help` to learn more', 'error'); | ||
setTimeout(process.exit, 500, 1); | ||
} catch (e) { | ||
if (!e.message.match(/Cannot find module/)) { | ||
throw (e) | ||
} else { | ||
api.log(['Error: `%s` is not a method I can perform', commands.join(' ')], 'error') | ||
api.log('run `actionhero help` to learn more', 'error') | ||
setTimeout(process.exit, 500, 1) | ||
} | ||
} | ||
}); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
module.exports = function (api, next) { | ||
const help = fs.readFileSync(__dirname + '/../templates/help.txt').toString() | ||
const help = fs.readFileSync(path.join(__dirname, '/../templates/help.txt')).toString() | ||
help.split('\n').forEach(function (line) { console.log(line) }) | ||
next(null, true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.