diff --git a/.gitattributes b/.gitattributes index 6de5c647..574ffd50 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ * text=auto /mithril.js binary /mithril.min.js binary +/stream/stream.js binary diff --git a/.travis.yml b/.travis.yml index af37c828..154fc1ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,10 @@ cache: directories: - node_modules -# Custom install step so the travis scripts don't need to be in package.json +# Custom install step so the travis-only stuff doesn't need to be in package.json install: - npm install -- npm install @alrra/travis-scripts@^3.0.1 +- npm install @alrra/travis-scripts@^3.0.1 gh-pages@^0.12.0 # Bundle before running tests so the bundle is always up-to-date before_script: npm run build @@ -21,37 +21,43 @@ before_script: npm run build # This is the default, but leaving so it is obvious # script: npm test -# After a successful build create bundles & commit back to the repo +# After a successful build commit changes back to repo after_success: - | + # Set up SSH environment + $(npm bin)/set-up-ssh \ + --key "$encrypted_8b86e0359d64_key" \ + --iv "$encrypted_8b86e0359d64_iv" \ + --path-encrypted-key "./.deploy.enc" + + # Commit bundle changes generated in before_script step + # --commands is a weird no-op but required for commit-changes to run + # --branch arg is to ensure this only runs against the `next` branch + $(npm bin)/commit-changes \ + --commands "echo committing" \ + --commit-message "Bundled output for commit $TRAVIS_COMMIT [skip ci]" \ + --branch "next" - # Only want to commit when building a push on whatever $BRANCH is + # Only want to commit docs when building pushes on master & + # this doesn't have the built-in branch protection likt commit-changes if [ "$TRAVIS_EVENT_TYPE" == "push" ] && \ - [ "$TRAVIS_BRANCH" == "$BRANCH" ] && \ - [ "$TRAVIS_REPO_SLUG" == "$REPO" ] + [ "$TRAVIS_BRANCH" == "master" ] && \ + [ "$TRAVIS_REPO_SLUG" == "lhorie/mithril.js" ] then - # Set up SSH environment - $(npm bin)/set-up-ssh \ - --key "$encrypted_8b86e0359d64_key" \ - --iv "$encrypted_8b86e0359d64_iv" \ - --path-encrypted-key "./.deploy.enc" + # Generate docs + $(npm-bin) run gendocs - # Commit changes (if there were any) from running build earlier - $(npm bin)/commit-changes \ - --commands "echo committing" \ - --commit-message "Bundled output for commit $TRAVIS_COMMIT [skip ci]" \ - --branch "$BRANCH" + # Commit docs to gh-pages branch + # Using --add to ensure that archived versions aren't lost + # Using --repo to force it to go over SSH so the saved keys are used (tschaub/gh-pages#160) + $(npm bin)/gh-pages --dist ./dist --add --repo "git@github.com:lhorie/mithril.js.git" else - echo "Not submitting build artifacts" + echo "Not submitting documentation updates" fi - + # Environment configuration env: global: - # Restrict the branch this will activate on - - BRANCH=next - - REPO=lhorie/mithril.js - # Set up GH_USER_EMAIL & GH_USER_NAME env variables used by travis-scripts package - secure: Xvqvm3+PvJu/rs3jl/NNn0RWLkkLkIoPHiL0GCfVRaywgjCYVN02g54NVvIDaOfybqPmu9E6PJFVs92vhF34NMFQHf4EWskynusIGV271R2BV0i+OJBfLMuLgiwm6zRn7/Zw4JvWIUGEwcnlz0qxbqdHsS0SOR3fIkFzePickW0= - secure: Rf/ldEO9d4vItJhe6EmqWpFAyCARzoCb422nHnjr1hYJknnwIXpgyZ1C/7On/9o7rWPPf+8WcHC/rgjK2rthKCldzdG5I60LfWSNzap9lk3Aa4TpSCoDBuEp7JVvDr5tc3rKnBXVT71hOay7RSx1StWzXiJs9mjaeVMJzYzRT78= diff --git a/bundler/bundle.js b/bundler/bundle.js index 34148951..54971214 100644 --- a/bundler/bundle.js +++ b/bundler/bundle.js @@ -114,7 +114,7 @@ function run(input, output) { .replace(/(\r|\n)+/g, "\n").replace(/(\r|\n)$/, "") // remove multiline breaks .replace(versionTag, isFile(packageFile) ? parse(packageFile).version : versionTag) // set version - code = "new function() {\n" + code + "\n}" + code = ";(function() {\n" + code + "\n}());" if (!isFile(output) || code !== read(output)) { //try {new Function(code); console.log("build completed at " + new Date())} catch (e) {} diff --git a/bundler/tests/test-bundler.js b/bundler/tests/test-bundler.js index 40175e19..f934afcc 100644 --- a/bundler/tests/test-bundler.js +++ b/bundler/tests/test-bundler.js @@ -24,9 +24,9 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b = 1\n}") + o(read("out.js")).equals(";(function() {\nvar b = 1\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) @@ -34,8 +34,8 @@ o.spec("bundler", function() { write("a.js", 'var b = require("./b");') write("b.js", "module.exports = 1;") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals("new function() {\nvar b = 1;\n}") + + o(read("out.js")).equals(";(function() {\nvar b = 1;\n}());") remove("a.js") remove("b.js") @@ -45,8 +45,8 @@ o.spec("bundler", function() { write("a.js", 'let b = require("./b")') write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals("new function() {\nlet b = 1\n}") + + o(read("out.js")).equals(";(function() {\nlet b = 1\n}());") remove("a.js") remove("b.js") @@ -56,8 +56,8 @@ o.spec("bundler", function() { write("a.js", 'const b = require("./b")') write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals("new function() {\nconst b = 1\n}") + + o(read("out.js")).equals(";(function() {\nconst b = 1\n}());") remove("a.js") remove("b.js") @@ -68,7 +68,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar a = {}\na.b = 1\n}") + o(read("out.js")).equals(";(function() {\nvar a = {}\na.b = 1\n}());") remove("a.js") remove("b.js") @@ -79,7 +79,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b = {}\nb = 1\n}") + o(read("out.js")).equals(";(function() {\nvar b = {}\nb = 1\n}());") remove("a.js") remove("b.js") @@ -89,8 +89,8 @@ o.spec("bundler", function() { write("a.js", '"use strict"\nvar b = require("./b")') write("b.js", '"use strict"\nmodule.exports = 1') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}') + + o(read("out.js")).equals(";(function() {\n"use strict"\nvar b = 1\n}());") remove("a.js") remove("b.js") @@ -101,7 +101,7 @@ o.spec("bundler", function() { write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\n'use strict'\nvar b = 1\n}") + o(read("out.js")).equals(";(function() {\n'use strict'\nvar b = 1\n}());") remove("a.js") remove("b.js") @@ -112,8 +112,8 @@ o.spec("bundler", function() { write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}') - + o(read("out.js")).equals(";(function() {\n"use strict"\nvar b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") @@ -123,7 +123,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nwindow.a = 1\nvar b = function() {return a}\n}") + o(read("out.js")).equals(";(function() {\nwindow.a = 1\nvar b = function() {return a}\n}());") remove("a.js") remove("b.js") @@ -134,7 +134,7 @@ o.spec("bundler", function() { write("b.js", "1 + 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\n1 + 1\n}") + o(read("out.js")).equals(";(function() {\n1 + 1\n}());") remove("a.js") remove("b.js") @@ -145,7 +145,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\n}());") remove("a.js") remove("b.js") @@ -156,9 +156,9 @@ o.spec("bundler", function() { write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) @@ -167,9 +167,9 @@ o.spec("bundler", function() { write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0()\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0()\n}());") - remove("a.js") + remove("a.js") remove("b.js") remove("out.js") }) @@ -178,7 +178,7 @@ o.spec("bundler", function() { write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0\n()\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0\n()\n}());") remove("a.js") remove("b.js") @@ -190,7 +190,7 @@ o.spec("bundler", function() { write("c.js", 'var b = require("./b")\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}());") remove("a.js") remove("b.js") @@ -203,7 +203,7 @@ o.spec("bundler", function() { write("c.js", "var x\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b = 1\nvar x\nvar c = 2\n}") + o(read("out.js")).equals(";(function() {\nvar b = 1\nvar x\nvar c = 2\n}());") remove("a.js") remove("b.js") @@ -216,7 +216,7 @@ o.spec("bundler", function() { write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}") + o(read("out.js")).equals(";(function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}());") remove("a.js") remove("b.js") @@ -229,7 +229,7 @@ o.spec("bundler", function() { write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals('new function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}') + o(read("out.js")).equals(";(function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}());") remove("a.js") remove("b.js") @@ -241,7 +241,7 @@ o.spec("bundler", function() { write("b.js", "var b = 1\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = 2\n}") + o(read("out.js")).equals(";(function() {\nvar b0 = 1\nvar b = 2\n}());") remove("a.js") remove("b.js") @@ -253,7 +253,7 @@ o.spec("bundler", function() { write("c.js", "var b = {}\nmodule.exports = b") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b = {}\nb.x = 1\n}") + o(read("out.js")).equals(";(function() {\nvar b = {}\nb.x = 1\n}());") remove("a.js") remove("b.js") @@ -267,7 +267,7 @@ o.spec("bundler", function() { write("d.js", "var a = 3\nmodule.exports = a") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}") + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}());") remove("a.js") remove("b.js") @@ -281,7 +281,7 @@ o.spec("bundler", function() { write("c.js", 'var a = require("./a").toString()\nvar b = require("./b")') bundle(ns + "c.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}());") remove("a.js") remove("b.js") @@ -293,7 +293,7 @@ o.spec("bundler", function() { write("c.js", 'var b = require("./b")\nvar a = require("./a").toString()') bundle(ns + "c.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}") + o(read("out.js")).equals(";(function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}());") remove("a.js") remove("b.js") @@ -306,7 +306,7 @@ o.spec("bundler", function() { write("d.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}") + o(read("out.js")).equals(";(function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}());") remove("a.js") remove("b.js") @@ -319,7 +319,7 @@ o.spec("bundler", function() { write("b.js", "var b = 1\nmodule.exports = function() {return b}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = function() {return b0}\n}") + o(read("out.js")).equals(";(function() {\nvar b0 = 1\nvar b = function() {return b0}\n}());") remove("a.js") remove("b.js") @@ -330,7 +330,7 @@ o.spec("bundler", function() { write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}") + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}());") remove("a.js") remove("b.js") @@ -341,7 +341,7 @@ o.spec("bundler", function() { write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}") + o(read("out.js")).equals(";(function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}());") remove("a.js") remove("b.js") @@ -353,7 +353,7 @@ o.spec("bundler", function() { write("c.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}") + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}());") remove("a.js") remove("b.js") @@ -365,7 +365,7 @@ o.spec("bundler", function() { write("b.js", 'var b = "b b b \\" b"\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals('new function() {\nvar b0 = "b b b \\" b"\nvar b = function() {return b0}\n}') + o(read("out.js")).equals(';(function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}());') remove("a.js") remove("b.js") @@ -376,7 +376,7 @@ o.spec("bundler", function() { write("b.js", "var b = {b: 1}\nmodule.exports = function() {return b.b}") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals("new function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}") + o(read("out.js")).equals(";(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());") remove("a.js") remove("b.js") diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..5c153480 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +mithril.js.org diff --git a/docs/generate.js b/docs/generate.js index 789563c8..438b8343 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -5,13 +5,13 @@ var path = require("path") var marked = require("marked") var layout = fs.readFileSync("./docs/layout.html", "utf-8") var version = JSON.parse(fs.readFileSync("./package.json", "utf-8")).version -try {fs.mkdirSync("../mithril")} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/archive")} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/lib")} catch (e) {/* ignore */} -try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version)} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version + "/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version + "/lib/prism")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/lib/prism")} catch (e) {/* ignore */} var guides = fs.readFileSync("docs/guides.md", "utf-8") var methods = fs.readFileSync("docs/methods.md", "utf-8") @@ -57,12 +57,12 @@ function generate(pathname) { .replace(/(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors return ".+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + '">' + text + "" }) - fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") - fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") + fs.writeFileSync("./dist/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") + fs.writeFileSync("./dist/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") } else if (!pathname.match(/lint|generate/)) { - fs.writeFileSync("../mithril/archive/v" + version + "/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") - fs.writeFileSync("../mithril/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") + fs.writeFileSync("./dist/archive/v" + version + "/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") + fs.writeFileSync("./dist/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") } } } diff --git a/docs/route.md b/docs/route.md index 1ecb8d62..65e9a600 100644 --- a/docs/route.md +++ b/docs/route.md @@ -257,8 +257,6 @@ In the example above, we defined a route `/edit/:id`. This creates a dynamic rou It's possible to have multiple arguments in a route, for example `/edit/:projectID/:userID` would yield the properties `projectID` and `userID` on the component's vnode attributes object. -In addition to routing parameters, the `attrs` object also includes a `path` property that contains the current route path, and a `route` property that contains the matched routed. - #### Key parameter When a user navigates from a parameterized route to the same route with a different parameter (e.g. going from `/page/1` to `/page/2` given a route `/page/:id`, the component would not be recreated from scratch since both routes resolve to the same component, and thus result in a virtual dom in-place diff. This has the side-effect of triggering the `onupdate` hook, rather than `oninit`/`oncreate`. However, it's relatively common for a developer to want to synchronize the recreation of the component to the route change event. diff --git a/docs/stream.md b/docs/stream.md index 17b0d407..250f3365 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -40,6 +40,14 @@ Streams are NOT bundled with Mithril's core distribution. To include the Streams var Stream = require("mithril/stream") ``` +You can also download the module directly if your environment does not support a bundling toolchain: + +```markup + +``` + +When loaded directly with a `