@taqueria/plugin-ligo 0.6.2 → 0.6.7

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "deno.codeLens.test": false
3
+ }
package/compile.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';
2
- import { LikeAPromise, PluginResponse, RequestArgs } from '@taqueria/node-sdk/types';
1
+ import { execCmd, getArch, getContracts, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';
2
+ import { RequestArgs } from '@taqueria/node-sdk/types';
3
3
  import { basename, extname, join } from 'path';
4
- import glob = require('fast-glob');
5
4
 
6
5
  interface Opts extends RequestArgs.t {
7
6
  entrypoint?: string;
@@ -57,28 +56,24 @@ const compileContract = (opts: Opts) =>
57
56
  });
58
57
  });
59
58
 
60
- const compileAll = (parsedArgs: Opts): Promise<{ contract: string; artifact: string }[]> => {
61
- // TODO: Fetch list of files from SDK
62
- return glob(
63
- ['**/*.ligo', '**/*.religo', '**/*.mligo', '**/*.jsligo'],
64
- { cwd: parsedArgs.config.contractsDir, absolute: false },
65
- )
59
+ const compileAll = (parsedArgs: Opts) =>
60
+ Promise.all(getContracts(/\.(ligo|religo|mligo|jsligo)$/, parsedArgs.config))
66
61
  .then(entries => entries.map(compileContract(parsedArgs)))
67
- .then(processes =>
68
- processes.length > 0
69
- ? processes
70
- : [{ contract: 'None found', artifact: 'N/A' }]
71
- )
62
+ .then(processes => {
63
+ if (processes.length > 0) return processes;
64
+ return [];
65
+ })
72
66
  .then(promises => Promise.all(promises));
73
- };
74
67
 
75
- export const compile = (parsedArgs: Opts): Promise<PluginResponse> => {
68
+ export const compile = (parsedArgs: Opts) => {
76
69
  const p = parsedArgs.sourceFile
77
70
  ? compileContract(parsedArgs)(parsedArgs.sourceFile as string)
78
71
  .then(result => [result])
79
72
  : compileAll(parsedArgs)
80
73
  .then(results => {
81
- if (results.length === 0) sendErr('No contracts found to compile.');
74
+ if (results.length === 0) {
75
+ sendErr('No contracts found to compile. Have you run "taq add-contract [sourceFile]" ?');
76
+ }
82
77
  return results;
83
78
  });
84
79
 
@@ -0,0 +1,46 @@
1
+ import { experimental, sendAsyncErr } from '@taqueria/node-sdk';
2
+ import * as RequestArgs from '@taqueria/protocol/RequestArgs';
3
+ import { writeFile } from 'fs/promises';
4
+ import { jsligo_template, mligo_template, pascaligo_template, religo_template } from './ligo_templates';
5
+
6
+ interface Opts extends RequestArgs.t {
7
+ sourceFileName?: string;
8
+ syntax?: string;
9
+ }
10
+
11
+ const registerContract = (arg: Opts, contractName: string) => {
12
+ experimental.registerContract(arg, contractName);
13
+ };
14
+
15
+ const getLigoTemplate = async (contractName: string, syntax: string | undefined): Promise<string> => {
16
+ const matchResult = contractName.match(/\.[^.]+$/);
17
+ const ext = matchResult ? matchResult[0].substring(1) : null;
18
+
19
+ if (syntax === 'mligo') return mligo_template;
20
+ if (syntax === 'ligo') return pascaligo_template;
21
+ if (syntax === 'religo') return religo_template;
22
+ if (syntax === 'jsligo') return jsligo_template;
23
+
24
+ if (syntax === undefined) {
25
+ if (ext === 'mligo') return mligo_template;
26
+ if (ext === 'ligo') return pascaligo_template;
27
+ if (ext === 'religo') return religo_template;
28
+ if (ext === 'jsligo') return jsligo_template;
29
+ return sendAsyncErr(
30
+ `Unable to infer LIGO syntax from "${contractName}". Please specify a LIGO syntax via the --syntax option`,
31
+ );
32
+ } else {
33
+ return sendAsyncErr(`"${syntax}" is not a valid syntax. Please specify a valid LIGO syntax`);
34
+ }
35
+ };
36
+
37
+ const createContract = (arg: Opts) => {
38
+ const contractName = arg.sourceFileName as string;
39
+ const syntax = arg.syntax;
40
+ const contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;
41
+ return getLigoTemplate(contractName, syntax)
42
+ .then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template))
43
+ .then(_ => registerContract(arg, contractName));
44
+ };
45
+
46
+ export default createContract;
package/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  var $kQNfl$taquerianodesdk = require("@taqueria/node-sdk");
2
2
  var $kQNfl$path = require("path");
3
- var $kQNfl$fastglob = require("fast-glob");
4
-
3
+ var $kQNfl$fspromises = require("fs/promises");
5
4
 
6
5
 
7
6
 
@@ -38,28 +37,15 @@ const $24b2f47d8f306cb3$var$compileContract = (opts)=>(sourceFile)=>(0, $kQNfl$t
38
37
  artifact: "Not compiled"
39
38
  });
40
39
  });
41
- const $24b2f47d8f306cb3$var$compileAll = (parsedArgs)=>{
42
- // TODO: Fetch list of files from SDK
43
- return $kQNfl$fastglob([
44
- "**/*.ligo",
45
- "**/*.religo",
46
- "**/*.mligo",
47
- "**/*.jsligo"
48
- ], {
49
- cwd: parsedArgs.config.contractsDir,
50
- absolute: false
51
- }).then((entries)=>entries.map($24b2f47d8f306cb3$var$compileContract(parsedArgs))).then((processes)=>processes.length > 0 ? processes : [
52
- {
53
- contract: "None found",
54
- artifact: "N/A"
55
- }
56
- ]).then((promises)=>Promise.all(promises));
57
- };
40
+ const $24b2f47d8f306cb3$var$compileAll = (parsedArgs)=>Promise.all((0, $kQNfl$taquerianodesdk.getContracts)(/\.(ligo|religo|mligo|jsligo)$/, parsedArgs.config)).then((entries)=>entries.map($24b2f47d8f306cb3$var$compileContract(parsedArgs))).then((processes)=>{
41
+ if (processes.length > 0) return processes;
42
+ return [];
43
+ }).then((promises)=>Promise.all(promises));
58
44
  const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
59
45
  const p = parsedArgs.sourceFile ? $24b2f47d8f306cb3$var$compileContract(parsedArgs)(parsedArgs.sourceFile).then((result)=>[
60
46
  result
61
47
  ]) : $24b2f47d8f306cb3$var$compileAll(parsedArgs).then((results)=>{
62
- if (results.length === 0) (0, $kQNfl$taquerianodesdk.sendErr)("No contracts found to compile.");
48
+ if (results.length === 0) (0, $kQNfl$taquerianodesdk.sendErr)('No contracts found to compile. Have you run "taq add-contract [sourceFile]" ?');
63
49
  return results;
64
50
  });
65
51
  return p.then((0, $kQNfl$taquerianodesdk.sendJsonRes)).catch((err)=>(0, $kQNfl$taquerianodesdk.sendAsyncErr)(err, false));
@@ -67,6 +53,143 @@ const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
67
53
  var $24b2f47d8f306cb3$export$2e2bcd8739ae039 = $24b2f47d8f306cb3$export$ef7acd7185315e22;
68
54
 
69
55
 
56
+
57
+
58
+ const $9d8c61104c8e60ad$export$1336661d942c7074 = `
59
+ type storage = int
60
+
61
+ type parameter =
62
+ Increment of int
63
+ | Decrement of int
64
+ | Reset
65
+
66
+ type return = operation list * storage
67
+
68
+ // Two entrypoints
69
+
70
+ let add (store, delta : storage * int) : storage = store + delta
71
+ let sub (store, delta : storage * int) : storage = store - delta
72
+
73
+ (* Main access point that dispatches to the entrypoints according to
74
+ the smart contract parameter. *)
75
+
76
+ let main (action, store : parameter * storage) : return =
77
+ ([] : operation list), // No operations
78
+ (match action with
79
+ Increment (n) -> add (store, n)
80
+ | Decrement (n) -> sub (store, n)
81
+ | Reset -> 0)
82
+ `;
83
+ const $9d8c61104c8e60ad$export$ec41334b92330d9b = `
84
+ type storage is int
85
+
86
+ type parameter is
87
+ Increment of int
88
+ | Decrement of int
89
+ | Reset
90
+
91
+ type return is list (operation) * storage
92
+
93
+ // Two entrypoints
94
+
95
+ function add (const store : storage; const delta : int) : storage is
96
+ store + delta
97
+
98
+ function sub (const store : storage; const delta : int) : storage is
99
+ store - delta
100
+
101
+ (* Main access point that dispatches to the entrypoints according to
102
+ the smart contract parameter. *)
103
+
104
+ function main (const action : parameter; const store : storage) : return is
105
+ ((nil : list (operation)), // No operations
106
+ case action of [
107
+ Increment (n) -> add (store, n)
108
+ | Decrement (n) -> sub (store, n)
109
+ | Reset -> 0
110
+ ])
111
+ `;
112
+ const $9d8c61104c8e60ad$export$9e59f1f7960689be = `
113
+ type storage = int;
114
+
115
+ type parameter =
116
+ Increment (int)
117
+ | Decrement (int)
118
+ | Reset;
119
+
120
+ type return = (list (operation), storage);
121
+
122
+ // Two entrypoints
123
+
124
+ let add = ((store, delta) : (storage, int)) : storage => store + delta;
125
+ let sub = ((store, delta) : (storage, int)) : storage => store - delta;
126
+
127
+ /* Main access point that dispatches to the entrypoints according to
128
+ the smart contract parameter. */
129
+
130
+ let main = ((action, store) : (parameter, storage)) : return => {
131
+ (([] : list (operation)), // No operations
132
+ (switch (action) {
133
+ | Increment (n) => add ((store, n))
134
+ | Decrement (n) => sub ((store, n))
135
+ | Reset => 0}))
136
+ };
137
+ `;
138
+ const $9d8c61104c8e60ad$export$6d35abb7f92d1079 = `
139
+ type storage = int;
140
+
141
+ type parameter =
142
+ ["Increment", int]
143
+ | ["Decrement", int]
144
+ | ["Reset"];
145
+
146
+ type ret = [list<operation>, storage];
147
+
148
+ // Two entrypoints
149
+
150
+ const add = ([store, delta] : [storage, int]) : storage => store + delta;
151
+ const sub = ([store, delta] : [storage, int]) : storage => store - delta;
152
+
153
+ /* Main access point that dispatches to the entrypoints according to
154
+ the smart contract parameter. */
155
+
156
+ const main = ([action, store] : [parameter, storage]) : ret => {
157
+ return [list([]) as list<operation>, // No operations
158
+ match (action, {
159
+ Increment:(n: int) => add ([store, n]),
160
+ Decrement:(n: int) => sub ([store, n]),
161
+ Reset :() => 0})]
162
+ };
163
+ `;
164
+
165
+
166
+ const $40622e3a438d0515$var$registerContract = (arg, contractName)=>{
167
+ (0, $kQNfl$taquerianodesdk.experimental).registerContract(arg, contractName);
168
+ };
169
+ const $40622e3a438d0515$var$getLigoTemplate = async (contractName, syntax)=>{
170
+ const matchResult = contractName.match(/\.[^.]+$/);
171
+ const ext = matchResult ? matchResult[0].substring(1) : null;
172
+ if (syntax === "mligo") return 0, $9d8c61104c8e60ad$export$1336661d942c7074;
173
+ if (syntax === "ligo") return 0, $9d8c61104c8e60ad$export$ec41334b92330d9b;
174
+ if (syntax === "religo") return 0, $9d8c61104c8e60ad$export$9e59f1f7960689be;
175
+ if (syntax === "jsligo") return 0, $9d8c61104c8e60ad$export$6d35abb7f92d1079;
176
+ if (syntax === undefined) {
177
+ if (ext === "mligo") return 0, $9d8c61104c8e60ad$export$1336661d942c7074;
178
+ if (ext === "ligo") return 0, $9d8c61104c8e60ad$export$ec41334b92330d9b;
179
+ if (ext === "religo") return 0, $9d8c61104c8e60ad$export$9e59f1f7960689be;
180
+ if (ext === "jsligo") return 0, $9d8c61104c8e60ad$export$6d35abb7f92d1079;
181
+ return (0, $kQNfl$taquerianodesdk.sendAsyncErr)(`Unable to infer LIGO syntax from "${contractName}". Please specify a LIGO syntax via the --syntax option`);
182
+ } else return (0, $kQNfl$taquerianodesdk.sendAsyncErr)(`"${syntax}" is not a valid syntax. Please specify a valid LIGO syntax`);
183
+ };
184
+ const $40622e3a438d0515$var$createContract = (arg)=>{
185
+ const contractName = arg.sourceFileName;
186
+ const syntax = arg.syntax;
187
+ const contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;
188
+ return $40622e3a438d0515$var$getLigoTemplate(contractName, syntax).then((ligo_template)=>(0, $kQNfl$fspromises.writeFile)(`${contractsDir}/${contractName}`, ligo_template)).then((_)=>$40622e3a438d0515$var$registerContract(arg, contractName));
189
+ };
190
+ var $40622e3a438d0515$export$2e2bcd8739ae039 = $40622e3a438d0515$var$createContract;
191
+
192
+
70
193
  (0, $kQNfl$taquerianodesdk.Plugin).create((i18n)=>({
71
194
  schema: "1.0",
72
195
  version: "0.1",
@@ -101,22 +224,29 @@ var $24b2f47d8f306cb3$export$2e2bcd8739ae039 = $24b2f47d8f306cb3$export$ef7acd71
101
224
  encoding: "json"
102
225
  }),
103
226
  ],
104
- checkRuntimeDependencies: ()=>Promise.resolve({
105
- status: "success",
106
- report: [
107
- {
108
- name: "LIGO",
109
- path: "ligo",
110
- version: ">=0.27.0",
111
- kind: "required",
112
- met: true
113
- },
114
- ]
115
- }),
116
- installRunTimeDependencies: ()=>Promise.resolve({
117
- status: "success",
118
- output: "LIGO was found in /usr/bin/ligo"
119
- }),
227
+ templates: [
228
+ (0, $kQNfl$taquerianodesdk.Template).create({
229
+ template: "contract",
230
+ command: "contract <sourceFileName>",
231
+ description: "Create a LIGO contract with boilerplate code",
232
+ positionals: [
233
+ (0, $kQNfl$taquerianodesdk.PositionalArg).create({
234
+ placeholder: "sourceFileName",
235
+ type: "string",
236
+ description: "The name of the LIGO contract to generate"
237
+ }),
238
+ ],
239
+ options: [
240
+ (0, $kQNfl$taquerianodesdk.Option).create({
241
+ shortFlag: "s",
242
+ flag: "syntax",
243
+ type: "string",
244
+ description: "The syntax used in the contract"
245
+ }),
246
+ ],
247
+ handler: (0, $40622e3a438d0515$export$2e2bcd8739ae039)
248
+ }),
249
+ ],
120
250
  proxy: (0, $24b2f47d8f306cb3$export$2e2bcd8739ae039)
121
251
  }), process.argv);
122
252
 
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;ACAA;;;AAWA,MAAM,iDAA2B,GAAG,CAAC,IAAU,GAC9C,CAAC,UAAkB,GAAK;QACvB,MAAM,OAAO,GAAG,CAAA,GAAA,oBAAQ,CAAA,CAAC,UAAU,EAAE,CAAA,GAAA,mBAAO,CAAA,CAAC,UAAU,CAAC,CAAC,AAAC;QAC1D,OAAO,CAAA,GAAA,gBAAI,CAAA,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;KACvD,AAAC;AAEH,MAAM,sCAAgB,GAAG,CAAC,IAAU,GACnC,CAAC,UAAkB,GAAK;QACvB,OAAO,CAAA,GAAA,gBAAI,CAAA,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;KAClD,AAAC;AAEH,MAAM,uCAAiB,GAAG,CAAC,IAAU,GACpC,CAAC,UAAkB,GAAK;QACvB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG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Q,EAAE,MAAM;aAChB,CAAC;SACF;QACD,wBAAwB,EAAE,IACzB,OAAO,CAAC,OAAO,CAAC;gBACf,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE;oBACP;wBAAE,IAAI,EAAE,MAAM;wBAAE,IAAI,EAAE,MAAM;wBAAE,OAAO,EAAE,UAAU;wBAAE,IAAI,EAAE,UAAU;wBAAE,GAAG,EAAE,IAAI;qBAAE;iBAChF;aACD,CAAC;QACH,0BAA0B,EAAE,IAC3B,OAAO,CAAC,OAAO,CAAC;gBACf,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,iCAAiC;aACzC,CAAC;QACH,KAAK,EAAE,CAAA,GAAA,wCAAO,CAAA;KACd,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-ligo/index.ts","taqueria-plugin-ligo/compile.ts"],"sourcesContent":["import { Option, Plugin, Task } from '@taqueria/node-sdk';\nimport compile from './compile';\n\nPlugin.create(i18n => ({\n\tschema: '1.0',\n\tversion: '0.1',\n\talias: 'ligo',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile [sourceFile]',\n\t\t\taliases: ['c', 'compile-ligo'],\n\t\t\tdescription: 'Compile a smart contract written in a Ligo syntax to Michelson code',\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 'e',\n\t\t\t\t\tflag: 'entrypoint',\n\t\t\t\t\tdescription: 'The entry point that will be compiled',\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 's',\n\t\t\t\t\tflag: 'syntax',\n\t\t\t\t\tdescription: 'The syntax used in the contract',\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tflag: 'infer',\n\t\t\t\t\tdescription: 'Enable type inference',\n\t\t\t\t}),\n\t\t\t],\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t],\n\tcheckRuntimeDependencies: () =>\n\t\tPromise.resolve({\n\t\t\tstatus: 'success',\n\t\t\treport: [\n\t\t\t\t{ name: 'LIGO', path: 'ligo', version: '>=0.27.0', kind: 'required', met: true },\n\t\t\t],\n\t\t}),\n\tinstallRunTimeDependencies: () =>\n\t\tPromise.resolve({\n\t\t\tstatus: 'success',\n\t\t\toutput: 'LIGO was found in /usr/bin/ligo', // TODO this should use i18n\n\t\t}),\n\tproxy: compile,\n}), process.argv);\n","import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { LikeAPromise, PluginResponse, RequestArgs } from '@taqueria/node-sdk/types';\nimport { basename, extname, join } from 'path';\nimport glob = require('fast-glob');\n\ninterface Opts extends RequestArgs.t {\n\tentrypoint?: string;\n\tsyntax?: string;\n\tsourceFile?: string;\n}\n\nconst getContractArtifactFilename = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst outFile = basename(sourceFile, extname(sourceFile));\n\t\treturn join(opts.config.artifactsDir, `${outFile}.tz`);\n\t};\n\nconst getInputFilename = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\treturn join(opts.config.contractsDir, sourceFile);\n\t};\n\nconst getCompileCommand = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst projectDir = process.env.PROJECT_DIR ?? opts.projectDir;\n\n\t\tif (!projectDir) throw `No project directory provided`;\n\n\t\tconst inputFile = getInputFilename(opts)(sourceFile);\n\t\tconst baseCommand =\n\t\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract ${inputFile}`;\n\t\tconst entryPoint = opts.entrypoint ? `-e ${opts.entrypoint}` : '';\n\t\tconst syntax = opts['syntax'] ? `-s ${opts['syntax']} : \"\"` : '';\n\t\tconst outFile = `-o ${getContractArtifactFilename(opts)(sourceFile)}`;\n\t\tconst cmd = `${baseCommand} ${entryPoint} ${syntax} ${outFile}`;\n\t\treturn cmd;\n\t};\n\nconst compileContract = (opts: Opts) =>\n\t(sourceFile: string): Promise<{ contract: string; artifact: string }> =>\n\t\tgetArch()\n\t\t\t.then(() => getCompileCommand(opts)(sourceFile))\n\t\t\t.then(execCmd)\n\t\t\t.then(({ stderr }) => { // How should we output warnings?\n\t\t\t\tif (stderr.length > 0) sendErr(stderr);\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: getContractArtifactFilename(opts)(sourceFile),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsendErr(' ');\n\t\t\t\tsendErr(err.message.split('\\n').slice(1).join('\\n'));\n\t\t\t\treturn Promise.resolve({\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: 'Not compiled',\n\t\t\t\t});\n\t\t\t});\n\nconst compileAll = (parsedArgs: Opts): Promise<{ contract: string; artifact: string }[]> => {\n\t// TODO: Fetch list of files from SDK\n\treturn glob(\n\t\t['**/*.ligo', '**/*.religo', '**/*.mligo', '**/*.jsligo'],\n\t\t{ cwd: parsedArgs.config.contractsDir, absolute: false },\n\t)\n\t\t.then(entries => entries.map(compileContract(parsedArgs)))\n\t\t.then(processes =>\n\t\t\tprocesses.length > 0\n\t\t\t\t? processes\n\t\t\t\t: [{ contract: 'None found', artifact: 'N/A' }]\n\t\t)\n\t\t.then(promises => Promise.all(promises));\n};\n\nexport const compile = (parsedArgs: Opts): Promise<PluginResponse> => {\n\tconst p = parsedArgs.sourceFile\n\t\t? compileContract(parsedArgs)(parsedArgs.sourceFile as string)\n\t\t\t.then(result => [result])\n\t\t: compileAll(parsedArgs)\n\t\t\t.then(results => {\n\t\t\t\tif (results.length === 0) sendErr('No contracts found to compile.');\n\t\t\t\treturn results;\n\t\t\t});\n\n\treturn p\n\t\t.then(sendJsonRes)\n\t\t.catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n"],"names":[],"version":3,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M,CAAA,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,GAAG;wBACd,IAAI,EAAE,OAAO;wBACb,WAAW,EAAE,uBAAuB;qBACpC,CAAC;iBACF;gBACD,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,MAAM;aAChB,CAAC;SACF;QACD,SAAS,EAAE;YACV,CAAA,GAAA,+BAAQ,CAAA,CAAC,MAAM,CAAC;gBACf,QAAQ,EAAE,UAAU;gBACpB,OAAO,EAAE,2BAA2B;gBACpC,WAAW,EAAE,8CAA8C;gBAC3D,WAAW,EAAE;oBACZ,CAAA,GAAA,oCAAa,CAAA,CAAC,MAAM,CAAC;wBACpB,WAAW,EAAE,gBAAgB;wBAC7B,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,2CAA2C;qBACxD,CAAC;iBACF;gBACD,OAAO,EAAE;oBACR,CAAA,GAAA,6BAAM,CAAA,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,GAAG;wBACd,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,iCAAiC;qBAC9C,CAAC;iBACF;gBACD,OAAO,EAAE,CAAA,GAAA,wCAAc,CAAA;aACvB,CAAC;SACF;QACD,KAAK,EAAE,CAAA,GAAA,wCAAO,CAAA;KACd,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-ligo/index.ts","taqueria-plugin-ligo/compile.ts","taqueria-plugin-ligo/createContract.ts","taqueria-plugin-ligo/ligo_templates.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport compile from './compile';\nimport createContract from './createContract';\n\nPlugin.create(i18n => ({\n\tschema: '1.0',\n\tversion: '0.1',\n\talias: 'ligo',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile [sourceFile]',\n\t\t\taliases: ['c', 'compile-ligo'],\n\t\t\tdescription: 'Compile a smart contract written in a Ligo syntax to Michelson code',\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 'e',\n\t\t\t\t\tflag: 'entrypoint',\n\t\t\t\t\tdescription: 'The entry point that will be compiled',\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 's',\n\t\t\t\t\tflag: 'syntax',\n\t\t\t\t\tdescription: 'The syntax used in the contract',\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tflag: 'infer',\n\t\t\t\t\tdescription: 'Enable type inference',\n\t\t\t\t}),\n\t\t\t],\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract',\n\t\t\tcommand: 'contract <sourceFileName>',\n\t\t\tdescription: 'Create a LIGO contract with boilerplate code',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'sourceFileName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The name of the LIGO contract to generate',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 's',\n\t\t\t\t\tflag: 'syntax',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The syntax used in the contract',\n\t\t\t\t}),\n\t\t\t],\n\t\t\thandler: createContract,\n\t\t}),\n\t],\n\tproxy: compile,\n}), process.argv);\n","import { execCmd, getArch, getContracts, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { basename, extname, join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tentrypoint?: string;\n\tsyntax?: string;\n\tsourceFile?: string;\n}\n\nconst getContractArtifactFilename = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst outFile = basename(sourceFile, extname(sourceFile));\n\t\treturn join(opts.config.artifactsDir, `${outFile}.tz`);\n\t};\n\nconst getInputFilename = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\treturn join(opts.config.contractsDir, sourceFile);\n\t};\n\nconst getCompileCommand = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst projectDir = process.env.PROJECT_DIR ?? opts.projectDir;\n\n\t\tif (!projectDir) throw `No project directory provided`;\n\n\t\tconst inputFile = getInputFilename(opts)(sourceFile);\n\t\tconst baseCommand =\n\t\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract ${inputFile}`;\n\t\tconst entryPoint = opts.entrypoint ? `-e ${opts.entrypoint}` : '';\n\t\tconst syntax = opts['syntax'] ? `-s ${opts['syntax']} : \"\"` : '';\n\t\tconst outFile = `-o ${getContractArtifactFilename(opts)(sourceFile)}`;\n\t\tconst cmd = `${baseCommand} ${entryPoint} ${syntax} ${outFile}`;\n\t\treturn cmd;\n\t};\n\nconst compileContract = (opts: Opts) =>\n\t(sourceFile: string): Promise<{ contract: string; artifact: string }> =>\n\t\tgetArch()\n\t\t\t.then(() => getCompileCommand(opts)(sourceFile))\n\t\t\t.then(execCmd)\n\t\t\t.then(({ stderr }) => { // How should we output warnings?\n\t\t\t\tif (stderr.length > 0) sendErr(stderr);\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: getContractArtifactFilename(opts)(sourceFile),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsendErr(' ');\n\t\t\t\tsendErr(err.message.split('\\n').slice(1).join('\\n'));\n\t\t\t\treturn Promise.resolve({\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: 'Not compiled',\n\t\t\t\t});\n\t\t\t});\n\nconst compileAll = (parsedArgs: Opts) =>\n\tPromise.all(getContracts(/\\.(ligo|religo|mligo|jsligo)$/, parsedArgs.config))\n\t\t.then(entries => entries.map(compileContract(parsedArgs)))\n\t\t.then(processes => {\n\t\t\tif (processes.length > 0) return processes;\n\t\t\treturn [];\n\t\t})\n\t\t.then(promises => Promise.all(promises));\n\nexport const compile = (parsedArgs: Opts) => {\n\tconst p = parsedArgs.sourceFile\n\t\t? compileContract(parsedArgs)(parsedArgs.sourceFile as string)\n\t\t\t.then(result => [result])\n\t\t: compileAll(parsedArgs)\n\t\t\t.then(results => {\n\t\t\t\tif (results.length === 0) {\n\t\t\t\t\tsendErr('No contracts found to compile. Have you run \"taq add-contract [sourceFile]\" ?');\n\t\t\t\t}\n\t\t\t\treturn results;\n\t\t\t});\n\n\treturn p\n\t\t.then(sendJsonRes)\n\t\t.catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n","import { experimental, sendAsyncErr } from '@taqueria/node-sdk';\nimport * as RequestArgs from '@taqueria/protocol/RequestArgs';\nimport { writeFile } from 'fs/promises';\nimport { jsligo_template, mligo_template, pascaligo_template, religo_template } from './ligo_templates';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFileName?: string;\n\tsyntax?: string;\n}\n\nconst registerContract = (arg: Opts, contractName: string) => {\n\texperimental.registerContract(arg, contractName);\n};\n\nconst getLigoTemplate = async (contractName: string, syntax: string | undefined): Promise<string> => {\n\tconst matchResult = contractName.match(/\\.[^.]+$/);\n\tconst ext = matchResult ? matchResult[0].substring(1) : null;\n\n\tif (syntax === 'mligo') return mligo_template;\n\tif (syntax === 'ligo') return pascaligo_template;\n\tif (syntax === 'religo') return religo_template;\n\tif (syntax === 'jsligo') return jsligo_template;\n\n\tif (syntax === undefined) {\n\t\tif (ext === 'mligo') return mligo_template;\n\t\tif (ext === 'ligo') return pascaligo_template;\n\t\tif (ext === 'religo') return religo_template;\n\t\tif (ext === 'jsligo') return jsligo_template;\n\t\treturn sendAsyncErr(\n\t\t\t`Unable to infer LIGO syntax from \"${contractName}\". Please specify a LIGO syntax via the --syntax option`,\n\t\t);\n\t} else {\n\t\treturn sendAsyncErr(`\"${syntax}\" is not a valid syntax. Please specify a valid LIGO syntax`);\n\t}\n};\n\nconst createContract = (arg: Opts) => {\n\tconst contractName = arg.sourceFileName as string;\n\tconst syntax = arg.syntax;\n\tconst contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;\n\treturn getLigoTemplate(contractName, syntax)\n\t\t.then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template))\n\t\t.then(_ => registerContract(arg, contractName));\n};\n\nexport default createContract;\n","export const mligo_template = `\ntype storage = int\n\ntype parameter =\n Increment of int\n| Decrement of int\n| Reset\n\ntype return = operation list * storage\n\n// Two entrypoints\n\nlet add (store, delta : storage * int) : storage = store + delta\nlet sub (store, delta : storage * int) : storage = store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nlet main (action, store : parameter * storage) : return =\n ([] : operation list), // No operations\n (match action with\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0)\n`;\n\nexport const pascaligo_template = `\ntype storage is int\n\ntype parameter is\n Increment of int\n| Decrement of int\n| Reset\n\ntype return is list (operation) * storage\n\n// Two entrypoints\n\nfunction add (const store : storage; const delta : int) : storage is \n store + delta\n\nfunction sub (const store : storage; const delta : int) : storage is \n store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nfunction main (const action : parameter; const store : storage) : return is\n ((nil : list (operation)), // No operations\n case action of [\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0\n ])\n`;\n\nexport const religo_template = `\ntype storage = int;\n\ntype parameter =\n Increment (int)\n| Decrement (int)\n| Reset;\n\ntype return = (list (operation), storage);\n\n// Two entrypoints\n\nlet add = ((store, delta) : (storage, int)) : storage => store + delta;\nlet sub = ((store, delta) : (storage, int)) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n \nlet main = ((action, store) : (parameter, storage)) : return => {\n (([] : list (operation)), // No operations\n (switch (action) {\n | Increment (n) => add ((store, n))\n | Decrement (n) => sub ((store, n))\n | Reset => 0}))\n};\n`;\n\nexport const jsligo_template = `\ntype storage = int;\n\ntype parameter =\n [\"Increment\", int]\n| [\"Decrement\", int]\n| [\"Reset\"];\n\ntype ret = [list<operation>, storage];\n\n// Two entrypoints\n\nconst add = ([store, delta] : [storage, int]) : storage => store + delta;\nconst sub = ([store, delta] : [storage, int]) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n\nconst main = ([action, store] : [parameter, storage]) : ret => {\n return [list([]) as list<operation>, // No operations\n match (action, {\n Increment:(n: int) => add ([store, n]),\n Decrement:(n: int) => sub ([store, n]),\n Reset :() => 0})]\n};\n`;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
package/index.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Option, Plugin, Task } from '@taqueria/node-sdk';
1
+ import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';
2
2
  import compile from './compile';
3
+ import createContract from './createContract';
3
4
 
4
5
  Plugin.create(i18n => ({
5
6
  schema: '1.0',
@@ -32,17 +33,28 @@ Plugin.create(i18n => ({
32
33
  encoding: 'json',
33
34
  }),
34
35
  ],
35
- checkRuntimeDependencies: () =>
36
- Promise.resolve({
37
- status: 'success',
38
- report: [
39
- { name: 'LIGO', path: 'ligo', version: '>=0.27.0', kind: 'required', met: true },
36
+ templates: [
37
+ Template.create({
38
+ template: 'contract',
39
+ command: 'contract <sourceFileName>',
40
+ description: 'Create a LIGO contract with boilerplate code',
41
+ positionals: [
42
+ PositionalArg.create({
43
+ placeholder: 'sourceFileName',
44
+ type: 'string',
45
+ description: 'The name of the LIGO contract to generate',
46
+ }),
40
47
  ],
48
+ options: [
49
+ Option.create({
50
+ shortFlag: 's',
51
+ flag: 'syntax',
52
+ type: 'string',
53
+ description: 'The syntax used in the contract',
54
+ }),
55
+ ],
56
+ handler: createContract,
41
57
  }),
42
- installRunTimeDependencies: () =>
43
- Promise.resolve({
44
- status: 'success',
45
- output: 'LIGO was found in /usr/bin/ligo', // TODO this should use i18n
46
- }),
58
+ ],
47
59
  proxy: compile,
48
60
  }), process.argv);
@@ -0,0 +1,109 @@
1
+ export const mligo_template = `
2
+ type storage = int
3
+
4
+ type parameter =
5
+ Increment of int
6
+ | Decrement of int
7
+ | Reset
8
+
9
+ type return = operation list * storage
10
+
11
+ // Two entrypoints
12
+
13
+ let add (store, delta : storage * int) : storage = store + delta
14
+ let sub (store, delta : storage * int) : storage = store - delta
15
+
16
+ (* Main access point that dispatches to the entrypoints according to
17
+ the smart contract parameter. *)
18
+
19
+ let main (action, store : parameter * storage) : return =
20
+ ([] : operation list), // No operations
21
+ (match action with
22
+ Increment (n) -> add (store, n)
23
+ | Decrement (n) -> sub (store, n)
24
+ | Reset -> 0)
25
+ `;
26
+
27
+ export const pascaligo_template = `
28
+ type storage is int
29
+
30
+ type parameter is
31
+ Increment of int
32
+ | Decrement of int
33
+ | Reset
34
+
35
+ type return is list (operation) * storage
36
+
37
+ // Two entrypoints
38
+
39
+ function add (const store : storage; const delta : int) : storage is
40
+ store + delta
41
+
42
+ function sub (const store : storage; const delta : int) : storage is
43
+ store - delta
44
+
45
+ (* Main access point that dispatches to the entrypoints according to
46
+ the smart contract parameter. *)
47
+
48
+ function main (const action : parameter; const store : storage) : return is
49
+ ((nil : list (operation)), // No operations
50
+ case action of [
51
+ Increment (n) -> add (store, n)
52
+ | Decrement (n) -> sub (store, n)
53
+ | Reset -> 0
54
+ ])
55
+ `;
56
+
57
+ export const religo_template = `
58
+ type storage = int;
59
+
60
+ type parameter =
61
+ Increment (int)
62
+ | Decrement (int)
63
+ | Reset;
64
+
65
+ type return = (list (operation), storage);
66
+
67
+ // Two entrypoints
68
+
69
+ let add = ((store, delta) : (storage, int)) : storage => store + delta;
70
+ let sub = ((store, delta) : (storage, int)) : storage => store - delta;
71
+
72
+ /* Main access point that dispatches to the entrypoints according to
73
+ the smart contract parameter. */
74
+
75
+ let main = ((action, store) : (parameter, storage)) : return => {
76
+ (([] : list (operation)), // No operations
77
+ (switch (action) {
78
+ | Increment (n) => add ((store, n))
79
+ | Decrement (n) => sub ((store, n))
80
+ | Reset => 0}))
81
+ };
82
+ `;
83
+
84
+ export const jsligo_template = `
85
+ type storage = int;
86
+
87
+ type parameter =
88
+ ["Increment", int]
89
+ | ["Decrement", int]
90
+ | ["Reset"];
91
+
92
+ type ret = [list<operation>, storage];
93
+
94
+ // Two entrypoints
95
+
96
+ const add = ([store, delta] : [storage, int]) : storage => store + delta;
97
+ const sub = ([store, delta] : [storage, int]) : storage => store - delta;
98
+
99
+ /* Main access point that dispatches to the entrypoints according to
100
+ the smart contract parameter. */
101
+
102
+ const main = ([action, store] : [parameter, storage]) : ret => {
103
+ return [list([]) as list<operation>, // No operations
104
+ match (action, {
105
+ Increment:(n: int) => add ([store, n]),
106
+ Decrement:(n: int) => sub ([store, n]),
107
+ Reset :() => 0})]
108
+ };
109
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taqueria/plugin-ligo",
3
- "version": "0.6.2",
3
+ "version": "0.6.7",
4
4
  "description": "A taqueria plugin for compiling LIGO smart contracts",
5
5
  "targets": {
6
6
  "default": {
@@ -41,11 +41,11 @@
41
41
  },
42
42
  "homepage": "https://github.com/ecadlabs/taqueria#readme",
43
43
  "dependencies": {
44
- "@taqueria/node-sdk": "^0.6.2",
44
+ "@taqueria/node-sdk": "^0.6.7",
45
45
  "fast-glob": "^3.2.11"
46
46
  },
47
47
  "devDependencies": {
48
- "parcel": "^2.6.0",
48
+ "parcel": "2.6.1",
49
49
  "typescript": "^4.7.2"
50
50
  }
51
51
  }