diff --git a/tools/builder.js b/tools/builder.js index 2594eef32a..7579e810e3 100755 --- a/tools/builder.js +++ b/tools/builder.js @@ -27,6 +27,16 @@ function replaceMapFilename(respecJs, outPath){ }; } +/** + * Replaces the version number in the boilerplate. + * + * @param {String} optimizedJs The optimized script. + * @param {String} version The version string. + */ +function replaceVersionString(optimizedJs, version){ + return optimizedJs.replace("<>", version); +} + /** * Async function that appends the boilerplate to the generated script * and writes out the result. It also creates the source map file. @@ -36,17 +46,10 @@ function replaceMapFilename(respecJs, outPath){ * @param {String} version The version of the script. * @return {Promise} Resolves when done writing the files. */ -function appendBoilerplate(outPath, version) { +function writeOutput(outPath, version) { return async(function*(optimizedJs, sourceMap) { - const respecJs = `"use strict"; -/* ReSpec ${version} -Created by Robin Berjon, http://berjon.com/ (@robinberjon) -Documentation: http://w3.org/respec/. -See original source for licenses: https://github.com/w3c/respec */ -window.respecVersion = "${version}"; -${optimizedJs} -require(['profile-w3c-common']);`; - const newSource = replaceMapFilename(respecJs, outPath); + let newSource = replaceMapFilename(optimizedJs, outPath); + newSource.source = replaceVersionString(newSource.source, version); const promiseToWriteJs = fsp.writeFile(outPath, newSource.source, "utf-8"); const promiseToWriteMap = fsp.writeFile(newSource.mapPath, sourceMap, "utf-8"); yield Promise.all([promiseToWriteJs, promiseToWriteMap]); @@ -77,8 +80,18 @@ var Builder = { return async.task(function*() { // optimisation settings const version = options.version || (yield this.getRespecVersion()); - const outputWritter = appendBoilerplate(options.out, version); + const outputWritter = writeOutput(options.out, version); const config = { + insertRequire: ["profile-w3c-common"], + wrap: { + startFile: [ + "tools/inserts/boilerplate.frag", + "tools/inserts/wrapperFunction.frag", + ], + endFile: [ + "tools/inserts/wrapperFunctionEnd.frag", + ], + }, generateSourceMaps: true, mainConfigFile: "js/profile-w3c-common.js", baseUrl: pth.join(__dirname, "../js/"), diff --git a/tools/inserts/boilerplate.frag b/tools/inserts/boilerplate.frag new file mode 100644 index 0000000000..8a786e6cf6 --- /dev/null +++ b/tools/inserts/boilerplate.frag @@ -0,0 +1,9 @@ +/** +* ReSpec <> +* Created by Robin Berjon, http://berjon.com/ (@robinberjon) +* See original source for licenses +* +* Repo: https://github.com/w3c/respec/ +* Contributors: https://github.com/w3c/respec/graphs/contributors +* Documentation: http://w3.org/respec/ +**/ \ No newline at end of file diff --git a/tools/inserts/wrapperFunction.frag b/tools/inserts/wrapperFunction.frag new file mode 100644 index 0000000000..a67b25e16e --- /dev/null +++ b/tools/inserts/wrapperFunction.frag @@ -0,0 +1,2 @@ +(function(){ + "use strict"; \ No newline at end of file diff --git a/tools/inserts/wrapperFunctionEnd.frag b/tools/inserts/wrapperFunctionEnd.frag new file mode 100644 index 0000000000..647f94d3e4 --- /dev/null +++ b/tools/inserts/wrapperFunctionEnd.frag @@ -0,0 +1 @@ +}()); \ No newline at end of file