# All files / dist/pluginTools index.js

12.97% Statements 24/185
0% Branches 0/113
0% Functions 0/23
12.58% Lines 20/159

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
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    3054x
    4x
    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x
     var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.getLocalRenativePlugin=exports.parsePlugins=exports.getMergedPlugin=exports.configurePlugins=exports.pluginUpdate=exports.pluginAdd=exports.pluginList=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _chalk=_interopRequireDefault(require("chalk"));
    var _inquirer=_interopRequireDefault(require("inquirer"));
    var _ora=_interopRequireDefault(require("ora"));
    var _fileutils=require("../systemTools/fileutils");
    var _common=require("../common");
    var _configParser=require("../configTools/configParser");

    var _constants=require("../constants");
    var _logger=require("../systemTools/logger");

    var _buildHooks=require("../projectTools/buildHooks");

    var pluginList=function pluginList(c){return new Promise(function(resolve){
    (0,_logger.logTask)('_runList');

    var o=_getPluginList(c);

    console.log(o.asString);

    resolve();
    });};exports.pluginList=pluginList;

    var _getPluginList=function _getPluginList(c){var isUpdate=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var
    plugins=c.files.rnv.pluginTemplates.config.plugins;
    var output={
    asString:'',
    asArray:[],
    plugins:[],
    json:plugins};

    var i=1;

    Object.keys(plugins).forEach(function(k){
    var p=plugins[k];

    var platforms='';
    _constants.SUPPORTED_PLATFORMS.forEach(function(v){
    if(p[v])platforms+=v+", ";
    });
    if(platforms.length)platforms=platforms.slice(0,platforms.length-2);
    var installedPlugin=c.buildConfig&&c.buildConfig.plugins&&c.buildConfig.plugins[k];
    var installedString=installedPlugin?_chalk.default.red('installed'):_chalk.default.green('not installed');
    if(isUpdate&&installedPlugin){
    output.plugins.push(k);
    var versionString;
    if(installedPlugin.version!==p.version){
    versionString="("+_chalk.default.red(installedPlugin.version)+") => ("+_chalk.default.green(p.version)+")";
    }else{
    versionString="("+_chalk.default.green(installedPlugin.version)+")";
    }
    output.asString+="-["+i+"] "+_chalk.default.white(k)+" "+versionString+"\n";
    output.asArray.push({name:k+" "+versionString,value:k});
    i++;
    }else if(!isUpdate){
    output.plugins.push(k);
    output.asString+="-["+i+"] "+_chalk.default.white(k)+" ("+_chalk.default.blue(p.version)+") ["+platforms+"] - "+installedString+"\n";
    output.asArray.push({name:k+" ("+_chalk.default.blue(p.version)+") ["+platforms+"] - "+installedString,value:k});

    i++;
    }
    output.asArray.sort(function(a,b){
    var aStr=a.name.toLowerCase();
    var bStr=b.name.toLowerCase();
    var com=0;
    if(aStr>bStr){
    com=1;
    }else if(aStr<bStr){
    com=-1;
    }
    return com;
    });
    });

    return output;
    };

    var pluginAdd=function pluginAdd(c){var o,_ref,plugins,installMessage,selectedPlugins,spinner;return _regenerator.default.async(function pluginAdd$(_context){while(1){switch(_context.prev=_context.next){case 0:
    (0,_logger.logTask)('pluginAdd');

    o=_getPluginList(c);_context.next=4;return _regenerator.default.awrap(

    _inquirer.default.prompt({
    name:'plugins',
    type:'rawlist',
    message:'Select the plugins you want to add',
    choices:o.asArray,
    pageSize:100}));case 4:_ref=_context.sent;plugins=_ref.plugins;

    installMessage=[];

    if(plugins.length){
    selectedPlugins={};
    plugins.forEach(function(plugin){
    selectedPlugins[plugin]=o.json[plugin];
    installMessage.push(_chalk.default.white(plugin)+" v("+_chalk.default.green(o.json[plugin].version)+")");
    });

    spinner=(0,_ora.default)("Installing: "+installMessage.join(', ')).start();

    Object.keys(selectedPlugins).forEach(function(key){

    c.files.project.config.plugins[key]='source:rnv';

    _checkAndAddDependantPlugins(c,selectedPlugins[key]);
    });

    (0,_fileutils.writeObjectSync)(c.paths.project.config,c.files.project.config);
    spinner.succeed('All plugins installed!');
    (0,_logger.logSuccess)('Plugins installed successfully!');
    }case 8:case"end":return _context.stop();}}});};exports.pluginAdd=pluginAdd;

    var _checkAndAddDependantPlugins=function _checkAndAddDependantPlugins(c,plugin){
    var templatePlugins=c.files.rnv.pluginTemplates.config.plugins;
    if(plugin.dependsOn){
    plugin.dependsOn.forEach(function(v){
    if(templatePlugins[v]){
    console.log("Added dependant plugin "+v);
    c.buildConfig.plugins[v]=templatePlugins[v];
    }
    });
    }
    };

    var pluginUpdate=function pluginUpdate(c){var o,_ref2,confirm,plugins;return _regenerator.default.async(function pluginUpdate$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
    (0,_logger.logTask)('pluginUpdate');

    o=_getPluginList(c,true);

    console.log(o.asString);_context2.next=5;return _regenerator.default.awrap(

    _inquirer.default.prompt({
    name:'confirm',
    type:'confirm',
    message:'Above installed plugins will be updated with RNV'}));case 5:_ref2=_context2.sent;confirm=_ref2.confirm;

    if(confirm){
    plugins=c.buildConfig.plugins;
    Object.keys(plugins).forEach(function(key){

    c.files.project.config.plugins[key]=o.json[key];
    });

    (0,_fileutils.writeObjectSync)(c.paths.project.config,c.files.project.config);

    (0,_logger.logSuccess)('Plugins updated successfully!');
    }case 8:case"end":return _context2.stop();}}});};exports.pluginUpdate=pluginUpdate;

    var getMergedPlugin=function getMergedPlugin(c,key,plugins){var noMerge=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;
    var plugin=plugins[key];
    var origPlugin=c.files.rnv.pluginTemplates.config.plugins[key];
    if(typeof plugin==='string'||plugin instanceof String){
    if(plugin==='source:rnv'){
    return origPlugin;
    }

    (0,_logger.logWarning)("Plugin "+key+" is not recognized RNV plugin");
    return null;
    }

    if(origPlugin){
    var mergedPlugin=(0,_fileutils.mergeObjects)(c,origPlugin,plugin,true,true);
    return mergedPlugin;
    }

    return plugin;
    };exports.getMergedPlugin=getMergedPlugin;

    var configurePlugins=function configurePlugins(c){return new Promise(function(resolve,reject){
    (0,_logger.logTask)('configurePlugins');

    if(!c.files.project.package.dependencies){
    c.files.project.package.dependencies={};
    }

    var hasPackageChanged=false;

    for(var k in c.buildConfig.plugins){var
    dependencies=c.files.project.package.dependencies;var
    devDependencies=c.files.project.package.devDependencies;
    var plugin=getMergedPlugin(c,k,c.buildConfig.plugins);

    if(!plugin){
    (0,_logger.logWarning)("Plugin with name "+
    _chalk.default.white(k)+" does not exists in ReNative source:rnv scope. you need to define it manually here: "+
    _chalk.default.white(c.paths.project.builds.config));
    }else if(dependencies&&dependencies[k]){
    if(plugin['no-active']!==true&&plugin['no-npm']!==true&&dependencies[k]!==plugin.version){
    if(k==='renative'&&c.runtime.isWrapper){
    (0,_logger.logWarning)('You\'re in ReNative wrapper mode. plugin renative will stay as local dep!');
    }else{
    (0,_logger.logWarning)("Version mismatch of dependency "+
    _chalk.default.white(k)+" between:\n  "+
    _chalk.default.white(c.paths.project.package)+": v("+_chalk.default.red(dependencies[k])+") and\n  "+
    _chalk.default.white(c.paths.project.builds.config)+": v("+_chalk.default.green(plugin.version)+").\n  package.json will be overriden");

    hasPackageChanged=true;
    dependencies[k]=plugin.version;
    }
    }
    }else if(devDependencies&&devDependencies[k]){
    if(plugin['no-active']!==true&&plugin['no-npm']!==true&&devDependencies[k]!==plugin.version){
    (0,_logger.logWarning)("Version mismatch of devDependency "+
    _chalk.default.white(k)+" between package.json: v("+_chalk.default.red(
    devDependencies[k])+") and plugins.json: v("+
    _chalk.default.red(plugin.version)+"). package.json will be overriden");

    hasPackageChanged=true;
    devDependencies[k]=plugin.version;
    }
    }else if(plugin['no-active']!==true&&plugin['no-npm']!==true){

    (0,_logger.logWarning)("Missing dependency "+
    _chalk.default.white(k)+" v("+_chalk.default.red(
    plugin.version)+") in package.json. package.json will be overriden");

    hasPackageChanged=true;
    dependencies[k]=plugin.version;
    }

    if(plugin&&plugin.npm){
    for(var npmKey in plugin.npm){
    var npmDep=plugin.npm[npmKey];
    if(dependencies[npmKey]!==npmDep){
    (0,_logger.logWarning)("Plugin "+_chalk.default.white(k)+" requires npm dependency "+_chalk.default.white(npmKey)+" .Adding missing npm dependency to you package.json");
    dependencies[npmKey]=npmDep;
    hasPackageChanged=true;
    }
    }
    }
    }

    (0,_logger.logTask)("configurePlugins:"+hasPackageChanged,_chalk.default.grey);
    (0,_configParser.versionCheck)(c).
    then(function(){
    if(hasPackageChanged){
    (0,_fileutils.writeObjectSync)(c.paths.project.package,c.files.project.package);
    c._requiresNpmInstall=true;
    }
    resolve();
    }).catch(function(e){return reject(e);});
    });};exports.configurePlugins=configurePlugins;

    var parsePlugins=function parsePlugins(c,platform,pluginCallback){
    (0,_logger.logTask)("parsePlugins:"+platform);

    if(c.buildConfig){
    var includedPlugins=(0,_common.getConfigProp)(c,platform,'includedPlugins',[]);
    var excludedPlugins=(0,_common.getConfigProp)(c,platform,'excludedPlugins',[]);
    if(includedPlugins){var
    plugins=c.buildConfig.plugins;
    if(plugins){
    Object.keys(plugins).forEach(function(key){
    if((includedPlugins.includes('*')||includedPlugins.includes(key))&&!excludedPlugins.includes(key)){
    var plugin=getMergedPlugin(c,key,plugins);
    if(plugin){
    var pluginPlat=plugin[platform];
    if(pluginPlat){
    if(plugin['no-active']!==true&&plugin.enabled!==false&&pluginPlat.enabled!==false){
    if(pluginCallback)pluginCallback(plugin,pluginPlat,key);
    }else{
    (0,_logger.logWarning)("Plugin "+key+" is marked disabled. skipping.");
    }
    }
    }
    }
    });
    }else{
    (0,_logger.logError)("You have no plugins defined in "+_chalk.default.white(c.paths.project.builds.config));
    }
    }else{
    (0,_logger.logWarning)("You haven't included any "+_chalk.default.white('{ common: { includedPlugins: [] }}')+" in your "+_chalk.default.white(c.paths.appConfig.config)+". Your app might not work correctly");
    }
    }
    };exports.parsePlugins=parsePlugins;

    var getLocalRenativePlugin=function getLocalRenativePlugin(){return{
    version:'file:./packages/renative',
    webpack:{
    modulePaths:[],
    moduleAliases:{
    renative:{
    projectPath:'packages/renative'}}}};};exports.getLocalRenativePlugin=getLocalRenativePlugin;var _default=

    {getMergedPlugin:getMergedPlugin,parsePlugins:parsePlugins,getLocalRenativePlugin:getLocalRenativePlugin};exports.default=_default;
    //# sourceMappingURL=index.js.map