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

Chore docs crawl #16451

Merged
merged 4 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .eslintrc-node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "./.eslintrc-base.json",

"env": {
"browser": false,
"node": true
}
},
"parserOptions": {
"ecmaVersion": 2017
},
"plugins": [
"promise"
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build/
/deploy/
/benchpress-build/
.DS_Store
gen_docs.disable
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
secret_access_key:
secure: tHIFdSq55qkyZf9zT/3+VkhUrTvOTMuswxXU3KyWaBrSieZqG0UnUDyNm+n3lSfX95zEl/+rJAWbfvhVSxZi13ndOtvRF+MdI1cvow2JynP0aDSiPffEvVrZOmihD6mt2SlMfhskr5FTduQ69kZG6DfLcve1PPDaIwnbOv3phb8=
bucket: code-angularjs-org-338b8.appspot.com
local-dir: uploadCode
local-dir: deploy/code
detect_encoding: true # detects gzip compression
on:
repo: angular/angular.js
Expand Down
42 changes: 31 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var semver = require('semver');
var exec = require('shelljs').exec;
var pkg = require(__dirname + '/package.json');

var docsScriptFolder = 'scripts/docs.angularjs.org-firebase';

// Node.js version checks
if (!semver.satisfies(process.version, pkg.engines.node)) {
reportOrFail('Invalid node version (' + process.version + '). ' +
Expand Down Expand Up @@ -163,7 +165,11 @@ module.exports = function(grunt) {
clean: {
build: ['build'],
tmp: ['tmp'],
deploy: ['uploadDocs', 'uploadCode']
deploy: [
'deploy/docs',
'deploy/code',
docsScriptFolder + '/functions/html'
]
},

eslint: {
Expand All @@ -174,6 +180,7 @@ module.exports = function(grunt) {
'docs/**/*.js',
'lib/**/*.js',
'scripts/**/*.js',
'!scripts/*/*/node_modules/**',
'src/**/*.js',
'test/**/*.js',
'i18n/**/*.js',
Expand Down Expand Up @@ -314,12 +321,12 @@ module.exports = function(grunt) {
},
deployFirebaseCode: {
files: [
// the zip file should not be compressed again.
// copy files that are not handled by compress
{
src: 'build/*.zip',
dest: 'uploadCode/' + deployVersion + '/',
expand: true,
flatten: true
cwd: 'build',
src: '**/*.{zip,jpg,jpeg,png}',
dest: 'deploy/code/' + deployVersion + '/',
expand: true
}
]
},
Expand All @@ -328,14 +335,26 @@ module.exports = function(grunt) {
// The source files are needed by the embedded examples in the docs app.
{
src: ['build/angular*.{js,js.map,min.js}', 'build/sitemap.xml'],
dest: 'uploadDocs/',
dest: 'deploy/docs/',
expand: true,
flatten: true
},
{
cwd: 'build/docs',
src: '**',
dest: 'uploadDocs/',
dest: 'deploy/docs/',
expand: true
},
{
src: ['build/docs/index-production.html'],
dest: docsScriptFolder + '/functions/content',
expand: true,
flatten: true
},
{
cwd: 'build/docs',
src: 'partials/**',
dest: docsScriptFolder + '/functions/content',
expand: true
}
]
Expand All @@ -356,10 +375,11 @@ module.exports = function(grunt) {
options: {
mode: 'gzip'
},
src: ['**', '!*.zip'],
// Already compressed files should not be compressed again
src: ['**', '!**/*.{zip,png,jpeg,jpg}'],
cwd: 'build',
expand: true,
dest: 'uploadCode/' + deployVersion + '/'
dest: 'deploy/code/' + deployVersion + '/'
}
},

Expand Down Expand Up @@ -459,7 +479,7 @@ module.exports = function(grunt) {
'merge-conflict',
'eslint'
]);
grunt.registerTask('prepareFirebaseDeploy', [
grunt.registerTask('prepareDeploy', [
'package',
'compress:deployFirebaseCode',
'copy:deployFirebaseCode',
Expand Down
7 changes: 5 additions & 2 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ module.exports = {
// Our Firebase projects are in subfolders, but Travis expects them in the root,
// so we need to modify the upload folder path and copy the file into the root
firebaseDocsJsonForTravis: function() {
var fileName = 'scripts/docs.angularjs.org-firebase/firebase.json';
var docsScriptFolder = 'scripts/docs.angularjs.org-firebase';

var fileName = docsScriptFolder + '/firebase.json';
var json = grunt.file.readJSON(fileName);

json.hosting.public = 'uploadDocs';
json.hosting.public = 'deploy/docs';
json.functions.source = docsScriptFolder + '/functions';

grunt.file.write('firebase.json', JSON.stringify(json));
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"cz-conventional-changelog": "1.1.4",
"dgeni": "^0.4.0",
"dgeni-packages": "^0.16.4",
"eslint-plugin-promise": "^3.6.0",
"event-stream": "~3.1.0",
"glob": "^6.0.1",
"google-code-prettify": "1.0.1",
Expand Down
13 changes: 9 additions & 4 deletions scripts/docs.angularjs.org-firebase/firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosting": {
"public": "../../uploadDocs",
"public": "../../deploy/docs",
"ignore": [
"/index.html",
"/index-debug.html",
Expand All @@ -23,9 +23,14 @@
"destination": "/index-production.html"
},
{
"source": "**/*!(.jpg|.jpeg|.gif|.png|.html|.js|.map|.json|.css|.svg|.ttf|.txt|.woff|.woff2|.eot|.xml)",
"destination": "/index-production.html"
"source": "**/*!(.@(jpg|jpeg|gif|png|html|js|map|json|css|svg|ttf|txt|woff|woff2|eot|xml))",
"function": "sendFile"
}
]
},
"functions": {
"predeploy": [
"npm --prefix $RESOURCE_DIR run lint"
]
}
}
}
49 changes: 49 additions & 0 deletions scripts/docs.angularjs.org-firebase/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const functions = require('firebase-functions');
const fs = require('fs');

const BROWSER_CACHE_DURATION = 60 * 60;
const CDN_CACHE_DURATION = 60 * 60 * 12;

const headers = {
'Cache-Control': `public max-age=${BROWSER_CACHE_DURATION} s-maxage=${CDN_CACHE_DURATION}`
};

const buildSnapshot = data => `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="/">
</head>
<body>
${data}
</body>
</html>`;

function sendFile(request, response) {

const snapshotRequested = typeof request.query._escaped_fragment_ !== 'undefined';
const filePath = `content/${snapshotRequested ? `partials${request.path}` : 'index-production'}.html`;

if (snapshotRequested) {
fs.readFile(filePath, {encoding: 'utf8'}, (error, data) => {
if (error) {
response
.status(404)
.end();
} else {
response
.set(headers)
.send(buildSnapshot(data));
}
});
} else {
response
.set(headers)
.sendFile(filePath, {root: __dirname});
}
}

exports.sendFile = functions.https.onRequest(sendFile);
Loading