Make sure that shown playground Prettier version always is in sync

This commit is contained in:
Simon Lydell committed 2017-09-12 22:17:06 +02:00
1 parent 951aed47f6
commit 8ba2acadbb
7 files changed
+41 -29

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ Tip! Don't write this stuff manually.
--> -->
**Prettier Version:** 1.6.1 / master **Prettier Version:** 1.6.1
([Playground link](https://prettier.io/playground/#.....)) ([Playground link](https://prettier.io/playground/#.....))
**Input:** **Input:**
-3
View File
@@ -106,9 +106,6 @@ shell.sed(
".github/ISSUE_TEMPLATE.md" ".github/ISSUE_TEMPLATE.md"
); );
shell.echo("Create prettier-version.js");
pipe(`prettierVersion = "${pkg.version}";\n`).to(`${docs}/prettier-version.js`);
shell.echo("Copy sw-toolbox.js to docs"); shell.echo("Copy sw-toolbox.js to docs");
shell.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`); shell.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`);
+1 -3
View File
@@ -23,7 +23,6 @@
<link rel="stylesheet" crossorigin href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/codemirror.css"> <link rel="stylesheet" crossorigin href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/codemirror.css">
<link rel="stylesheet" crossorigin href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/theme/neat.css"> <link rel="stylesheet" crossorigin href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/theme/neat.css">
<script src="/lib/prettier-version.js"></script>
<script src="/playground.js"></script> <script src="/playground.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/codemirror.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/codemirror.js"></script>
@@ -346,9 +345,8 @@
<footer> <footer>
<p class="version-link"> <p class="version-link">
<a href="https://github.com/prettier/prettier"> <a href="https://github.com/prettier/prettier">
prettier version Prettier
<span class="version"></span> <span class="version"></span>
/ master
</a> </a>
</p> </p>
</footer> </footer>
-1
View File
@@ -1 +0,0 @@
prettierVersion = "1.6.1";
+33 -19
View File
@@ -1,6 +1,12 @@
/* eslint-env browser */ /* eslint-env browser */
/* eslint no-var: off, strict: off, prefer-arrow-callback: off */ /* eslint no-var: off, strict: off, prefer-arrow-callback: off */
/* global Clipboard CodeMirror prettierVersion */ /* global Clipboard CodeMirror */
var prettierVersion = "?";
var inputEditor;
var docEditor;
var astEditor;
var outputEditor;
var state = (function loadState(hash) { var state = (function loadState(hash) {
try { try {
@@ -20,6 +26,19 @@ var state = (function loadState(hash) {
})(decodeURIComponent(location.hash.slice(1))); })(decodeURIComponent(location.hash.slice(1)));
var worker = new Worker("/worker.js"); var worker = new Worker("/worker.js");
worker.onmessage = function(message) {
if (prettierVersion === "?") {
prettierVersion = message.data.version;
document.querySelector(".version").textContent = prettierVersion;
}
if (outputEditor && docEditor && astEditor) {
outputEditor.setValue(message.data.formatted);
docEditor.setValue(message.data.doc || "");
astEditor.setValue(message.data.ast || "");
}
};
// Warm up the worker (load the current parser while CodeMirror loads) // Warm up the worker (load the current parser while CodeMirror loads)
worker.postMessage({ text: "", options: state.options }); worker.postMessage({ text: "", options: state.options });
@@ -184,21 +203,23 @@ window.onload = function() {
theme: theme, theme: theme,
tabWidth: 2 tabWidth: 2
}; };
var inputEditor = CodeMirror.fromTextArea( inputEditor = CodeMirror.fromTextArea(
document.getElementById("input-editor"), document.getElementById("input-editor"),
editorOptions editorOptions
); );
inputEditor.on("change", formatAsync); inputEditor.on("change", formatAsync);
var docEditor = CodeMirror.fromTextArea( docEditor = CodeMirror.fromTextArea(document.getElementById("doc-editor"), {
document.getElementById("doc-editor"), readOnly: true,
{ readOnly: true, lineNumbers: false, theme: theme } lineNumbers: false,
); theme: theme
var astEditor = CodeMirror.fromTextArea( });
document.getElementById("ast-editor"), astEditor = CodeMirror.fromTextArea(document.getElementById("ast-editor"), {
{ readOnly: true, lineNumbers: false, theme: theme } readOnly: true,
); lineNumbers: false,
var outputEditor = CodeMirror.fromTextArea( theme: theme
});
outputEditor = CodeMirror.fromTextArea(
document.getElementById("output-editor"), document.getElementById("output-editor"),
{ readOnly: true, lineNumbers: true, theme: theme } { readOnly: true, lineNumbers: true, theme: theme }
); );
@@ -210,15 +231,8 @@ window.onload = function() {
element.classList.remove("loading"); element.classList.remove("loading");
}); });
worker.onmessage = function(message) {
outputEditor.setValue(message.data.formatted);
docEditor.setValue(message.data.doc || "");
astEditor.setValue(message.data.ast || "");
};
inputEditor.setValue(state.content); inputEditor.setValue(state.content);
document.querySelector(".options-container").onchange = formatAsync; document.querySelector(".options-container").onchange = formatAsync;
document.querySelector(".version").innerText = prettierVersion;
var clipboard = new Clipboard(".copy-markdown", { var clipboard = new Clipboard(".copy-markdown", {
text: function() { text: function() {
@@ -239,7 +253,7 @@ var util = (function() {
var optionsString = formatCLIOptions(cliOptions); var optionsString = formatCLIOptions(cliOptions);
return [ return [
"**Prettier " + version + " / master**", "**Prettier " + version,
"[Playground link](" + url + ")", "[Playground link](" + url + ")",
optionsString === "" ? null : codeBlock(optionsString), optionsString === "" ? null : codeBlock(optionsString),
"", "",
-1
View File
@@ -7,7 +7,6 @@ importScripts("lib/sw-toolbox.js");
toolbox.precache([ toolbox.precache([
// Scripts // Scripts
"lib/prettier-version.js",
"lib/index.js", "lib/index.js",
"lib/parser-babylon.js", "lib/parser-babylon.js",
"lib/parser-typescript.js", "lib/parser-typescript.js",
+6 -1
View File
@@ -63,7 +63,12 @@ self.onmessage = function(message) {
} }
} }
self.postMessage({ formatted: formatted, doc: doc, ast: ast }); self.postMessage({
formatted: formatted,
doc: doc,
ast: ast,
version: prettier.version
});
}; };
function formatCode(text, options) { function formatCode(text, options) {