Skip to content

Commit

Permalink
chore: add scripts for manual upload to Firebaes
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Feb 5, 2018
1 parent da86ade commit d7ec21a
Show file tree
Hide file tree
Showing 5 changed files with 1,866 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
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
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,34 @@ The site code.angularjs.org is *not* a CDN. The AngularJS builds there are to be
used only during development. The site is not suitable for production usage.

If you are looking for a CDN link to AngularJS visit [angularjs.org](https://www.angularjs.org/).


## Project Maintainers Note

Here are the stesp to do a manual upload of folders to Firebase Storage:

**Be aware that some file paths contain colons `:`, which are not valid on Windows, so you must upload from a Unix-based OS.**

* Clone this repo:

```bash
git clone https://github.com/angular/code.angularjs.org
cd code.angularjs.org
```

* Install package dependencies

```bash
yarn
```

* Generate a keyfile in the Firebase Storage web console (https://cloud.google.com/iam/docs/creating-managing-service-account-keys)
and store it in the root of the project as `code-angularjs-org.json`

* Run the grunt task to upload the chosen files. For example to upload all the partials for v1.0.5:

```bash
node_modules/.bin/grunt --target=1.0.5 --filter=docs*/**
```

* Remember to delete the keyfile from you local system when done, as this gives unlimited access to the Storage.
118 changes: 118 additions & 0 deletions gruntFile.js
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']);
}
25 changes: 25 additions & 0 deletions package.json
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": {}
}
Loading

0 comments on commit d7ec21a

Please sign in to comment.