@timescaledb/utils
Version:
This package contains utilities like formatting and escaping sql strings plus other helper functions.
47 lines • 1.82 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchAndReplace = searchAndReplace;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const version = process.env.VERSION;
const startPath = process.env.START_PATH;
const shouldIgnoreWorkspace = process.env.IGNORE_WORKSPACE;
function updatePackageJsonVersion(filePath, version) {
const content = fs_1.default.readFileSync(filePath, 'utf-8');
const json = JSON.parse(content);
json.version = version;
const updatedContent = JSON.stringify(json, function (key, value) {
if (key === 'version' || (String(value).includes('workspace:^') && !shouldIgnoreWorkspace)) {
return version;
}
return value;
}, 2);
fs_1.default.writeFileSync(filePath, updatedContent);
}
function searchAndReplace(rootDir, version) {
const entries = fs_1.default.readdirSync(rootDir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path_1.default.join(rootDir, entry.name);
if (fullPath.includes('node_modules'))
continue;
if (entry.isDirectory()) {
searchAndReplace(fullPath, version);
}
else if (entry.isFile() && entry.name === 'package.json') {
updatePackageJsonVersion(fullPath, version);
}
}
}
if (!version) {
console.error('Please set the VERSION environment variable.');
process.exit(1);
}
if (!startPath) {
console.error('Please set the START_PATH environment variable.');
process.exit(1);
}
searchAndReplace(startPath, version);
//# sourceMappingURL=bump-versions.js.map