Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: add snapshot builds for pr previews #1525

Merged
merged 2 commits into from
Sep 5, 2019
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build": "npm run build-master",
"build-for-pdf": "npm run build-master -- --old-toc",
"build-travis": "npm run build-master && npm run build-es2019",
"prebuild-snapshot": "npm run clean",
"build-snapshot": "npm run build-master && node scripts/insert_snapshot_warning.js",
"clean": "rm -rf out",
"test": "exit 0",
"watch": "npm run build-master -- --watch"
Expand All @@ -22,6 +24,7 @@
"ecmarkup": "^3.16.0"
},
"devDependencies": {
"@alrra/travis-scripts": "^2.1.0"
"@alrra/travis-scripts": "^2.1.0",
"jsdom": "^15.0.0"
}
}
33 changes: 33 additions & 0 deletions scripts/insert_snapshot_warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const fs = require('fs');
const path = require('path');
const { JSDOM } = require('jsdom');
const { execSync } = require('child_process');

const COMMIT = String(execSync('git rev-parse --verify HEAD'));

const WARNING_HTML = fs.readFileSync(path.join(__dirname, 'snapshot_warning.html'), 'utf8')
.replace(/{COMMIT}/g, COMMIT);
const WARNING_CSS = fs.readFileSync(path.join(__dirname, 'snapshot_warning.css'), 'utf8');

console.log('Inserting snapshot reference warning...');

JSDOM.fromFile('./out/index.html', { contentType: 'text/html; charset=utf-8' }).then((dom) => {
const { document } = dom.window;

const style = document.createElement('style');
style.textContent = WARNING_CSS;
document.head.append(style);

// insert WARNING_HTML in beginning of body so it renders
// first even on slower devices and browsers
document.body.insertAdjacentHTML('afterbegin', WARNING_HTML);

fs.writeFileSync('./out/index.html', dom.serialize(), 'utf8');

console.log('Done!');
}).catch((reason) => {
console.error(reason);
process.exitCode = 1;
});
9 changes: 9 additions & 0 deletions scripts/netlify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -ex

npm run build-master
ljharb marked this conversation as resolved.
Show resolved Hide resolved

if [ "${CONTEXT}" != 'production' ]; then
node scripts/insert_snapshot_warning
fi
66 changes: 66 additions & 0 deletions scripts/snapshot_warning.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
details.annoying-warning {
background-color: #920800;
background-image: linear-gradient(transparent 40%, rgba(255, 255, 255, 0.2));
border: solid rgba(0, 0, 0, 0.4);
border-radius: 3px;
border-width: 1px 1px 0 1px;
box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.5);
color: rgba(255, 255, 255, 0.95);
opacity: .95;
position: fixed;
left: 5%;
margin: 0 auto;
right: 5%;
z-index: 10;
}

details.annoying-warning[open] {
top: 10%;
top: calc(5vw + 5vh);
max-width: 1024px;
outline: solid 10000px rgba(255, 255, 255, 0.6);
}

details.annoying-warning:not([open]) {
bottom: 0;
left: 0;
right: 0;
border-radius: 0;
}

details.annoying-warning > summary {
display: list-item; /* polyfill */
font-size: 0.875em;
font-weight: bold;
letter-spacing: 0.02em;
padding: 10px 5px;
text-align: center;
text-transform: uppercase;
text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.85);
cursor: default;
}

details.annoying-warning > summary::after {
content: " Expand";
position: absolute;
top: 0;
right: 5px;
font-size: smaller;
font-weight: bold;
}

details.annoying-warning[open] > summary::after {
content: " Collapse";
}

details.annoying-warning p {
padding: 0 7.5% 1em;
line-height: 1.4;
margin: 0;
text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.85);
}

details.annoying-warning a {
color: white;
text-decoration: underline;
}
15 changes: 15 additions & 0 deletions scripts/snapshot_warning.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<details class="annoying-warning" open="">
<summary>This is a commit snapshot of the specification</summary>
<p>
This document contains the contents of the specification as of
<a href="https://github.com/tc39/ecma262/commit/{COMMIT}">commit {COMMIT}</a>,
and should only be used as a historical reference. This commit may not
have even been merged into the specification.
</p>
<p>
Do not attempt to implement this version of the specification. Do not
reference this version as authoritative in any way. Instead, see
<a href="https://tc39.github.io/ecma262">https://tc39.github.io/ecma262</a>
for the living specification.
</p>
</details>