@dosmond37/firebase-storage-cli
Version:
Upload anything, right from your command line.
61 lines (60 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const chalk = require("chalk");
const fs = require("fs-extra");
const command_1 = require("@oclif/command");
class ConfigSet extends command_1.Command {
async run() {
const { args } = this.parse(ConfigSet);
// Check if Config Directory exists, otherwise create directory
const configPath = path.join(this.config.configDir, 'config.json');
this.log(configPath);
await fs.ensureDir(this.config.configDir);
// Initialize Empty Object to bypass TSLint Errors
let userConfig = {
serviceAccount: '',
storageBucket: '',
};
// Read Existing Values to Append
try {
userConfig = await fs.readJSON(configPath);
}
catch (error) { }
// Set Service Account JSON Path
if (args.key === 'service.account') {
userConfig.serviceAccount = args.value;
this.log(chalk.bold('Service Account JSON has been updated.'));
}
// Set Firebase Storage Bucket URL
if (args.key === 'storage.bucket') {
userConfig.storageBucket = args.value;
this.log(chalk.bold('Firebase Storage Bucket URL has been updated.'));
}
// Finally, write the updated JSON to file
await fs.writeJSON(configPath, userConfig, { spaces: 2 });
}
}
exports.default = ConfigSet;
ConfigSet.description = 'set global config vars';
ConfigSet.aliases = ['cs'];
ConfigSet.examples = [
`$ fireup cs service.account /path/to/file.json`,
`$ fireup config:set storage.bucket <project-id>.appspot.com`,
];
ConfigSet.flags = {
help: command_1.flags.help({ char: 'h' }),
};
ConfigSet.args = [
{
name: 'key',
required: true,
description: 'config variable to modify',
options: ['service.account', 'storage.bucket'],
},
{
name: 'value',
required: true,
description: 'value to be set',
},
];