@prosopo/scripts 3.1.13 → 3.1.20
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 +81 -0
- package/dist/cjs/cli/index.cjs +0 -17
- package/dist/cjs/index.cjs +0 -3
- package/dist/cli/index.js +0 -17
- package/dist/index.js +0 -3
- package/package.json +15 -15
- package/dist/cjs/contract/import.cjs +0 -183
- package/dist/cjs/contract/index.cjs +0 -4
- package/dist/contract/import.js +0 -184
- package/dist/contract/index.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
1
|
# @prosopo/scripts
|
|
2
2
|
|
|
3
|
+
## 3.1.20
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [c9d8fdf]
|
|
7
|
+
- Updated dependencies [b8185a4]
|
|
8
|
+
- Updated dependencies [3a027ef]
|
|
9
|
+
- Updated dependencies [3a027ef]
|
|
10
|
+
- @prosopo/common@3.1.21
|
|
11
|
+
- @prosopo/cli@3.4.13
|
|
12
|
+
- @prosopo/provider@3.12.10
|
|
13
|
+
- @prosopo/config@3.1.21
|
|
14
|
+
- @prosopo/datasets@3.0.38
|
|
15
|
+
- @prosopo/dotenv@3.0.26
|
|
16
|
+
- @prosopo/env@3.2.17
|
|
17
|
+
- @prosopo/keyring@2.8.31
|
|
18
|
+
- @prosopo/types-env@2.7.42
|
|
19
|
+
- @prosopo/workspace@3.1.14
|
|
20
|
+
- @prosopo/locale@3.1.21
|
|
21
|
+
- @prosopo/types@3.5.7
|
|
22
|
+
- @prosopo/util@3.1.6
|
|
23
|
+
- @prosopo/util-crypto@13.5.23
|
|
24
|
+
|
|
25
|
+
## 3.1.19
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [8491159]
|
|
29
|
+
- @prosopo/provider@3.12.9
|
|
30
|
+
- @prosopo/cli@3.4.12
|
|
31
|
+
|
|
32
|
+
## 3.1.18
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [5d11a81]
|
|
36
|
+
- @prosopo/provider@3.12.8
|
|
37
|
+
- @prosopo/types@3.5.6
|
|
38
|
+
- @prosopo/cli@3.4.11
|
|
39
|
+
- @prosopo/datasets@3.0.37
|
|
40
|
+
- @prosopo/env@3.2.16
|
|
41
|
+
- @prosopo/keyring@2.8.30
|
|
42
|
+
- @prosopo/types-env@2.7.41
|
|
43
|
+
|
|
44
|
+
## 3.1.17
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [cbc5d8e]
|
|
48
|
+
- @prosopo/provider@3.12.7
|
|
49
|
+
- @prosopo/cli@3.4.10
|
|
50
|
+
|
|
51
|
+
## 3.1.16
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [494c5a8]
|
|
55
|
+
- @prosopo/provider@3.12.6
|
|
56
|
+
- @prosopo/types@3.5.5
|
|
57
|
+
- @prosopo/cli@3.4.9
|
|
58
|
+
- @prosopo/datasets@3.0.36
|
|
59
|
+
- @prosopo/types-env@2.7.40
|
|
60
|
+
- @prosopo/env@3.2.15
|
|
61
|
+
- @prosopo/keyring@2.8.29
|
|
62
|
+
|
|
63
|
+
## 3.1.15
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- 4ba029e: repo maintainance
|
|
67
|
+
- Updated dependencies [4ba029e]
|
|
68
|
+
- @prosopo/provider@3.12.5
|
|
69
|
+
- @prosopo/cli@3.4.8
|
|
70
|
+
|
|
71
|
+
## 3.1.14
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- Updated dependencies [08ff50f]
|
|
75
|
+
- Updated dependencies [08ff50f]
|
|
76
|
+
- @prosopo/cli@3.4.7
|
|
77
|
+
- @prosopo/provider@3.12.4
|
|
78
|
+
- @prosopo/types@3.5.4
|
|
79
|
+
- @prosopo/datasets@3.0.35
|
|
80
|
+
- @prosopo/types-env@2.7.39
|
|
81
|
+
- @prosopo/env@3.2.14
|
|
82
|
+
- @prosopo/keyring@2.8.28
|
|
83
|
+
|
|
3
84
|
## 3.1.13
|
|
4
85
|
### Patch Changes
|
|
5
86
|
|
package/dist/cjs/cli/index.cjs
CHANGED
|
@@ -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",
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,14 +3,12 @@ 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
8
|
const loadContractFiles = require("./util/loadContractFiles.cjs");
|
|
10
9
|
const updateEnv = require("./util/updateEnv.cjs");
|
|
11
10
|
const exec = require("./util/exec.cjs");
|
|
12
11
|
const fluxLogDappDetails = require("./util/fluxLogDappDetails.cjs");
|
|
13
|
-
const _import = require("./contract/import.cjs");
|
|
14
12
|
exports.processArgs = index.processArgs;
|
|
15
13
|
exports.setup = setup.setup;
|
|
16
14
|
exports.updateEnvFile = setup.updateEnvFile;
|
|
@@ -22,4 +20,3 @@ exports.updateDemoHTMLFiles = updateEnv.updateDemoHTMLFiles;
|
|
|
22
20
|
exports.updateEnvFiles = updateEnv.updateEnvFiles;
|
|
23
21
|
exports.exec = exec.exec;
|
|
24
22
|
exports.extractReferrersFromLogs = fluxLogDappDetails.extractReferrersFromLogs;
|
|
25
|
-
exports.importContract = _import;
|
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,18 @@
|
|
|
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
6
|
import { AbiJSON, Wasm } from "./util/loadContractFiles.js";
|
|
8
7
|
import { findEnvFiles, updateDemoHTMLFiles, updateEnvFiles } from "./util/updateEnv.js";
|
|
9
8
|
import { exec } from "./util/exec.js";
|
|
10
9
|
import { extractReferrersFromLogs } from "./util/fluxLogDappDetails.js";
|
|
11
|
-
import { default as default2 } from "./contract/import.js";
|
|
12
10
|
export {
|
|
13
11
|
AbiJSON,
|
|
14
12
|
Wasm,
|
|
15
13
|
exec,
|
|
16
14
|
extractReferrersFromLogs,
|
|
17
15
|
findEnvFiles,
|
|
18
|
-
default2 as importContract,
|
|
19
16
|
processArgs,
|
|
20
17
|
setup,
|
|
21
18
|
setupProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/scripts",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.20",
|
|
4
4
|
"description": "Dev scripts for working with prosopo packages",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
"@polkadot/api-contract": "10.13.1",
|
|
33
33
|
"@polkadot/util": "12.6.2",
|
|
34
34
|
"@polkadot/util-crypto": "12.6.2",
|
|
35
|
-
"@prosopo/cli": "3.4.
|
|
36
|
-
"@prosopo/common": "3.1.
|
|
37
|
-
"@prosopo/config": "3.1.
|
|
38
|
-
"@prosopo/datasets": "3.0.
|
|
39
|
-
"@prosopo/dotenv": "3.0.
|
|
40
|
-
"@prosopo/env": "3.2.
|
|
41
|
-
"@prosopo/keyring": "2.8.
|
|
42
|
-
"@prosopo/locale": "3.1.
|
|
43
|
-
"@prosopo/provider": "3.12.
|
|
44
|
-
"@prosopo/types": "3.5.
|
|
45
|
-
"@prosopo/types-env": "2.7.
|
|
46
|
-
"@prosopo/util": "3.1.
|
|
47
|
-
"@prosopo/util-crypto": "13.5.
|
|
48
|
-
"@prosopo/workspace": "3.1.
|
|
35
|
+
"@prosopo/cli": "3.4.13",
|
|
36
|
+
"@prosopo/common": "3.1.21",
|
|
37
|
+
"@prosopo/config": "3.1.21",
|
|
38
|
+
"@prosopo/datasets": "3.0.38",
|
|
39
|
+
"@prosopo/dotenv": "3.0.26",
|
|
40
|
+
"@prosopo/env": "3.2.17",
|
|
41
|
+
"@prosopo/keyring": "2.8.31",
|
|
42
|
+
"@prosopo/locale": "3.1.21",
|
|
43
|
+
"@prosopo/provider": "3.12.10",
|
|
44
|
+
"@prosopo/types": "3.5.7",
|
|
45
|
+
"@prosopo/types-env": "2.7.42",
|
|
46
|
+
"@prosopo/util": "3.1.6",
|
|
47
|
+
"@prosopo/util-crypto": "13.5.23",
|
|
48
|
+
"@prosopo/workspace": "3.1.14",
|
|
49
49
|
"dotenv": "16.4.5",
|
|
50
50
|
"fast-glob": "3.3.2",
|
|
51
51
|
"fs-extra": "11.2.0",
|
|
@@ -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;
|
package/dist/contract/import.js
DELETED
|
@@ -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
|
-
};
|
package/dist/contract/index.js
DELETED