-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add scripts for manual upload to Firebaes
- Loading branch information
1 parent
da86ade
commit d7ec21a
Showing
5 changed files
with
1,866 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
wlizer/ | ||
gitFetchSite.log | ||
.DS_Store | ||
/code-angularjs-org*.json | ||
node_modules | ||
/upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
const fs = require('fs-extra') | ||
const semver = require('semver'); | ||
const PQueue = require('p-queue'); | ||
const path = require( 'path' ); | ||
const gcs = require('@google-cloud/storage')({ | ||
projectId: 'code-angularjs-org-338b8', | ||
keyFilename: 'code-angularjs-org.json' | ||
}); | ||
const gcsBucket = 'code-angularjs-org-338b8.appspot.com'; | ||
|
||
const bucket = gcs.bucket(gcsBucket); | ||
|
||
function getDirectories(path) { | ||
return fs.readdirSync(path).filter(function (file) { | ||
return fs.statSync(path+'/'+file).isDirectory(); | ||
}); | ||
} | ||
|
||
module.exports = function(grunt) { | ||
|
||
function upload(files, basePath, zipped) { | ||
const queue = new PQueue({concurrency: 15}); | ||
|
||
files.forEach(function(filePath, index) { | ||
var fromPath = path.join(basePath, filePath); | ||
|
||
const options = { | ||
destination: filePath | ||
} | ||
|
||
if (zipped) { | ||
options.metadata = { | ||
contentEncoding: 'gzip' | ||
} | ||
} | ||
|
||
queue.add(() => { | ||
return bucket.upload(fromPath, options).then(() => { | ||
console.log('uploaded ' + filePath) | ||
}).catch((error) => { | ||
queue.clear(); | ||
grunt.util.error('Upload failed', error); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
console.log('files queued: ', queue.size); | ||
|
||
return new Promise(function(resolve, reject) { | ||
queue.onEmpty().then(() => { | ||
|
||
if (queue.pending === 0) { | ||
console.log('success'); | ||
resolve('success'); | ||
} | ||
|
||
}).catch((error) => { | ||
grunt.util.error('Upload failed', error); | ||
resolve(error); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
// this loads all the node_modules that start with `grunt-` as plugins | ||
require('load-grunt-tasks')(grunt); | ||
|
||
const version = grunt.option('target'); | ||
|
||
grunt.initConfig({ | ||
|
||
compress: { | ||
firebaseCodeDeploy: { | ||
options: { | ||
mode: 'gzip' | ||
}, | ||
src: ['**'], | ||
cwd: version, | ||
expand: true, | ||
dest: 'upload/' + version + '/' | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('gcs', function() { | ||
const doneFn = this.async(); | ||
|
||
const deployVersion = grunt.option('target'); | ||
if (!deployVersion) { | ||
console.log('No target version supplied. Use --target="<version>"'); | ||
doneFn(false); | ||
return; | ||
} | ||
|
||
const glob = deployVersion + '/' + (grunt.option('filter') || '**/*'); | ||
|
||
const files = grunt.file.expand({ | ||
filter: 'isFile', | ||
cwd: 'upload/' | ||
}, glob); | ||
|
||
if (!files.length) { | ||
console.log('no files to deploy in upload/' + deployVersion); | ||
doneFn(false); | ||
return; | ||
} | ||
|
||
console.log('uploading files from ' + glob); | ||
|
||
upload(files, 'upload', true).then(function() { | ||
doneFn(); | ||
}); | ||
|
||
}); | ||
|
||
grunt.registerTask('default', ['compress', 'gcs']); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
{ | ||
"name": "angularjs", | ||
"license": "MIT", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/angular/code.angular.js.git" | ||
}, | ||
"engines": { | ||
"node": "^8.9.1" | ||
}, | ||
"scripts": {}, | ||
"devDependencies": { | ||
"@google-cloud/storage": "^1.1.1", | ||
"fs-extra": "^3.0.1", | ||
"grunt": "^1.0.1", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-contrib-compress": "^1.3.0", | ||
"load-grunt-tasks": "^3.5.0", | ||
"p-queue": "^1.1.0" | ||
}, | ||
"dependencies": {}, | ||
"config": {} | ||
} |
Oops, something went wrong.