meshjs 1.9.0-beta.7 → 1.9.0-beta.71
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/README.md +3 -3
- package/dist/index.cjs +108 -7
- package/dist/index.js +108 -7
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
Mesh is an open-source library to make building
|
|
3
|
+
Mesh is an open-source library to make building applications accessible. Whether you're a beginner developer, startup, web3 market leader, or a large enterprise, Mesh makes web3 development easy with reliable, scalable, and well-engineered APIs & developer tools.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
Usage: create-mesh-app [options] <name>
|
|
7
7
|
|
|
8
|
-
A quick and easy way to bootstrap your
|
|
8
|
+
A quick and easy way to bootstrap your Web3 app using Mesh.
|
|
9
9
|
|
|
10
10
|
Arguments:
|
|
11
|
-
name Set a name for your
|
|
11
|
+
name Set a name for your app.
|
|
12
12
|
|
|
13
13
|
Options:
|
|
14
14
|
-V, --version output the version number
|
package/dist/index.cjs
CHANGED
|
@@ -91,6 +91,29 @@ var isInMercurialRepository = () => {
|
|
|
91
91
|
return false;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
// src/helpers/typeMap.ts
|
|
95
|
+
var jsonImportCodeMap = {
|
|
96
|
+
Int: "Integer",
|
|
97
|
+
Bool: "Bool",
|
|
98
|
+
ByteArray: "ByteString",
|
|
99
|
+
VerificationKeyHash: "PubKeyHash",
|
|
100
|
+
ScriptHash: "ScriptHash",
|
|
101
|
+
PolicyId: "PolicyId",
|
|
102
|
+
AssetName: "AssetName",
|
|
103
|
+
Pairs: "Pairs",
|
|
104
|
+
Tuple: "Tuple",
|
|
105
|
+
Option: "Option",
|
|
106
|
+
"cardano/address/Credential": "Credential",
|
|
107
|
+
"cardano/transaction/OutputReference": "OutputReference",
|
|
108
|
+
"cardano/address/Address": "PubKeyAddress | ScriptAddress"
|
|
109
|
+
};
|
|
110
|
+
var blueprintImportCodeMap = {
|
|
111
|
+
spend: "SpendingBlueprint",
|
|
112
|
+
mint: "MintingBlueprint",
|
|
113
|
+
withdraw: "WithdrawalBlueprint",
|
|
114
|
+
publish: "WithdrawalBlueprint"
|
|
115
|
+
};
|
|
116
|
+
|
|
94
117
|
// src/utils/logger.ts
|
|
95
118
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
96
119
|
var logError = (message) => {
|
|
@@ -148,7 +171,7 @@ var createDirectory = (name) => {
|
|
|
148
171
|
logError("\u274C Unable to create a project in current directory.");
|
|
149
172
|
process.exit(1);
|
|
150
173
|
}
|
|
151
|
-
logInfo("\u{1F3D7}\uFE0F - Creating a new
|
|
174
|
+
logInfo("\u{1F3D7}\uFE0F - Creating a new app in current directory...");
|
|
152
175
|
process.chdir(path);
|
|
153
176
|
};
|
|
154
177
|
var fetchRepository = async (template) => {
|
|
@@ -174,6 +197,73 @@ var installDependencies = () => {
|
|
|
174
197
|
}
|
|
175
198
|
};
|
|
176
199
|
|
|
200
|
+
// src/actions/blueprint.ts
|
|
201
|
+
var import_fs3 = require("fs");
|
|
202
|
+
var import_path2 = require("path");
|
|
203
|
+
var import_cardano_bar = require("@sidan-lab/cardano-bar");
|
|
204
|
+
var blueprint = async (blueprintPath, outputPath) => {
|
|
205
|
+
const resolvedBlueprintPath = (0, import_path2.resolve)(blueprintPath);
|
|
206
|
+
const resolvedOutputPath = (0, import_path2.resolve)(outputPath);
|
|
207
|
+
try {
|
|
208
|
+
validateFiles(resolvedBlueprintPath, resolvedOutputPath);
|
|
209
|
+
const blueprintData = parseBlueprintFile(resolvedBlueprintPath);
|
|
210
|
+
logInfo("\u{1F50D} Parsing Cardano blueprint...");
|
|
211
|
+
const generatedCode = parseCardanoBlueprint(
|
|
212
|
+
blueprintData,
|
|
213
|
+
resolvedBlueprintPath
|
|
214
|
+
);
|
|
215
|
+
const outputDir = (0, import_path2.dirname)(resolvedOutputPath);
|
|
216
|
+
if (!(0, import_fs3.existsSync)(outputDir)) {
|
|
217
|
+
if ((0, import_fs3.mkdirSync)(outputDir, { recursive: true }) === void 0) {
|
|
218
|
+
logError("\u274C Unable to create output directory.");
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
logInfo("\u{1F4BE} Writing generated code to file...");
|
|
223
|
+
(0, import_fs3.writeFileSync)(resolvedOutputPath, generatedCode);
|
|
224
|
+
logSuccess(`\u2728 Generated TypeScript file: ${resolvedOutputPath}`);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
logError(error);
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var validateFiles = (blueprintPath, outputPath) => {
|
|
231
|
+
if (!(0, import_fs3.existsSync)(blueprintPath)) {
|
|
232
|
+
logError(`\u2757 Blueprint file not found: ${blueprintPath}`);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
if ((0, import_path2.extname)(blueprintPath) !== ".json") {
|
|
236
|
+
logError("\u2757 Blueprint file must be a JSON file");
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
if ((0, import_path2.extname)(outputPath) !== ".ts") {
|
|
240
|
+
logError("\u2757 Output file must have .ts extension");
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var parseBlueprintFile = (blueprintPath) => {
|
|
245
|
+
logInfo("\u{1F4D6} Reading and parsing blueprint file...");
|
|
246
|
+
const blueprintContent = (0, import_fs3.readFileSync)(blueprintPath, "utf8");
|
|
247
|
+
try {
|
|
248
|
+
return JSON.parse(blueprintContent);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
logError("\u2757 Invalid JSON in blueprint file");
|
|
251
|
+
process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var parseCardanoBlueprint = (script, blueprintPath) => {
|
|
255
|
+
logInfo("\u26A1 Generating TypeScript code...");
|
|
256
|
+
const blueprint2 = new import_cardano_bar.BlueprintParser(
|
|
257
|
+
script,
|
|
258
|
+
jsonImportCodeMap,
|
|
259
|
+
blueprintImportCodeMap,
|
|
260
|
+
new import_cardano_bar.TSCodeBuilder()
|
|
261
|
+
);
|
|
262
|
+
blueprint2.analyzeDefinitions().generateBlueprints().generateImports(blueprintPath).generateTypes();
|
|
263
|
+
const fullSnippet = blueprint2.getFullSnippet();
|
|
264
|
+
return fullSnippet.join("\n\n");
|
|
265
|
+
};
|
|
266
|
+
|
|
177
267
|
// src/index.ts
|
|
178
268
|
var main = async () => {
|
|
179
269
|
console.clear();
|
|
@@ -187,11 +277,9 @@ var main = async () => {
|
|
|
187
277
|
);
|
|
188
278
|
console.log("\n");
|
|
189
279
|
const program = (0, import_commander.createCommand)();
|
|
190
|
-
program.name("meshjs").description(
|
|
191
|
-
"A quick and easy way to bootstrap your dApps on Cardano using Mesh."
|
|
192
|
-
).version("1.0.0");
|
|
280
|
+
program.name("meshjs").description("A quick and easy way to bootstrap your Web3 app using Mesh.").version("1.0.0");
|
|
193
281
|
program.addArgument(
|
|
194
|
-
(0, import_commander.createArgument)("name", "Set a name for your
|
|
282
|
+
(0, import_commander.createArgument)("name", "Set a name for your app.").argParser((name) => {
|
|
195
283
|
if (/^([A-Za-z\-\\_\d])+$/.test(name)) return name;
|
|
196
284
|
throw new import_commander.InvalidArgumentError(
|
|
197
285
|
import_chalk2.default.redBright(
|
|
@@ -215,11 +303,24 @@ var main = async () => {
|
|
|
215
303
|
`The language you want to use.`
|
|
216
304
|
).choices(["ts"])
|
|
217
305
|
).action(create);
|
|
306
|
+
program.command("blueprint").description("Generate TypeScript code from Cardano blueprint").addArgument(
|
|
307
|
+
(0, import_commander.createArgument)(
|
|
308
|
+
"blueprint-path",
|
|
309
|
+
"Path to the blueprint JSON file"
|
|
310
|
+
).argRequired()
|
|
311
|
+
).addArgument(
|
|
312
|
+
(0, import_commander.createArgument)(
|
|
313
|
+
"output-path",
|
|
314
|
+
"Path to the output TypeScript file"
|
|
315
|
+
).argRequired()
|
|
316
|
+
).action(blueprint);
|
|
218
317
|
await program.parseAsync(process.argv);
|
|
219
318
|
};
|
|
220
319
|
main().then(() => {
|
|
221
|
-
|
|
222
|
-
|
|
320
|
+
if (process.argv.includes("create")) {
|
|
321
|
+
logSuccess("\u2728\u2728 Welcome to Web 3.0! \u2728\u2728");
|
|
322
|
+
logInfo('Run "cd <project-name>" and "npm run dev" to start your app.');
|
|
323
|
+
}
|
|
223
324
|
process.exit(0);
|
|
224
325
|
}).catch((error) => {
|
|
225
326
|
logError(error);
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,29 @@ var isInMercurialRepository = () => {
|
|
|
72
72
|
return false;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
// src/helpers/typeMap.ts
|
|
76
|
+
var jsonImportCodeMap = {
|
|
77
|
+
Int: "Integer",
|
|
78
|
+
Bool: "Bool",
|
|
79
|
+
ByteArray: "ByteString",
|
|
80
|
+
VerificationKeyHash: "PubKeyHash",
|
|
81
|
+
ScriptHash: "ScriptHash",
|
|
82
|
+
PolicyId: "PolicyId",
|
|
83
|
+
AssetName: "AssetName",
|
|
84
|
+
Pairs: "Pairs",
|
|
85
|
+
Tuple: "Tuple",
|
|
86
|
+
Option: "Option",
|
|
87
|
+
"cardano/address/Credential": "Credential",
|
|
88
|
+
"cardano/transaction/OutputReference": "OutputReference",
|
|
89
|
+
"cardano/address/Address": "PubKeyAddress | ScriptAddress"
|
|
90
|
+
};
|
|
91
|
+
var blueprintImportCodeMap = {
|
|
92
|
+
spend: "SpendingBlueprint",
|
|
93
|
+
mint: "MintingBlueprint",
|
|
94
|
+
withdraw: "WithdrawalBlueprint",
|
|
95
|
+
publish: "WithdrawalBlueprint"
|
|
96
|
+
};
|
|
97
|
+
|
|
75
98
|
// src/utils/logger.ts
|
|
76
99
|
import chalk from "chalk";
|
|
77
100
|
var logError = (message) => {
|
|
@@ -129,7 +152,7 @@ var createDirectory = (name) => {
|
|
|
129
152
|
logError("\u274C Unable to create a project in current directory.");
|
|
130
153
|
process.exit(1);
|
|
131
154
|
}
|
|
132
|
-
logInfo("\u{1F3D7}\uFE0F - Creating a new
|
|
155
|
+
logInfo("\u{1F3D7}\uFE0F - Creating a new app in current directory...");
|
|
133
156
|
process.chdir(path);
|
|
134
157
|
};
|
|
135
158
|
var fetchRepository = async (template) => {
|
|
@@ -155,6 +178,73 @@ var installDependencies = () => {
|
|
|
155
178
|
}
|
|
156
179
|
};
|
|
157
180
|
|
|
181
|
+
// src/actions/blueprint.ts
|
|
182
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
183
|
+
import { resolve, dirname, extname } from "path";
|
|
184
|
+
import { BlueprintParser, TSCodeBuilder } from "@sidan-lab/cardano-bar";
|
|
185
|
+
var blueprint = async (blueprintPath, outputPath) => {
|
|
186
|
+
const resolvedBlueprintPath = resolve(blueprintPath);
|
|
187
|
+
const resolvedOutputPath = resolve(outputPath);
|
|
188
|
+
try {
|
|
189
|
+
validateFiles(resolvedBlueprintPath, resolvedOutputPath);
|
|
190
|
+
const blueprintData = parseBlueprintFile(resolvedBlueprintPath);
|
|
191
|
+
logInfo("\u{1F50D} Parsing Cardano blueprint...");
|
|
192
|
+
const generatedCode = parseCardanoBlueprint(
|
|
193
|
+
blueprintData,
|
|
194
|
+
resolvedBlueprintPath
|
|
195
|
+
);
|
|
196
|
+
const outputDir = dirname(resolvedOutputPath);
|
|
197
|
+
if (!existsSync2(outputDir)) {
|
|
198
|
+
if (mkdirSync2(outputDir, { recursive: true }) === void 0) {
|
|
199
|
+
logError("\u274C Unable to create output directory.");
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
logInfo("\u{1F4BE} Writing generated code to file...");
|
|
204
|
+
writeFileSync2(resolvedOutputPath, generatedCode);
|
|
205
|
+
logSuccess(`\u2728 Generated TypeScript file: ${resolvedOutputPath}`);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
logError(error);
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var validateFiles = (blueprintPath, outputPath) => {
|
|
212
|
+
if (!existsSync2(blueprintPath)) {
|
|
213
|
+
logError(`\u2757 Blueprint file not found: ${blueprintPath}`);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
if (extname(blueprintPath) !== ".json") {
|
|
217
|
+
logError("\u2757 Blueprint file must be a JSON file");
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
if (extname(outputPath) !== ".ts") {
|
|
221
|
+
logError("\u2757 Output file must have .ts extension");
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var parseBlueprintFile = (blueprintPath) => {
|
|
226
|
+
logInfo("\u{1F4D6} Reading and parsing blueprint file...");
|
|
227
|
+
const blueprintContent = readFileSync2(blueprintPath, "utf8");
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(blueprintContent);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
logError("\u2757 Invalid JSON in blueprint file");
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var parseCardanoBlueprint = (script, blueprintPath) => {
|
|
236
|
+
logInfo("\u26A1 Generating TypeScript code...");
|
|
237
|
+
const blueprint2 = new BlueprintParser(
|
|
238
|
+
script,
|
|
239
|
+
jsonImportCodeMap,
|
|
240
|
+
blueprintImportCodeMap,
|
|
241
|
+
new TSCodeBuilder()
|
|
242
|
+
);
|
|
243
|
+
blueprint2.analyzeDefinitions().generateBlueprints().generateImports(blueprintPath).generateTypes();
|
|
244
|
+
const fullSnippet = blueprint2.getFullSnippet();
|
|
245
|
+
return fullSnippet.join("\n\n");
|
|
246
|
+
};
|
|
247
|
+
|
|
158
248
|
// src/index.ts
|
|
159
249
|
var main = async () => {
|
|
160
250
|
console.clear();
|
|
@@ -168,11 +258,9 @@ var main = async () => {
|
|
|
168
258
|
);
|
|
169
259
|
console.log("\n");
|
|
170
260
|
const program = createCommand();
|
|
171
|
-
program.name("meshjs").description(
|
|
172
|
-
"A quick and easy way to bootstrap your dApps on Cardano using Mesh."
|
|
173
|
-
).version("1.0.0");
|
|
261
|
+
program.name("meshjs").description("A quick and easy way to bootstrap your Web3 app using Mesh.").version("1.0.0");
|
|
174
262
|
program.addArgument(
|
|
175
|
-
createArgument("name", "Set a name for your
|
|
263
|
+
createArgument("name", "Set a name for your app.").argParser((name) => {
|
|
176
264
|
if (/^([A-Za-z\-\\_\d])+$/.test(name)) return name;
|
|
177
265
|
throw new InvalidArgumentError(
|
|
178
266
|
chalk2.redBright(
|
|
@@ -196,11 +284,24 @@ var main = async () => {
|
|
|
196
284
|
`The language you want to use.`
|
|
197
285
|
).choices(["ts"])
|
|
198
286
|
).action(create);
|
|
287
|
+
program.command("blueprint").description("Generate TypeScript code from Cardano blueprint").addArgument(
|
|
288
|
+
createArgument(
|
|
289
|
+
"blueprint-path",
|
|
290
|
+
"Path to the blueprint JSON file"
|
|
291
|
+
).argRequired()
|
|
292
|
+
).addArgument(
|
|
293
|
+
createArgument(
|
|
294
|
+
"output-path",
|
|
295
|
+
"Path to the output TypeScript file"
|
|
296
|
+
).argRequired()
|
|
297
|
+
).action(blueprint);
|
|
199
298
|
await program.parseAsync(process.argv);
|
|
200
299
|
};
|
|
201
300
|
main().then(() => {
|
|
202
|
-
|
|
203
|
-
|
|
301
|
+
if (process.argv.includes("create")) {
|
|
302
|
+
logSuccess("\u2728\u2728 Welcome to Web 3.0! \u2728\u2728");
|
|
303
|
+
logInfo('Run "cd <project-name>" and "npm run dev" to start your app.');
|
|
304
|
+
}
|
|
204
305
|
process.exit(0);
|
|
205
306
|
}).catch((error) => {
|
|
206
307
|
logError(error);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meshjs",
|
|
3
|
-
"description": "A quick and easy way to bootstrap your
|
|
3
|
+
"description": "A quick and easy way to bootstrap your Web3 app using Mesh.",
|
|
4
4
|
"homepage": "https://meshjs.dev",
|
|
5
5
|
"author": "MeshJS",
|
|
6
|
-
"version": "1.9.0-beta.
|
|
6
|
+
"version": "1.9.0-beta.71",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"blockchain",
|
|
23
23
|
"cardano",
|
|
24
24
|
"dapp",
|
|
25
|
-
"npx"
|
|
25
|
+
"npx",
|
|
26
|
+
"web3"
|
|
26
27
|
],
|
|
27
28
|
"scripts": {
|
|
28
29
|
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"start": "preconstruct watch"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
35
|
+
"@sidan-lab/cardano-bar": "^0.0.7",
|
|
34
36
|
"chalk": "5.3.0",
|
|
35
37
|
"commander": "12.1.0",
|
|
36
38
|
"figlet": "1.7.0",
|
|
@@ -43,9 +45,10 @@
|
|
|
43
45
|
"@types/figlet": "1.5.8",
|
|
44
46
|
"@types/got": "^9.6.12",
|
|
45
47
|
"@types/prompts": "2.4.9",
|
|
46
|
-
"@types/tar": "6.1.13"
|
|
48
|
+
"@types/tar": "6.1.13",
|
|
49
|
+
"tsup": "^8.0.2"
|
|
47
50
|
},
|
|
48
51
|
"files": [
|
|
49
52
|
"dist/**"
|
|
50
53
|
]
|
|
51
|
-
}
|
|
54
|
+
}
|