diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 356fa46f..04c3249c 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -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/#.....)) **Input:** diff --git a/scripts/build/build.js b/scripts/build/build.js index 0be20271..e7df784d 100755 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -106,9 +106,6 @@ shell.sed( ".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.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`); diff --git a/website/pages/playground/index.html b/website/pages/playground/index.html index f19efbd3..8710880c 100644 --- a/website/pages/playground/index.html +++ b/website/pages/playground/index.html @@ -23,7 +23,6 @@ - @@ -346,9 +345,8 @@ diff --git a/website/static/lib/prettier-version.js b/website/static/lib/prettier-version.js deleted file mode 100644 index 4924a180..00000000 --- a/website/static/lib/prettier-version.js +++ /dev/null @@ -1 +0,0 @@ -prettierVersion = "1.6.1"; diff --git a/website/static/playground.js b/website/static/playground.js index 77c15a2f..562e3fa4 100644 --- a/website/static/playground.js +++ b/website/static/playground.js @@ -1,6 +1,12 @@ /* eslint-env browser */ /* 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) { try { @@ -20,6 +26,19 @@ var state = (function loadState(hash) { })(decodeURIComponent(location.hash.slice(1))); 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) worker.postMessage({ text: "", options: state.options }); @@ -184,21 +203,23 @@ window.onload = function() { theme: theme, tabWidth: 2 }; - var inputEditor = CodeMirror.fromTextArea( + inputEditor = CodeMirror.fromTextArea( document.getElementById("input-editor"), editorOptions ); inputEditor.on("change", formatAsync); - var docEditor = CodeMirror.fromTextArea( - document.getElementById("doc-editor"), - { readOnly: true, lineNumbers: false, theme: theme } - ); - var astEditor = CodeMirror.fromTextArea( - document.getElementById("ast-editor"), - { readOnly: true, lineNumbers: false, theme: theme } - ); - var outputEditor = CodeMirror.fromTextArea( + docEditor = CodeMirror.fromTextArea(document.getElementById("doc-editor"), { + readOnly: true, + lineNumbers: false, + theme: theme + }); + astEditor = CodeMirror.fromTextArea(document.getElementById("ast-editor"), { + readOnly: true, + lineNumbers: false, + theme: theme + }); + outputEditor = CodeMirror.fromTextArea( document.getElementById("output-editor"), { readOnly: true, lineNumbers: true, theme: theme } ); @@ -210,15 +231,8 @@ window.onload = function() { 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); document.querySelector(".options-container").onchange = formatAsync; - document.querySelector(".version").innerText = prettierVersion; var clipboard = new Clipboard(".copy-markdown", { text: function() { @@ -239,7 +253,7 @@ var util = (function() { var optionsString = formatCLIOptions(cliOptions); return [ - "**Prettier " + version + " / master**", + "**Prettier " + version, "[Playground link](" + url + ")", optionsString === "" ? null : codeBlock(optionsString), "", diff --git a/website/static/service-worker.js b/website/static/service-worker.js index 0abbd4d2..11149bdf 100644 --- a/website/static/service-worker.js +++ b/website/static/service-worker.js @@ -7,7 +7,6 @@ importScripts("lib/sw-toolbox.js"); toolbox.precache([ // Scripts - "lib/prettier-version.js", "lib/index.js", "lib/parser-babylon.js", "lib/parser-typescript.js", diff --git a/website/static/worker.js b/website/static/worker.js index 3c6612d5..577e3faa 100644 --- a/website/static/worker.js +++ b/website/static/worker.js @@ -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) {