From a06e6a8ffa670882f9e7bf4e891742982bd2d939 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 22 Mar 2016 11:06:43 -0400 Subject: [PATCH] Make build process repeatable. Fixes #7 Previously when you ran `npm run build`, it would change index.html in a way that prevented you from running `npm run build` again. This change makes the builder more sophisticated, ensuring that START and STOP markers stay in the index.html file, letting you re-run the command. --- index.html | 2 +- src/render.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 1f77f57..6e62149 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ -
APP
+
diff --git a/src/render.js b/src/render.js index 029123e..4e5c1b8 100644 --- a/src/render.js +++ b/src/render.js @@ -14,7 +14,14 @@ var template = fs.readFileSync('./index.html', 'utf8'); var target = process.argv[2]; +var startDiv = `
`; +var stopDiv = '
'; +var startMarker = '' + startDiv; +var stopMarker = stopDiv + ''; +var startIdx = template.indexOf(startMarker) + startMarker.length; +var stopIdx = template.indexOf(stopMarker); + fs.writeFileSync(target, - template.replace('APP', - ReactDOMServer.renderToString( - ))); + template.substring(0, startIdx) + + ReactDOMServer.renderToString() + + template.substring(stopIdx));