UNPKG

build_salesforce_package

Version:

Build Saleforce Package to be deployed using git diff

68 lines (51 loc) 1.29 kB
var fs = require('fs-extra'); var chalk = require('chalk'); var Cryptr = require('cryptr'); var Profile = require('./profile'); var Util = require('./util'); class Config{ constructor(){ this.profiles = []; this.storage = {}; } loadFile(key){ if(fs.existsSync(Util.configPath())){ this.storage = JSON.parse(fs.readFileSync(Util.configPath(), 'utf8')); } for(var key in this.storage){ let _tempData = this.storage[key]; _tempData.name = key; let _profile = new Profile(); _profile.load(_tempData,key); this.profiles.push(_profile); } return this; } print(){ for(var key in this.profiles){ this.profiles[key].print(); } } saveFile(){ fs.writeFileSync(Util.configPath(),JSON.stringify(this.storage)); return this; } remove(name){ delete this.storage[name]; console.log(chalk.bold.cyan(name+' removed from config')); return this; } add(name,data){ this.storage[name] = data; console.log(chalk.bold.cyan('Profile '+name+' added')); return this; } getProfile(name,key){ if(!this.storage.hasOwnProperty(name)){ console.log(chalk.red('Profile doesn\'t exist')); process.exit(1); } return new Profile().load(this.storage[name],key); } } module.exports = Config;