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