* * @param command
(cm: string[])
| 114 | * @param command |
| 115 | */ |
| 116 | function saveCommand (cm: string[]) { |
| 117 | const commands = cm.slice (2); |
| 118 | const command = commands.join (' '); |
| 119 | const cachePath = getCacheDirectory (); |
| 120 | const historyPath = path.join (cachePath, 'history'); |
| 121 | if (!fs.existsSync (historyPath)) { |
| 122 | try { |
| 123 | fs.mkdirSync (historyPath, { |
| 124 | 'recursive': true, |
| 125 | }); |
| 126 | } catch (e) { |
| 127 | log.red ('Error creating cache directory', cachePath); |
| 128 | } |
| 129 | } |
| 130 | const historyFile = path.join (historyPath, 'commands.json'); |
| 131 | let list: any[] = []; |
| 132 | if (!fs.existsSync (historyFile)) { |
| 133 | fs.writeFileSync (historyFile, JSON.stringify (list, null, 2)); |
| 134 | } else { |
| 135 | list = JSON.parse (fs.readFileSync (historyFile).toString ()) || []; |
| 136 | } |
| 137 | list.push (command); |
| 138 | fs.writeFileSync (historyFile, JSON.stringify (list, null, 2)); |
| 139 | } |
| 140 | |
| 141 | function changeConfigPath (newPath: string) { |
| 142 | log ('The config file now will be loaded from: ', newPath); |