Skip to content

Commit

Permalink
Merge branch 'future' into migrate/rating
Browse files Browse the repository at this point in the history
lluerich committed May 27, 2019
2 parents 33d0ce8 + a611af2 commit ee0a58e
Showing 106 changed files with 2,961 additions and 1,222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ examples/static/samples/samples.json
# Ignore files created during build process
platform/pages*
platform/static
platform/config/build-info.yaml

# Ignore pipeline cache
.cache/**/*
Binary file added .prod.key.json.enc
Binary file not shown.
112 changes: 95 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,103 @@
language: node_js
node_js:
- lts/*
- lts/*
git:
depth: 3
addons:
apt:
packages:
- expect-dev
cache:
- pip
- npm
install:
- pip install grow==0.7.4 --user
- grow --version
- which grow
- npm ci
before_deploy:
- npm run build:staging
deploy:
provider: gae
keyfile: ".staging.key.json"
project: amp-dev-staging
skip_cleanup: true
on:
branch: future
- pip
- npm
before_install:
- openssl aes-256-cbc -K $encrypted_b44033ffb787_key -iv $encrypted_b44033ffb787_iv
-in .prod.key.json.enc -out .prod.key.json -d
- openssl aes-256-cbc -K $encrypted_d4a09416a845_key -iv $encrypted_d4a09416a845_iv
-in .staging.key.json.enc -out .staging.key.json -d
- gcloud auth activate-service-account --key-file=.staging.key.json
install:
- npm ci
stages:
- preparation
- name: build
if: branch = future
- name: deploy
if: branch = future
jobs:
include:
- stage: preparation
env: APP_ENV=staging
name: Check code, import documents, build samples, playground & boilerplate
before_script:
- unbuffer gulp buildSamples
- unbuffer gulp lintAll
script:
- if [ $TRAVIS_BRANCH == "future" ]; then unbuffer gulp buildPrepare; fi
- stage: build
env: APP_ENV=staging
install: &1
- npm ci
- pip install grow==0.7.4 --user
name: Build Pages (EN)
script: unbuffer gulp buildPages --locales en
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (FR)
script: unbuffer gulp buildPages --locales fr
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (AR)
script: unbuffer gulp buildPages --locales ar
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (ES)
script: unbuffer gulp buildPages --locales es
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (IT)
script: unbuffer gulp buildPages --locales it
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (ID)
script: unbuffer gulp buildPages --locales id
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (JA)
script: unbuffer gulp buildPages --locales ja
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (KO)
script: unbuffer gulp buildPages --locales ko
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (BR)
script: unbuffer gulp buildPages --locales pt_BR
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (RU)
script: unbuffer gulp buildPages --locales ru
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (TR)
script: unbuffer gulp buildPages --locales tr
- stage: build
env: APP_ENV=staging
install: *1
name: Build Pages (CN)
script: unbuffer gulp buildPages --locales zh_CN
- stage: deploy
env: APP_ENV=staging
script:
- unbuffer gulp buildFinalize
- gcloud app deploy --project=amp-dev-staging --quiet
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,44 +24,58 @@ that makes a merge over to the original repository beneficial.
```

## Develop
To start developing start a pipeline that takes care of building the frontend, collecting all needed files and start Grow when finished. The pipeline then watches the sources files for changes and rebuilds them if needed.
If it's your first time working on amp.dev it is recommended to bootstrap your local environment. To do so make sure you have setup a valid [GitHub access token](https://github.com/settings/tokens) in an environment variable named `AMP_DOC_TOKEN` like:
```sh
$ npm run develop
$ export AMP_DOC_TOKEN="c59f6..."
```
### Import data & documents
If you additionally want to import the needed documents and data from GitHub pass in the `--import` option to the command and export a valid [GitHub access token](https://github.com/settings/tokens) beforehand like with
This enables the import from GitHub to run flawlessly which can be started by the following command which additionally will build the Playground and Boilerplate Generator once:
```sh
$ export AMP_DOC_TOKEN="c59f6..."
$ npm run develop -- --import
$ gulp bootstrap
```
You can then start developing in your local environment with the command below. The task will take care of building and copying all files, watching them for changes and rebuild them when needed. Beware that changes to the [express.js](https://expressjs.com/) backend require to restart the task.
```sh
$ gulp develop
```
This command prints a lot to the shell and will most probably end on `Server ready. Press ctrl-c to quit.`. This means everything went fine so far but other than stated in the logs the site is then available at [http://localhost:8080/](http://localhost:8080/). The service running on 8081 is only Grow rendering the pages.
### Maintenance
#### Documents

Made changes to a lot of Grow documents at once and not quite sure if all references are still valid? You can run `npm run lint:grow` to pick up broken ones.
Also see MAINTENANCE.md for a more detailed explanation of the various frontmatter keys used throughout the project.
#### Samples
Building the samples creates a lot of individual files per sample. In order to still have a quick startup time for development only changed samples are rebuilt. To freshly build *all* samples you can run `npm run develop -- --clean-samples`.
Building the samples creates a lot of individual files per sample. In order to still have a quick startup time for development only changed samples are rebuilt. To freshly build *all* samples you can run `gulp develop --clean-samples`.
### Run a test build
To run a local test build that does all the minifying and vends the static pages instead of
proxying them through to Grow you can run
```sh
$ npm run build:local
$ gulp build --env local
$ npm run start:local
```
## Build & Deploy
To build and deploy to the staging environment on [Google App Engine](https://cloud.google.com/appengine/) run the following
## Build
Caution: starting a build automatically cleans all locations of possible remainings from previous builds. Make sure you don't have anything there that you want to keep - additionally check your working copy for eventual unintended local changes.

To perform a build run the following command with `--env` being one of the following valid environments: `development`, `local`, `staging` or `production`:

```sh
$ gulp build --env <environment>
```

This builds all parts of the project and might take a while. Usually all builds on amp-dev-staging.appspot.com and amp.dev are built using [Travis CI](https://travis-ci.org/ampproject/docs). In case you want to reproduce one of those remote builds in your local environment you can fetch the build artifacts by running:

```sh
$ npm run build:staging
$ npm run deploy:staging
$ gulp fetchArtifacts --travis-build <build_number>
```

- - -
6 changes: 3 additions & 3 deletions TRANSLATIONS.md
Original file line number Diff line number Diff line change
@@ -36,9 +36,9 @@ Some volunteer translators have created channels on Slack where a localized docu

### Creating localized files

The [ampproject.org](https://www.ampproject.org/) website differentiates localized files by suffixing the `@` symbol followed by the appropriate language code to the translated document. For example, `example.md` would become `example@ko.md` if translated to Korean.
The [amp.dev](https://amp.dev/) website differentiates localized files by suffixing the `@` symbol followed by the appropriate language code to the translated document. For example, `example.md` would become `example@ko.md` if translated to Korean.

#### ampproject.org translation file suffixes
#### amp.dev translation file suffixes

| Language | Suffix |
| ------------- |:-------------: |
@@ -68,4 +68,4 @@ Don’t see a channel for your language? Join the general [AMP-Translation chann

#### [Korean Glossary](https://github.com/ampproject/docs/blob/master/glossaries/KOREAN.md)

Don't see a term glossary for your language? File an issue and start one!
Don't see a term glossary for your language? File an issue and start one!
11 changes: 4 additions & 7 deletions boilerplate/build.js
Original file line number Diff line number Diff line change
@@ -16,8 +16,7 @@

'use strict';

const ampOptimizer = require('amp-toolbox-optimizer');
const runtimeVersion = require('amp-toolbox-runtime-version');
const AmpOptimizer = require('amp-toolbox-optimizer');
const path = require('path');

const io = require('./lib/io');
@@ -31,6 +30,7 @@ const generatorTemplate = io.readFile(INPUT_FILE);
const config = initConfig();
const generatorPage = templates.render(generatorTemplate, config);
generateOptimizedAmpFiles(generatorPage);
console.log('Built boilerplate generator.');

function initConfig() {
const config = {
@@ -61,9 +61,6 @@ async function generateOptimizedAmpFiles(output) {
}

async function optimizeAmp(html) {
const ampRuntimeVersion = await runtimeVersion.currentVersion();
return await ampOptimizer.transformHtml(html, {
ampUrl: './' + AMP_PATH,
ampRuntimeVersion,
});
const optimizer = AmpOptimizer.create();
return await optimizer.transformHtml(html);
}
119 changes: 119 additions & 0 deletions examples/api/autosuggest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

const express = require('express');
const multer = require('multer');
const upload = multer();

// eslint-disable-next-line new-cap
const examples = express.Router();
const MAX_RESULT_SIZE = 4;
const US_CAPITAL_CITIES = [
'Montgomery, Alabama',
'Juneau, Alaska',
'Phoenix, Arizona',
'Little Rock, Arkansas',
'Sacramento, California',
'Denver, Colorado',
'Hartford, Connecticut',
'Dover, Delaware',
'Tallahassee, Florida',
'Atlanta, Georgia',
'Honolulu, Hawaii',
'Boise, Idaho',
'Springfield, Illinois',
'Indianapolis, Indiana',
'Des Moines, Iowa',
'Topeka, Kansas',
'Frankfort, Kentucky',
'Baton Rouge, Louisiana',
'Augusta, Maine',
'Annapolis, Maryland',
'Boston, Massachusetts',
'Lansing, Michigan',
'Saint Paul, Minnesota',
'Jackson, Mississippi',
'Jefferson City, Missouri',
'Helena, Montana',
'Lincoln, Nebraska',
'Carson City, Nevada',
'Concord, New Hampshire',
'Trenton, New Jersey',
'Santa Fe, New Mexico',
'Albany, New York',
'Raleigh, North Carolina',
'Bismarck, North Dakota',
'Columbus, Ohio',
'Oklahoma City, Oklahoma',
'Salem, Oregon',
'Harrisburg, Pennsylvania',
'Providence, Rhode Island',
'Columbia, South Carolina',
'Pierre, South Dakota',
'Nashville, Tennessee',
'Austin, Texas',
'Salt Lake City, Utah',
'Montpelier, Vermont',
'Richmond, Virginia',
'Olympia, Washington',
'Charleston, West Virginia',
'Madison, Wisconsin',
'Cheyenne, Wyoming',
];

examples.get('/autosuggest/search_list', upload.none(), handleSearchRequest);
examples.post('/autosuggest/address', upload.none(), handleAddressRequest);

function handleSearchRequest(request, response) {
const query = request.query ? request.query.q : '';

let results = US_CAPITAL_CITIES.filter((key) => {
return key.toUpperCase().includes(query.toUpperCase());
});

if (results.length > MAX_RESULT_SIZE) {
results = results.slice(0, MAX_RESULT_SIZE);
}

const items = ({
items: [
{
query,
results,
},
],
});

response.json(items);
};

function handleAddressRequest(request, response) {
const city = request.body ? request.body.city : '';
let result;

if (US_CAPITAL_CITIES.includes(city)) {
result = `Success! Your package is on it's way to ${city}.`;
} else {
result = `Sorry! We don't ship to ${city}.`;
}

response.json({
result,
});
};

module.exports = examples;
4 changes: 2 additions & 2 deletions examples/api/photo-stream.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ examples.get('/photo-stream', (req, res) => {
const {query} = req;
const items = [];
const numberOfItems = Number(query.items) || 10;
const pagesLeft = Number(query.left) || 1;
const pagesLeft = Number.isNaN(Number(query.left)) ? 1 : Number(query.left);
const latency = Number(query.latency) || 0;
const width = Number(query.width) || 200;
const height = Number(query.height) || width;
@@ -48,7 +48,7 @@ examples.get('/photo-stream', (req, res) => {
items.push(r);
}

const nextUrl = '/photo-stream?items=' +
const nextUrl = req.baseUrl + '/photo-stream?items=' +
numberOfItems + '&left=' + JSON.stringify(pagesLeft - 1);

const randomFalsy = () => {
2 changes: 2 additions & 0 deletions examples/source/0.introduction/AMPHTML_Ads_Hello_World.html
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
preview: a4a
skipValidation: 'true'
width: 350
height: 70
--->

Loading
Oops, something went wrong.

0 comments on commit ee0a58e

Please sign in to comment.