@prosopo/scripts 3.1.13 → 3.1.25

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,170 @@
1
1
  # @prosopo/scripts
2
2
 
3
+ ## 3.1.25
4
+ ### Patch Changes
5
+
6
+ - 8ce9205: Change engine requirements
7
+ - b6e98b2: Run npm audit
8
+ - Updated dependencies [fdef625]
9
+ - Updated dependencies [15ae7cf]
10
+ - Updated dependencies [bb5f41c]
11
+ - Updated dependencies [55a64c6]
12
+ - Updated dependencies [aa8216a]
13
+ - Updated dependencies [8ce9205]
14
+ - Updated dependencies [df79c03]
15
+ - Updated dependencies [6ac5367]
16
+ - Updated dependencies [b6e98b2]
17
+ - Updated dependencies [55a64c6]
18
+ - @prosopo/provider@3.13.0
19
+ - @prosopo/types@3.6.0
20
+ - @prosopo/util@3.2.0
21
+ - @prosopo/cli@3.5.0
22
+ - @prosopo/util-crypto@13.5.24
23
+ - @prosopo/types-env@2.7.47
24
+ - @prosopo/datasets@3.0.43
25
+ - @prosopo/keyring@2.8.36
26
+ - @prosopo/common@3.1.22
27
+ - @prosopo/dotenv@3.0.27
28
+ - @prosopo/locale@3.1.22
29
+ - @prosopo/workspace@3.1.15
30
+ - @prosopo/env@3.2.22
31
+ - @prosopo/config@3.1.22
32
+
33
+ ## 3.1.24
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [8f1773a]
37
+ - @prosopo/types@3.5.11
38
+ - @prosopo/cli@3.4.17
39
+ - @prosopo/datasets@3.0.42
40
+ - @prosopo/env@3.2.21
41
+ - @prosopo/keyring@2.8.35
42
+ - @prosopo/provider@3.12.14
43
+ - @prosopo/types-env@2.7.46
44
+
45
+ ## 3.1.23
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [cb8ab85]
49
+ - @prosopo/provider@3.12.13
50
+ - @prosopo/types@3.5.10
51
+ - @prosopo/cli@3.4.16
52
+ - @prosopo/datasets@3.0.41
53
+ - @prosopo/types-env@2.7.45
54
+ - @prosopo/env@3.2.20
55
+ - @prosopo/keyring@2.8.34
56
+
57
+ ## 3.1.22
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [43907e8]
61
+ - Updated dependencies [b4639ec]
62
+ - Updated dependencies [005ce66]
63
+ - Updated dependencies [7101036]
64
+ - @prosopo/types@3.5.9
65
+ - @prosopo/provider@3.12.12
66
+ - @prosopo/util@3.1.7
67
+ - @prosopo/cli@3.4.15
68
+ - @prosopo/datasets@3.0.40
69
+ - @prosopo/types-env@2.7.44
70
+ - @prosopo/env@3.2.19
71
+ - @prosopo/keyring@2.8.33
72
+
73
+ ## 3.1.21
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [4b6dc9d]
77
+ - Updated dependencies [e5c259d]
78
+ - Updated dependencies [6420187]
79
+ - @prosopo/provider@3.12.11
80
+ - @prosopo/types@3.5.8
81
+ - @prosopo/cli@3.4.14
82
+ - @prosopo/datasets@3.0.39
83
+ - @prosopo/types-env@2.7.43
84
+ - @prosopo/env@3.2.18
85
+ - @prosopo/keyring@2.8.32
86
+
87
+ ## 3.1.20
88
+ ### Patch Changes
89
+
90
+ - Updated dependencies [c9d8fdf]
91
+ - Updated dependencies [b8185a4]
92
+ - Updated dependencies [3a027ef]
93
+ - Updated dependencies [3a027ef]
94
+ - @prosopo/common@3.1.21
95
+ - @prosopo/cli@3.4.13
96
+ - @prosopo/provider@3.12.10
97
+ - @prosopo/config@3.1.21
98
+ - @prosopo/datasets@3.0.38
99
+ - @prosopo/dotenv@3.0.26
100
+ - @prosopo/env@3.2.17
101
+ - @prosopo/keyring@2.8.31
102
+ - @prosopo/types-env@2.7.42
103
+ - @prosopo/workspace@3.1.14
104
+ - @prosopo/locale@3.1.21
105
+ - @prosopo/types@3.5.7
106
+ - @prosopo/util@3.1.6
107
+ - @prosopo/util-crypto@13.5.23
108
+
109
+ ## 3.1.19
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies [8491159]
113
+ - @prosopo/provider@3.12.9
114
+ - @prosopo/cli@3.4.12
115
+
116
+ ## 3.1.18
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [5d11a81]
120
+ - @prosopo/provider@3.12.8
121
+ - @prosopo/types@3.5.6
122
+ - @prosopo/cli@3.4.11
123
+ - @prosopo/datasets@3.0.37
124
+ - @prosopo/env@3.2.16
125
+ - @prosopo/keyring@2.8.30
126
+ - @prosopo/types-env@2.7.41
127
+
128
+ ## 3.1.17
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [cbc5d8e]
132
+ - @prosopo/provider@3.12.7
133
+ - @prosopo/cli@3.4.10
134
+
135
+ ## 3.1.16
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [494c5a8]
139
+ - @prosopo/provider@3.12.6
140
+ - @prosopo/types@3.5.5
141
+ - @prosopo/cli@3.4.9
142
+ - @prosopo/datasets@3.0.36
143
+ - @prosopo/types-env@2.7.40
144
+ - @prosopo/env@3.2.15
145
+ - @prosopo/keyring@2.8.29
146
+
147
+ ## 3.1.15
148
+ ### Patch Changes
149
+
150
+ - 4ba029e: repo maintainance
151
+ - Updated dependencies [4ba029e]
152
+ - @prosopo/provider@3.12.5
153
+ - @prosopo/cli@3.4.8
154
+
155
+ ## 3.1.14
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [08ff50f]
159
+ - Updated dependencies [08ff50f]
160
+ - @prosopo/cli@3.4.7
161
+ - @prosopo/provider@3.12.4
162
+ - @prosopo/types@3.5.4
163
+ - @prosopo/datasets@3.0.35
164
+ - @prosopo/types-env@2.7.39
165
+ - @prosopo/env@3.2.14
166
+ - @prosopo/keyring@2.8.28
167
+
3
168
  ## 3.1.13
4
169
  ### Patch Changes
5
170
 
@@ -8,13 +8,11 @@ const types = require("@prosopo/types");
8
8
  const workspace = require("@prosopo/workspace");
9
9
  const yargs = require("yargs");
10
10
  const helpers = require("yargs/helpers");
11
- require("../contract/index.cjs");
12
11
  const setVersion = require("../scripts/setVersion.cjs");
13
12
  require("../setup/index.cjs");
14
13
  require("../util/index.cjs");
15
14
  const exec = require("../util/exec.cjs");
16
15
  const setup = require("../setup/setup.cjs");
17
- const _import = require("../contract/import.cjs");
18
16
  const rootDir = path.resolve(".");
19
17
  dotenv.loadEnv(rootDir);
20
18
  async function processArgs(args) {
@@ -51,21 +49,6 @@ async function processArgs(args) {
51
49
  log.info(() => ({ msg: "Running setup scripts" }));
52
50
  await setup.setup(argv.provider, argv.sites);
53
51
  }
54
- }).command({
55
- command: "import_contract",
56
- describe: "Import a contract into the contract package.",
57
- builder: (yargs2) => yargs2.option("in", {
58
- type: "string",
59
- demandOption: true,
60
- desc: "The path to the contract's abi"
61
- }).option("out", {
62
- type: "string",
63
- demandOption: true,
64
- desc: "The path to the output directory"
65
- }),
66
- handler: async (argv) => {
67
- await _import(argv.in, argv.out);
68
- }
69
52
  }).command({
70
53
  command: "version",
71
54
  describe: "Set the version of packages",
@@ -3,23 +3,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  require("./setup/index.cjs");
4
4
  require("./util/index.cjs");
5
5
  const index = require("./cli/index.cjs");
6
- require("./contract/index.cjs");
7
6
  const setup = require("./setup/setup.cjs");
8
7
  const provider = require("./setup/provider.cjs");
9
- const loadContractFiles = require("./util/loadContractFiles.cjs");
10
8
  const updateEnv = require("./util/updateEnv.cjs");
11
9
  const exec = require("./util/exec.cjs");
12
10
  const fluxLogDappDetails = require("./util/fluxLogDappDetails.cjs");
13
- const _import = require("./contract/import.cjs");
14
11
  exports.processArgs = index.processArgs;
15
12
  exports.setup = setup.setup;
16
13
  exports.updateEnvFile = setup.updateEnvFile;
17
14
  exports.setupProvider = provider.setupProvider;
18
- exports.AbiJSON = loadContractFiles.AbiJSON;
19
- exports.Wasm = loadContractFiles.Wasm;
20
15
  exports.findEnvFiles = updateEnv.findEnvFiles;
21
16
  exports.updateDemoHTMLFiles = updateEnv.updateDemoHTMLFiles;
22
17
  exports.updateEnvFiles = updateEnv.updateEnvFiles;
23
18
  exports.exec = exec.exec;
24
19
  exports.extractReferrersFromLogs = fluxLogDappDetails.extractReferrersFromLogs;
25
- exports.importContract = _import;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const loadContractFiles = require("./loadContractFiles.cjs");
4
3
  const updateEnv = require("./updateEnv.cjs");
5
4
  const exec = require("./exec.cjs");
6
5
  const fluxLogDappDetails = require("./fluxLogDappDetails.cjs");
7
- exports.AbiJSON = loadContractFiles.AbiJSON;
8
- exports.Wasm = loadContractFiles.Wasm;
9
6
  exports.findEnvFiles = updateEnv.findEnvFiles;
10
7
  exports.updateDemoHTMLFiles = updateEnv.updateDemoHTMLFiles;
11
8
  exports.updateEnvFiles = updateEnv.updateEnvFiles;
package/dist/cli/index.js CHANGED
@@ -6,14 +6,12 @@ import { encodeProcaptchaOutput, decodeProcaptchaOutput } from "@prosopo/types";
6
6
  import "../workspace/dist/index.js";
7
7
  import yargs from "yargs";
8
8
  import { hideBin } from "yargs/helpers";
9
- import "../contract/index.js";
10
9
  import setVersion from "../scripts/setVersion.js";
11
10
  import "../setup/index.js";
12
11
  import "../util/index.js";
13
12
  import { getScriptsPkgDir } from "../workspace/dist/projectInfo.js";
14
13
  import { exec } from "../util/exec.js";
15
14
  import { setup } from "../setup/setup.js";
16
- import importContract from "../contract/import.js";
17
15
  const rootDir = path.resolve(".");
18
16
  loadEnv(rootDir);
19
17
  async function processArgs(args) {
@@ -50,21 +48,6 @@ async function processArgs(args) {
50
48
  log.info(() => ({ msg: "Running setup scripts" }));
51
49
  await setup(argv.provider, argv.sites);
52
50
  }
53
- }).command({
54
- command: "import_contract",
55
- describe: "Import a contract into the contract package.",
56
- builder: (yargs2) => yargs2.option("in", {
57
- type: "string",
58
- demandOption: true,
59
- desc: "The path to the contract's abi"
60
- }).option("out", {
61
- type: "string",
62
- demandOption: true,
63
- desc: "The path to the output directory"
64
- }),
65
- handler: async (argv) => {
66
- await importContract(argv.in, argv.out);
67
- }
68
51
  }).command({
69
52
  command: "version",
70
53
  describe: "Set the version of packages",
package/dist/index.js CHANGED
@@ -1,21 +1,15 @@
1
1
  import "./setup/index.js";
2
2
  import "./util/index.js";
3
3
  import { processArgs } from "./cli/index.js";
4
- import "./contract/index.js";
5
4
  import { setup, updateEnvFile } from "./setup/setup.js";
6
5
  import { setupProvider } from "./setup/provider.js";
7
- import { AbiJSON, Wasm } from "./util/loadContractFiles.js";
8
6
  import { findEnvFiles, updateDemoHTMLFiles, updateEnvFiles } from "./util/updateEnv.js";
9
7
  import { exec } from "./util/exec.js";
10
8
  import { extractReferrersFromLogs } from "./util/fluxLogDappDetails.js";
11
- import { default as default2 } from "./contract/import.js";
12
9
  export {
13
- AbiJSON,
14
- Wasm,
15
10
  exec,
16
11
  extractReferrersFromLogs,
17
12
  findEnvFiles,
18
- default2 as importContract,
19
13
  processArgs,
20
14
  setup,
21
15
  setupProvider,
@@ -1,10 +1,7 @@
1
- import { AbiJSON, Wasm } from "./loadContractFiles.js";
2
1
  import { findEnvFiles, updateDemoHTMLFiles, updateEnvFiles } from "./updateEnv.js";
3
2
  import { exec } from "./exec.js";
4
3
  import { extractReferrersFromLogs } from "./fluxLogDappDetails.js";
5
4
  export {
6
- AbiJSON,
7
- Wasm,
8
5
  exec,
9
6
  extractReferrersFromLogs,
10
7
  findEnvFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/scripts",
3
- "version": "3.1.13",
3
+ "version": "3.1.25",
4
4
  "description": "Dev scripts for working with prosopo packages",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "type": "module",
15
15
  "engines": {
16
- "node": "20",
17
- "npm": "10.8.2"
16
+ "node": ">=v20.0.0",
17
+ "npm": ">=10.6.0"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.esm.config.ts --mode $NODE_ENV",
@@ -28,43 +28,38 @@
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
30
  "@iarna/toml": "2.2.5",
31
- "@polkadot/api": "10.13.1",
32
- "@polkadot/api-contract": "10.13.1",
33
- "@polkadot/util": "12.6.2",
34
- "@polkadot/util-crypto": "12.6.2",
35
- "@prosopo/cli": "3.4.6",
36
- "@prosopo/common": "3.1.20",
37
- "@prosopo/config": "3.1.20",
38
- "@prosopo/datasets": "3.0.34",
39
- "@prosopo/dotenv": "3.0.25",
40
- "@prosopo/env": "3.2.13",
41
- "@prosopo/keyring": "2.8.27",
42
- "@prosopo/locale": "3.1.20",
43
- "@prosopo/provider": "3.12.3",
44
- "@prosopo/types": "3.5.3",
45
- "@prosopo/types-env": "2.7.38",
46
- "@prosopo/util": "3.1.5",
47
- "@prosopo/util-crypto": "13.5.22",
48
- "@prosopo/workspace": "3.1.13",
31
+ "@polkadot/util": "13.5.7",
32
+ "@polkadot/util-crypto": "13.5.7",
33
+ "@prosopo/cli": "3.5.0",
34
+ "@prosopo/common": "3.1.22",
35
+ "@prosopo/config": "3.1.22",
36
+ "@prosopo/datasets": "3.0.43",
37
+ "@prosopo/dotenv": "3.0.27",
38
+ "@prosopo/env": "3.2.22",
39
+ "@prosopo/keyring": "2.8.36",
40
+ "@prosopo/locale": "3.1.22",
41
+ "@prosopo/provider": "3.13.0",
42
+ "@prosopo/types": "3.6.0",
43
+ "@prosopo/types-env": "2.7.47",
44
+ "@prosopo/util": "3.2.0",
45
+ "@prosopo/util-crypto": "13.5.24",
46
+ "@prosopo/workspace": "3.1.15",
49
47
  "dotenv": "16.4.5",
50
48
  "fast-glob": "3.3.2",
51
49
  "fs-extra": "11.2.0",
52
50
  "yargs": "17.7.2"
53
51
  },
54
- "overrides": {
55
- "@polkadot/keyring": "12.6.2"
56
- },
57
52
  "devDependencies": {
58
53
  "@types/fs-extra": "11.0.4",
59
54
  "@types/node": "22.10.2",
60
- "@vitest/coverage-v8": "3.0.9",
55
+ "@vitest/coverage-v8": "3.2.4",
61
56
  "concurrently": "9.0.1",
62
57
  "del-cli": "6.0.0",
63
58
  "npm-run-all": "4.1.5",
64
59
  "tslib": "2.7.0",
65
60
  "tsx": "4.20.3",
66
61
  "typescript": "5.6.2",
67
- "vite": "6.3.5",
68
- "vitest": "3.0.9"
62
+ "vite": "6.4.1",
63
+ "vitest": "3.2.4"
69
64
  }
70
65
  }
@@ -1,183 +0,0 @@
1
- "use strict";
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
- const common = require("@prosopo/common");
5
- const lodash = require("@prosopo/util/lodash");
6
- require("../util/index.cjs");
7
- const exec = require("../util/exec.cjs");
8
- const replaceExtension = (file, ext) => {
9
- const parts = file.split(".");
10
- parts.pop();
11
- parts.push(ext);
12
- return parts.join(".");
13
- };
14
- async function importContract(pathToAbis, pathToOutput) {
15
- const verbose = false;
16
- pathToAbis = path.relative(process.cwd(), pathToAbis);
17
- pathToOutput = path.relative(process.cwd(), pathToOutput);
18
- if (!fs.existsSync(pathToAbis))
19
- throw new common.ProsopoEnvError("FS.FILE_NOT_FOUND", {
20
- context: { error: `Path to ABIs does not exist: ${pathToAbis}` }
21
- });
22
- await exec.exec(`mkdir -p ${pathToOutput}`);
23
- const cmd = `npx @prosopo/typechain-polkadot --in ${pathToAbis} --out ${pathToOutput}`;
24
- await exec.exec(cmd);
25
- const name = path.basename(pathToAbis);
26
- await exec.exec(`cp ${pathToAbis}/${name}.json ${pathToOutput}/${name}.json`);
27
- const _ = lodash.lodash();
28
- const writeIndexJsFiles = (src) => {
29
- const typeChainDirs = fs.readdirSync(src).filter((file2) => {
30
- return fs.lstatSync(`${src}/${file2}`).isDirectory();
31
- });
32
- const rootExports = [];
33
- const typeChainExports = [
34
- {
35
- dir: "build-extrinsic",
36
- defaultExportName: "extrinsics"
37
- },
38
- {
39
- dir: "constructors"
40
- },
41
- {
42
- dir: "contract-info",
43
- exports: [
44
- {
45
- name: "ContractAbi"
46
- },
47
- {
48
- name: "ContractFile"
49
- }
50
- ]
51
- },
52
- {
53
- dir: "contracts",
54
- defaultExportName: "contract"
55
- },
56
- {
57
- dir: "data"
58
- },
59
- {
60
- dir: "event-data"
61
- },
62
- // { // no events used so this is empty - not sure about structure so left out
63
- // dir: 'event-types'
64
- // },
65
- {
66
- dir: "events"
67
- },
68
- {
69
- dir: "mixed-methods",
70
- defaultExportName: "methods"
71
- },
72
- {
73
- dir: "query",
74
- defaultExportName: "query"
75
- },
76
- {
77
- dir: "tx-sign-and-send",
78
- defaultExportName: "tx"
79
- }
80
- ];
81
- let file = "";
82
- for (const typeChainExport of typeChainExports) {
83
- const dirPath = `${src}/${typeChainExport.dir}`;
84
- const files = fs.readdirSync(dirPath);
85
- if (files.length !== 1) {
86
- throw new common.ProsopoEnvError("FS.INVALID_DIR_FORMAT", {
87
- context: {
88
- error: `Expected 1 file in ${dirPath}, found ${files.length}`
89
- }
90
- });
91
- }
92
- file = files[0] || "";
93
- if (file === "") {
94
- throw new common.ProsopoEnvError("FS.FILE_NOT_FOUND", {
95
- context: { error: `No file found in ${dirPath}` }
96
- });
97
- }
98
- if (file.endsWith(".ts")) {
99
- file = replaceExtension(file, "js");
100
- }
101
- if (typeChainExport.defaultExportName !== void 0) {
102
- const name2 = _.upperFirst(
103
- _.camelCase(typeChainExport.defaultExportName || typeChainExport.dir)
104
- );
105
- rootExports.push(
106
- `export { default as ${name2} } from './${typeChainExport.dir}/${file}'`
107
- );
108
- }
109
- if (typeChainExport.exports !== void 0) {
110
- for (const namedExport of typeChainExport.exports) {
111
- const alias = namedExport.alias ? ` as ${namedExport.alias}` : "";
112
- rootExports.push(
113
- `export { ${namedExport.name}${alias} } from './${typeChainExport.dir}/${file}'`
114
- );
115
- }
116
- }
117
- }
118
- rootExports.push(`export * from './shared/utils.js'`);
119
- const regex = /export\s+([a-z]+)\s+(\w+)/g;
120
- const fileTs = replaceExtension(file, "ts");
121
- const typesArgumentsFileContent = fs.readFileSync(
122
- `${src}/types-arguments/${fileTs}`,
123
- "utf8"
124
- );
125
- const typesReturnsFileContent = fs.readFileSync(
126
- `${src}/types-returns/${fileTs}`,
127
- "utf8"
128
- );
129
- const argumentTypes = Array.from(
130
- typesArgumentsFileContent.matchAll(regex)
131
- ).map((match) => {
132
- return {
133
- name: match[2] || "",
134
- category: match[1] || ""
135
- };
136
- });
137
- const returnTypes = Array.from(
138
- typesReturnsFileContent.matchAll(regex)
139
- ).map((match) => {
140
- return {
141
- name: match[2] || "",
142
- category: match[1] || ""
143
- };
144
- });
145
- const argumentTypeNames = argumentTypes.map((entry) => entry.name);
146
- const uniqueTypes = [...argumentTypes];
147
- const locations = [...argumentTypes.map(() => "types-arguments")];
148
- for (const entry of returnTypes) {
149
- if (!argumentTypeNames.includes(entry.name)) {
150
- uniqueTypes.push(entry);
151
- locations.push("types-arguments");
152
- } else {
153
- locations.push("types-returns");
154
- }
155
- }
156
- uniqueTypes.forEach((entry, i) => {
157
- const location = locations[i];
158
- const prefix = entry.category === "type" || entry.category === "interface" ? " type" : "";
159
- rootExports.push(
160
- `export${prefix} { ${entry.name} } from './${location}/${file}'`
161
- );
162
- });
163
- fs.writeFileSync(`${src}/index.ts`, rootExports.join("\n"));
164
- };
165
- writeIndexJsFiles(pathToOutput);
166
- }
167
- const getExtension = (str) => {
168
- const i = str.indexOf("assert");
169
- if (i >= 0) {
170
- str = str.slice(0, i);
171
- }
172
- const arr = str.split(".");
173
- if (arr.length <= 1) {
174
- return "";
175
- }
176
- return arr.pop();
177
- };
178
- const getPath = (str) => {
179
- const j = Math.max(str.lastIndexOf('"'), str.lastIndexOf("'"));
180
- const i = Math.max(str.indexOf('"'), str.indexOf("'"));
181
- return str.slice(i + 1, j);
182
- };
183
- module.exports = importContract;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const _import = require("./import.cjs");
4
- exports.importContract = _import;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
4
- const apiContract = require("@polkadot/api-contract");
5
- const util = require("@polkadot/util");
6
- const common = require("@prosopo/common");
7
- const fse = require("fs-extra");
8
- const __dirname$1 = path.resolve();
9
- async function AbiJSON(filePath) {
10
- const resolvedFilePath = path.resolve(__dirname$1, filePath);
11
- await fse.ensureFile(resolvedFilePath);
12
- const fileExists = await fse.pathExists(resolvedFilePath);
13
- if (fileExists) {
14
- const json = JSON.parse(
15
- await fse.readFile(resolvedFilePath, {
16
- encoding: "utf8"
17
- })
18
- );
19
- return new apiContract.Abi(json);
20
- }
21
- throw new common.ProsopoError("FS.FILE_NOT_FOUND", {
22
- context: { error: `File ${filePath} does not exist` }
23
- });
24
- }
25
- async function Wasm(filePath) {
26
- const resolvedFilePath = path.resolve(__dirname$1, filePath);
27
- await fse.ensureFile(resolvedFilePath);
28
- const fileExists = await fse.pathExists(resolvedFilePath);
29
- if (fileExists) {
30
- const wasm = `0x${fse.readFileSync(resolvedFilePath).toString("hex")}`;
31
- const wasmBytes = util.hexToU8a(wasm);
32
- if (util.isWasm(wasmBytes)) {
33
- return wasmBytes;
34
- }
35
- console.error(`Error loading contract wasm: ${wasm.slice(0, 10)}...`);
36
- process.exit(1);
37
- } else {
38
- throw new common.ProsopoError("FS.FILE_NOT_FOUND", {
39
- context: { error: `File ${filePath} does not exist` }
40
- });
41
- }
42
- }
43
- exports.AbiJSON = AbiJSON;
44
- exports.Wasm = Wasm;
@@ -1,184 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { ProsopoEnvError } from "@prosopo/common";
4
- import { lodash } from "@prosopo/util/lodash";
5
- import "../util/index.js";
6
- import { exec } from "../util/exec.js";
7
- const replaceExtension = (file, ext) => {
8
- const parts = file.split(".");
9
- parts.pop();
10
- parts.push(ext);
11
- return parts.join(".");
12
- };
13
- async function importContract(pathToAbis, pathToOutput) {
14
- const verbose = false;
15
- pathToAbis = path.relative(process.cwd(), pathToAbis);
16
- pathToOutput = path.relative(process.cwd(), pathToOutput);
17
- if (!fs.existsSync(pathToAbis))
18
- throw new ProsopoEnvError("FS.FILE_NOT_FOUND", {
19
- context: { error: `Path to ABIs does not exist: ${pathToAbis}` }
20
- });
21
- await exec(`mkdir -p ${pathToOutput}`);
22
- const cmd = `npx @prosopo/typechain-polkadot --in ${pathToAbis} --out ${pathToOutput}`;
23
- await exec(cmd);
24
- const name = path.basename(pathToAbis);
25
- await exec(`cp ${pathToAbis}/${name}.json ${pathToOutput}/${name}.json`);
26
- const _ = lodash();
27
- const writeIndexJsFiles = (src) => {
28
- const typeChainDirs = fs.readdirSync(src).filter((file2) => {
29
- return fs.lstatSync(`${src}/${file2}`).isDirectory();
30
- });
31
- const rootExports = [];
32
- const typeChainExports = [
33
- {
34
- dir: "build-extrinsic",
35
- defaultExportName: "extrinsics"
36
- },
37
- {
38
- dir: "constructors"
39
- },
40
- {
41
- dir: "contract-info",
42
- exports: [
43
- {
44
- name: "ContractAbi"
45
- },
46
- {
47
- name: "ContractFile"
48
- }
49
- ]
50
- },
51
- {
52
- dir: "contracts",
53
- defaultExportName: "contract"
54
- },
55
- {
56
- dir: "data"
57
- },
58
- {
59
- dir: "event-data"
60
- },
61
- // { // no events used so this is empty - not sure about structure so left out
62
- // dir: 'event-types'
63
- // },
64
- {
65
- dir: "events"
66
- },
67
- {
68
- dir: "mixed-methods",
69
- defaultExportName: "methods"
70
- },
71
- {
72
- dir: "query",
73
- defaultExportName: "query"
74
- },
75
- {
76
- dir: "tx-sign-and-send",
77
- defaultExportName: "tx"
78
- }
79
- ];
80
- let file = "";
81
- for (const typeChainExport of typeChainExports) {
82
- const dirPath = `${src}/${typeChainExport.dir}`;
83
- const files = fs.readdirSync(dirPath);
84
- if (files.length !== 1) {
85
- throw new ProsopoEnvError("FS.INVALID_DIR_FORMAT", {
86
- context: {
87
- error: `Expected 1 file in ${dirPath}, found ${files.length}`
88
- }
89
- });
90
- }
91
- file = files[0] || "";
92
- if (file === "") {
93
- throw new ProsopoEnvError("FS.FILE_NOT_FOUND", {
94
- context: { error: `No file found in ${dirPath}` }
95
- });
96
- }
97
- if (file.endsWith(".ts")) {
98
- file = replaceExtension(file, "js");
99
- }
100
- if (typeChainExport.defaultExportName !== void 0) {
101
- const name2 = _.upperFirst(
102
- _.camelCase(typeChainExport.defaultExportName || typeChainExport.dir)
103
- );
104
- rootExports.push(
105
- `export { default as ${name2} } from './${typeChainExport.dir}/${file}'`
106
- );
107
- }
108
- if (typeChainExport.exports !== void 0) {
109
- for (const namedExport of typeChainExport.exports) {
110
- const alias = namedExport.alias ? ` as ${namedExport.alias}` : "";
111
- rootExports.push(
112
- `export { ${namedExport.name}${alias} } from './${typeChainExport.dir}/${file}'`
113
- );
114
- }
115
- }
116
- }
117
- rootExports.push(`export * from './shared/utils.js'`);
118
- const regex = /export\s+([a-z]+)\s+(\w+)/g;
119
- const fileTs = replaceExtension(file, "ts");
120
- const typesArgumentsFileContent = fs.readFileSync(
121
- `${src}/types-arguments/${fileTs}`,
122
- "utf8"
123
- );
124
- const typesReturnsFileContent = fs.readFileSync(
125
- `${src}/types-returns/${fileTs}`,
126
- "utf8"
127
- );
128
- const argumentTypes = Array.from(
129
- typesArgumentsFileContent.matchAll(regex)
130
- ).map((match) => {
131
- return {
132
- name: match[2] || "",
133
- category: match[1] || ""
134
- };
135
- });
136
- const returnTypes = Array.from(
137
- typesReturnsFileContent.matchAll(regex)
138
- ).map((match) => {
139
- return {
140
- name: match[2] || "",
141
- category: match[1] || ""
142
- };
143
- });
144
- const argumentTypeNames = argumentTypes.map((entry) => entry.name);
145
- const uniqueTypes = [...argumentTypes];
146
- const locations = [...argumentTypes.map(() => "types-arguments")];
147
- for (const entry of returnTypes) {
148
- if (!argumentTypeNames.includes(entry.name)) {
149
- uniqueTypes.push(entry);
150
- locations.push("types-arguments");
151
- } else {
152
- locations.push("types-returns");
153
- }
154
- }
155
- uniqueTypes.forEach((entry, i) => {
156
- const location = locations[i];
157
- const prefix = entry.category === "type" || entry.category === "interface" ? " type" : "";
158
- rootExports.push(
159
- `export${prefix} { ${entry.name} } from './${location}/${file}'`
160
- );
161
- });
162
- fs.writeFileSync(`${src}/index.ts`, rootExports.join("\n"));
163
- };
164
- writeIndexJsFiles(pathToOutput);
165
- }
166
- const getExtension = (str) => {
167
- const i = str.indexOf("assert");
168
- if (i >= 0) {
169
- str = str.slice(0, i);
170
- }
171
- const arr = str.split(".");
172
- if (arr.length <= 1) {
173
- return "";
174
- }
175
- return arr.pop();
176
- };
177
- const getPath = (str) => {
178
- const j = Math.max(str.lastIndexOf('"'), str.lastIndexOf("'"));
179
- const i = Math.max(str.indexOf('"'), str.indexOf("'"));
180
- return str.slice(i + 1, j);
181
- };
182
- export {
183
- importContract as default
184
- };
@@ -1,4 +0,0 @@
1
- import { default as default2 } from "./import.js";
2
- export {
3
- default2 as importContract
4
- };
@@ -1,44 +0,0 @@
1
- import path from "node:path";
2
- import { Abi } from "@polkadot/api-contract";
3
- import { hexToU8a, isWasm } from "@polkadot/util";
4
- import { ProsopoError } from "@prosopo/common";
5
- import fse from "fs-extra";
6
- const __dirname = path.resolve();
7
- async function AbiJSON(filePath) {
8
- const resolvedFilePath = path.resolve(__dirname, filePath);
9
- await fse.ensureFile(resolvedFilePath);
10
- const fileExists = await fse.pathExists(resolvedFilePath);
11
- if (fileExists) {
12
- const json = JSON.parse(
13
- await fse.readFile(resolvedFilePath, {
14
- encoding: "utf8"
15
- })
16
- );
17
- return new Abi(json);
18
- }
19
- throw new ProsopoError("FS.FILE_NOT_FOUND", {
20
- context: { error: `File ${filePath} does not exist` }
21
- });
22
- }
23
- async function Wasm(filePath) {
24
- const resolvedFilePath = path.resolve(__dirname, filePath);
25
- await fse.ensureFile(resolvedFilePath);
26
- const fileExists = await fse.pathExists(resolvedFilePath);
27
- if (fileExists) {
28
- const wasm = `0x${fse.readFileSync(resolvedFilePath).toString("hex")}`;
29
- const wasmBytes = hexToU8a(wasm);
30
- if (isWasm(wasmBytes)) {
31
- return wasmBytes;
32
- }
33
- console.error(`Error loading contract wasm: ${wasm.slice(0, 10)}...`);
34
- process.exit(1);
35
- } else {
36
- throw new ProsopoError("FS.FILE_NOT_FOUND", {
37
- context: { error: `File ${filePath} does not exist` }
38
- });
39
- }
40
- }
41
- export {
42
- AbiJSON,
43
- Wasm
44
- };