7986bc2a9a293f67d984d27d5441495f23c930c8
[platform/framework/web/crosswalk-tizen.git] /
1 #!/usr/bin/env node
2 "use strict";
3
4 // resolve allow us to load the locally installed esformatter instead of using
5 // the global version
6 var requireResolve = require('resolve').sync;
7 var path = require('path');
8 var dirname = path.dirname;
9 var pathResolve = path.resolve;
10
11 var argv = process.argv.slice(2);
12
13 // if user sets a config file we use that as the base directory to start the
14 // search because we assume that some settings aren't backwards compatible
15 // otherwise we just use the process.cwd()
16 var opts = require('../lib/cli.js').parse(argv);
17 var basedir = opts.config ?
18   pathResolve(dirname(opts.config)) :
19   process.cwd();
20
21 var cliPath;
22 try {
23   cliPath = requireResolve('esformatter', {
24     basedir: basedir
25   });
26   cliPath = pathResolve(dirname(cliPath), './cli.js');
27 } catch (err) {
28   // fallback to this version instead
29   cliPath = '../lib/cli.js';
30 }
31
32 var cli = require(cliPath);
33 // until v0.5 the cli module only exposed a single `parse` method, after v0.6
34 // we expose 2 methods to allow processing the data before executing the
35 // command (all the logic above)
36 if ('run' in cli) {
37   cli.run(cli.parse(argv));
38 } else {
39   cli.parse(argv);
40 }