All files / piscosour/plugins/system-saver index.js

0% Statements 0/19
0% Branches 0/10
0% Functions 0/2
0% Lines 0/19
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                                                                     
'use strict';
 
// Plugins: ['launcher', 'piscosour', 'fsutils']
 
const fs = require('fs');
 
module.exports = {
 
  //TODO: Mejorar esto 1) guardar el resultado en una variable global en lugar de escribir en disco 2) detectar (this.isLast) el Ășltimo shot del straw y escribir entonces
  'core-check': function() {
    const fileName = 'requirements.json';
    let requirements = {};
    if (this.params.saveRequirements) {
      if (this.params.requirements) {
        requirements = this.fsReadConfig(fileName);
        if (requirements.empty) {
          delete requirements.empty;
        }
        let tmp = {};
        const reqTmp = this.piscoConfig.mergeObject(this.params.versions, this.params.requirements);
        Object.getOwnPropertyNames(this.params.requirements).forEach((cmd) => {
          const options = reqTmp[cmd];
          if (!options.installer) {
            tmp[cmd] = options;
          }
        });
        requirements = this.piscoConfig.mergeObject(requirements, tmp);
        fs.writeFileSync(fileName, JSON.stringify(requirements, null, 2));
      } else if (!this.fsExists(fileName)) {
        fs.writeFileSync(fileName, JSON.stringify(requirements, null, 2));
      }
    }
  }
};