@taqueria/plugin-ligo 0.27.2-alpha → 0.27.3-rc

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/index.mjs ADDED
@@ -0,0 +1,588 @@
1
+ // index.ts
2
+ import { Option, Plugin, PositionalArg, Task, Template } from "@taqueria/node-sdk";
3
+
4
+ // createContract.ts
5
+ import { sendAsyncErr } from "@taqueria/node-sdk";
6
+ import { writeFile } from "fs/promises";
7
+
8
+ // ligo_templates.ts
9
+ var mligo_template = `
10
+ type storage = int
11
+
12
+ type parameter =
13
+ Increment of int
14
+ | Decrement of int
15
+ | Reset
16
+
17
+ type return = operation list * storage
18
+
19
+ // Two entrypoints
20
+
21
+ let add (store, delta : storage * int) : storage = store + delta
22
+ let sub (store, delta : storage * int) : storage = store - delta
23
+
24
+ (* Main access point that dispatches to the entrypoints according to
25
+ the smart contract parameter. *)
26
+
27
+ let main (action, store : parameter * storage) : return =
28
+ ([] : operation list), // No operations
29
+ (match action with
30
+ Increment (n) -> add (store, n)
31
+ | Decrement (n) -> sub (store, n)
32
+ | Reset -> 0)
33
+ `;
34
+ var pascaligo_template = `
35
+ type storage is int
36
+
37
+ type parameter is
38
+ Increment of int
39
+ | Decrement of int
40
+ | Reset
41
+
42
+ type return is list (operation) * storage
43
+
44
+ // Two entrypoints
45
+
46
+ function add (const store : storage; const delta : int) : storage is
47
+ store + delta
48
+
49
+ function sub (const store : storage; const delta : int) : storage is
50
+ store - delta
51
+
52
+ (* Main access point that dispatches to the entrypoints according to
53
+ the smart contract parameter. *)
54
+
55
+ function main (const action : parameter; const store : storage) : return is
56
+ ((nil : list (operation)), // No operations
57
+ case action of [
58
+ Increment (n) -> add (store, n)
59
+ | Decrement (n) -> sub (store, n)
60
+ | Reset -> 0
61
+ ])
62
+ `;
63
+ var religo_template = `
64
+ type storage = int;
65
+
66
+ type parameter =
67
+ Increment (int)
68
+ | Decrement (int)
69
+ | Reset;
70
+
71
+ type return = (list (operation), storage);
72
+
73
+ // Two entrypoints
74
+
75
+ let add = ((store, delta) : (storage, int)) : storage => store + delta;
76
+ let sub = ((store, delta) : (storage, int)) : storage => store - delta;
77
+
78
+ /* Main access point that dispatches to the entrypoints according to
79
+ the smart contract parameter. */
80
+
81
+ let main = ((action, store) : (parameter, storage)) : return => {
82
+ (([] : list (operation)), // No operations
83
+ (switch (action) {
84
+ | Increment (n) => add ((store, n))
85
+ | Decrement (n) => sub ((store, n))
86
+ | Reset => 0}))
87
+ };
88
+ `;
89
+ var jsligo_template = `
90
+ type storage = int;
91
+
92
+ type parameter =
93
+ ["Increment", int]
94
+ | ["Decrement", int]
95
+ | ["Reset"];
96
+
97
+ type ret = [list<operation>, storage];
98
+
99
+ // Two entrypoints
100
+
101
+ const add = ([store, delta] : [storage, int]) : storage => store + delta;
102
+ const sub = ([store, delta] : [storage, int]) : storage => store - delta;
103
+
104
+ /* Main access point that dispatches to the entrypoints according to
105
+ the smart contract parameter. */
106
+
107
+ const main = ([action, store] : [parameter, storage]) : ret => {
108
+ return [list([]) as list<operation>, // No operations
109
+ match (action, {
110
+ Increment:(n: int) => add ([store, n]),
111
+ Decrement:(n: int) => sub ([store, n]),
112
+ Reset :() => 0})]
113
+ };
114
+ `;
115
+
116
+ // createContract.ts
117
+ var getLigoTemplate = async (contractName, syntax) => {
118
+ const matchResult = contractName.match(/\.[^.]+$/);
119
+ const ext = matchResult ? matchResult[0].substring(1) : null;
120
+ if (syntax === "mligo")
121
+ return mligo_template;
122
+ if (syntax === "ligo")
123
+ return pascaligo_template;
124
+ if (syntax === "religo")
125
+ return religo_template;
126
+ if (syntax === "jsligo")
127
+ return jsligo_template;
128
+ if (syntax === void 0) {
129
+ if (ext === "mligo")
130
+ return mligo_template;
131
+ if (ext === "ligo")
132
+ return pascaligo_template;
133
+ if (ext === "religo")
134
+ return religo_template;
135
+ if (ext === "jsligo")
136
+ return jsligo_template;
137
+ return sendAsyncErr(
138
+ `Unable to infer LIGO syntax from "${contractName}". Please specify a LIGO syntax via the --syntax option`
139
+ );
140
+ } else {
141
+ return sendAsyncErr(`"${syntax}" is not a valid syntax. Please specify a valid LIGO syntax`);
142
+ }
143
+ };
144
+ var createContract = (args) => {
145
+ const unsafeOpts = args;
146
+ const contractName = unsafeOpts.sourceFileName;
147
+ const syntax = unsafeOpts.syntax;
148
+ const contractsDir = `${args.config.projectDir}/${args.config.contractsDir}`;
149
+ return getLigoTemplate(contractName, syntax).then((ligo_template) => writeFile(`${contractsDir}/${contractName}`, ligo_template));
150
+ };
151
+ var createContract_default = createContract;
152
+
153
+ // main.ts
154
+ import { sendAsyncErr as sendAsyncErr5, sendAsyncRes } from "@taqueria/node-sdk";
155
+
156
+ // common.ts
157
+ import { getDockerImage, sendErr } from "@taqueria/node-sdk";
158
+ import { join } from "path";
159
+ var LIGO_DEFAULT_IMAGE = "ligolang/ligo:0.57.0";
160
+ var LIGO_IMAGE_ENV_VAR = "TAQ_LIGO_IMAGE";
161
+ var getLigoDockerImage = () => getDockerImage(LIGO_DEFAULT_IMAGE, LIGO_IMAGE_ENV_VAR);
162
+ var getInputFilenameAbsPath = (parsedArgs, sourceFile) => join(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts", sourceFile);
163
+ var getInputFilenameRelPath = (parsedArgs, sourceFile) => join(parsedArgs.config.contractsDir ?? "contracts", sourceFile);
164
+ var emitExternalError = (err, sourceFile) => {
165
+ sendErr(`
166
+ === Error messages for ${sourceFile} ===`);
167
+ err instanceof Error ? sendErr(err.message.replace(/Command failed.+?\n/, "")) : sendErr(err);
168
+ sendErr(`
169
+ ===`);
170
+ };
171
+
172
+ // compile.ts
173
+ import { execCmd, getArch, getArtifactsDir, sendAsyncErr as sendAsyncErr2, sendErr as sendErr2, sendJsonRes, sendWarn } from "@taqueria/node-sdk";
174
+ import { access, readFile, writeFile as writeFile2 } from "fs/promises";
175
+ import { basename, extname, join as join2 } from "path";
176
+ var COMPILE_ERR_MSG = "Not compiled";
177
+ var isStorageKind = (exprKind) => exprKind === "storage" || exprKind === "default_storage";
178
+ var isLIGOFile = (sourceFile) => /.+\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
179
+ var isStorageListFile = (sourceFile) => /.+\.(storageList|storages)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
180
+ var isParameterListFile = (sourceFile) => /.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
181
+ var isContractFile = (sourceFile) => isLIGOFile(sourceFile) && !isStorageListFile(sourceFile) && !isParameterListFile(sourceFile);
182
+ var extractExt = (path) => {
183
+ const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
184
+ return matchResult ? matchResult[0] : "";
185
+ };
186
+ var removeExt = (path) => {
187
+ const extRegex = new RegExp(extractExt(path));
188
+ return path.replace(extRegex, "");
189
+ };
190
+ var isOutputFormatJSON = (parsedArgs) => parsedArgs.json;
191
+ var getOutputContractFilename = (parsedArgs, sourceFile) => {
192
+ const outputFile = basename(sourceFile, extname(sourceFile));
193
+ const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
194
+ return join2(getArtifactsDir(parsedArgs), `${outputFile}${ext}`);
195
+ };
196
+ var getContractNameForExpr = (sourceFile, exprKind) => {
197
+ try {
198
+ return isStorageKind(exprKind) ? sourceFile.match(/.+(?=\.(?:storageList|storages)\.(ligo|religo|mligo|jsligo))/).join(".") : sourceFile.match(/.+(?=\.(?:parameterList|parameters)\.(ligo|religo|mligo|jsligo))/).join(".");
199
+ } catch (err) {
200
+ throw new Error(`Something went wrong internally when dealing with filename format: ${err}`);
201
+ }
202
+ };
203
+ var getOutputExprFilename = (parsedArgs, sourceFile, exprKind, exprName) => {
204
+ const contractName = basename(getContractNameForExpr(sourceFile, exprKind), extname(sourceFile));
205
+ const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
206
+ const outputFile = exprKind === "default_storage" ? `${contractName}.default_storage${ext}` : `${contractName}.${exprKind}.${exprName}${ext}`;
207
+ return join2(getArtifactsDir(parsedArgs), `${outputFile}`);
208
+ };
209
+ var getCompileContractCmd = (parsedArgs, sourceFile) => {
210
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
211
+ if (!projectDir)
212
+ throw `No project directory provided`;
213
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
214
+ const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
215
+ const outputFile = `-o ${getOutputContractFilename(parsedArgs, sourceFile)}`;
216
+ const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
217
+ const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}`;
218
+ return cmd;
219
+ };
220
+ var getCompileExprCmd = (parsedArgs, sourceFile, exprKind, exprName) => {
221
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
222
+ if (!projectDir)
223
+ throw `No project directory provided`;
224
+ const compilerType = isStorageKind(exprKind) ? "storage" : "parameter";
225
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
226
+ const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
227
+ const outputFile = `-o ${getOutputExprFilename(parsedArgs, sourceFile, exprKind, exprName)}`;
228
+ const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
229
+ const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile} ${flags}`;
230
+ return cmd;
231
+ };
232
+ var compileContract = (parsedArgs, sourceFile) => getArch().then(() => getCompileContractCmd(parsedArgs, sourceFile)).then(execCmd).then(({ stderr }) => {
233
+ if (stderr.length > 0)
234
+ sendWarn(stderr);
235
+ return {
236
+ contract: sourceFile,
237
+ artifact: getOutputContractFilename(parsedArgs, sourceFile)
238
+ };
239
+ }).catch((err) => {
240
+ emitExternalError(err, sourceFile);
241
+ return {
242
+ contract: sourceFile,
243
+ artifact: COMPILE_ERR_MSG
244
+ };
245
+ });
246
+ var compileExpr = (parsedArgs, sourceFile, exprKind) => (exprName) => getArch().then(() => getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName)).then(execCmd).then(({ stderr }) => {
247
+ if (stderr.length > 0)
248
+ sendWarn(stderr);
249
+ return {
250
+ contract: sourceFile,
251
+ artifact: getOutputExprFilename(parsedArgs, sourceFile, exprKind, exprName)
252
+ };
253
+ }).catch((err) => {
254
+ emitExternalError(err, sourceFile);
255
+ return {
256
+ contract: sourceFile,
257
+ artifact: COMPILE_ERR_MSG
258
+ };
259
+ });
260
+ var getExprNames = (parsedArgs, sourceFile) => readFile(getInputFilenameAbsPath(parsedArgs, sourceFile), "utf8").then((data) => data.match(/(?<=\n\s*(let|const)\s+)[a-zA-Z0-9_]+/g) ?? []);
261
+ var compileExprs = (parsedArgs, sourceFile, exprKind) => getExprNames(parsedArgs, sourceFile).then((exprNames) => {
262
+ if (exprNames.length === 0)
263
+ return [];
264
+ const firstExprName = exprNames.slice(0, 1)[0];
265
+ const restExprNames = exprNames.slice(1, exprNames.length);
266
+ const firstExprKind = isStorageKind(exprKind) ? "default_storage" : "parameter";
267
+ const restExprKind = isStorageKind(exprKind) ? "storage" : "parameter";
268
+ const firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);
269
+ const restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));
270
+ return Promise.all([firstExprResult].concat(restExprResults));
271
+ }).catch((err) => {
272
+ emitExternalError(err, sourceFile);
273
+ return [{
274
+ contract: sourceFile,
275
+ artifact: `No ${isStorageKind(exprKind) ? "storage" : "parameter"} values compiled`
276
+ }];
277
+ }).then(mergeArtifactsOutput(sourceFile));
278
+ var tryLegacyStorageNamingConvention = (parsedArgs, sourceFile) => {
279
+ const storageListFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;
280
+ const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
281
+ return access(storageListFilename).then(() => {
282
+ sendWarn(
283
+ `Warning: The naming convention of "<CONTRACT>.storages.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.storageList.<EXTENSION>". Please adjust your storage file names accordingly
284
+ `
285
+ );
286
+ return compileExprs(parsedArgs, storageListFile, "storage");
287
+ });
288
+ };
289
+ var tryLegacyParameterNamingConvention = (parsedArgs, sourceFile) => {
290
+ const parameterListFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;
291
+ const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
292
+ return access(parameterListFilename).then(() => {
293
+ sendWarn(
294
+ `Warning: The naming convention of "<CONTRACT>.parameters.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.parameterList.<EXTENSION>". Please adjust your parameter file names accordingly
295
+ `
296
+ );
297
+ return compileExprs(parsedArgs, parameterListFile, "parameter");
298
+ });
299
+ };
300
+ var initContentForStorage = (sourceFile) => {
301
+ const linkToContract = `#include "${sourceFile}"
302
+
303
+ `;
304
+ const instruction = "// Define your initial storage values as a list of LIGO variable definitions,\n// the first of which will be considered the default value to be used for origination later on\n";
305
+ const ext = extractExt(sourceFile);
306
+ let syntax = "";
307
+ if (ext === ".ligo")
308
+ syntax = "// E.g. const aStorageValue : aStorageType = 10;\n\n";
309
+ else if (ext === ".religo")
310
+ syntax = "// E.g. let aStorageValue : aStorageType = 10;\n\n";
311
+ else if (ext === ".mligo")
312
+ syntax = "// E.g. let aStorageValue : aStorageType = 10\n\n";
313
+ else if (ext === ".jsligo")
314
+ syntax = "// E.g. const aStorageValue : aStorageType = 10;\n\n";
315
+ return linkToContract + instruction + syntax;
316
+ };
317
+ var initContentForParameter = (sourceFile) => {
318
+ const linkToContract = `#include "${sourceFile}"
319
+
320
+ `;
321
+ const instruction = "// Define your parameter values as a list of LIGO variable definitions\n";
322
+ const ext = extractExt(sourceFile);
323
+ let syntax = "";
324
+ if (ext === ".ligo")
325
+ syntax = "// E.g. const aParameterValue : aParameterType = Increment(1);\n\n";
326
+ else if (ext === ".religo")
327
+ syntax = "// E.g. let aParameterValue : aParameterType = (Increment (1));\n\n";
328
+ else if (ext === ".mligo")
329
+ syntax = "// E.g. let aParameterValue : aParameterType = Increment 1\n\n";
330
+ else if (ext === ".jsligo")
331
+ syntax = "// E.g. const aParameterValue : aParameterType = (Increment (1));\n\n";
332
+ return linkToContract + instruction + syntax;
333
+ };
334
+ var compileContractWithStorageAndParameter = async (parsedArgs, sourceFile) => {
335
+ const contractCompileResult = await compileContract(parsedArgs, sourceFile);
336
+ if (contractCompileResult.artifact === COMPILE_ERR_MSG)
337
+ return [contractCompileResult];
338
+ const storageListFile = `${removeExt(sourceFile)}.storageList${extractExt(sourceFile)}`;
339
+ const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
340
+ const storageCompileResult = await access(storageListFilename).then(() => compileExprs(parsedArgs, storageListFile, "storage")).catch(() => tryLegacyStorageNamingConvention(parsedArgs, sourceFile)).catch(() => {
341
+ sendWarn(
342
+ `Note: storage file associated with "${sourceFile}" can't be found, so "${storageListFile}" has been created for you. Use this file to define all initial storage values for this contract
343
+ `
344
+ );
345
+ writeFile2(storageListFilename, initContentForStorage(sourceFile), "utf8");
346
+ });
347
+ const parameterListFile = `${removeExt(sourceFile)}.parameterList${extractExt(sourceFile)}`;
348
+ const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
349
+ const parameterCompileResult = await access(parameterListFilename).then(() => compileExprs(parsedArgs, parameterListFile, "parameter")).catch(() => tryLegacyParameterNamingConvention(parsedArgs, sourceFile)).catch(() => {
350
+ sendWarn(
351
+ `Note: parameter file associated with "${sourceFile}" can't be found, so "${parameterListFile}" has been created for you. Use this file to define all parameter values for this contract
352
+ `
353
+ );
354
+ writeFile2(parameterListFilename, initContentForParameter(sourceFile), "utf8");
355
+ });
356
+ let compileResults = [contractCompileResult];
357
+ if (storageCompileResult)
358
+ compileResults = compileResults.concat(storageCompileResult);
359
+ if (parameterCompileResult)
360
+ compileResults = compileResults.concat(parameterCompileResult);
361
+ return compileResults;
362
+ };
363
+ var mergeArtifactsOutput = (sourceFile) => (tableRows) => {
364
+ const artifactsOutput = tableRows.reduce(
365
+ (acc, row) => row.artifact === COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}
366
+ `,
367
+ ""
368
+ );
369
+ return [{
370
+ contract: sourceFile,
371
+ artifact: artifactsOutput
372
+ }];
373
+ };
374
+ var compile = (parsedArgs) => {
375
+ const sourceFile = parsedArgs.sourceFile;
376
+ let p;
377
+ if (isStorageListFile(sourceFile))
378
+ p = compileExprs(parsedArgs, sourceFile, "storage");
379
+ else if (isParameterListFile(sourceFile))
380
+ p = compileExprs(parsedArgs, sourceFile, "parameter");
381
+ else if (isContractFile(sourceFile))
382
+ p = compileContractWithStorageAndParameter(parsedArgs, sourceFile);
383
+ else {
384
+ return sendAsyncErr2(
385
+ `${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`
386
+ );
387
+ }
388
+ return p.then(sendJsonRes).catch((err) => sendErr2(err, false));
389
+ };
390
+ var compile_default = compile;
391
+
392
+ // compile-all.ts
393
+ import { sendErr as sendErr3, sendJsonRes as sendJsonRes2 } from "@taqueria/node-sdk";
394
+ import glob from "fast-glob";
395
+ import { readFile as readFile2 } from "fs/promises";
396
+ import { join as join3 } from "path";
397
+ var isMainContract = (parsedArgs, contactFilename) => readFile2(getInputFilenameAbsPath(parsedArgs, contactFilename), "utf8").then((data) => /(const|let|function)\s+main/.test(data));
398
+ var compileAll = async (parsedArgs) => {
399
+ let p = [];
400
+ const contractFilenames = await glob(
401
+ ["**/*.ligo", "**/*.religo", "**/*.mligo", "**/*.jsligo"],
402
+ { cwd: join3(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts"), absolute: false }
403
+ );
404
+ for (const filename of contractFilenames) {
405
+ if (await isMainContract(parsedArgs, filename)) {
406
+ p.push(compileContractWithStorageAndParameter(parsedArgs, filename));
407
+ }
408
+ }
409
+ return Promise.all(p).then((tables) => tables.flat()).then(sendJsonRes2).catch((err) => sendErr3(err, false));
410
+ };
411
+ var compile_all_default = compileAll;
412
+
413
+ // ligo.ts
414
+ import { getArch as getArch2, sendAsyncErr as sendAsyncErr3, sendRes, spawnCmd } from "@taqueria/node-sdk";
415
+ var getArbitraryLigoCmd = (parsedArgs, userArgs) => {
416
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
417
+ if (!projectDir)
418
+ throw `No project directory provided`;
419
+ const binary = "docker";
420
+ const baseArgs = ["run", "--rm", "-v", `${projectDir}:/project`, "-w", "/project", getLigoDockerImage()];
421
+ const processedUserArgs = userArgs.split(" ").map((arg) => arg.startsWith("\\-") ? arg.substring(1) : arg).filter(
422
+ (arg) => arg
423
+ );
424
+ const args = baseArgs.concat(processedUserArgs);
425
+ const envVars = { "DOCKER_DEFAULT_PLATFORM": "linux/amd64" };
426
+ return [
427
+ [binary, ...args].join(" "),
428
+ envVars
429
+ ];
430
+ };
431
+ var runArbitraryLigoCmd = (parsedArgs, cmd) => getArch2().then(() => getArbitraryLigoCmd(parsedArgs, cmd)).then(([cmd2, envVars]) => spawnCmd(cmd2, envVars)).then(
432
+ (code) => code !== null && code === 0 ? `Command "${cmd}" ran successfully by LIGO` : `Command "${cmd}" failed. Please check your command`
433
+ ).catch((err) => sendAsyncErr3(`An internal error has occurred: ${err.message}`));
434
+ var ligo = (parsedArgs) => {
435
+ const args = parsedArgs.command;
436
+ return runArbitraryLigoCmd(parsedArgs, args).then(sendRes).catch((err) => sendAsyncErr3(err, false));
437
+ };
438
+ var ligo_default = ligo;
439
+
440
+ // test.ts
441
+ import { execCmd as execCmd2, getArch as getArch3, sendAsyncErr as sendAsyncErr4, sendJsonRes as sendJsonRes3, sendWarn as sendWarn2 } from "@taqueria/node-sdk";
442
+ var getTestContractCmd = (parsedArgs, sourceFile) => {
443
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
444
+ if (!projectDir)
445
+ throw `No project directory provided`;
446
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} run test`;
447
+ const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
448
+ const cmd = `${baseCmd} ${inputFile}`;
449
+ return cmd;
450
+ };
451
+ var testContract = (parsedArgs, sourceFile) => getArch3().then(() => getTestContractCmd(parsedArgs, sourceFile)).then(execCmd2).then(({ stdout, stderr }) => {
452
+ if (stderr.length > 0)
453
+ sendWarn2(stderr);
454
+ const result = "\u{1F389} All tests passed \u{1F389}";
455
+ return {
456
+ contract: sourceFile,
457
+ testResults: stdout.length > 0 ? `${stdout}
458
+ ${result}` : result
459
+ };
460
+ }).catch((err) => {
461
+ emitExternalError(err, sourceFile);
462
+ return {
463
+ contract: sourceFile,
464
+ testResults: "Some tests failed :("
465
+ };
466
+ });
467
+ var test = (parsedArgs) => {
468
+ const sourceFile = parsedArgs.sourceFile;
469
+ if (!sourceFile)
470
+ return sendAsyncErr4(`No source file provided`);
471
+ return testContract(parsedArgs, sourceFile).then((result) => [result]).then(sendJsonRes3).catch(
472
+ (err) => sendAsyncErr4(err, false)
473
+ );
474
+ };
475
+ var test_default = test;
476
+
477
+ // main.ts
478
+ var main = (parsedArgs) => {
479
+ const unsafeOpts = parsedArgs;
480
+ switch (unsafeOpts.task) {
481
+ case "ligo":
482
+ return ligo_default(unsafeOpts);
483
+ case "compile":
484
+ return compile_default(unsafeOpts);
485
+ case "compile-all":
486
+ return compile_all_default(unsafeOpts);
487
+ case "test":
488
+ return test_default(parsedArgs);
489
+ case "get-image":
490
+ return sendAsyncRes(getLigoDockerImage());
491
+ default:
492
+ return sendAsyncErr5(`${unsafeOpts.task} is not an understood task by the LIGO plugin`);
493
+ }
494
+ };
495
+ var main_default = main;
496
+
497
+ // index.ts
498
+ Plugin.create((i18n) => ({
499
+ schema: "1.0",
500
+ version: "0.1",
501
+ alias: "ligo",
502
+ tasks: [
503
+ Task.create({
504
+ task: "ligo",
505
+ command: "ligo",
506
+ description: "This task allows you to run arbitrary LIGO native commands. Note that they might not benefit from the abstractions provided by Taqueria",
507
+ options: [
508
+ Option.create({
509
+ shortFlag: "c",
510
+ flag: "command",
511
+ type: "string",
512
+ description: "The command to be passed to the underlying LIGO binary, wrapped in quotes",
513
+ required: true
514
+ })
515
+ ],
516
+ handler: "proxy",
517
+ encoding: "none"
518
+ }),
519
+ Task.create({
520
+ task: "compile",
521
+ command: "compile <sourceFile>",
522
+ aliases: ["c", "compile-ligo"],
523
+ description: "Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storage/parameter list files if they are found",
524
+ options: [
525
+ Option.create({
526
+ flag: "json",
527
+ boolean: true,
528
+ description: "Emit JSON-encoded Michelson"
529
+ })
530
+ ],
531
+ handler: "proxy",
532
+ encoding: "json"
533
+ }),
534
+ Task.create({
535
+ task: "compile-all",
536
+ command: "compile-all",
537
+ description: "Compile all main smart contracts written in a LIGO syntax to Michelson code, along with their associated storage/parameter list files if they are found",
538
+ options: [
539
+ Option.create({
540
+ flag: "json",
541
+ boolean: true,
542
+ description: "Emit JSON-encoded Michelson"
543
+ })
544
+ ],
545
+ handler: "proxy",
546
+ encoding: "json"
547
+ }),
548
+ Task.create({
549
+ task: "test",
550
+ command: "test <sourceFile>",
551
+ description: "Test a smart contract written in LIGO",
552
+ handler: "proxy",
553
+ encoding: "json"
554
+ }),
555
+ Task.create({
556
+ task: "get-image",
557
+ command: "get-image",
558
+ description: "Gets the name of the image to be used",
559
+ handler: "proxy",
560
+ hidden: true
561
+ })
562
+ ],
563
+ templates: [
564
+ Template.create({
565
+ template: "contract",
566
+ command: "contract <sourceFileName>",
567
+ description: "Create a LIGO contract with boilerplate code",
568
+ positionals: [
569
+ PositionalArg.create({
570
+ placeholder: "sourceFileName",
571
+ type: "string",
572
+ description: "The name of the LIGO contract to generate"
573
+ })
574
+ ],
575
+ options: [
576
+ Option.create({
577
+ shortFlag: "s",
578
+ flag: "syntax",
579
+ type: "string",
580
+ description: "The syntax used in the contract"
581
+ })
582
+ ],
583
+ handler: createContract_default
584
+ })
585
+ ],
586
+ proxy: main_default
587
+ }), process.argv);
588
+ //# sourceMappingURL=index.mjs.map