Skip to content

Commit

Permalink
Make templates previewable
Browse files Browse the repository at this point in the history
* moves templates to a new root dir `templates
* adds a new build task to zip the templates
* adds a new static router serving the templates under http://localhost:8080/documentation/templates/preview/websites/gallery/templates/gallery.amp.html
  • Loading branch information
sebastianbenz committed Jul 17, 2019
1 parent 4e405b6 commit 07a306f
Show file tree
Hide file tree
Showing 340 changed files with 71 additions and 12 deletions.
49 changes: 39 additions & 10 deletions gulpfile.js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
const gulp = require('gulp');
const {sh} = require('@lib/utils/sh');
const grow = require('@lib/utils/grow');
const mkdirp = require('mkdirp').sync;
const config = require('@lib/config');
const signale = require('signale');
const del = require('del');
Expand Down Expand Up @@ -111,7 +112,7 @@ function sass() {
* @return {Stream}
*/
function templates() {
return gulp.src(`${project.paths.TEMPLATES}/**/*`)
return gulp.src(`${project.paths.FRONTEND_TEMPLATES}/**/*`)
.pipe(gulp.dest(project.paths.GROW_POD));
}

Expand Down Expand Up @@ -163,6 +164,33 @@ function buildSamples() {
return samplesBuilder.build(true);
}

/**
* Zips templates for download.
*/
function zipTemplates() {
const templateDir = path.join(project.paths.DIST, 'static/files/templates/');
mkdirp(templateDir);
return gulp.src(project.paths.TEMPLATES + '/*/*/')
.pipe(through.obj(async (file, encoding, callback) => {
const archive = archiver('zip', {
'zlib': {'level': 9},
});
const zipFilePath = path.join(templateDir, file.basename + '.zip');
const zipFileStream = fs.createWriteStream(zipFilePath);
archive.directory(file.path + '/', false)
.pipe(zipFileStream)
.on('close', () => {
signale.success(`Zipped template ${zipFilePath}`);
callback();
})
.on('error', (e) => {
signale.error(`Writing template zip ${zipFilePath} failed`, e);
callback(e);
});
archive.finalize();
}));
}


/**
* Runs all importers
Expand Down Expand Up @@ -191,7 +219,7 @@ function buildPrepare(done) {
test.lintNode,
// Build playground and boilerplate that early in the flow as they are
// fairly quick to build and would be annoying to eventually fail downstream
gulp.parallel(buildPlayground, buildBoilerplate, buildSamples, importAll),
gulp.parallel(buildPlayground, buildBoilerplate, buildSamples, importAll, zipTemplates),
// TODO: Fix working but malformatted references before reenabling
// test.lintGrow,
// eslint-disable-next-line prefer-arrow-callback
Expand All @@ -216,7 +244,7 @@ function buildPrepare(done) {
await sh('mkdir -p build');
await sh(`tar cfj ${SETUP_ARCHIVE} ${SETUP_STORED_PATHS.join(' ')}`);
await sh(`gsutil cp ${SETUP_ARCHIVE} ` +
`${TRAVIS_GCS_PATH}${travis.build.number}/setup.tar.gz`);
`${TRAVIS_GCS_PATH}${travis.build.number}/setup.tar.gz`);
})(done);
}

Expand Down Expand Up @@ -261,32 +289,32 @@ async function buildPages(done) {
try {
await grow('deploy --noconfirm --threaded');
} catch (e) {
// If building the pages fails, force exit here to make sure
// especially Travis gets the correct exit code
// If building the pages fails, force exit here to make sure
// especially Travis gets the correct exit code
process.exit(1);
}
}, transformPages,
// eslint-disable-next-line prefer-arrow-callback
function sharedPages() {
// Copy shared pages separated from PageTransformer as they should
// not be transformed
// Copy shared pages separated from PageTransformer as they should
// not be transformed
return gulp.src(`${project.paths.GROW_BUILD_DEST}/shared/*.html`)
.pipe(gulp.dest(`${project.paths.PAGES_DEST}/shared`));
},
// eslint-disable-next-line prefer-arrow-callback
function sitemap() {
// Copy XML files written by Grow
// Copy XML files written by Grow
return gulp.src(`${project.paths.GROW_BUILD_DEST}/**/*.xml`)
.pipe(gulp.dest(`${project.paths.PAGES_DEST}`));
},
// eslint-disable-next-line prefer-arrow-callback
async function storeArtifacts() {
// ... and again if on Travis store all built files for a later stage to pick up
// ... and again if on Travis store all built files for a later stage to pick up
if (travis.onTravis()) {
const archive = `build/pages-${travis.build.job}.tar.gz`;
await sh(`tar cfj ${archive} ./dist/pages ./dist/inline-examples`);
await sh(`gsutil cp ${archive} ` +
`${TRAVIS_GCS_PATH}${travis.build.number}/pages-${travis.build.job}.tar.gz`);
`${TRAVIS_GCS_PATH}${travis.build.number}/pages-${travis.build.job}.tar.gz`);
}
})(done);
}
Expand Down Expand Up @@ -443,6 +471,7 @@ exports.buildPlayground = buildPlayground;
exports.buildBoilerplate = buildBoilerplate;
exports.buildFrontend = buildFrontend;
exports.buildSamples = buildSamples;
exports.zipTemplates = zipTemplates;
exports.buildPages = buildPages;

exports.buildPrepare = buildPrepare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The `multipart/alternative` must contain at least one non-AMP (`text/plain` or `
`text/x-amp-html` node. This will be displayed to users whose email clients don't support AMP or who opted out via
their email provider's settings.

Note: Some email clients[[1]](https://openradar.appspot.com/radar?id=6054696888303616) will only render the last MIME part,
Note: Some email clients[[1]](https://openradar.appspot.com/radar?id=6054696888303616) will only render the last MIME part,
so we recommend placing the `text/x-amp-html` MIME part *before* the `text/html` MIME part.

### Replying/forwarding semantics
Expand Down
2 changes: 2 additions & 0 deletions platform/lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const routers = {
pages: require('@lib/routers/pages.js'),
playground: require('../../playground/backend/'),
static: require('@lib/routers/static.js'),
templates: require('@lib/routers/templates.js'),
whoAmI: require('@lib/routers/whoAmI.js'),
};

Expand Down Expand Up @@ -134,6 +135,7 @@ class Platform {
this.server.use(routers.example.api);
this.server.use(routers.boilerplate);
this.server.use(routers.static);
this.server.use(routers.templates);
// Register the following router at last as it works as a catch-all
this.server.use(routers.pages);
}
Expand Down
27 changes: 27 additions & 0 deletions platform/lib/routers/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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 project = require('@lib/utils/project');

// eslint-disable-next-line new-cap
const templatesRouter = express.Router();

templatesRouter.use('/documentation/templates/preview/', express.static(project.paths.TEMPLATES));

module.exports = templatesRouter;
3 changes: 2 additions & 1 deletion platform/lib/utils/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const paths = {
BUILD: absolute('build'),
DIST: absolute('dist'),
ICONS: absolute('frontend/icons'),
TEMPLATES: absolute('frontend/templates'),
TEMPLATES: absolute('templates'),
FRONTEND_TEMPLATES: absolute('frontend/templates'),
SCSS: absolute('frontend/scss'),
CSS: absolute('pages/css'),
GROW_POD: absolute('pages'),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 07a306f

Please sign in to comment.