How to use the @ts-common/azure-js-dev-tools.findPackageJsonFileSync function in @ts-common/azure-js-dev-tools

To help you get started, we’ve selected a few @ts-common/azure-js-dev-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / core / core-http / .scripts / checkConstantsVersion.ts View on Github external
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");
      if (!fileExistsSync(constantsTsFilePath)) {
        error(`${constantsTsFilePath} doesn't exist anymore. Where'd it go?`);
      } else {
        const constantsTsFileContents: string = readFileSync(constantsTsFilePath, { encoding: "utf8" });
        const regularExpressionString = `msRestVersion: "(.*)"`;
        const regularExpression = new RegExp(regularExpressionString);