@taqueria/plugin-ligo 0.12.0 → 0.13.16

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/compile.ts CHANGED
@@ -1,85 +1,242 @@
1
- import { execCmd, getArch, getContracts, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';
1
+ import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';
2
2
  import { RequestArgs } from '@taqueria/node-sdk/types';
3
+ import { access, readFile, writeFile } from 'fs/promises';
3
4
  import { basename, extname, join } from 'path';
4
5
 
5
6
  interface Opts extends RequestArgs.t {
6
- entrypoint?: string;
7
- syntax?: string;
8
- sourceFile?: string;
7
+ sourceFile: string;
9
8
  }
10
9
 
11
- const getContractArtifactFilename = (opts: Opts) =>
12
- (sourceFile: string) => {
13
- const outFile = basename(sourceFile, extname(sourceFile));
14
- return join(opts.config.artifactsDir, `${outFile}.tz`);
15
- };
10
+ type TableRow = { contract: string; artifact: string };
16
11
 
17
- const getInputFilename = (opts: Opts) =>
18
- (sourceFile: string) => {
19
- return join(opts.config.contractsDir, sourceFile);
20
- };
12
+ type ExprKind = 'storage' | 'default_storage' | 'parameter';
21
13
 
22
- const getCompileCommand = (opts: Opts) =>
23
- (sourceFile: string) => {
24
- const projectDir = process.env.PROJECT_DIR ?? opts.projectDir;
14
+ const COMPILE_ERR_MSG: string = 'Not compiled';
25
15
 
26
- if (!projectDir) throw `No project directory provided`;
16
+ const isStorageKind = (exprKind: ExprKind): boolean => exprKind === 'storage' || exprKind === 'default_storage';
27
17
 
28
- const inputFile = getInputFilename(opts)(sourceFile);
29
- const baseCommand =
30
- `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract ${inputFile}`;
31
- const entryPoint = opts.entrypoint ? `-e ${opts.entrypoint}` : '';
32
- const syntax = opts['syntax'] ? `-s ${opts['syntax']} : ""` : '';
33
- const outFile = `-o ${getContractArtifactFilename(opts)(sourceFile)}`;
34
- const cmd = `${baseCommand} ${entryPoint} ${syntax} ${outFile}`;
35
- return cmd;
36
- };
18
+ const isLIGOFile = (sourceFile: string): boolean => /.+\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
19
+
20
+ const isStoragesFile = (sourceFile: string): boolean => /.+\.storages\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
21
+
22
+ const isParametersFile = (sourceFile: string): boolean =>
23
+ /.+\.parameters\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
24
+
25
+ const isContractFile = (sourceFile: string): boolean =>
26
+ isLIGOFile(sourceFile) && !isStoragesFile(sourceFile) && !isParametersFile(sourceFile);
27
+
28
+ const extractExt = (path: string): string => {
29
+ const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
30
+ return matchResult ? matchResult[0] : '';
31
+ };
32
+
33
+ const removeExt = (path: string): string => {
34
+ const extRegex = new RegExp(extractExt(path));
35
+ return path.replace(extRegex, '');
36
+ };
37
+
38
+ const getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>
39
+ join(parsedArgs.config.contractsDir, sourceFile);
40
+
41
+ const getOutputFilename = (parsedArgs: Opts, sourceFile: string): string => {
42
+ const outputFile = basename(sourceFile, extname(sourceFile));
43
+ return join(parsedArgs.config.artifactsDir, `${outputFile}.tz`);
44
+ };
45
+
46
+ // Get the contract name that the storage/parameter file is associated with
47
+ // e.g. If sourceFile is token.storages.mligo, then it'll return token.mligo
48
+ const getContractNameForExpr = (sourceFile: string, exprKind: ExprKind): string => {
49
+ try {
50
+ return isStorageKind(exprKind)
51
+ ? sourceFile.match(/.+(?=\.storages\.(ligo|religo|mligo|jsligo))/)!.join('.')
52
+ : sourceFile.match(/.+(?=\.parameters\.(ligo|religo|mligo|jsligo))/)!.join('.');
53
+ } catch (err) {
54
+ throw new Error(`Something went wrong internally when dealing with filename format: ${err}`);
55
+ }
56
+ };
57
+
58
+ // If sourceFile is token.storages.mligo, then it'll return token.storage.{storageName}.tz
59
+ const getOutputExprFileName = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {
60
+ const contractName = basename(getContractNameForExpr(sourceFile, exprKind), extname(sourceFile));
61
+ const outputFile = exprKind === 'default_storage'
62
+ ? `${contractName}.default_storage.tz`
63
+ : `${contractName}.${exprKind}.${exprName}.tz`;
64
+ return join(parsedArgs.config.artifactsDir, `${outputFile}`);
65
+ };
66
+
67
+ const getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string => {
68
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
69
+ if (!projectDir) throw `No project directory provided`;
70
+ const baseCmd =
71
+ `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract`;
72
+ const inputFile = getInputFilename(parsedArgs, sourceFile);
73
+ const outputFile = `-o ${getOutputFilename(parsedArgs, sourceFile)}`;
74
+ const cmd = `${baseCmd} ${inputFile} ${outputFile}`;
75
+ return cmd;
76
+ };
77
+
78
+ const getCompileExprCmd = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {
79
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
80
+ if (!projectDir) throw `No project directory provided`;
81
+ const compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';
82
+ const baseCmd =
83
+ `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile ${compilerType}`;
84
+ const inputFile = getInputFilename(parsedArgs, sourceFile);
85
+ const outputFile = `-o ${getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)}`;
86
+ const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile}`;
87
+ return cmd;
88
+ };
89
+
90
+ const compileContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>
91
+ getArch()
92
+ .then(() => getCompileContractCmd(parsedArgs, sourceFile))
93
+ .then(execCmd)
94
+ .then(({ stderr }) => {
95
+ if (stderr.length > 0) sendWarn(stderr);
96
+ return {
97
+ contract: sourceFile,
98
+ artifact: getOutputFilename(parsedArgs, sourceFile),
99
+ };
100
+ })
101
+ .catch(err => {
102
+ sendErr(`\n=== For ${sourceFile} ===`);
103
+ sendErr(err.message.replace(/Command failed.+?\n/, ''));
104
+ return {
105
+ contract: sourceFile,
106
+ artifact: COMPILE_ERR_MSG,
107
+ };
108
+ });
37
109
 
38
- const compileContract = (opts: Opts) =>
39
- (sourceFile: string): Promise<{ contract: string; artifact: string }> =>
110
+ const compileExpr = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind) =>
111
+ (exprName: string): Promise<TableRow> =>
40
112
  getArch()
41
- .then(() => getCompileCommand(opts)(sourceFile))
113
+ .then(() => getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName))
42
114
  .then(execCmd)
43
- .then(({ stderr }) => { // How should we output warnings?
44
- if (stderr.length > 0) sendErr(stderr);
115
+ .then(({ stderr }) => {
116
+ if (stderr.length > 0) sendWarn(stderr);
45
117
  return {
46
118
  contract: sourceFile,
47
- artifact: getContractArtifactFilename(opts)(sourceFile),
119
+ artifact: getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName),
48
120
  };
49
121
  })
50
122
  .catch(err => {
51
- sendErr(' ');
52
- sendErr(err.message.split('\n').slice(1).join('\n'));
53
- return Promise.resolve({
123
+ sendErr(`\n=== For ${sourceFile} ===`);
124
+ sendErr(err.message.replace(/Command failed.+?\n/, ''));
125
+ return {
54
126
  contract: sourceFile,
55
- artifact: 'Not compiled',
56
- });
127
+ artifact: COMPILE_ERR_MSG,
128
+ };
57
129
  });
58
130
 
59
- const compileAll = (parsedArgs: Opts) =>
60
- Promise.all(getContracts(/\.(ligo|religo|mligo|jsligo)$/, parsedArgs.config))
61
- .then(entries => entries.map(compileContract(parsedArgs)))
62
- .then(processes => {
63
- if (processes.length > 0) return processes;
64
- return [];
131
+ const compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind): Promise<TableRow[]> =>
132
+ readFile(getInputFilename(parsedArgs, sourceFile), 'utf8')
133
+ .then(data => {
134
+ if (!data.includes('#include')) {
135
+ writeFile(
136
+ getInputFilename(parsedArgs, sourceFile),
137
+ `#include "${getContractNameForExpr(sourceFile, exprKind)}"\n` + data,
138
+ 'utf8',
139
+ );
140
+ }
141
+ return data;
65
142
  })
66
- .then(promises => Promise.all(promises));
67
-
68
- export const compile = (parsedArgs: Opts) => {
69
- const p = parsedArgs.sourceFile
70
- ? compileContract(parsedArgs)(parsedArgs.sourceFile as string)
71
- .then(result => [result])
72
- : compileAll(parsedArgs)
73
- .then(results => {
74
- if (results.length === 0) {
75
- sendErr('No contracts found to compile. Have you run "taq add-contract [sourceFile]" ?');
76
- }
77
- return results;
78
- });
143
+ .then(data => data.match(/(?<=\s*(let|const)\s+)[a-zA-Z0-9_]+/g))
144
+ .then(exprNames => {
145
+ if (!exprNames) return [];
146
+ const firstExprName = exprNames.slice(0, 1)[0];
147
+ const restExprNames = exprNames.slice(1, exprNames.length);
148
+ const firstExprKind = isStorageKind(exprKind) ? 'default_storage' : 'parameter';
149
+ const restExprKind = isStorageKind(exprKind) ? 'storage' : 'parameter';
150
+ const firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);
151
+ const restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));
152
+ return Promise.all([firstExprResult].concat(restExprResults));
153
+ })
154
+ .catch(err => {
155
+ sendErr(`\n=== For ${sourceFile} ===`);
156
+ sendErr(err.message);
157
+ return [{
158
+ contract: sourceFile,
159
+ artifact: `No ${isStorageKind(exprKind) ? 'storages' : 'parameters'} compiled`,
160
+ }];
161
+ })
162
+ .then(mergeArtifactsOutput(sourceFile));
163
+
164
+ const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string) => {
165
+ const contractCompileResult = await compileContract(parsedArgs, sourceFile);
166
+ if (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];
167
+
168
+ const storagesFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;
169
+ const parametersFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;
170
+ const storagesFilename = getInputFilename(parsedArgs, storagesFile);
171
+ const parametersFilename = getInputFilename(parsedArgs, parametersFile);
172
+
173
+ const storageCompileResult = await access(storagesFilename)
174
+ .then(() => compileExprs(parsedArgs, storagesFile, 'storage'))
175
+ .catch(() => {
176
+ // sendWarn(
177
+ // `Note: storage file associated with "${sourceFile}" can't be found. You should create a file "${storagesFile}" and define initial storage values as a list of LIGO variable definitions. e.g. "let STORAGE_NAME: storage = LIGO_EXPR" for CameLigo`,
178
+ // )
179
+ });
180
+
181
+ const parameterCompileResult = await access(parametersFilename)
182
+ .then(() => compileExprs(parsedArgs, parametersFile, 'parameter'))
183
+ .catch(() => {
184
+ // sendWarn(
185
+ // `Note: parameter file associated with "${sourceFile}" can't be found. You should create a file "${parametersFile}" and define parameter values as a list of LIGO variable definitions. e.g. "let PARAMETER_NAME: parameter = LIGO_EXPR" for CameLigo`,
186
+ // )
187
+ });
188
+
189
+ let compileResults: TableRow[] = [contractCompileResult];
190
+ if (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);
191
+ if (parameterCompileResult) compileResults = compileResults.concat(parameterCompileResult);
192
+ return compileResults;
193
+ };
194
+
195
+ /*
196
+ Compiling storage/parameter file amounts to compiling multiple expressions in that file,
197
+ resulting in multiple rows with the same file name but different artifact names.
198
+ This will merge these rows into one row with just one mention of the file name.
199
+ e.g.
200
+ ┌──────────────────────┬─────────────────────────────────────────────┐
201
+ │ Contract │ Artifact │
202
+ ├──────────────────────┼─────────────────────────────────────────────┤
203
+ │ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │
204
+ ├──────────────────────┼─────────────────────────────────────────────┤
205
+ │ hello.storages.mligo │ artifacts/hello.storage.storage2.tz │
206
+ └──────────────────────┴─────────────────────────────────────────────┘
207
+ versus
208
+ ┌──────────────────────┬─────────────────────────────────────────────┐
209
+ │ Contract │ Artifact │
210
+ ├──────────────────────┼─────────────────────────────────────────────┤
211
+ │ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │
212
+ │ │ artifacts/hello.storage.storage2.tz │
213
+ └──────────────────────┴─────────────────────────────────────────────┘
214
+ */
215
+ const mergeArtifactsOutput = (sourceFile: string) =>
216
+ (tableRows: TableRow[]): TableRow[] => {
217
+ const artifactsOutput = tableRows.reduce(
218
+ (acc: string, row: TableRow) => row.artifact === COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}\n`,
219
+ '',
220
+ );
221
+ return [{
222
+ contract: sourceFile,
223
+ artifact: artifactsOutput,
224
+ }];
225
+ };
79
226
 
80
- return p
81
- .then(sendJsonRes)
82
- .catch(err => sendAsyncErr(err, false));
227
+ export const compile = (parsedArgs: Opts): Promise<void> => {
228
+ const sourceFile = parsedArgs.sourceFile;
229
+ if (!sourceFile) return sendAsyncErr('No source file specified.');
230
+ let p: Promise<TableRow[]>;
231
+ if (isStoragesFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'storage');
232
+ else if (isParametersFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'parameter');
233
+ else if (isContractFile(sourceFile)) p = compileContractWithStorageAndParameter(parsedArgs, sourceFile);
234
+ else {
235
+ return sendAsyncErr(
236
+ `${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`,
237
+ );
238
+ }
239
+ return p.then(sendJsonRes).catch(err => sendAsyncErr(err, false));
83
240
  };
84
241
 
85
242
  export default compile;
package/index.js CHANGED
@@ -1,56 +1,6 @@
1
1
  var $kQNfl$taquerianodesdk = require("@taqueria/node-sdk");
2
- var $kQNfl$path = require("path");
3
2
  var $kQNfl$fspromises = require("fs/promises");
4
-
5
-
6
-
7
-
8
- const $24b2f47d8f306cb3$var$getContractArtifactFilename = (opts)=>(sourceFile)=>{
9
- const outFile = (0, $kQNfl$path.basename)(sourceFile, (0, $kQNfl$path.extname)(sourceFile));
10
- return (0, $kQNfl$path.join)(opts.config.artifactsDir, `${outFile}.tz`);
11
- };
12
- const $24b2f47d8f306cb3$var$getInputFilename = (opts)=>(sourceFile)=>{
13
- return (0, $kQNfl$path.join)(opts.config.contractsDir, sourceFile);
14
- };
15
- const $24b2f47d8f306cb3$var$getCompileCommand = (opts)=>(sourceFile)=>{
16
- const projectDir = process.env.PROJECT_DIR ?? opts.projectDir;
17
- if (!projectDir) throw `No project directory provided`;
18
- const inputFile = $24b2f47d8f306cb3$var$getInputFilename(opts)(sourceFile);
19
- const baseCommand = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract ${inputFile}`;
20
- const entryPoint = opts.entrypoint ? `-e ${opts.entrypoint}` : "";
21
- const syntax = opts["syntax"] ? `-s ${opts["syntax"]} : ""` : "";
22
- const outFile = `-o ${$24b2f47d8f306cb3$var$getContractArtifactFilename(opts)(sourceFile)}`;
23
- const cmd = `${baseCommand} ${entryPoint} ${syntax} ${outFile}`;
24
- return cmd;
25
- };
26
- const $24b2f47d8f306cb3$var$compileContract = (opts)=>(sourceFile)=>(0, $kQNfl$taquerianodesdk.getArch)().then(()=>$24b2f47d8f306cb3$var$getCompileCommand(opts)(sourceFile)).then((0, $kQNfl$taquerianodesdk.execCmd)).then(({ stderr: stderr })=>{
27
- if (stderr.length > 0) (0, $kQNfl$taquerianodesdk.sendErr)(stderr);
28
- return {
29
- contract: sourceFile,
30
- artifact: $24b2f47d8f306cb3$var$getContractArtifactFilename(opts)(sourceFile)
31
- };
32
- }).catch((err)=>{
33
- (0, $kQNfl$taquerianodesdk.sendErr)(" ");
34
- (0, $kQNfl$taquerianodesdk.sendErr)(err.message.split("\n").slice(1).join("\n"));
35
- return Promise.resolve({
36
- contract: sourceFile,
37
- artifact: "Not compiled"
38
- });
39
- });
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));
44
- const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
45
- const p = parsedArgs.sourceFile ? $24b2f47d8f306cb3$var$compileContract(parsedArgs)(parsedArgs.sourceFile).then((result)=>[
46
- result
47
- ]) : $24b2f47d8f306cb3$var$compileAll(parsedArgs).then((results)=>{
48
- if (results.length === 0) (0, $kQNfl$taquerianodesdk.sendErr)('No contracts found to compile. Have you run "taq add-contract [sourceFile]" ?');
49
- return results;
50
- });
51
- return p.then((0, $kQNfl$taquerianodesdk.sendJsonRes)).catch((err)=>(0, $kQNfl$taquerianodesdk.sendAsyncErr)(err, false));
52
- };
53
- var $24b2f47d8f306cb3$export$2e2bcd8739ae039 = $24b2f47d8f306cb3$export$ef7acd7185315e22;
3
+ var $kQNfl$path = require("path");
54
4
 
55
5
 
56
6
 
@@ -190,6 +140,195 @@ const $40622e3a438d0515$var$createContract = (arg)=>{
190
140
  var $40622e3a438d0515$export$2e2bcd8739ae039 = $40622e3a438d0515$var$createContract;
191
141
 
192
142
 
143
+
144
+
145
+
146
+
147
+ const $24b2f47d8f306cb3$var$COMPILE_ERR_MSG = "Not compiled";
148
+ const $24b2f47d8f306cb3$var$isStorageKind = (exprKind)=>exprKind === "storage" || exprKind === "default_storage";
149
+ const $24b2f47d8f306cb3$var$isLIGOFile = (sourceFile)=>/.+\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
150
+ const $24b2f47d8f306cb3$var$isStoragesFile = (sourceFile)=>/.+\.storages\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
151
+ const $24b2f47d8f306cb3$var$isParametersFile = (sourceFile)=>/.+\.parameters\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
152
+ const $24b2f47d8f306cb3$var$isContractFile = (sourceFile)=>$24b2f47d8f306cb3$var$isLIGOFile(sourceFile) && !$24b2f47d8f306cb3$var$isStoragesFile(sourceFile) && !$24b2f47d8f306cb3$var$isParametersFile(sourceFile);
153
+ const $24b2f47d8f306cb3$var$extractExt = (path)=>{
154
+ const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
155
+ return matchResult ? matchResult[0] : "";
156
+ };
157
+ const $24b2f47d8f306cb3$var$removeExt = (path)=>{
158
+ const extRegex = new RegExp($24b2f47d8f306cb3$var$extractExt(path));
159
+ return path.replace(extRegex, "");
160
+ };
161
+ const $24b2f47d8f306cb3$var$getInputFilename = (parsedArgs, sourceFile)=>(0, $kQNfl$path.join)(parsedArgs.config.contractsDir, sourceFile);
162
+ const $24b2f47d8f306cb3$var$getOutputFilename = (parsedArgs, sourceFile)=>{
163
+ const outputFile = (0, $kQNfl$path.basename)(sourceFile, (0, $kQNfl$path.extname)(sourceFile));
164
+ return (0, $kQNfl$path.join)(parsedArgs.config.artifactsDir, `${outputFile}.tz`);
165
+ };
166
+ // Get the contract name that the storage/parameter file is associated with
167
+ // e.g. If sourceFile is token.storages.mligo, then it'll return token.mligo
168
+ const $24b2f47d8f306cb3$var$getContractNameForExpr = (sourceFile, exprKind)=>{
169
+ try {
170
+ return $24b2f47d8f306cb3$var$isStorageKind(exprKind) ? sourceFile.match(/.+(?=\.storages\.(ligo|religo|mligo|jsligo))/).join(".") : sourceFile.match(/.+(?=\.parameters\.(ligo|religo|mligo|jsligo))/).join(".");
171
+ } catch (err) {
172
+ throw new Error(`Something went wrong internally when dealing with filename format: ${err}`);
173
+ }
174
+ };
175
+ // If sourceFile is token.storages.mligo, then it'll return token.storage.{storageName}.tz
176
+ const $24b2f47d8f306cb3$var$getOutputExprFileName = (parsedArgs, sourceFile, exprKind, exprName)=>{
177
+ const contractName = (0, $kQNfl$path.basename)($24b2f47d8f306cb3$var$getContractNameForExpr(sourceFile, exprKind), (0, $kQNfl$path.extname)(sourceFile));
178
+ const outputFile = exprKind === "default_storage" ? `${contractName}.default_storage.tz` : `${contractName}.${exprKind}.${exprName}.tz`;
179
+ return (0, $kQNfl$path.join)(parsedArgs.config.artifactsDir, `${outputFile}`);
180
+ };
181
+ const $24b2f47d8f306cb3$var$getCompileContractCmd = (parsedArgs, sourceFile)=>{
182
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
183
+ if (!projectDir) throw `No project directory provided`;
184
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract`;
185
+ const inputFile = $24b2f47d8f306cb3$var$getInputFilename(parsedArgs, sourceFile);
186
+ const outputFile = `-o ${$24b2f47d8f306cb3$var$getOutputFilename(parsedArgs, sourceFile)}`;
187
+ const cmd = `${baseCmd} ${inputFile} ${outputFile}`;
188
+ return cmd;
189
+ };
190
+ const $24b2f47d8f306cb3$var$getCompileExprCmd = (parsedArgs, sourceFile, exprKind, exprName)=>{
191
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
192
+ if (!projectDir) throw `No project directory provided`;
193
+ const compilerType = $24b2f47d8f306cb3$var$isStorageKind(exprKind) ? "storage" : "parameter";
194
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile ${compilerType}`;
195
+ const inputFile = $24b2f47d8f306cb3$var$getInputFilename(parsedArgs, sourceFile);
196
+ const outputFile = `-o ${$24b2f47d8f306cb3$var$getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)}`;
197
+ const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile}`;
198
+ return cmd;
199
+ };
200
+ const $24b2f47d8f306cb3$var$compileContract = (parsedArgs, sourceFile)=>(0, $kQNfl$taquerianodesdk.getArch)().then(()=>$24b2f47d8f306cb3$var$getCompileContractCmd(parsedArgs, sourceFile)).then((0, $kQNfl$taquerianodesdk.execCmd)).then(({ stderr: stderr })=>{
201
+ if (stderr.length > 0) (0, $kQNfl$taquerianodesdk.sendWarn)(stderr);
202
+ return {
203
+ contract: sourceFile,
204
+ artifact: $24b2f47d8f306cb3$var$getOutputFilename(parsedArgs, sourceFile)
205
+ };
206
+ }).catch((err)=>{
207
+ (0, $kQNfl$taquerianodesdk.sendErr)(`\n=== For ${sourceFile} ===`);
208
+ (0, $kQNfl$taquerianodesdk.sendErr)(err.message.replace(/Command failed.+?\n/, ""));
209
+ return {
210
+ contract: sourceFile,
211
+ artifact: $24b2f47d8f306cb3$var$COMPILE_ERR_MSG
212
+ };
213
+ });
214
+ const $24b2f47d8f306cb3$var$compileExpr = (parsedArgs, sourceFile, exprKind)=>(exprName)=>(0, $kQNfl$taquerianodesdk.getArch)().then(()=>$24b2f47d8f306cb3$var$getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName)).then((0, $kQNfl$taquerianodesdk.execCmd)).then(({ stderr: stderr })=>{
215
+ if (stderr.length > 0) (0, $kQNfl$taquerianodesdk.sendWarn)(stderr);
216
+ return {
217
+ contract: sourceFile,
218
+ artifact: $24b2f47d8f306cb3$var$getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)
219
+ };
220
+ }).catch((err)=>{
221
+ (0, $kQNfl$taquerianodesdk.sendErr)(`\n=== For ${sourceFile} ===`);
222
+ (0, $kQNfl$taquerianodesdk.sendErr)(err.message.replace(/Command failed.+?\n/, ""));
223
+ return {
224
+ contract: sourceFile,
225
+ artifact: $24b2f47d8f306cb3$var$COMPILE_ERR_MSG
226
+ };
227
+ });
228
+ const $24b2f47d8f306cb3$var$compileExprs = (parsedArgs, sourceFile, exprKind)=>(0, $kQNfl$fspromises.readFile)($24b2f47d8f306cb3$var$getInputFilename(parsedArgs, sourceFile), "utf8").then((data)=>{
229
+ if (!data.includes("#include")) (0, $kQNfl$fspromises.writeFile)($24b2f47d8f306cb3$var$getInputFilename(parsedArgs, sourceFile), `#include "${$24b2f47d8f306cb3$var$getContractNameForExpr(sourceFile, exprKind)}"\n` + data, "utf8");
230
+ return data;
231
+ }).then((data)=>data.match(/(?<=\s*(let|const)\s+)[a-zA-Z0-9_]+/g)).then((exprNames)=>{
232
+ if (!exprNames) return [];
233
+ const firstExprName = exprNames.slice(0, 1)[0];
234
+ const restExprNames = exprNames.slice(1, exprNames.length);
235
+ const firstExprKind = $24b2f47d8f306cb3$var$isStorageKind(exprKind) ? "default_storage" : "parameter";
236
+ const restExprKind = $24b2f47d8f306cb3$var$isStorageKind(exprKind) ? "storage" : "parameter";
237
+ const firstExprResult = $24b2f47d8f306cb3$var$compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);
238
+ const restExprResults = restExprNames.map($24b2f47d8f306cb3$var$compileExpr(parsedArgs, sourceFile, restExprKind));
239
+ return Promise.all([
240
+ firstExprResult
241
+ ].concat(restExprResults));
242
+ }).catch((err)=>{
243
+ (0, $kQNfl$taquerianodesdk.sendErr)(`\n=== For ${sourceFile} ===`);
244
+ (0, $kQNfl$taquerianodesdk.sendErr)(err.message);
245
+ return [
246
+ {
247
+ contract: sourceFile,
248
+ artifact: `No ${$24b2f47d8f306cb3$var$isStorageKind(exprKind) ? "storages" : "parameters"} compiled`
249
+ }
250
+ ];
251
+ }).then($24b2f47d8f306cb3$var$mergeArtifactsOutput(sourceFile));
252
+ const $24b2f47d8f306cb3$var$compileContractWithStorageAndParameter = async (parsedArgs, sourceFile)=>{
253
+ const contractCompileResult = await $24b2f47d8f306cb3$var$compileContract(parsedArgs, sourceFile);
254
+ if (contractCompileResult.artifact === $24b2f47d8f306cb3$var$COMPILE_ERR_MSG) return [
255
+ contractCompileResult
256
+ ];
257
+ const storagesFile = `${$24b2f47d8f306cb3$var$removeExt(sourceFile)}.storages${$24b2f47d8f306cb3$var$extractExt(sourceFile)}`;
258
+ const parametersFile = `${$24b2f47d8f306cb3$var$removeExt(sourceFile)}.parameters${$24b2f47d8f306cb3$var$extractExt(sourceFile)}`;
259
+ const storagesFilename = $24b2f47d8f306cb3$var$getInputFilename(parsedArgs, storagesFile);
260
+ const parametersFilename = $24b2f47d8f306cb3$var$getInputFilename(parsedArgs, parametersFile);
261
+ const storageCompileResult = await (0, $kQNfl$fspromises.access)(storagesFilename).then(()=>$24b2f47d8f306cb3$var$compileExprs(parsedArgs, storagesFile, "storage")).catch(()=>{
262
+ // sendWarn(
263
+ // `Note: storage file associated with "${sourceFile}" can't be found. You should create a file "${storagesFile}" and define initial storage values as a list of LIGO variable definitions. e.g. "let STORAGE_NAME: storage = LIGO_EXPR" for CameLigo`,
264
+ // )
265
+ });
266
+ const parameterCompileResult = await (0, $kQNfl$fspromises.access)(parametersFilename).then(()=>$24b2f47d8f306cb3$var$compileExprs(parsedArgs, parametersFile, "parameter")).catch(()=>{
267
+ // sendWarn(
268
+ // `Note: parameter file associated with "${sourceFile}" can't be found. You should create a file "${parametersFile}" and define parameter values as a list of LIGO variable definitions. e.g. "let PARAMETER_NAME: parameter = LIGO_EXPR" for CameLigo`,
269
+ // )
270
+ });
271
+ let compileResults = [
272
+ contractCompileResult
273
+ ];
274
+ if (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);
275
+ if (parameterCompileResult) compileResults = compileResults.concat(parameterCompileResult);
276
+ return compileResults;
277
+ };
278
+ /*
279
+ Compiling storage/parameter file amounts to compiling multiple expressions in that file,
280
+ resulting in multiple rows with the same file name but different artifact names.
281
+ This will merge these rows into one row with just one mention of the file name.
282
+ e.g.
283
+ ┌──────────────────────┬─────────────────────────────────────────────┐
284
+ │ Contract │ Artifact │
285
+ ├──────────────────────┼─────────────────────────────────────────────┤
286
+ │ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │
287
+ ├──────────────────────┼─────────────────────────────────────────────┤
288
+ │ hello.storages.mligo │ artifacts/hello.storage.storage2.tz │
289
+ └──────────────────────┴─────────────────────────────────────────────┘
290
+ versus
291
+ ┌──────────────────────┬─────────────────────────────────────────────┐
292
+ │ Contract │ Artifact │
293
+ ├──────────────────────┼─────────────────────────────────────────────┤
294
+ │ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │
295
+ │ │ artifacts/hello.storage.storage2.tz │
296
+ └──────────────────────┴─────────────────────────────────────────────┘
297
+ */ const $24b2f47d8f306cb3$var$mergeArtifactsOutput = (sourceFile)=>(tableRows)=>{
298
+ const artifactsOutput = tableRows.reduce((acc, row)=>row.artifact === $24b2f47d8f306cb3$var$COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}\n`, "");
299
+ return [
300
+ {
301
+ contract: sourceFile,
302
+ artifact: artifactsOutput
303
+ }
304
+ ];
305
+ };
306
+ const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
307
+ const sourceFile = parsedArgs.sourceFile;
308
+ if (!sourceFile) return (0, $kQNfl$taquerianodesdk.sendAsyncErr)("No source file specified.");
309
+ let p;
310
+ if ($24b2f47d8f306cb3$var$isStoragesFile(sourceFile)) p = $24b2f47d8f306cb3$var$compileExprs(parsedArgs, sourceFile, "storage");
311
+ else if ($24b2f47d8f306cb3$var$isParametersFile(sourceFile)) p = $24b2f47d8f306cb3$var$compileExprs(parsedArgs, sourceFile, "parameter");
312
+ else if ($24b2f47d8f306cb3$var$isContractFile(sourceFile)) p = $24b2f47d8f306cb3$var$compileContractWithStorageAndParameter(parsedArgs, sourceFile);
313
+ else return (0, $kQNfl$taquerianodesdk.sendAsyncErr)(`${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`);
314
+ return p.then((0, $kQNfl$taquerianodesdk.sendJsonRes)).catch((err)=>(0, $kQNfl$taquerianodesdk.sendAsyncErr)(err, false));
315
+ };
316
+ var $24b2f47d8f306cb3$export$2e2bcd8739ae039 = $24b2f47d8f306cb3$export$ef7acd7185315e22;
317
+
318
+
319
+ const $0be740342372c80a$export$e476ec665a77580b = (parsedArgs)=>{
320
+ switch(parsedArgs.task){
321
+ case "compile":
322
+ return (0, $24b2f47d8f306cb3$export$2e2bcd8739ae039)(parsedArgs);
323
+ // case 'test':
324
+ // return test(parsedArgs); // TODO: to be implemented in the future
325
+ default:
326
+ return (0, $kQNfl$taquerianodesdk.sendAsyncErr)(`${parsedArgs.task} is not an understood task by the LIGO plugin`);
327
+ }
328
+ };
329
+ var $0be740342372c80a$export$2e2bcd8739ae039 = $0be740342372c80a$export$e476ec665a77580b;
330
+
331
+
193
332
  (0, $kQNfl$taquerianodesdk.Plugin).create((i18n)=>({
194
333
  schema: "1.0",
195
334
  version: "0.1",
@@ -197,29 +336,12 @@ var $40622e3a438d0515$export$2e2bcd8739ae039 = $40622e3a438d0515$var$createContr
197
336
  tasks: [
198
337
  (0, $kQNfl$taquerianodesdk.Task).create({
199
338
  task: "compile",
200
- command: "compile [sourceFile]",
339
+ command: "compile <sourceFile>",
201
340
  aliases: [
202
341
  "c",
203
342
  "compile-ligo"
204
343
  ],
205
- description: "Compile a smart contract written in a Ligo syntax to Michelson code",
206
- options: [
207
- (0, $kQNfl$taquerianodesdk.Option).create({
208
- shortFlag: "e",
209
- flag: "entrypoint",
210
- description: "The entry point that will be compiled"
211
- }),
212
- (0, $kQNfl$taquerianodesdk.Option).create({
213
- shortFlag: "s",
214
- flag: "syntax",
215
- description: "The syntax used in the contract"
216
- }),
217
- (0, $kQNfl$taquerianodesdk.Option).create({
218
- shortFlag: "i",
219
- flag: "infer",
220
- description: "Enable type inference"
221
- }),
222
- ],
344
+ description: "Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found",
223
345
  handler: "proxy",
224
346
  encoding: "json"
225
347
  }),
@@ -247,7 +369,7 @@ var $40622e3a438d0515$export$2e2bcd8739ae039 = $40622e3a438d0515$var$createContr
247
369
  handler: (0, $40622e3a438d0515$export$2e2bcd8739ae039)
248
370
  }),
249
371
  ],
250
- proxy: (0, $24b2f47d8f306cb3$export$2e2bcd8739ae039)
372
+ proxy: (0, $0be740342372c80a$export$2e2bcd8739ae039)
251
373
  }), process.argv);
252
374
 
253
375
 
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;ACAA;;AAUA,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,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,AAAC;QAE9D,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,6BAA6B,CAAC,CAAC;QAEvD,MAAM,SAAS,GAAG,sCAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,AAAC;QACrD,MAAM,WAAW,GAChB,CAAC,yDAAyD,EAAE,UAAU,CAAC,iFAAiF,EAAE,SAAS,CAAC,CAAC,AAAC;QACvK,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,AAAC;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC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AM,CAAA,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,GAAG;wBACd,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,iCAAiC;qBAC9C,CAAC;oBACF,CAAA,GAAA,6BAAM,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":"../"}
1
+ {"mappings":";;;;AAAA;ACAA;;ACAO,MAAM,yCAAc,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAwB/B,CAAC,AAAC;AAEK,MAAM,yCAAkB,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BnC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;;;ADlGF,MAAM,sCAAgB,GAAG,CAAC,GAAS,EAAE,YAAoB,GAAK;IAC7D,CAAA,GAAA,mCAAY,CAAA,CAAC,gBAAgB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;CACjD,AAAC;AAEF,MAAM,qCAAe,GAAG,OAAO,YAAoB,EAAE,MAA0B,GAAsB;I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AC7B,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,wCAAI,CAAA;KACX,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-ligo/index.ts","taqueria-plugin-ligo/createContract.ts","taqueria-plugin-ligo/ligo_templates.ts","taqueria-plugin-ligo/ligo.ts","taqueria-plugin-ligo/compile.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport createContract from './createContract';\nimport ligo from './ligo';\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:\n\t\t\t\t'Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found',\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: ligo,\n}), process.argv);\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","import { sendAsyncErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport compile from './compile';\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\tsourceFile: string;\n}\n\nexport const ligo = (parsedArgs: Opts): Promise<void> => {\n\tswitch (parsedArgs.task) {\n\t\tcase 'compile':\n\t\t\treturn compile(parsedArgs);\n\t\t// case 'test':\n\t\t// \treturn test(parsedArgs); // TODO: to be implemented in the future\n\t\tdefault:\n\t\t\treturn sendAsyncErr(`${parsedArgs.task} is not an understood task by the LIGO plugin`);\n\t}\n};\n\nexport default ligo;\n","import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { access, readFile, writeFile } from 'fs/promises';\nimport { basename, extname, join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFile: string;\n}\n\ntype TableRow = { contract: string; artifact: string };\n\ntype ExprKind = 'storage' | 'default_storage' | 'parameter';\n\nconst COMPILE_ERR_MSG: string = 'Not compiled';\n\nconst isStorageKind = (exprKind: ExprKind): boolean => exprKind === 'storage' || exprKind === 'default_storage';\n\nconst isLIGOFile = (sourceFile: string): boolean => /.+\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isStoragesFile = (sourceFile: string): boolean => /.+\\.storages\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isParametersFile = (sourceFile: string): boolean =>\n\t/.+\\.parameters\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isContractFile = (sourceFile: string): boolean =>\n\tisLIGOFile(sourceFile) && !isStoragesFile(sourceFile) && !isParametersFile(sourceFile);\n\nconst extractExt = (path: string): string => {\n\tconst matchResult = path.match(/\\.(ligo|religo|mligo|jsligo)$/);\n\treturn matchResult ? matchResult[0] : '';\n};\n\nconst removeExt = (path: string): string => {\n\tconst extRegex = new RegExp(extractExt(path));\n\treturn path.replace(extRegex, '');\n};\n\nconst getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.contractsDir, sourceFile);\n\nconst getOutputFilename = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}.tz`);\n};\n\n// Get the contract name that the storage/parameter file is associated with\n// e.g. If sourceFile is token.storages.mligo, then it'll return token.mligo\nconst getContractNameForExpr = (sourceFile: string, exprKind: ExprKind): string => {\n\ttry {\n\t\treturn isStorageKind(exprKind)\n\t\t\t? sourceFile.match(/.+(?=\\.storages\\.(ligo|religo|mligo|jsligo))/)!.join('.')\n\t\t\t: sourceFile.match(/.+(?=\\.parameters\\.(ligo|religo|mligo|jsligo))/)!.join('.');\n\t} catch (err) {\n\t\tthrow new Error(`Something went wrong internally when dealing with filename format: ${err}`);\n\t}\n};\n\n// If sourceFile is token.storages.mligo, then it'll return token.storage.{storageName}.tz\nconst getOutputExprFileName = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst contractName = basename(getContractNameForExpr(sourceFile, exprKind), extname(sourceFile));\n\tconst outputFile = exprKind === 'default_storage'\n\t\t? `${contractName}.default_storage.tz`\n\t\t: `${contractName}.${exprKind}.${exprName}.tz`;\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}`);\n};\n\nconst getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst baseCmd =\n\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`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputFilename(parsedArgs, sourceFile)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${outputFile}`;\n\treturn cmd;\n};\n\nconst getCompileExprCmd = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile ${compilerType}`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile}`;\n\treturn cmd;\n};\n\nconst compileContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => getCompileContractCmd(parsedArgs, sourceFile))\n\t\t.then(execCmd)\n\t\t.then(({ stderr }) => {\n\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: getOutputFilename(parsedArgs, sourceFile),\n\t\t\t};\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t};\n\t\t});\n\nconst compileExpr = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind) =>\n\t(exprName: string): Promise<TableRow> =>\n\t\tgetArch()\n\t\t\t.then(() => getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName))\n\t\t\t.then(execCmd)\n\t\t\t.then(({ stderr }) => {\n\t\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t\t};\n\t\t\t});\n\nconst compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind): Promise<TableRow[]> =>\n\treadFile(getInputFilename(parsedArgs, sourceFile), 'utf8')\n\t\t.then(data => {\n\t\t\tif (!data.includes('#include')) {\n\t\t\t\twriteFile(\n\t\t\t\t\tgetInputFilename(parsedArgs, sourceFile),\n\t\t\t\t\t`#include \"${getContractNameForExpr(sourceFile, exprKind)}\"\\n` + data,\n\t\t\t\t\t'utf8',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn data;\n\t\t})\n\t\t.then(data => data.match(/(?<=\\s*(let|const)\\s+)[a-zA-Z0-9_]+/g))\n\t\t.then(exprNames => {\n\t\t\tif (!exprNames) return [];\n\t\t\tconst firstExprName = exprNames.slice(0, 1)[0];\n\t\t\tconst restExprNames = exprNames.slice(1, exprNames.length);\n\t\t\tconst firstExprKind = isStorageKind(exprKind) ? 'default_storage' : 'parameter';\n\t\t\tconst restExprKind = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\t\t\tconst firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);\n\t\t\tconst restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));\n\t\t\treturn Promise.all([firstExprResult].concat(restExprResults));\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message);\n\t\t\treturn [{\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: `No ${isStorageKind(exprKind) ? 'storages' : 'parameters'} compiled`,\n\t\t\t}];\n\t\t})\n\t\t.then(mergeArtifactsOutput(sourceFile));\n\nconst compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string) => {\n\tconst contractCompileResult = await compileContract(parsedArgs, sourceFile);\n\tif (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];\n\n\tconst storagesFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;\n\tconst parametersFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;\n\tconst storagesFilename = getInputFilename(parsedArgs, storagesFile);\n\tconst parametersFilename = getInputFilename(parsedArgs, parametersFile);\n\n\tconst storageCompileResult = await access(storagesFilename)\n\t\t.then(() => compileExprs(parsedArgs, storagesFile, 'storage'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: storage file associated with \"${sourceFile}\" can't be found. You should create a file \"${storagesFile}\" and define initial storage values as a list of LIGO variable definitions. e.g. \"let STORAGE_NAME: storage = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tconst parameterCompileResult = await access(parametersFilename)\n\t\t.then(() => compileExprs(parsedArgs, parametersFile, 'parameter'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: parameter file associated with \"${sourceFile}\" can't be found. You should create a file \"${parametersFile}\" and define parameter values as a list of LIGO variable definitions. e.g. \"let PARAMETER_NAME: parameter = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tlet compileResults: TableRow[] = [contractCompileResult];\n\tif (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);\n\tif (parameterCompileResult) compileResults = compileResults.concat(parameterCompileResult);\n\treturn compileResults;\n};\n\n/*\nCompiling storage/parameter file amounts to compiling multiple expressions in that file,\nresulting in multiple rows with the same file name but different artifact names.\nThis will merge these rows into one row with just one mention of the file name.\ne.g.\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n\t\t\t\t\t\t\t\tversus\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n│ │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n*/\nconst mergeArtifactsOutput = (sourceFile: string) =>\n\t(tableRows: TableRow[]): TableRow[] => {\n\t\tconst artifactsOutput = tableRows.reduce(\n\t\t\t(acc: string, row: TableRow) => row.artifact === COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}\\n`,\n\t\t\t'',\n\t\t);\n\t\treturn [{\n\t\t\tcontract: sourceFile,\n\t\t\tartifact: artifactsOutput,\n\t\t}];\n\t};\n\nexport const compile = (parsedArgs: Opts): Promise<void> => {\n\tconst sourceFile = parsedArgs.sourceFile;\n\tif (!sourceFile) return sendAsyncErr('No source file specified.');\n\tlet p: Promise<TableRow[]>;\n\tif (isStoragesFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'storage');\n\telse if (isParametersFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'parameter');\n\telse if (isContractFile(sourceFile)) p = compileContractWithStorageAndParameter(parsedArgs, sourceFile);\n\telse {\n\t\treturn sendAsyncErr(\n\t\t\t`${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`,\n\t\t);\n\t}\n\treturn p.then(sendJsonRes).catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';
2
- import compile from './compile';
3
2
  import createContract from './createContract';
3
+ import ligo from './ligo';
4
4
 
5
5
  Plugin.create(i18n => ({
6
6
  schema: '1.0',
@@ -9,26 +9,10 @@ Plugin.create(i18n => ({
9
9
  tasks: [
10
10
  Task.create({
11
11
  task: 'compile',
12
- command: 'compile [sourceFile]',
12
+ command: 'compile <sourceFile>',
13
13
  aliases: ['c', 'compile-ligo'],
14
- description: 'Compile a smart contract written in a Ligo syntax to Michelson code',
15
- options: [
16
- Option.create({
17
- shortFlag: 'e',
18
- flag: 'entrypoint',
19
- description: 'The entry point that will be compiled',
20
- }),
21
- Option.create({
22
- shortFlag: 's',
23
- flag: 'syntax',
24
- description: 'The syntax used in the contract',
25
- }),
26
- Option.create({
27
- shortFlag: 'i',
28
- flag: 'infer',
29
- description: 'Enable type inference',
30
- }),
31
- ],
14
+ description:
15
+ 'Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found',
32
16
  handler: 'proxy',
33
17
  encoding: 'json',
34
18
  }),
@@ -56,5 +40,5 @@ Plugin.create(i18n => ({
56
40
  handler: createContract,
57
41
  }),
58
42
  ],
59
- proxy: compile,
43
+ proxy: ligo,
60
44
  }), process.argv);
package/ligo.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { sendAsyncErr } from '@taqueria/node-sdk';
2
+ import { RequestArgs } from '@taqueria/node-sdk/types';
3
+ import compile from './compile';
4
+
5
+ interface Opts extends RequestArgs.ProxyRequestArgs {
6
+ sourceFile: string;
7
+ }
8
+
9
+ export const ligo = (parsedArgs: Opts): Promise<void> => {
10
+ switch (parsedArgs.task) {
11
+ case 'compile':
12
+ return compile(parsedArgs);
13
+ // case 'test':
14
+ // return test(parsedArgs); // TODO: to be implemented in the future
15
+ default:
16
+ return sendAsyncErr(`${parsedArgs.task} is not an understood task by the LIGO plugin`);
17
+ }
18
+ };
19
+
20
+ export default ligo;
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
1
  {
2
- "name": "@taqueria/plugin-ligo",
3
- "version": "0.12.0",
4
- "description": "A taqueria plugin for compiling LIGO smart contracts",
5
- "targets": {
6
- "default": {
7
- "source": "./index.ts",
8
- "distDir": "./",
9
- "context": "node",
10
- "isLibrary": true
11
- }
12
- },
13
- "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1",
15
- "build": "npx tsc -noEmit && npx parcel build --no-cache 2>&1",
16
- "pluginInfo": "npx ts-node index.ts --taqRun pluginInfo --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\",\"artifactsDir\": \"artifacts\"}' --projectDir ../test-project --configDir ./.taq",
17
- "compile": "npx ts-node index.ts --taqRun proxy --task compile --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\",\"artifactsDir\": \"artifacts\"}' --projectDir ../test-project --configDir ./.taq",
18
- "debugPluginInfo": "npx ts-node --inspect index.ts --taqRun pluginInfo --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\"}' --projectDir ../test-project --configDir ./.taq"
19
- },
20
- "keywords": [
21
- "taqueria",
22
- "tezos",
23
- "build",
24
- "ecad",
25
- "ecadlabs",
26
- "plugin",
27
- "ligo",
28
- "ligolang",
29
- "smart contract",
30
- "compile"
31
- ],
32
- "author": "ECAD Labs",
33
- "license": "Apache-2.0",
34
- "repository": {
35
- "type": "git",
36
- "url": "https://github.com/ecadlabs/taqueria.git",
37
- "directory": "taqueria-plugin-ligo"
38
- },
39
- "bugs": {
40
- "url": "https://github.com/ecadlabs/taqueria/issues"
41
- },
42
- "homepage": "https://github.com/ecadlabs/taqueria#readme",
43
- "dependencies": {
44
- "@taqueria/node-sdk": "^0.12.0",
45
- "fast-glob": "^3.2.11"
46
- },
47
- "devDependencies": {
48
- "parcel": "2.6.1",
49
- "typescript": "^4.7.2"
50
- }
2
+ "name": "@taqueria/plugin-ligo",
3
+ "version": "0.13.16",
4
+ "description": "A taqueria plugin for compiling LIGO smart contracts",
5
+ "targets": {
6
+ "default": {
7
+ "source": "./index.ts",
8
+ "distDir": "./",
9
+ "context": "node",
10
+ "isLibrary": true
11
+ }
12
+ },
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "build": "npx tsc -noEmit && npx parcel build --no-cache 2>&1",
16
+ "pluginInfo": "npx ts-node index.ts --taqRun pluginInfo --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\",\"artifactsDir\": \"artifacts\"}' --projectDir ../test-project --configDir ./.taq",
17
+ "compile": "npx ts-node index.ts --taqRun proxy --task compile --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\",\"artifactsDir\": \"artifacts\"}' --projectDir ../test-project --configDir ./.taq",
18
+ "debugPluginInfo": "npx ts-node --inspect index.ts --taqRun pluginInfo --i18n '{\"foo\":\"bar\"}' --config '{\"contractsDir\":\"contracts\",\"testsDir\": \"tests\"}' --projectDir ../test-project --configDir ./.taq"
19
+ },
20
+ "keywords": [
21
+ "taqueria",
22
+ "tezos",
23
+ "build",
24
+ "ecad",
25
+ "ecadlabs",
26
+ "plugin",
27
+ "ligo",
28
+ "ligolang",
29
+ "smart contract",
30
+ "compile"
31
+ ],
32
+ "author": "ECAD Labs",
33
+ "license": "Apache-2.0",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/ecadlabs/taqueria.git",
37
+ "directory": "taqueria-plugin-ligo"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/ecadlabs/taqueria/issues"
41
+ },
42
+ "homepage": "https://github.com/ecadlabs/taqueria#readme",
43
+ "dependencies": {
44
+ "@taqueria/node-sdk": "^0.13.16",
45
+ "fast-glob": "^3.2.11"
46
+ },
47
+ "devDependencies": {
48
+ "parcel": "2.6.1",
49
+ "typescript": "^4.7.2"
50
+ }
51
51
  }