2021-02-02 04:54:34 +03:00
|
|
|
import {
|
|
|
|
findPackageJsonFileSync,
|
|
|
|
PackageJson,
|
|
|
|
readPackageJsonFileSync,
|
|
|
|
getParentFolderPath,
|
|
|
|
joinPath,
|
|
|
|
fileExistsSync,
|
|
|
|
} from "@ts-common/azure-js-dev-tools";
|
2019-01-15 23:53:12 +03:00
|
|
|
import { readFileSync } from "fs";
|
2019-05-11 02:58:13 +03:00
|
|
|
import { Logger, getDefaultLogger } from "@azure/logger-js";
|
2019-01-15 23:53:12 +03:00
|
|
|
|
|
|
|
export function checkConstantsVersion(): number {
|
|
|
|
const logger: Logger = getDefaultLogger();
|
|
|
|
let exitCode = 0;
|
|
|
|
|
|
|
|
function error(text: string): void {
|
|
|
|
logger.logError(text);
|
|
|
|
exitCode = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const packageJsonFilePath: string | undefined = findPackageJsonFileSync(__dirname);
|
|
|
|
if (!packageJsonFilePath) {
|
|
|
|
error("Could not find a package.json file.");
|
|
|
|
} else {
|
|
|
|
const packageJson: PackageJson = readPackageJsonFileSync(packageJsonFilePath);
|
|
|
|
const packageVersion: string | undefined = packageJson.version;
|
|
|
|
if (!packageVersion) {
|
|
|
|
error(`Could not find a version property in ${packageJsonFilePath}.`);
|
|
|
|
} else {
|
|
|
|
const repositoryRootFolderPath: string = getParentFolderPath(packageJsonFilePath);
|
2021-02-02 04:54:34 +03:00
|
|
|
const constantsTsFilePath: string = joinPath(
|
|
|
|
repositoryRootFolderPath,
|
|
|
|
"lib/util/constants.ts"
|
|
|
|
);
|
2019-01-15 23:53:12 +03:00
|
|
|
if (!fileExistsSync(constantsTsFilePath)) {
|
|
|
|
error(`${constantsTsFilePath} doesn't exist anymore. Where'd it go?`);
|
|
|
|
} else {
|
2021-02-02 04:54:34 +03:00
|
|
|
const constantsTsFileContents: string = readFileSync(constantsTsFilePath, {
|
|
|
|
encoding: "utf8",
|
|
|
|
});
|
2019-01-15 23:53:12 +03:00
|
|
|
const regularExpressionString = `msRestVersion: "(.*)"`;
|
|
|
|
const regularExpression = new RegExp(regularExpressionString);
|
|
|
|
const match: RegExpMatchArray | null = constantsTsFileContents.match(regularExpression);
|
|
|
|
if (!match) {
|
|
|
|
error(`${constantsTsFilePath} doesn't contain a match for ${regularExpressionString}.`);
|
|
|
|
} else if (match[1] !== packageVersion) {
|
2021-02-02 04:54:34 +03:00
|
|
|
error(
|
|
|
|
`Expected ${constantsTsFilePath} to contain an msRestVersion property with the value "${packageVersion}", but it was "${match[1]}" instead.`
|
|
|
|
);
|
2019-01-15 23:53:12 +03:00
|
|
|
} else {
|
2021-02-02 04:54:34 +03:00
|
|
|
logger.logInfo(
|
|
|
|
`${constantsTsFilePath} contained the correct value for msRestVersion ("${packageVersion}").`
|
|
|
|
);
|
2019-01-15 23:53:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
process.exitCode = exitCode;
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof require != undefined && require.main === module) {
|
|
|
|
checkConstantsVersion();
|
2019-05-11 02:58:13 +03:00
|
|
|
}
|