Skip to content

Commit a90f317

Browse files
author
Chris Raynor
committed
Merge pull request #25 from firebase/v1.1.0
v1.1.0
2 parents dc70fb8 + 99b55dc commit a90f317

File tree

3 files changed

+131
-61
lines changed

3 files changed

+131
-61
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v1.1.0
2+
- Supports new advanced features parameters in the `firebase.json` to allow greater customization of hosting parameters
3+
- improves default "ignore" rules to specify any dot file, regardless of whether in a sub-directory
4+
5+
- - -
6+
17
## v1.0.6
28
- 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
39
- `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

lib/app.js

Lines changed: 115 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var request = require('request'),
1919

2020
var defaultSettings = {
2121
'public': '.',
22-
'ignore': ['firebase.json', '.*', '**/node_modules/**']
22+
'ignore': ['firebase.json', '**/.*', '**/node_modules/**']
2323
};
2424

2525
temp.track();
@@ -57,6 +57,115 @@ function getPrompt(argv, schema, onComplete, index, results) {
5757
});
5858
}
5959

60+
function updateRules(settings, tokens) {
61+
return _when.promise(function(resolve, reject, notify) {
62+
auth.updateRules(settings.firebase,
63+
tokens.personalToken,
64+
settings.rules,
65+
function(statusCode, response) {
66+
if (response.error) {
67+
console.log(chalk.red('Security Rules Error') + ' - ' +
68+
response.error.replace(/\n$/, ''));
69+
process.exit(1);
70+
}
71+
resolve();
72+
});
73+
});
74+
}
75+
76+
function updateRedirects(firebaseRef, settings) {
77+
return _when.promise(function(resolve, reject, notify) {
78+
var redirects = settings.redirects || null;
79+
firebaseRef.child('hosting/path-redirects').child(settings.firebase).set(redirects, function(err) {
80+
if (err) {
81+
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "redirects" entry in the firebase.json');
82+
process.exit(1);
83+
}
84+
resolve();
85+
});
86+
});
87+
}
88+
89+
function updateRewrites(firebaseRef, settings) {
90+
return _when.promise(function(resolve, reject, notify) {
91+
var rewrites = settings.rewrites || null;
92+
firebaseRef.child('hosting/rewrites').child(settings.firebase).set(rewrites, function(err) {
93+
if (err) {
94+
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "rewrites" entry in the firebase.json');
95+
process.exit(1);
96+
}
97+
resolve();
98+
});
99+
});
100+
}
101+
102+
function updateHeaders(firebaseRef, settings) {
103+
return _when.promise(function(resolve, reject, notify) {
104+
var headers = settings.headers || null;
105+
firebaseRef.child('hosting/headers').child(settings.firebase).set(headers, function(err) {
106+
if (err) {
107+
console.log(chalk.red('Settings Error') + ' - Incorrectly formatted "headers" entry in the firebase.json');
108+
process.exit(1);
109+
}
110+
resolve();
111+
});
112+
});
113+
}
114+
115+
function uploadSite(settings, directoryRef, argv) {
116+
return function() {
117+
var bar = null;
118+
var total = 0;
119+
directoryRef.on('value', function(snapshot) {
120+
var status = snapshot.child('status').val();
121+
if (status === 'deployed') {
122+
var url = api.hostingUrl.replace(/\/\//, util.format('//%s.', settings.firebase));
123+
console.log(chalk.green('Successfully deployed'));
124+
console.log('Site URL: %s, or use %s', chalk.cyan(url), chalk.bold('firebase open'));
125+
console.log('Hosting Dashboard: %s then view the hosting section of your app', chalk.cyan('https://firebase.com/account'));
126+
process.exit(0);
127+
} else if (status === 'deploying') {
128+
if (!bar && snapshot.hasChild('fileCount')) {
129+
total = snapshot.child('fileCount').val();
130+
bar = new ProgressBar(chalk.yellow('progress: :percent'), {
131+
total: total
132+
});
133+
}
134+
if (bar) {
135+
var uploadedCount = snapshot.hasChild('uploadedCount') ? snapshot.child('uploadedCount').val() : 0;
136+
bar.update(uploadedCount / total);
137+
}
138+
} else if (status === 'removed') {
139+
console.log(chalk.green('Sucessfully removed'));
140+
process.exit(0);
141+
} else if (status === 'failed') {
142+
if (bar) {
143+
bar.terminate();
144+
}
145+
var message = chalk.red('Deploy Failed');
146+
if (snapshot.hasChild('statusMessage')) {
147+
message += ' - ' + snapshot.child('statusMessage').val();
148+
}
149+
console.log(message);
150+
process.exit(1);
151+
}
152+
});
153+
154+
var message = null;
155+
if (argv.message && (typeof(argv.message) === 'string')) {
156+
message = argv.message;
157+
}
158+
159+
upload.send(settings.firebase, settings['public'], settings.ignore, directoryRef.name(), message, function(err, directory) {
160+
if (err) {
161+
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
162+
console.log(err);
163+
process.exit(1);
164+
}
165+
});
166+
}
167+
}
168+
60169
function getSettings(argv) {
61170
var settingsFile = path.resolve('./firebase.json');
62171
var settingsJSON, settings;
@@ -402,65 +511,12 @@ module.exports = {
402511
.child('hosting/versions')
403512
.child(settings.firebase)
404513
.push();
405-
auth.updateRules(settings.firebase,
406-
tokens.personalToken,
407-
settings.rules,
408-
function(statusCode, response) {
409-
if (response.error) {
410-
console.log(chalk.red('Security Rules Error') + ' - ' +
411-
response.error.replace(/\n$/, ''));
412-
process.exit(1);
413-
}
414-
var bar = null;
415-
var total = 0;
416-
directoryRef.on('value', function(snapshot) {
417-
var status = snapshot.child('status').val();
418-
if (status === 'deployed') {
419-
var url = api.hostingUrl.replace(/\/\//, util.format('//%s.', settings.firebase));
420-
console.log(chalk.green('Successfully deployed'));
421-
console.log('Site URL: %s, or use %s', chalk.cyan(url), chalk.bold('firebase open'));
422-
console.log('Hosting Dashboard: %s then view the hosting section of your app', chalk.cyan('https://firebase.com/account'));
423-
process.exit(0);
424-
} else if (status === 'deploying') {
425-
if (!bar && snapshot.hasChild('fileCount')) {
426-
total = snapshot.child('fileCount').val();
427-
bar = new ProgressBar(chalk.yellow('progress: :percent'), {
428-
total: total
429-
});
430-
}
431-
if (bar) {
432-
var uploadedCount = snapshot.hasChild('uploadedCount') ? snapshot.child('uploadedCount').val() : 0;
433-
bar.update(uploadedCount / total);
434-
}
435-
} else if (status === 'removed') {
436-
console.log(chalk.green('Sucessfully removed'));
437-
process.exit(0);
438-
} else if (status === 'failed') {
439-
if (bar) {
440-
bar.terminate();
441-
}
442-
var message = chalk.red('Deploy Failed');
443-
if (snapshot.hasChild('statusMessage')) {
444-
message += ' - ' + snapshot.child('statusMessage').val();
445-
}
446-
console.log(message);
447-
process.exit(1);
448-
}
449-
});
450-
451-
var message = null;
452-
if (argv.message && (typeof(argv.message) === 'string')) {
453-
message = argv.message;
454-
}
455514

456-
upload.send(settings.firebase, settings['public'], settings.ignore, directoryRef.name(), message, function(err, directory) {
457-
if (err) {
458-
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
459-
console.log(err);
460-
process.exit(1);
461-
}
462-
});
463-
});
515+
_when.join(updateRules(settings, tokens),
516+
updateRedirects(firebaseRef, settings),
517+
updateRewrites(firebaseRef, settings),
518+
updateHeaders(firebaseRef, settings))
519+
.done(uploadSite(settings, directoryRef, argv));
464520
});
465521
});
466522
},

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
{
22
"name": "firebase-tools",
33
"preferGlobal": true,
4-
"version": "1.0.6",
4+
"version": "1.1.0",
55
"description": "The Firebase Command Line Tools",
66
"keywords": [
7-
"firebase"
7+
"firebase",
8+
"hosting",
9+
"ssl",
10+
"cdn",
11+
"cli",
12+
"synchronization",
13+
"real-time",
14+
"websockets",
15+
"cloud"
816
],
917
"author": "Firebase <[email protected]>",
1018
"contributors": [

0 commit comments

Comments
 (0)