UNPKG

2.06 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict';
3
4var _fs = require('fs');
5
6var _fs2 = _interopRequireDefault(_fs);
7
8var _meow = require('meow');
9
10var _meow2 = _interopRequireDefault(_meow);
11
12var _path = require('path');
13
14var _path2 = _interopRequireDefault(_path);
15
16var _resolveFrom = require('resolve-from');
17
18var _resolveFrom2 = _interopRequireDefault(_resolveFrom);
19
20var _standalone = require('./standalone');
21
22var _standalone2 = _interopRequireDefault(_standalone);
23
24function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26var cli = (0, _meow2.default)('\n Usage\n $ generate-robotstxt [options] <dest>\n Options\n --config Path to a specific configuration file.\n\n', {
27 alias: {
28 /* eslint-disable id-length */
29 h: 'help',
30 v: 'version'
31 /* eslint-enable id-length */
32 },
33 string: ['config']
34});
35
36var optionsBase = {};
37
38if (cli.flags.config) {
39 // Should check these possibilities:
40 // a. name of a node_module
41 // b. absolute path
42 // c. relative path relative to `process.cwd()`.
43 // If none of the above work, we'll try a relative path starting
44 // in `process.cwd()`.
45 optionsBase.configFile = (0, _resolveFrom2.default)(process.cwd(), cli.flags.config) || _path2.default.join(process.cwd(), cli.flags.config);
46}
47
48if (cli.input.length === 0) {
49 throw new Error('Require `dest` argument');
50}
51
52Promise.resolve().then(function () {
53 return Object.assign({}, optionsBase);
54}).then(function (options) {
55 return (0, _standalone2.default)(options);
56}).then(function (output) {
57 var dest = cli.input.pop();
58
59 return new Promise(function (resolve, reject) {
60 _fs2.default.writeFile(dest, output, function (error) {
61 if (error) {
62 return reject(new Error(error));
63 }
64
65 return resolve(output);
66 });
67 });
68}).catch(function (error) {
69 console.log(error); // eslint-disable-line no-console
70 process.exit(error.code || 1); // eslint-disable-line no-process-exit
71});
\No newline at end of file