@taqueria/plugin-ligo 0.40.10 → 0.40.13

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 CHANGED
@@ -1,666 +1,61 @@
1
- // index.ts
2
- import { Option, Plugin, PositionalArg, Task, Template } from "@taqueria/node-sdk";
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
3
6
 
4
- // createContract.ts
5
- import { sendAsyncErr } from "@taqueria/node-sdk";
6
- import { writeFile } from "fs/promises";
7
+ // index.ts
8
+ import { configurePlugin } from "@taqueria/lib-ligo";
7
9
 
8
10
  // ligo_templates.ts
11
+ var ligo_templates_exports = {};
12
+ __export(ligo_templates_exports, {
13
+ jsligo_template: () => jsligo_template,
14
+ mligo_template: () => mligo_template
15
+ });
9
16
  var mligo_template = `
10
- type storage = int
11
- type return = operation list * storage
12
-
13
- (* Three entrypoints *)
14
- [@entry] let increment (delta : int) (store : storage) : return =
15
- [], store + delta
16
- [@entry] let decrement (delta : int) (store : storage) : return =
17
- [], store - delta
18
- [@entry] let reset (() : unit) (_ : storage) : return =
19
- [], 0
20
- `;
21
- var jsligo_template = `
22
- type storage = int;
23
- type ret = [list<operation>, storage];
24
-
25
- // Three entrypoints
26
-
27
- // @entry
28
- const increment = (delta : int, store : storage) : ret =>
29
- [list([]), store + delta];
30
-
31
- // @entry
32
- const decrement = (delta : int, store : storage) : ret =>
33
- [list([]), store - delta];
34
-
35
- // @entry
36
- const reset = (_ : unit, _ : storage) : ret =>
37
- [list([]), 0];
38
- `;
39
-
40
- // createContract.ts
41
- var getLigoTemplate = async (contractName, syntax) => {
42
- const matchResult = contractName.match(/\.[^.]+$/);
43
- const ext = matchResult ? matchResult[0].substring(1) : null;
44
- if (syntax === "mligo")
45
- return mligo_template;
46
- if (syntax === "jsligo")
47
- return jsligo_template;
48
- if (syntax === void 0) {
49
- if (ext === "mligo")
50
- return mligo_template;
51
- if (ext === "jsligo")
52
- return jsligo_template;
53
- return sendAsyncErr(
54
- `Unable to infer LIGO syntax from "${contractName}". Please specify a LIGO syntax via the --syntax option`
55
- );
56
- } else {
57
- return sendAsyncErr(`"${syntax}" is not a valid syntax. Please specify a valid LIGO syntax`);
58
- }
59
- };
60
- var createContract = (args) => {
61
- const unsafeOpts = args;
62
- const contractName = unsafeOpts.sourceFileName;
63
- const syntax = unsafeOpts.syntax;
64
- const contractsDir = `${args.config.projectDir}/${args.config.contractsDir}`;
65
- return getLigoTemplate(contractName, syntax).then((ligo_template) => writeFile(`${contractsDir}/${contractName}`, ligo_template));
66
- };
67
- var createContract_default = createContract;
17
+ module Counter = struct
18
+ type storage = int
68
19
 
69
- // main.ts
70
- import { sendAsyncErr as sendAsyncErr5, sendAsyncRes } from "@taqueria/node-sdk";
71
-
72
- // common.ts
73
- import { getDockerImage, sendErr } from "@taqueria/node-sdk";
74
- import { join } from "path";
75
- var LIGO_DEFAULT_IMAGE = "ligolang/ligo:0.73.0";
76
- var LIGO_IMAGE_ENV_VAR = "TAQ_LIGO_IMAGE";
77
- var getLigoDockerImage = () => getDockerImage(LIGO_DEFAULT_IMAGE, LIGO_IMAGE_ENV_VAR);
78
- var getInputFilenameAbsPath = (parsedArgs, sourceFile) => join(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts", sourceFile);
79
- var getInputFilenameRelPath = (parsedArgs, sourceFile) => join(parsedArgs.config.contractsDir ?? "contracts", sourceFile);
80
- var formatLigoError = (err) => {
81
- let result = err.message.replace(/Command failed.+?\n/, "");
82
- if (result.includes("An internal error ocurred. Please, contact the developers.") && result.includes("Module Contract not found with last Contract.")) {
83
- result = `By convention, Taqueria expects you to import your contract with Contract as the module name.
84
- For instance, if you have a contract in a file called "increment.mligo", in your parameter/storage list file you must include #import "Increment.mligo" "Contract" for compilation to be successful.`;
85
- }
86
- err.message = result.replace(
87
- "An internal error ocurred. Please, contact the developers.",
88
- "The LIGO compiler experienced an internal error. Please contact the LIGO developers."
89
- );
90
- return err;
91
- };
92
- var emitExternalError = (errs, sourceFile) => {
93
- sendErr(`
94
- === Error messages for ${sourceFile} ===`);
95
- const errors = Array.isArray(errs) ? errs : [errs];
96
- errors.map((err) => {
97
- err instanceof Error ? sendErr(err.message) : sendErr(err);
98
- });
99
- sendErr(`===`);
100
- };
101
-
102
- // compile.ts
103
- import {
104
- execCmd,
105
- getArch,
106
- getArtifactsDir,
107
- sendErr as sendErr2,
108
- sendJsonRes,
109
- sendWarn
110
- } from "@taqueria/node-sdk";
111
- import { createReadStream } from "fs";
112
- import { access, writeFile as writeFile2 } from "fs/promises";
113
- import { basename, join as join2 } from "path";
114
- import * as readline from "readline";
115
- var COMPILE_ERR_MSG = "Not compiled";
116
- var isStorageKind = (exprKind) => exprKind === "storage" || exprKind === "default_storage";
117
- var isSupportedLigoSyntax = (sourceFile) => /\.(mligo|jsligo)$/.test(sourceFile);
118
- var isUnsupportedLigoSyntax = (sourceFile) => /\.(ligo|religo)$/.test(sourceFile);
119
- var isLIGOFile = (sourceFile) => isSupportedLigoSyntax(sourceFile) || isUnsupportedLigoSyntax(sourceFile);
120
- var isStorageListFile = (sourceFile) => /.+\.(storageList|storages)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
121
- var isParameterListFile = (sourceFile) => /.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
122
- var listContractModules = async (parsedArgs, sourceFile) => {
123
- try {
124
- await getArch();
125
- const cmd = await getListDeclarationsCmd(parsedArgs, sourceFile);
126
- const { stderr, stdout } = await execCmd(cmd);
127
- if (stderr.length > 0)
128
- return Promise.reject(stderr);
129
- return JSON.parse(stdout).declarations.reduce(
130
- (acc, decl) => {
131
- const srcFile = removeExt(basename(sourceFile));
132
- const syntax = extractExt(sourceFile).replace(".", "");
133
- if (decl === "main") {
134
- return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-main", syntax }];
135
- } else if (decl === "$main") {
136
- return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-entry", syntax }];
137
- } else if (decl.endsWith(".main")) {
138
- const moduleName = decl.replace(/\.main$/, "");
139
- return [...acc, {
140
- moduleName,
141
- sourceName: `${sourceFile}/${moduleName}`,
142
- sourceFile,
143
- type: "module-main",
144
- syntax
145
- }];
146
- } else if (decl.endsWith(".$main")) {
147
- const moduleName = decl.replace(/\.\$main$/, "");
148
- return [...acc, {
149
- moduleName,
150
- sourceName: `${sourceFile}/${moduleName}`,
151
- sourceFile,
152
- type: "module-entry",
153
- syntax
154
- }];
155
- }
156
- return acc;
157
- },
158
- []
159
- );
160
- } catch (err) {
161
- emitExternalError(err, sourceFile);
162
- return [];
163
- }
164
- };
165
- var getListDeclarationsCmd = async (parsedArgs, sourceFile) => {
166
- const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
167
- if (!projectDir)
168
- throw new Error(`No project directory provided`);
169
- const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} info list-declarations`;
170
- const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
171
- const flags = "--display-format json";
172
- const cmd = `${baseCmd} ${inputFile} ${flags}`;
173
- return cmd;
174
- };
175
- var extractExt = (path) => {
176
- const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
177
- return matchResult ? matchResult[0] : "";
178
- };
179
- var removeExt = (path) => {
180
- const extRegex = new RegExp(extractExt(path));
181
- return path.replace(extRegex, "");
182
- };
183
- var isOutputFormatJSON = (parsedArgs) => parsedArgs.json;
184
- var getOutputContractFilename = (parsedArgs, module) => {
185
- const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
186
- return join2(getArtifactsDir(parsedArgs), `${module.moduleName}${ext}`);
187
- };
188
- var getOutputExprFilename = (parsedArgs, module, exprKind, exprName) => {
189
- const contractName = module.moduleName;
190
- const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
191
- const outputFile = exprKind === "default_storage" ? `${contractName}.default_storage${ext}` : `${contractName}.${exprKind}.${exprName}${ext}`;
192
- return join2(getArtifactsDir(parsedArgs), `${outputFile}`);
193
- };
194
- var getCompileContractCmd = async (parsedArgs, sourceFile, module) => {
195
- const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
196
- if (!projectDir)
197
- throw new Error(`No project directory provided`);
198
- const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
199
- const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
200
- const outputFile = `-o ${getOutputContractFilename(parsedArgs, module)}`;
201
- const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
202
- const moduleFlag = module.type.startsWith("file-") ? "" : `-m ${module.moduleName}`;
203
- const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}${moduleFlag}`;
204
- return cmd;
205
- };
206
- var getCompileExprCmd = (parsedArgs, sourceFile, module, exprKind, exprName) => {
207
- const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
208
- if (!projectDir)
209
- throw new Error(`No project directory provided`);
210
- const compilerType = isStorageKind(exprKind) ? "storage" : "parameter";
211
- const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
212
- const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
213
- const outputFile = `-o ${getOutputExprFilename(parsedArgs, module, exprKind, exprName)}`;
214
- const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
215
- const moduleFlag = (() => {
216
- switch (module.type) {
217
- case "file-main":
218
- case "file-entry":
219
- return "-m Contract";
220
- default:
221
- return `-m Contract.${module.moduleName}`;
222
- }
223
- })();
224
- const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile} ${flags} ${moduleFlag}`;
225
- return cmd;
226
- };
227
- var compileContract = async (parsedArgs, sourceFile, module) => {
228
- try {
229
- await getArch();
230
- const cmd = await getCompileContractCmd(parsedArgs, sourceFile, module);
231
- const { stderr } = await execCmd(cmd);
232
- if (stderr.length > 0)
233
- sendWarn(stderr);
234
- return {
235
- source: module.sourceName,
236
- artifact: getOutputContractFilename(parsedArgs, module)
237
- };
238
- } catch (err) {
239
- emitExternalError(err, sourceFile);
240
- return {
241
- source: module.sourceName,
242
- artifact: COMPILE_ERR_MSG
243
- };
244
- }
245
- };
246
- var compileExpr = (parsedArgs, sourceFile, module, exprKind) => (exprName) => {
247
- return getArch().then(() => getCompileExprCmd(parsedArgs, sourceFile, module, exprKind, exprName)).then(execCmd).then(({ stderr }) => {
248
- if (stderr.length > 0)
249
- sendWarn(stderr);
250
- const artifactName = getOutputExprFilename(parsedArgs, module, exprKind, exprName);
251
- return {
252
- source: module.sourceName,
253
- artifact: artifactName
254
- };
255
- }).catch((err) => {
256
- return {
257
- source: module.sourceName,
258
- artifact: `${exprName} in ${sourceFile} not compiled`,
259
- err
260
- };
261
- });
262
- };
263
- var getExprNames = (parsedArgs, sourceFile) => {
264
- return new Promise((resolve, reject) => {
265
- const inputFilePath = getInputFilenameAbsPath(parsedArgs, sourceFile);
266
- const readInterface = readline.createInterface({
267
- input: createReadStream(inputFilePath),
268
- output: process.stdout
269
- });
270
- const variableNames = [];
271
- readInterface.on("line", function(line) {
272
- if (!line.trim().startsWith("//")) {
273
- const matches = line.match(/(?<=\s*(let|const)\s+)[a-zA-Z0-9_]+/g);
274
- if (matches) {
275
- variableNames.push(...matches);
276
- }
277
- }
278
- });
279
- readInterface.on("close", function() {
280
- resolve(variableNames);
281
- });
282
- });
283
- };
284
- var compileExprs = async (parsedArgs, sourceFile, module, exprKind) => {
285
- let exprs = [];
286
- try {
287
- exprs = await getExprNames(parsedArgs, sourceFile);
288
- } catch (err) {
289
- emitExternalError(err, sourceFile);
290
- return [{
291
- source: module.sourceName,
292
- artifact: `No ${isStorageKind(exprKind) ? "storage" : "parameter"} expressions compiled`
293
- }];
294
- }
295
- const results = await Promise.all(exprs.map(async (exprName, index) => {
296
- const compileResult = await compileExpr(
297
- parsedArgs,
298
- sourceFile,
299
- module,
300
- exprKind === "storage" && index === 0 ? "default_storage" : exprKind
301
- )(exprName);
302
- return compileResult;
303
- }));
304
- const errors = results.reduce(
305
- (acc, result) => {
306
- if (result.err) {
307
- if (!(result.err instanceof Error))
308
- return [...acc, result.err];
309
- const ligoErrs = acc.filter((err) => err instanceof Error).map((err) => err.message);
310
- const formattedError = formatLigoError(result.err);
311
- return ligoErrs.includes(formattedError.message) ? acc : [...acc, formattedError];
312
- }
313
- return acc;
314
- },
315
- []
316
- );
317
- const retval = results.map(({ source, artifact }) => ({ source, artifact }));
318
- if (errors.length)
319
- emitExternalError(errors, sourceFile);
320
- return retval;
321
- };
322
- var getInitialMessage = (pair, module) => {
323
- const messages = {
324
- "mligo-file-main": `// When this file was created, the smart contract was defined with a main function that was not within a named module. As such, the examples below are written with that assumption in mind.`,
325
- "mligo-file-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was not within a named module. As such, the examples below are written with that assumption in mind.`,
326
- "mligo-module-main": `// When this file was created, the smart contract was defined with a main function that was within a named module. As such, the examples below are written with that assumption in mind.`,
327
- "mligo-module-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was within a named module. As such, the examples below are written with that assumption in mind.`,
328
- "jsligo-file-main": `// When this file was created, the smart contract was defined with a main function that was not within a namespace. As such, the examples below are written with that assumption in mind.
329
- // NOTE: The "storage" type should be exported from the contract file (${module.sourceFile})`,
330
- "jsligo-file-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was not within a namespace. As such, the examples below are written with that assumption in mind.`,
331
- "jsligo-module-main": `// When this file was created, the smart contract was defined with a main function that was within a namespace. As such, the examples below are written with that assumption in mind.
332
- // NOTE: The "storage" type should be exported from the contract file (${module.sourceFile})`,
333
- "jsligo-module-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was within a namespace. As such, the examples below are written with that assumption in mind.`
334
- // ... any other combinations
335
- };
336
- return messages[pair] || "// This file was created by Taqueria.";
337
- };
338
- var getCommonMsg = (langType, listType) => {
339
- const varKeyword = langType === "mligo" ? "let" : "const";
340
- const commonMsgForStorage = `// IMPORTANT: We suggest always explicitly typing your storage values:
341
- // E.g.: \`${varKeyword} storage: int = 10\` or \`${varKeyword} storage: Contract.storage = 10\``;
342
- const commonMsgForParameter = `// IMPORTANT: We suggest always explicitly typing your parameter values:
343
- // E.g.: \`${varKeyword} parameter: int = 10\` or \`${varKeyword} parameter: Contract.parameter = 10\``;
344
- return listType === "storage" ? commonMsgForStorage : commonMsgForParameter;
345
- };
346
- var getContent = (moduleInfo, listType) => {
347
- const linkToContract = `#import "${moduleInfo.sourceFile}" "Contract"`;
348
- const pair = `${moduleInfo.syntax}-${moduleInfo.type}`;
349
- const initialMsg = getInitialMessage(pair, moduleInfo);
350
- const commonMsg = getCommonMsg(moduleInfo.syntax, listType);
351
- return `${linkToContract}
20
+ type ret = operation list * storage
352
21
 
353
- ${initialMsg}
22
+ (* Three entrypoints *)
354
23
 
355
- ${commonMsg}`;
356
- };
357
- var initContentForStorage = (moduleInfo) => getContent(moduleInfo, "storage");
358
- var initContentForParameter = (moduleInfo) => getContent(moduleInfo, "parameter");
359
- var compileContractWithStorageAndParameter = async (parsedArgs, sourceFile, module) => {
360
- const contractCompileResult = await compileContract(parsedArgs, sourceFile, module);
361
- if (contractCompileResult.artifact === COMPILE_ERR_MSG)
362
- return [contractCompileResult];
363
- debugger;
364
- const storageListFile = `${module.moduleName}.storageList${extractExt(sourceFile)}`;
365
- const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
366
- const storageCompileResult = await access(storageListFilename).then(() => compileExprs(parsedArgs, storageListFile, module, "storage")).catch(() => {
367
- sendWarn(
368
- `Note: storage file associated with "${module.moduleName}" can't be found, so "${storageListFile}" has been created for you. Use this file to define all initial storage values for this contract
369
- `
370
- );
371
- return writeFile2(storageListFilename, initContentForStorage(module), "utf8");
372
- });
373
- const parameterListFile = `${module.moduleName}.parameterList${extractExt(sourceFile)}`;
374
- const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
375
- const parameterCompileResult = await access(parameterListFilename).then(() => compileExprs(parsedArgs, parameterListFile, module, "parameter")).catch(() => {
376
- sendWarn(
377
- `Note: parameter file associated with "${module.moduleName}" can't be found, so "${parameterListFile}" has been created for you. Use this file to define all parameter values for this contract
378
- `
379
- );
380
- return writeFile2(parameterListFilename, initContentForParameter(module), "utf8");
381
- });
382
- const storageArtifacts = storageCompileResult ? storageCompileResult.map((res) => res.artifact).join("\n") : "";
383
- const parameterArtifacts = parameterCompileResult ? parameterCompileResult.map((res) => res.artifact).join("\n") : "";
384
- const combinedArtifact = [
385
- contractCompileResult.artifact,
386
- storageArtifacts,
387
- parameterArtifacts
388
- ].filter(Boolean).join("\n");
389
- const combinedRow = {
390
- source: module.sourceName,
391
- artifact: combinedArtifact
392
- };
393
- return [combinedRow];
394
- };
395
- var compile = async (parsedArgs) => {
396
- const sourceFile = parsedArgs.sourceFile;
397
- if (!isLIGOFile(sourceFile)) {
398
- sendErr2(`${sourceFile} is not a LIGO file`);
399
- return;
400
- }
401
- if (isStorageListFile(sourceFile) || isParameterListFile(sourceFile)) {
402
- sendErr2(`Storage and parameter list files are not meant to be compiled directly`);
403
- return;
404
- }
405
- if (isUnsupportedLigoSyntax(sourceFile)) {
406
- sendErr2(`Unsupported LIGO syntax detected in ${sourceFile}. Note, we only support .jsligo and .mligo files.`);
407
- return;
408
- }
409
- try {
410
- const modules = await listContractModules(parsedArgs, sourceFile);
411
- if (modules.length === 0) {
412
- return sendJsonRes([
413
- {
414
- source: sourceFile,
415
- artifact: `No contract modules found in "${sourceFile}"`
416
- }
417
- ]);
418
- }
419
- let allCompileResults = [];
420
- for (const module of modules) {
421
- if (parsedArgs.module && parsedArgs.module !== module.moduleName)
422
- continue;
423
- const compileResults = await compileContractWithStorageAndParameter(parsedArgs, sourceFile, module);
424
- allCompileResults = allCompileResults.concat(compileResults);
425
- }
426
- sendJsonRes(allCompileResults, { footer: `
427
- Compiled ${allCompileResults.length} contract(s) in "${sourceFile}"` });
428
- } catch (err) {
429
- sendErr2(`Error processing "${sourceFile}": ${err}`);
430
- }
431
- };
432
- var compile_default = compile;
24
+ [@entry]
25
+ let increment (delta : int) (store : storage) : ret = [], store + delta
433
26
 
434
- // compile-all.ts
435
- import { sendErr as sendErr3, sendJsonRes as sendJsonRes2 } from "@taqueria/node-sdk";
436
- import glob from "fast-glob";
437
- import { join as join3 } from "path";
438
- var compileAll = async (parsedArgs) => {
439
- let compilePromises = [];
440
- const contractFilenames = await glob(
441
- ["**/*.ligo", "**/*.religo", "**/*.mligo", "**/*.jsligo"],
442
- {
443
- cwd: join3(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts"),
444
- absolute: false
445
- }
446
- );
447
- for (const filename of contractFilenames) {
448
- if (isStorageListFile(filename) || isParameterListFile(filename))
449
- continue;
450
- const moduleNames = await listContractModules(parsedArgs, filename);
451
- for (const moduleName of moduleNames) {
452
- compilePromises.push(compileContractWithStorageAndParameter(parsedArgs, filename, moduleName));
453
- }
454
- }
455
- return Promise.all(compilePromises).then((tables) => tables.flat()).then(sendJsonRes2).catch((err) => sendErr3(err, false));
456
- };
457
- var compile_all_default = compileAll;
27
+ [@entry]
28
+ let decrement (delta : int) (store : storage) : ret = [], store - delta
458
29
 
459
- // ligo.ts
460
- import { execCmd as execCmd2, getArch as getArch2, sendAsyncErr as sendAsyncErr3, sendRes as sendRes2, spawnCmd } from "@taqueria/node-sdk";
461
- import { readJsonFile, writeJsonFile } from "@taqueria/node-sdk";
462
- import { join as join4 } from "path";
463
- var getArbitraryLigoCmd = (parsedArgs, uid, gid, userArgs) => {
464
- const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
465
- if (!projectDir)
466
- throw `No project directory provided`;
467
- const userMap = uid && gid ? `${uid}:${gid}` : uid;
468
- const userMapArgs = uid ? ["-u", userMap] : [];
469
- const binary = "docker";
470
- const baseArgs = [
471
- "run",
472
- "--rm",
473
- "-v",
474
- `${projectDir}:/project`,
475
- "-w",
476
- "/project",
477
- ...userMapArgs,
478
- getLigoDockerImage()
479
- ];
480
- const processedUserArgs = userArgs.split(" ").map((arg) => arg.startsWith("\\-") ? arg.substring(1) : arg).filter(
481
- (arg) => arg
482
- );
483
- const args = [...baseArgs, ...processedUserArgs, "--skip-analytics"];
484
- const envVars = { "DOCKER_DEFAULT_PLATFORM": "linux/amd64" };
485
- return [
486
- [binary, ...args].join(" "),
487
- envVars
488
- ];
489
- };
490
- var ensureEsyExists = async (parsedArgs) => {
491
- const esyJsonPath = join4(parsedArgs.projectDir, "esy.json");
492
- try {
493
- return await readJsonFile(esyJsonPath);
494
- } catch {
495
- return await writeJsonFile(esyJsonPath)({});
496
- }
497
- };
498
- var runArbitraryLigoCmd = (parsedArgs, cmd) => ensureEsyExists(parsedArgs).then(getArch2).then(async () => {
499
- const uid = await execCmd2("id -u");
500
- const gid = await execCmd2("id -g");
501
- return [uid.stdout.trim(), gid.stdout.trim()];
502
- }).then(([uid, gid]) => getArbitraryLigoCmd(parsedArgs, uid, gid, cmd)).then(([cmd2, envVars]) => spawnCmd(cmd2, envVars)).then(
503
- (code) => code !== null && code === 0 ? `Command "${cmd}" ran successfully by LIGO` : `Command "${cmd}" failed. Please check your command`
504
- ).catch((err) => sendAsyncErr3(`An internal error has occurred: ${err.message}`));
505
- var ligo = (parsedArgs) => {
506
- const args = parsedArgs.command;
507
- return runArbitraryLigoCmd(parsedArgs, args).then(sendRes2).catch((err) => sendAsyncErr3(err, false));
508
- };
509
- var ligo_default = ligo;
30
+ [@entry]
31
+ let reset (() : unit) (_ : storage) : ret = [], 0
510
32
 
511
- // test.ts
512
- import { execCmd as execCmd3, getArch as getArch3, sendAsyncErr as sendAsyncErr4, sendJsonRes as sendJsonRes3, sendWarn as sendWarn2 } from "@taqueria/node-sdk";
513
- var getTestContractCmd = (parsedArgs, sourceFile) => {
514
- const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
515
- if (!projectDir)
516
- throw `No project directory provided`;
517
- const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} run test`;
518
- const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
519
- const cmd = `${baseCmd} ${inputFile}`;
520
- return cmd;
521
- };
522
- var testContract = (parsedArgs, sourceFile) => getArch3().then(() => getTestContractCmd(parsedArgs, sourceFile)).then(execCmd3).then(({ stdout, stderr }) => {
523
- if (stderr.length > 0)
524
- sendWarn2(stderr);
525
- const result = "\u{1F389} All tests passed \u{1F389}";
526
- return {
527
- contract: sourceFile,
528
- testResults: stdout.length > 0 ? `${stdout}
529
- ${result}` : result
530
- };
531
- }).catch((err) => {
532
- emitExternalError(err, sourceFile);
533
- return {
534
- contract: sourceFile,
535
- testResults: "Some tests failed :("
33
+ end
34
+ `;
35
+ var jsligo_template = `
36
+ export namespace Counter {
37
+ export type storage = int;
38
+ type ret = [list<operation>, storage];
39
+ // Three entrypoints
40
+
41
+ @entry
42
+ const increment = (delta: int, store: storage): ret =>
43
+ [list([]), store + delta];
44
+ @entry
45
+ const decrement = (delta: int, store: storage): ret =>
46
+ [list([]), store - delta];
47
+ @entry
48
+ const reset = (_p: unit, _s: storage): ret => [list([]), 0]
536
49
  };
537
- });
538
- var test = (parsedArgs) => {
539
- const sourceFile = parsedArgs.sourceFile;
540
- if (!sourceFile)
541
- return sendAsyncErr4(`No source file provided`);
542
- return testContract(parsedArgs, sourceFile).then((result) => [result]).then(sendJsonRes3).catch(
543
- (err) => sendAsyncErr4(err, false)
544
- );
545
- };
546
- var test_default = test;
547
-
548
- // main.ts
549
- var main = (parsedArgs) => {
550
- const unsafeOpts = parsedArgs;
551
- switch (unsafeOpts.task) {
552
- case "ligo":
553
- return ligo_default(unsafeOpts);
554
- case "compile":
555
- return compile_default(unsafeOpts);
556
- case "compile-all":
557
- return compile_all_default(unsafeOpts);
558
- case "test":
559
- return test_default(parsedArgs);
560
- case "get-image":
561
- return sendAsyncRes(getLigoDockerImage());
562
- default:
563
- return sendAsyncErr5(`${unsafeOpts.task} is not an understood task by the LIGO plugin`);
564
- }
565
- };
566
- var main_default = main;
50
+ `;
567
51
 
568
52
  // index.ts
569
- Plugin.create((i18n) => ({
570
- schema: "1.0",
571
- version: "0.1",
53
+ configurePlugin({
54
+ name: "@taqueria/plugin-ligo",
572
55
  alias: "ligo",
573
- tasks: [
574
- Task.create({
575
- task: "ligo",
576
- command: "ligo",
577
- description: "This task allows you to run arbitrary LIGO native commands. Note that they might not benefit from the abstractions provided by Taqueria",
578
- options: [
579
- Option.create({
580
- shortFlag: "c",
581
- flag: "command",
582
- type: "string",
583
- description: "The command to be passed to the underlying LIGO binary, wrapped in quotes",
584
- required: true
585
- })
586
- ],
587
- handler: "proxy",
588
- encoding: "none"
589
- }),
590
- Task.create({
591
- task: "compile",
592
- command: "compile <sourceFile>",
593
- aliases: ["c", "compile-ligo"],
594
- 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",
595
- options: [
596
- Option.create({
597
- flag: "json",
598
- boolean: true,
599
- description: "Emit JSON-encoded Michelson"
600
- }),
601
- Option.create({
602
- flag: "module",
603
- shortFlag: "m",
604
- type: "string",
605
- description: "The LIGO module to be compiled"
606
- })
607
- ],
608
- handler: "proxy",
609
- encoding: "json"
610
- }),
611
- Task.create({
612
- task: "compile-all",
613
- command: "compile-all",
614
- 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",
615
- options: [
616
- Option.create({
617
- flag: "json",
618
- boolean: true,
619
- description: "Emit JSON-encoded Michelson"
620
- })
621
- ],
622
- handler: "proxy",
623
- encoding: "json"
624
- }),
625
- Task.create({
626
- task: "test",
627
- command: "test <sourceFile>",
628
- description: "Test a smart contract written in LIGO",
629
- handler: "proxy",
630
- encoding: "json"
631
- }),
632
- Task.create({
633
- task: "get-image",
634
- command: "get-image",
635
- description: "Gets the name of the image to be used",
636
- handler: "proxy",
637
- hidden: true
638
- })
639
- ],
640
- templates: [
641
- Template.create({
642
- template: "contract",
643
- command: "contract <sourceFileName>",
644
- description: "Create a LIGO contract with boilerplate code",
645
- positionals: [
646
- PositionalArg.create({
647
- placeholder: "sourceFileName",
648
- type: "string",
649
- description: "The name of the LIGO contract to generate"
650
- })
651
- ],
652
- options: [
653
- Option.create({
654
- shortFlag: "s",
655
- flag: "syntax",
656
- type: "string",
657
- description: "The syntax used in the contract"
658
- })
659
- ],
660
- handler: createContract_default
661
- })
662
- ],
663
- proxy: main_default,
664
- postInstall: `node ${__dirname}/postinstall.js`
665
- }), process.argv);
56
+ dockerImage: "ligolang/ligo:1.0.0",
57
+ dockerImageEnvVar: "TAQ_LIGO_IMAGE",
58
+ unparsedArgs: process.argv,
59
+ templates: ligo_templates_exports
60
+ });
666
61
  //# sourceMappingURL=index.mjs.map