| 145 | } |
| 146 | |
| 147 | const deref = (c) => { |
| 148 | if (!c) { |
| 149 | return |
| 150 | } |
| 151 | |
| 152 | // Translate camelCase to snake-case (i.e. installTest to install-test) |
| 153 | if (c.match(/[A-Z]/)) { |
| 154 | c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase()) |
| 155 | } |
| 156 | |
| 157 | // if they asked for something exactly we are done |
| 158 | if (commands.includes(c)) { |
| 159 | return c |
| 160 | } |
| 161 | |
| 162 | // if they asked for a direct alias |
| 163 | if (aliases[c]) { |
| 164 | return aliases[c] |
| 165 | } |
| 166 | |
| 167 | const abbrevs = abbrev(commands.concat(Object.keys(aliases))) |
| 168 | |
| 169 | // first deref the abbrev, |
| 170 | // if there is one then resolve any aliases so `npm install-cl` will resolve to `install-clean` then to `ci` |
| 171 | let a = abbrevs[c] |
| 172 | while (aliases[a]) { |
| 173 | a = aliases[a] |
| 174 | } |
| 175 | return a |
| 176 | } |
| 177 | |
| 178 | module.exports = { |
| 179 | aliases, |