scripts/version-update.js (45 lines of code) (raw):
#!/usr/bin/env node
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* Adapted from
* https://github.com/open-telemetry/opentelemetry-js/blob/stable/v1.0.0/scripts/version-update.js
*
* Run this from within the package root by setting it as a precompile script.
* This will regenerate src/version.ts files as part of the build to always be
* up to date.
*/
const fs = require("fs");
const path = require("path");
const packageJsonUrl = path.resolve(`${process.cwd()}/package.json`);
const pjson = require(packageJsonUrl);
const content = `// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Autogenerated by scripts/version-update.js during compilation. Check this
// file in.
export const VERSION = '${pjson.version}';
`;
const fileUrl = path.join("src", "version.ts");
fs.writeFileSync(fileUrl, content);