Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.1.0
- Supports new advanced features parameters in the `firebase.json` to allow greater customization of hosting parameters
- improves default "ignore" rules to specify any dot file, regardless of whether in a sub-directory

- - -

## v1.0.6
- Adds `-s` functionality to all commands for silent mode while scripting - commands will error with non-zero status code instead of waiting for prompt if not enough information supplied
- `delete-site` command as a convenience method for removing a site from hosting. Site shows up as 'Site Not Found' as if never deployed to
Expand Down
174 changes: 115 additions & 59 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var request = require('request'),

var defaultSettings = {
'public': '.',
'ignore': ['firebase.json', '.*', '**/node_modules/**']
'ignore': ['firebase.json', '**/.*', '**/node_modules/**']
};

temp.track();
Expand Down Expand Up @@ -57,6 +57,115 @@ function getPrompt(argv, schema, onComplete, index, results) {
});
}

function updateRules(settings, tokens) {
return _when.promise(function(resolve, reject, notify) {
auth.updateRules(settings.firebase,
tokens.personalToken,
settings.rules,
function(statusCode, response) {
if (response.error) {
console.log(chalk.red('Security Rules Error') + ' - ' +
response.error.replace(/\n$/, ''));
process.exit(1);
}
resolve();
});
});
}

function updateRedirects(firebaseRef, settings) {
return _when.promise(function(resolve, reject, notify) {
var redirects = settings.redirects || null;
firebaseRef.child('hosting/path-redirects').child(settings.firebase).set(redirects, function(err) {
if (err) {
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "redirects" entry in the firebase.json');
process.exit(1);
}
resolve();
});
});
}

function updateRewrites(firebaseRef, settings) {
return _when.promise(function(resolve, reject, notify) {
var rewrites = settings.rewrites || null;
firebaseRef.child('hosting/rewrites').child(settings.firebase).set(rewrites, function(err) {
if (err) {
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "rewrites" entry in the firebase.json');
process.exit(1);
}
resolve();
});
});
}

function updateHeaders(firebaseRef, settings) {
return _when.promise(function(resolve, reject, notify) {
var headers = settings.headers || null;
firebaseRef.child('hosting/headers').child(settings.firebase).set(headers, function(err) {
if (err) {
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "headers" entry in the firebase.json');
process.exit(1);
}
resolve();
});
});
}

function uploadSite(settings, directoryRef, argv) {
return function() {
var bar = null;
var total = 0;
directoryRef.on('value', function(snapshot) {
var status = snapshot.child('status').val();
if (status === 'deployed') {
var url = api.hostingUrl.replace(/\/\//, util.format('//%s.', settings.firebase));
console.log(chalk.green('Successfully deployed'));
console.log('Site URL: %s, or use %s', chalk.cyan(url), chalk.bold('firebase open'));
console.log('Hosting Dashboard: %s then view the hosting section of your app', chalk.cyan('https://firebase.com/account'));
process.exit(0);
} else if (status === 'deploying') {
if (!bar && snapshot.hasChild('fileCount')) {
total = snapshot.child('fileCount').val();
bar = new ProgressBar(chalk.yellow('progress: :percent'), {
total: total
});
}
if (bar) {
var uploadedCount = snapshot.hasChild('uploadedCount') ? snapshot.child('uploadedCount').val() : 0;
bar.update(uploadedCount / total);
}
} else if (status === 'removed') {
console.log(chalk.green('Sucessfully removed'));
process.exit(0);
} else if (status === 'failed') {
if (bar) {
bar.terminate();
}
var message = chalk.red('Deploy Failed');
if (snapshot.hasChild('statusMessage')) {
message += ' - ' + snapshot.child('statusMessage').val();
}
console.log(message);
process.exit(1);
}
});

var message = null;
if (argv.message && (typeof(argv.message) === 'string')) {
message = argv.message;
}

upload.send(settings.firebase, settings['public'], settings.ignore, directoryRef.name(), message, function(err, directory) {
if (err) {
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
console.log(err);
process.exit(1);
}
});
}
}

function getSettings(argv) {
var settingsFile = path.resolve('./firebase.json');
var settingsJSON, settings;
Expand Down Expand Up @@ -402,65 +511,12 @@ module.exports = {
.child('hosting/versions')
.child(settings.firebase)
.push();
auth.updateRules(settings.firebase,
tokens.personalToken,
settings.rules,
function(statusCode, response) {
if (response.error) {
console.log(chalk.red('Security Rules Error') + ' - ' +
response.error.replace(/\n$/, ''));
process.exit(1);
}
var bar = null;
var total = 0;
directoryRef.on('value', function(snapshot) {
var status = snapshot.child('status').val();
if (status === 'deployed') {
var url = api.hostingUrl.replace(/\/\//, util.format('//%s.', settings.firebase));
console.log(chalk.green('Successfully deployed'));
console.log('Site URL: %s, or use %s', chalk.cyan(url), chalk.bold('firebase open'));
console.log('Hosting Dashboard: %s then view the hosting section of your app', chalk.cyan('https://firebase.com/account'));
process.exit(0);
} else if (status === 'deploying') {
if (!bar && snapshot.hasChild('fileCount')) {
total = snapshot.child('fileCount').val();
bar = new ProgressBar(chalk.yellow('progress: :percent'), {
total: total
});
}
if (bar) {
var uploadedCount = snapshot.hasChild('uploadedCount') ? snapshot.child('uploadedCount').val() : 0;
bar.update(uploadedCount / total);
}
} else if (status === 'removed') {
console.log(chalk.green('Sucessfully removed'));
process.exit(0);
} else if (status === 'failed') {
if (bar) {
bar.terminate();
}
var message = chalk.red('Deploy Failed');
if (snapshot.hasChild('statusMessage')) {
message += ' - ' + snapshot.child('statusMessage').val();
}
console.log(message);
process.exit(1);
}
});

var message = null;
if (argv.message && (typeof(argv.message) === 'string')) {
message = argv.message;
}

upload.send(settings.firebase, settings['public'], settings.ignore, directoryRef.name(), message, function(err, directory) {
if (err) {
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
console.log(err);
process.exit(1);
}
});
});
_when.join(updateRules(settings, tokens),
updateRedirects(firebaseRef, settings),
updateRewrites(firebaseRef, settings),
updateHeaders(firebaseRef, settings))
.done(uploadSite(settings, directoryRef, argv));
});
});
},
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"name": "firebase-tools",
"preferGlobal": true,
"version": "1.0.6",
"version": "1.1.0",
"description": "The Firebase Command Line Tools",
"keywords": [
"firebase"
"firebase",
"hosting",
"ssl",
"cdn",
"cli",
"synchronization",
"real-time",
"websockets",
"cloud"
],
"author": "Firebase <support@firebase.com>",
"contributors": [
Expand Down