| 72 | } |
| 73 | |
| 74 | run (params, callback) { |
| 75 | |
| 76 | let debug = !!params.flags.d; |
| 77 | let infoMode = !!params.flags.i; |
| 78 | let isLocal = false; |
| 79 | let gateway; |
| 80 | |
| 81 | if (params.name.indexOf('.') === -1) { |
| 82 | if (params.name.indexOf('/') > -1) { |
| 83 | let names = params.name.split('/'); |
| 84 | if (names[1].indexOf('@') > -1) { |
| 85 | names[1] = names[1].split('@'); |
| 86 | if (names[1].length > 1) { |
| 87 | names[1][1] = names[1][1] && `[@${names[1][1]}]`; |
| 88 | } |
| 89 | names[1] = names[1].slice(0, 2).join(''); |
| 90 | } |
| 91 | return callback(new Error(`Deprecated service path usage, please try \`lib ${names.join('.')}\` instead`)); |
| 92 | } |
| 93 | return callback(new Error(`Command "${params.name}" does not exist.`)); |
| 94 | } else if (params.name[0] === '.') { |
| 95 | isLocal = true; |
| 96 | let pkg; |
| 97 | let env; |
| 98 | try { |
| 99 | pkg = serviceConfig.get() |
| 100 | } catch (e) { |
| 101 | if (!config.workspace()) { |
| 102 | return callback(new Error([ |
| 103 | 'You have not set up a Autocode workspace yet.', |
| 104 | '\nTry running `lib init` in a directory that you would like to use as a workspace.' |
| 105 | ].join(''))); |
| 106 | } else if (!config.location(2)) { |
| 107 | return callback( |
| 108 | new Error( |
| 109 | [ |
| 110 | 'There was an error parsing "package.json" from this directory.', |
| 111 | '\nIt could be malformed, but it\'s more likely you\'re running', |
| 112 | ' this command from the wrong directory.', |
| 113 | '\n\nYour Autocode workspace is located in:', |
| 114 | '\n ' + config.workspace(), |
| 115 | '\nAnd you\'re currently in:', |
| 116 | '\n ' + process.cwd(), |
| 117 | '\n\nAutocode services are normally two levels down from your workspace directory.', |
| 118 | '\n (i.e. workspace/username/servicename)' |
| 119 | ].join('') |
| 120 | ) |
| 121 | ); |
| 122 | } else if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) { |
| 123 | return callback(new Error( |
| 124 | [ |
| 125 | 'There was no "package.json" found in this directory, you may have deleted it.', |
| 126 | '\nTry creating a new service (using `lib create`) from your Autocode workspace directory:', |
| 127 | '\n ' + config.workspace() |
| 128 | ].join('')) |
| 129 | ); |
| 130 | } else { |
| 131 | return callback(new Error('Invalid "package.json" in this directory, your JSON syntax is likely malformed.')); |