@cosmwasm/ts-codegen 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import { join, dirname, basename, extname } from "path";
2
2
  import { sync as mkdirp } from "mkdirp";
3
- import pkg from "../../package.json";
4
3
  import { writeContentToFile } from "../utils/files";
4
+ import { readAndParsePackageJson } from "../utils/package";
5
5
  import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from "../helpers";
6
+ const pkg = readAndParsePackageJson();
6
7
  const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
7
8
  const header = `/**
8
9
  * This file and any referenced files were automatically generated by ${pkg.name}@${version}
@@ -1,4 +1,5 @@
1
- import pkg from '../../package.json';
1
+ import { readAndParsePackageJson } from "./package";
2
+ const pkg = readAndParsePackageJson();
2
3
  const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
3
4
  export const header = `/**
4
5
  * This file was automatically generated by ${pkg.name}@${version}.
@@ -0,0 +1,26 @@
1
+ import { join, dirname } from "path";
2
+ import { readFileSync, existsSync } from "fs";
3
+ // need to search due to the dist/ folder and src/, etc.
4
+ function findPackageJson(currentDir) {
5
+ const filePath = join(currentDir, 'package.json');
6
+ // Check if package.json exists in the current directory
7
+ if (existsSync(filePath)) {
8
+ return filePath;
9
+ }
10
+ // Get the parent directory
11
+ const parentDir = dirname(currentDir);
12
+ // If reached the root directory, package.json is not found
13
+ if (parentDir === currentDir) {
14
+ throw new Error('package.json not found in any parent directory');
15
+ }
16
+ // Recursively look in the parent directory
17
+ return findPackageJson(parentDir);
18
+ }
19
+ export function readAndParsePackageJson() {
20
+ // Start searching from the current directory
21
+ const pkgPath = findPackageJson(__dirname);
22
+ // Read and parse the package.json
23
+ const str = readFileSync(pkgPath, 'utf8');
24
+ const pkg = JSON.parse(str);
25
+ return pkg;
26
+ }
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.createHelpers = void 0;
7
4
  const path_1 = require("path");
8
5
  const mkdirp_1 = require("mkdirp");
9
- const package_json_1 = __importDefault(require("../../package.json"));
10
6
  const files_1 = require("../utils/files");
7
+ const package_1 = require("../utils/package");
11
8
  const helpers_1 = require("../helpers");
12
- const version = process.env.NODE_ENV === "test" ? "latest" : package_json_1.default.version;
9
+ const pkg = (0, package_1.readAndParsePackageJson)();
10
+ const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
13
11
  const header = `/**
14
- * This file and any referenced files were automatically generated by ${package_json_1.default.name}@${version}
12
+ * This file and any referenced files were automatically generated by ${pkg.name}@${version}
15
13
  * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
16
14
  * and run the transpile command or yarn proto command to regenerate this bundle.
17
15
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmwasm/ts-codegen",
@@ -63,5 +63,5 @@
63
63
  "smart contracts",
64
64
  "codegen"
65
65
  ],
66
- "gitHead": "f584b91783521be1dd42f0392dfbd73020321862"
66
+ "gitHead": "f7230f9ef06a3fe5a7e3f64302abc1f726c7bf33"
67
67
  }
package/utils/header.js CHANGED
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.header = void 0;
7
- const package_json_1 = __importDefault(require("../../package.json"));
8
- const version = process.env.NODE_ENV === 'test' ? 'latest' : package_json_1.default.version;
4
+ const package_1 = require("./package");
5
+ const pkg = (0, package_1.readAndParsePackageJson)();
6
+ const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
9
7
  exports.header = `/**
10
- * This file was automatically generated by ${package_json_1.default.name}@${version}.
8
+ * This file was automatically generated by ${pkg.name}@${version}.
11
9
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
12
- * and run the ${package_json_1.default.name} generate command to regenerate this file.
10
+ * and run the ${pkg.name} generate command to regenerate this file.
13
11
  */
14
12
  \n`;
@@ -0,0 +1 @@
1
+ export declare function readAndParsePackageJson(): any;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readAndParsePackageJson = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ // need to search due to the dist/ folder and src/, etc.
7
+ function findPackageJson(currentDir) {
8
+ const filePath = (0, path_1.join)(currentDir, 'package.json');
9
+ // Check if package.json exists in the current directory
10
+ if ((0, fs_1.existsSync)(filePath)) {
11
+ return filePath;
12
+ }
13
+ // Get the parent directory
14
+ const parentDir = (0, path_1.dirname)(currentDir);
15
+ // If reached the root directory, package.json is not found
16
+ if (parentDir === currentDir) {
17
+ throw new Error('package.json not found in any parent directory');
18
+ }
19
+ // Recursively look in the parent directory
20
+ return findPackageJson(parentDir);
21
+ }
22
+ function readAndParsePackageJson() {
23
+ // Start searching from the current directory
24
+ const pkgPath = findPackageJson(__dirname);
25
+ // Read and parse the package.json
26
+ const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
27
+ const pkg = JSON.parse(str);
28
+ return pkg;
29
+ }
30
+ exports.readAndParsePackageJson = readAndParsePackageJson;