UNPKG

2.3 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _cliEngineCommand = require('cli-engine-command');
8
9var _cliEngineCommand2 = _interopRequireDefault(_cliEngineCommand);
10
11var _plugins = require('../plugins');
12
13var _plugins2 = _interopRequireDefault(_plugins);
14
15var _fsExtra = require('fs-extra');
16
17var _fsExtra2 = _interopRequireDefault(_fsExtra);
18
19var _path = require('path');
20
21var _path2 = _interopRequireDefault(_path);
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25const debug = require('debug')('cli:commands');
26
27class Commands extends _cliEngineCommand2.default {
28
29 async run() {
30 this.out.warn('heroku-cli: This CLI is deprecated. Please reinstall from https://cli.heroku.com');
31 await this.addV6Hack();
32 let plugins = new _plugins2.default(this.config);
33 await plugins.load();
34 let topics = plugins.topics.filter(t => !t.hidden);
35 let commands = plugins.commands.map(c => ({
36 command: c.command,
37 topic: c.topic,
38 usage: c.usage,
39 description: c.description,
40 help: c.help,
41 fullHelp: c.help,
42 hidden: c.hidden
43 }));
44 this.out.styledJSON({ topics, commands });
45 }
46
47 async addV6Hack() {
48 try {
49 const hack = `### begin v6 v.1
50begin
51 pluginsDir = File.join(Dir.home, ".heroku", "plugins")
52 bin = File.join(Dir.home, ".local", "share", "heroku", "client", "bin", "heroku")
53 if File.exists?(bin) && (!Dir.exists?(pluginsDir) || Dir.entries(pluginsDir).count <= 2)
54 puts "Running: #{bin}" if ENV['HEROKU_DEBUG'] || ENV['DEBUG']
55 system bin, *ARGV
56 status = $?.exitstatus
57 exit status
58 end
59rescue => e
60 puts e
61end
62### end v6 v.1
63
64`;
65 if (this.config.windows) return;
66 let cliRB = _path2.default.join(this.config.home, '.heroku', 'client', 'lib', 'heroku', 'cli.rb');
67 if (!(await _fsExtra2.default.exists(cliRB))) return;
68 let contents = await _fsExtra2.default.readFile(cliRB, 'utf8');
69 if (contents.startsWith('### begin v6 v.1')) return;
70 await _fsExtra2.default.outputFile(cliRB, hack + contents);
71 } catch (err) {
72 debug(err);
73 }
74 }
75}
76exports.default = Commands;
77Commands.topic = 'commands';
78Commands.hidden = true;
79Commands.flags = { json: _cliEngineCommand.flags.boolean() };
\No newline at end of file