Skip to content

Commit

Permalink
Other: Manually merged gentests improvements, fixes #733
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 31, 2017
1 parent 6f74d30 commit 2c2d400
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions scripts/gentests.js
Expand Up @@ -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");
});
});

0 comments on commit 2c2d400

Please sign in to comment.