Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 4x 1x 1x 1x 1x 4x 1x 1x 1x 1x 78x 78x 78x 1170x 78x 78x 78x 78x 78x 78x 78x 78x 1x 4x 4x 4x 4x | /* eslint-disable import/no-cycle */ // @todo fix cycle import chalk from 'chalk'; import fs from 'fs'; import readline from 'readline'; import { SUPPORTED_PLATFORMS } from '../constants'; import { logTask, logSuccess, } from '../common'; import { askQuestion, generateOptions, getQuestion, finishQuestion } from '../systemTools/prompt'; import { executePipe } from '../projectTools/buildHooks'; import { writeObjectSync } from '../systemTools/fileutils'; const LIST = 'list'; const ADD = 'add'; const UPDATE = 'update'; const PIPES = { PLUGIN_LIST_BEFORE: 'plugin:list:before', PLUGIN_LIST_AFTER: 'plugin:list:after', PLUGIN_ADD_BEFORE: 'plugin:add:before', PLUGIN_ADD_AFTER: 'plugin:add:after', PLUGIN_UPDATE_BEFORE: 'plugin:update:before', PLUGIN_UPDATE_AFTER: 'plugin:update:after', }; // ########################################## // PUBLIC API // ########################################## const run = (c) => { logTask('run'); switch (c.subCommand) { case LIST: return executePipe(c, PIPES.PLUGIN_LIST_BEFORE) .then(() => _runList(c)) .then(() => executePipe(c, PIPES.PLUGIN_LIST_AFTER)); case ADD: executePipe(c, PIPES.PLUGIN_ADD_BEFORE); return _runAdd(c).then(() => executePipe(c, PIPES.PLUGIN_ADD_AFTER)); case UPDATE: executePipe(c, PIPES.PLUGIN_UPDATE_BEFORE); return _runUpdate(c).then(() => executePipe(c, PIPES.PLUGIN_UPDATE_AFTER)); default: return Promise.reject(`cli:plugin: Sub-Command ${chalk.white.bold(c.subCommand)} not supported!`); } }; // ########################################## // PRIVATE // ########################################## const _runList = c => new Promise((resolve) => { logTask('_runList'); const o = _getPluginList(c); console.log(o.asString); resolve(); }); const _getPluginList = (c, isUpdate = false) => { const { plugins } = c.files.rnv.pluginTemplates.config; const output = { asString: '', plugins: [], json: plugins, }; let i = 1; Object.keys(plugins).forEach((k) => { const p = plugins[k]; let platforms = ''; SUPPORTED_PLATFORMS.forEach((v) => { if (p[v]) platforms += `${v}, `; }); if (platforms.length) platforms = platforms.slice(0, platforms.length - 2); const installedPlugin = c.buildConfig && c.buildConfig.plugins && c.buildConfig.plugins[k]; const installedString = installedPlugin ? chalk.red('installed') : chalk.green('not installed'); I if (isUpdate && installedPlugin) { output.plugins.push(k); let versionString; if (installedPlugin.version !== p.version) { versionString = `(${chalk.red(installedPlugin.version)}) => (${chalk.green(p.version)})`; } else { versionString = `(${chalk.green(installedPlugin.version)})`; } output.asString += `-[${i}] ${chalk.white(k)} ${versionString}\n`; i++; } eElse if (!isUpdate) { output.plugins.push(k); output.asString += `-[${i}] ${chalk.white(k)} (${chalk.blue(p.version)}) [${platforms}] - ${installedString}\n`; i++; } }); return output; }; const _runAdd = c => new Promise((resolve) => { logTask('_runAdd'); const o = _getPluginList(c); console.log(o.asString); const readlineInterface = readline.createInterface({ input: process.stdin, output: process.stdout, }); readlineInterface.question(getQuestion('Type plugin numbers you want to add (comma separated)'), (v) => { const choices = v.split(','); const selectedPlugins = {}; let msg = 'Installing: \n'; choices.forEach((choice) => { const i = parseInt(choice, 10) - 1; const key = o.plugins[i]; if (key) { selectedPlugins[key] = o.json[key]; msg += `- ${chalk.white(key)} v(${chalk.green(o.json[key].version)})\n`; } }); console.log(msg); Object.keys(selectedPlugins).forEach((key) => { // c.buildConfig.plugins[key] = 'source:rnv'; c.files.project.config.plugins[key] = 'source:rnv'; // c.buildConfig.plugins[key] = selectedPlugins[key]; _checkAndAddDependantPlugins(c, selectedPlugins[key]); }); writeObjectSync(c.paths.project.config, c.files.project.config); logSuccess('Plugins installed successfully!'); resolve(); }); }); const _checkAndAddDependantPlugins = (c, plugin) => { const templatePlugins = c.files.rnv.pluginTemplates.config.plugins; if (plugin.dependsOn) { plugin.dependsOn.forEach((v) => { if (templatePlugins[v]) { console.log(`Added dependant plugin ${v}`); c.buildConfig.plugins[v] = templatePlugins[v]; } }); } }; const _runUpdate = c => new Promise((resolve) => { logTask('_runUpdate'); const o = _getPluginList(c, true); console.log(o.asString); askQuestion('Above installed plugins will be updated with RNV. press (y) to confirm') .then((v) => { finishQuestion(); const { plugins } = c.buildConfig; Object.keys(plugins).forEach((key) => { // c.buildConfig.plugins[key] = o.json[key]; c.files.project.config.plugins[key] = o.json[key]; }); writeObjectSync(c.paths.project.config, c.files.project.config); logSuccess('Plugins updated successfully!'); resolve(); }); }); export { PIPES }; export default run; |