From 2c2d4002d6776f3edde608bd813c37d798d87e6b Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 31 Mar 2017 14:50:24 +0200 Subject: [PATCH] Other: Manually merged gentests improvements, fixes #733 --- scripts/gentests.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/scripts/gentests.js b/scripts/gentests.js index 0e730d6cf..407bd1f85 100644 --- a/scripts/gentests.js +++ b/scripts/gentests.js @@ -5,50 +5,54 @@ var fs = require("fs"), pbts = require("../cli/pbts"); [ - "tests/data/package.proto", - "tests/data/rpc.proto", - "tests/data/mapbox/vector_tile.proto", - "tests/data/test.proto", - "tests/data/convert.proto", - "tests/data/comments.proto" + { file: "tests/data/comments.proto", flags: [] }, + { file: "tests/data/convert.proto", flags: [] }, + { file: "tests/data/mapbox/vector_tile.proto", flags: [] }, + { file: "tests/data/package.proto", flags: [] }, + { file: "tests/data/rpc.proto", flags: [ "es6" ] }, + { file: "tests/data/rpc.proto", flags: [] }, + { file: "tests/data/test.proto", flags: [] }, ] -.forEach(function(file) { - var out = file.replace(/\.proto$/, ".js"); +.forEach(function({ file, flags }) { + var basename = file.replace(/\.proto$/, ""); + var out = [ basename ].concat(flags).join("-") + ".js"; pbjs.main([ "--target", "static-module", "--wrap", "commonjs", - "--root", "test_" + path.basename(out, ".js"), - "--out", out, + "--root", "test_" + path.basename(basename, ".js"), file - ], function(err) { + ].concat(flags.map(function(flag) { + return "--" + flag; + })), function(err, output) { if (err) throw err; var pathToProtobufjs = path.relative(path.dirname(out), "minimal").replace(/\\/g, "/"); - fs.writeFileSync(out, fs.readFileSync(out).toString("utf8").replace(/"protobufjs\/minimal"/g, JSON.stringify(pathToProtobufjs)), "utf8"); + fs.writeFileSync(out, output.replace(/"protobufjs\/minimal"/g, JSON.stringify(pathToProtobufjs))); process.stdout.write("pbjs: " + file + " -> " + out + "\n"); try { require(path.join(__dirname, "..", out)); - } catch (err2) { - process.stderr.write("ERROR: " + err2.message + "\n"); + } catch (err) { + if (!flags.includes("es6")) { + process.stderr.write("ERROR: " + err.message + "\n"); + } } }); }); [ + "tests/data/rpc.js", "tests/data/test.js", - "tests/data/rpc.js" ] .forEach(function(file) { var out = file.replace(/\.js$/, ".d.ts"); pbts.main([ - "--out", out, "--no-comments", file - ], function(err) { + ], function(err, output) { if (err) throw err; var pathToProtobufjs = path.relative(path.dirname(out), "").replace(/\\/g, "/"); - fs.writeFileSync(out, fs.readFileSync(out).toString("utf8").replace(/"protobufjs"/g, JSON.stringify(pathToProtobufjs)), "utf8"); + fs.writeFileSync(out, output.replace(/"protobufjs"/g, JSON.stringify(pathToProtobufjs))); process.stdout.write("pbts: " + file + " -> " + out + "\n"); }); }); \ No newline at end of file