mirror of
https://github.com/zhigang1992/firebase-tools.git
synced 2026-05-07 16:45:06 +08:00
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
var RSVP = require('rsvp');
|
|
var tar = require('tar');
|
|
var tmp = require('tmp');
|
|
|
|
var FirebaseError = require('./error');
|
|
var fsutils = require('./fsutils');
|
|
var listFiles = require('./listFiles');
|
|
|
|
module.exports = function(options) {
|
|
var hostingConfig = options.config.get('hosting');
|
|
var publicDir = options.config.path(hostingConfig.public);
|
|
var indexPath = path.join(publicDir, 'index.html');
|
|
|
|
var tmpFile = tmp.fileSync({prefix: 'firebase-upload-', postfix: '.tar.gz'});
|
|
var manifest = listFiles(publicDir, hostingConfig.ignore);
|
|
|
|
return tar.c({
|
|
gzip: true,
|
|
file: tmpFile.name,
|
|
cwd: publicDir,
|
|
prefix: 'public',
|
|
follow: true,
|
|
noDirRecurse: true,
|
|
portable: true
|
|
}, manifest.slice(0)).then(function() {
|
|
var stats = fs.statSync(tmpFile.name);
|
|
return {
|
|
file: tmpFile.name,
|
|
stream: fs.createReadStream(tmpFile.name),
|
|
manifest: manifest,
|
|
foundIndex: fsutils.fileExistsSync(indexPath),
|
|
size: stats.size
|
|
};
|
|
}).catch(function(err) {
|
|
return RSVP.reject(new FirebaseError('There was an issue preparing Hosting files for upload.', {
|
|
original: err,
|
|
exit: 2
|
|
}));
|
|
});
|
|
};
|