ms-rest-js/.scripts/checkConstantsVersion.ts

67 строки
2.3 KiB
TypeScript
Исходник Обычный вид История

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";
Add script to run tests on dependent projects (#345) * Add script to run tests on dependent projects * Bump the version * Fix logging statements * Update constants * Update Azure Pipelines configuration * Fix Azure Pipeline job name * Add gulp build command * Add npm run local * Flip order * Add build step * Add more logging * Fix undefined result print * Remove inheriting stdio * Change to spawnSync * Add more logging * Remove build step * Change exec to run from JS dev tools * Add logger-js package * Add build step back * Add process.exit * Add logging * Change error logging * Add command printing * Extract options object * Add fullOptions parameter * Change NPM command name * Remove logging * Remove npm run test * Await additional commands * Add test command to package.json * Add timeout * Add test as separate task * Change foreach to for * Remove test from package.json command * Uncomment npm install commands * Add latest ms-rest-js to npm install * Add autorest.typescript DevOps task * Add npm link * Change link to install * Remove prepack script * Change package name to ../.. * Remove rm -rf * Add build step * Add git checkout * Add dependent project directory * Remove git branch checkout * Bump the version to 1.8.6 * Add git checkout * Change branch name * Add execution directory * Remove git checkout * Add tsc --version command * Remove local ms-rest-js install * Move .tmp folder * Change .tmp path creation * Fix path in Azure DevOps config * Renable logging * Add run to build command * Move scripts back to TypeScript * Improve logging
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);
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 {
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) {
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 {
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();
Add script to run tests on dependent projects (#345) * Add script to run tests on dependent projects * Bump the version * Fix logging statements * Update constants * Update Azure Pipelines configuration * Fix Azure Pipeline job name * Add gulp build command * Add npm run local * Flip order * Add build step * Add more logging * Fix undefined result print * Remove inheriting stdio * Change to spawnSync * Add more logging * Remove build step * Change exec to run from JS dev tools * Add logger-js package * Add build step back * Add process.exit * Add logging * Change error logging * Add command printing * Extract options object * Add fullOptions parameter * Change NPM command name * Remove logging * Remove npm run test * Await additional commands * Add test command to package.json * Add timeout * Add test as separate task * Change foreach to for * Remove test from package.json command * Uncomment npm install commands * Add latest ms-rest-js to npm install * Add autorest.typescript DevOps task * Add npm link * Change link to install * Remove prepack script * Change package name to ../.. * Remove rm -rf * Add build step * Add git checkout * Add dependent project directory * Remove git branch checkout * Bump the version to 1.8.6 * Add git checkout * Change branch name * Add execution directory * Remove git checkout * Add tsc --version command * Remove local ms-rest-js install * Move .tmp folder * Change .tmp path creation * Fix path in Azure DevOps config * Renable logging * Add run to build command * Move scripts back to TypeScript * Improve logging
2019-05-11 02:58:13 +03:00
}