Skip to content

Commit 098ef04

Browse files
committed
centralize version info in package.json for easier updating
1 parent 0fd0b20 commit 098ef04

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
66
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
77
load("//:protobuf_javascript_release.bzl", "package_naming")
88

9+
exports_files(["generate-version-header.js", "package.json"])
10+
911
config_setting(
1012
name = "x64_x86_windows",
1113
values = {"cpu": "x64_x86_windows"},

download-protoc-gen-js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const os = require('os');
33
const path = require('path');
44
const AdmZip = require('adm-zip');
55

6-
const VERSION = '4.0.0';
6+
const VERSION = require('./package.json').version;
77
const BIN_DIR = path.join(__dirname, 'bin');
88

99
function getPlatform() {

generate-version-header.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const version = require('./package.json').version;
5+
const headerContent = `// Generated by generate-version-header.js
6+
#ifndef PROTOBUF_JAVASCRIPT_VERSION_H__
7+
#define PROTOBUF_JAVASCRIPT_VERSION_H__
8+
9+
const char* const kProtobufJavascriptVersion = "${version}";
10+
11+
#endif // PROTOBUF_JAVASCRIPT_VERSION_H__
12+
`;
13+
14+
fs.writeFileSync(process.argv[2], headerContent);

generator/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
genrule(
2+
name = "generate_version_header",
3+
srcs = ["//:package.json"],
4+
outs = ["version.h"],
5+
cmd = "node $(location //:generate-version-header.js) $(OUTS)",
6+
tools = ["//:generate-version-header.js"],
7+
)
8+
19
cc_binary(
210
name = "protoc-gen-js",
311
srcs = [
@@ -6,6 +14,7 @@ cc_binary(
614
"protoc-gen-js.cc",
715
"well_known_types_embed.cc",
816
"well_known_types_embed.h",
17+
":version.h",
918
],
1019
visibility = ["//visibility:public"],
1120
deps = [

generator/protoc-gen-js.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@
2525
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2626
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2727
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT of THE USE
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131
#include <google/protobuf/compiler/plugin.h>
3232
#include <iostream>
3333
#include <string>
3434

3535
#include "generator/js_generator.h"
36-
37-
const char* kVersion = "4.0.0";
36+
#include "generator/version.h"
3837

3938
int main(int argc, char** argv) {
4039
for (int i = 1; i < argc; ++i) {
4140
if (std::string(argv[i]) == "--version") {
42-
std::cout << "protoc-gen-js version " << kVersion << std::endl;
41+
std::cout << "protoc-gen-js version " << kProtobufJavascriptVersion << std::endl;
4342
return 0;
4443
}
4544
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"jasmine": "~3.5.0"
2222
},
2323
"scripts": {
24+
"prebuild": "node update-bazel-versions.js",
2425
"build": "node ./node_modules/gulp/bin/gulp.js dist",
2526
"test": "node ./node_modules/gulp/bin/gulp.js test",
2627
"clean": "node ./node_modules/gulp/bin/gulp.js clean",

update-bazel-versions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const version = require('./package.json').version;
5+
6+
// Update MODULE.bazel
7+
const moduleBazelPath = path.join(__dirname, 'MODULE.bazel');
8+
let moduleBazelContent = fs.readFileSync(moduleBazelPath, 'utf8');
9+
moduleBazelContent = moduleBazelContent.replace(/version = ".*"/, `version = "${version}"`);
10+
fs.writeFileSync(moduleBazelPath, moduleBazelContent);
11+
12+
// Update protobuf_javascript_release.bzl
13+
const releaseBzlPath = path.join(__dirname, 'protobuf_javascript_release.bzl');
14+
let releaseBzlContent = fs.readFileSync(releaseBzlPath, 'utf8');
15+
releaseBzlContent = releaseBzlContent.replace(/_PROTOBUF_JAVASCRIPT_VERSION = ".*"/, `_PROTOBUF_JAVASCRIPT_VERSION = "${version}"`);
16+
fs.writeFileSync(releaseBzlPath, releaseBzlContent);

0 commit comments

Comments
 (0)