Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Export `COA.Cmd` object to be able to use commands as API calls

  • Loading branch information...
commit 1f316b8c6401090a98b4a92cfdac411af9172117 1 parent 72bd0b8
@arikon arikon authored
Showing with 49 additions and 54 deletions.
  1. +1 −1  bin/bem
  2. +48 −53 lib/bem.js
View
2  bin/bem
@@ -1,3 +1,3 @@
#!/usr/bin/env node
-require('../lib/bem').main();
+require('../lib/bem').run();
View
101 lib/bem.js
@@ -1,59 +1,54 @@
-exports.main = function () {
+var Q = require('q'),
+ CP = require('child_process'),
+ PATH = require('./path');
- var Q = require('q'),
- CP = require('child_process'),
- PATH = require('./path');
-
- require('coa').Cmd()
- .name(PATH.basename(process.argv[1]))
- .title('Инструменты работы с файлами, написанными по БЭМ-методу.')
- .helpful()
- .opt()
- .name('version').title('Версия')
- .short('v').long('version')
- .flag()
- .only()
- .act(function() {
- return JSON.parse(require('fs').readFileSync(
- PATH.join(__dirname, '..', 'package.json')))
- .version;
- })
- .end()
- .cmd().name('decl').apply(require('./commands/decl')).end()
- .cmd().name('build').apply(require('./commands/build')).end()
- .cmd().name('create').apply(require('./commands/create')).end()
- .completable()
+module.exports = require('coa').Cmd()
+ .name(PATH.basename(process.argv[1]))
+ .title('Инструменты работы с файлами, написанными по БЭМ-методу.')
+ .helpful()
+ .opt()
+ .name('version').title('Версия')
+ .short('v').long('version')
+ .flag()
+ .only()
.act(function() {
- var defer = Q.defer(),
- readline = require('readline'),
- rl = readline.createInterface(process.stdin, process.stdout),
- prefix = '> ';
- rl.setPrompt(prefix, prefix.length);
+ return JSON.parse(require('fs').readFileSync(
+ PATH.join(__dirname, '..', 'package.json')))
+ .version;
+ })
+ .end()
+ .cmd().name('decl').apply(require('./commands/decl')).end()
+ .cmd().name('build').apply(require('./commands/build')).end()
+ .cmd().name('create').apply(require('./commands/create')).end()
+ .completable()
+ .act(function() {
+ var defer = Q.defer(),
+ readline = require('readline'),
+ rl = readline.createInterface(process.stdin, process.stdout),
+ prefix = '> ';
+ rl.setPrompt(prefix, prefix.length);
- rl.on('line', function(line) {
- line = line.trim();
- if (!line) {
- rl.prompt();
- return;
- }
- var child = CP.spawn(process.argv[0],
- process.argv.slice(1, 2).concat(line.split(' ')),
- { cwd: process.cwd(), customFds: [-1, 1, 2] });
- child.on('exit', function (code) {
- rl.prompt();
- });
- })
- .on('close', function() {
- console.log('');
- process.stdin.destroy();
- defer.resolve();
+ rl.on('line', function(line) {
+ line = line.trim();
+ if (!line) {
+ rl.prompt();
+ return;
+ }
+ var child = CP.spawn(process.argv[0],
+ process.argv.slice(1, 2).concat(line.split(' ')),
+ { cwd: process.cwd(), customFds: [-1, 1, 2] });
+ child.on('exit', function (code) {
+ rl.prompt();
});
-
- console.log("Type '--help' for help, press ctrl+d or ctrl+c to exit");
- rl.prompt();
-
- return defer.promise;
})
- .run();
+ .on('close', function() {
+ console.log('');
+ process.stdin.destroy();
+ defer.resolve();
+ });
+
+ console.log("Type '--help' for help, press ctrl+d or ctrl+c to exit");
+ rl.prompt();
-};
+ return defer.promise;
+ });
Please sign in to comment.
Something went wrong with that request. Please try again.