UNPKG

@cosmwasm/ts-codegen

Version:

@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.

31 lines (30 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readAndParsePackageJson = void 0; const fs_1 = require("fs"); const path_1 = require("path"); // need to search due to the dist/ folder and src/, etc. function findPackageJson(currentDir) { const filePath = (0, path_1.join)(currentDir, 'package.json'); // Check if package.json exists in the current directory if ((0, fs_1.existsSync)(filePath)) { return filePath; } // Get the parent directory const parentDir = (0, path_1.dirname)(currentDir); // If reached the root directory, package.json is not found if (parentDir === currentDir) { throw new Error('package.json not found in any parent directory'); } // Recursively look in the parent directory return findPackageJson(parentDir); } function readAndParsePackageJson() { // Start searching from the current directory const pkgPath = findPackageJson(__dirname); // Read and parse the package.json const str = (0, fs_1.readFileSync)(pkgPath, 'utf8'); const pkg = JSON.parse(str); return pkg; } exports.readAndParsePackageJson = readAndParsePackageJson;