Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit d7ec21a

Browse files
chore: add scripts for manual upload to Firebaes
1 parent da86ade commit d7ec21a

File tree

5 files changed

+1866
-0
lines changed

5 files changed

+1866
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
wlizer/
22
gitFetchSite.log
33
.DS_Store
4+
/code-angularjs-org*.json
5+
node_modules
6+
/upload

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,34 @@ The site code.angularjs.org is *not* a CDN. The AngularJS builds there are to be
99
used only during development. The site is not suitable for production usage.
1010

1111
If you are looking for a CDN link to AngularJS visit [angularjs.org](https://www.angularjs.org/).
12+
13+
14+
## Project Maintainers Note
15+
16+
Here are the stesp to do a manual upload of folders to Firebase Storage:
17+
18+
**Be aware that some file paths contain colons `:`, which are not valid on Windows, so you must upload from a Unix-based OS.**
19+
20+
* Clone this repo:
21+
22+
```bash
23+
git clone https://github.com/angular/code.angularjs.org
24+
cd code.angularjs.org
25+
```
26+
27+
* Install package dependencies
28+
29+
```bash
30+
yarn
31+
```
32+
33+
* Generate a keyfile in the Firebase Storage web console (https://cloud.google.com/iam/docs/creating-managing-service-account-keys)
34+
and store it in the root of the project as `code-angularjs-org.json`
35+
36+
* Run the grunt task to upload the chosen files. For example to upload all the partials for v1.0.5:
37+
38+
```bash
39+
node_modules/.bin/grunt --target=1.0.5 --filter=docs*/**
40+
```
41+
42+
* Remember to delete the keyfile from you local system when done, as this gives unlimited access to the Storage.

gruntFile.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
const fs = require('fs-extra')
2+
const semver = require('semver');
3+
const PQueue = require('p-queue');
4+
const path = require( 'path' );
5+
const gcs = require('@google-cloud/storage')({
6+
projectId: 'code-angularjs-org-338b8',
7+
keyFilename: 'code-angularjs-org.json'
8+
});
9+
const gcsBucket = 'code-angularjs-org-338b8.appspot.com';
10+
11+
const bucket = gcs.bucket(gcsBucket);
12+
13+
function getDirectories(path) {
14+
return fs.readdirSync(path).filter(function (file) {
15+
return fs.statSync(path+'/'+file).isDirectory();
16+
});
17+
}
18+
19+
module.exports = function(grunt) {
20+
21+
function upload(files, basePath, zipped) {
22+
const queue = new PQueue({concurrency: 15});
23+
24+
files.forEach(function(filePath, index) {
25+
var fromPath = path.join(basePath, filePath);
26+
27+
const options = {
28+
destination: filePath
29+
}
30+
31+
if (zipped) {
32+
options.metadata = {
33+
contentEncoding: 'gzip'
34+
}
35+
}
36+
37+
queue.add(() => {
38+
return bucket.upload(fromPath, options).then(() => {
39+
console.log('uploaded ' + filePath)
40+
}).catch((error) => {
41+
queue.clear();
42+
grunt.util.error('Upload failed', error);
43+
});
44+
});
45+
46+
});
47+
48+
console.log('files queued: ', queue.size);
49+
50+
return new Promise(function(resolve, reject) {
51+
queue.onEmpty().then(() => {
52+
53+
if (queue.pending === 0) {
54+
console.log('success');
55+
resolve('success');
56+
}
57+
58+
}).catch((error) => {
59+
grunt.util.error('Upload failed', error);
60+
resolve(error);
61+
});
62+
});
63+
64+
}
65+
66+
// this loads all the node_modules that start with `grunt-` as plugins
67+
require('load-grunt-tasks')(grunt);
68+
69+
const version = grunt.option('target');
70+
71+
grunt.initConfig({
72+
73+
compress: {
74+
firebaseCodeDeploy: {
75+
options: {
76+
mode: 'gzip'
77+
},
78+
src: ['**'],
79+
cwd: version,
80+
expand: true,
81+
dest: 'upload/' + version + '/'
82+
}
83+
}
84+
});
85+
86+
grunt.registerTask('gcs', function() {
87+
const doneFn = this.async();
88+
89+
const deployVersion = grunt.option('target');
90+
if (!deployVersion) {
91+
console.log('No target version supplied. Use --target="<version>"');
92+
doneFn(false);
93+
return;
94+
}
95+
96+
const glob = deployVersion + '/' + (grunt.option('filter') || '**/*');
97+
98+
const files = grunt.file.expand({
99+
filter: 'isFile',
100+
cwd: 'upload/'
101+
}, glob);
102+
103+
if (!files.length) {
104+
console.log('no files to deploy in upload/' + deployVersion);
105+
doneFn(false);
106+
return;
107+
}
108+
109+
console.log('uploading files from ' + glob);
110+
111+
upload(files, 'upload', true).then(function() {
112+
doneFn();
113+
});
114+
115+
});
116+
117+
grunt.registerTask('default', ['compress', 'gcs']);
118+
}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
{
3+
"name": "angularjs",
4+
"license": "MIT",
5+
"private": true,
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/angular/code.angular.js.git"
9+
},
10+
"engines": {
11+
"node": "^8.9.1"
12+
},
13+
"scripts": {},
14+
"devDependencies": {
15+
"@google-cloud/storage": "^1.1.1",
16+
"fs-extra": "^3.0.1",
17+
"grunt": "^1.0.1",
18+
"grunt-cli": "^1.2.0",
19+
"grunt-contrib-compress": "^1.3.0",
20+
"load-grunt-tasks": "^3.5.0",
21+
"p-queue": "^1.1.0"
22+
},
23+
"dependencies": {},
24+
"config": {}
25+
}

0 commit comments

Comments
 (0)