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