有人可以解释一下如何firebase-tools
用作 javascript 模块吗?我已经实现了一个命令行工具,我想在其中执行该功能data:push
。问题是我没有收到文档中描述的承诺。
这是我到目前为止所拥有的:
module.exports = new Command('createLicense [command]')
.description('creates a license for an organization')
.option('--type <full|light>', 'the license type (full|light)')
.option('--slots <number of slots>', 'the amount of free slots')
.option('--orgaId <id>', 'the organization id')
.option('-y, --confirm', 'pass this option to bypass confirmation prompt')
.action(function(commandName) {
var options = options || {};
return prompt(options, [
{
type: 'list',
name: 'licType',
message: 'What kind of license type should be created?',
default: 0,
choices: ['full', 'light']
},
{
type: 'input',
name: 'slots',
message: 'How many slots should the license serve:',
validate: function ( value ) {
if (!value || parseInt(value) === 0 || isNaN(parseInt(value))) return "Please enter a valid number > 0";
else return true;
}
},
{
type: 'input',
name: 'orgaId',
message: "What's the organization Id?",
validate: function ( value ) {
if (!value || typeof(value) !== 'string') return "Please enter a GUID with format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`";
else return true;
}
}
]).then(function() {
logger.info('License type: ' + options.licType);
logger.info('License slots: ' + options.slots);
logger.info('Organization: ' + options.orgaId);
var result = firebase.data.push({
firebase: 'zxlkchjiuihsdasdslkhas',
path: '/orga/' + options.orgaId + '/licenses/',
token: process.env.FIREBASE_TOKEN,
options: {data: {'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' : {
date : moment().utc(),
no : 'xyz',
nuser : options.slots,
type : options.licType,
validUntil : 1478735999}}}
});
result.then(function (resolve) {
return logger.info('License created');
process.exit(0);
});
result.then(function (reject) {
logger.info('Error occured: ' + reject);
process.exit(1);
})
});
});
我如何提供path
,options
以及???data
firebase.data.push