Skip to content

Commit

Permalink
WIP - Moderninze builder.js (issue #634)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Apr 15, 2016
1 parent 9cd2e13 commit f73becc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
35 changes: 24 additions & 11 deletions tools/builder.js
Expand Up @@ -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("<<ReSpec-Version-Number>>", version);
}

/**
* Async function that appends the boilerplate to the generated script
* and writes out the result. It also creates the source map file.
Expand All @@ -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]);
Expand Down Expand Up @@ -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/"),
Expand Down
9 changes: 9 additions & 0 deletions tools/inserts/boilerplate.frag
@@ -0,0 +1,9 @@
/**
* ReSpec <<ReSpec-Version-Number>>
* 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/
**/
2 changes: 2 additions & 0 deletions tools/inserts/wrapperFunction.frag
@@ -0,0 +1,2 @@
(function(){
"use strict";
1 change: 1 addition & 0 deletions tools/inserts/wrapperFunctionEnd.frag
@@ -0,0 +1 @@
}());

0 comments on commit f73becc

Please sign in to comment.