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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@ The LIGO plugin provides tasks to work with LIGO smart contracts such as compili
4
4
 
5
5
  ## Requirements
6
6
 
7
- - Taqueria v0.24.2 or later
7
+ - Taqueria v0.26.0 or later
8
8
  - Node.js v16.17.1 or later
9
9
  - Docker v20.10.12 or later
10
10
 
@@ -55,6 +55,16 @@ Lastly, `taq compile hello.mligo` will compile `hello.mligo` and emit `hello.tz`
55
55
 
56
56
  The `--json` flag will make the task emit JSON-encoded Michelson instead of pure Michelson `.tz`
57
57
 
58
+ ## The `taq compile-all` Task
59
+
60
+ Basic usage is:
61
+
62
+ ```shell
63
+ taq compile-all
64
+ ```
65
+
66
+ It works just like the `compile` task but it compiles all main contracts, a.k.a contracts with a `main` function.
67
+
58
68
  ## The `taq test` Task
59
69
 
60
70
  Basic usage is:
package/_readme.eta CHANGED
@@ -6,7 +6,7 @@ The LIGO plugin provides tasks to work with LIGO smart contracts such as compili
6
6
 
7
7
  ## Requirements
8
8
 
9
- - Taqueria v0.24.2 or later
9
+ - Taqueria v0.26.0 or later
10
10
  - Node.js v16.17.1 or later
11
11
  - Docker v20.10.12 or later
12
12
 
@@ -60,6 +60,16 @@ Lastly, `taq compile hello.mligo` will compile `hello.mligo` and emit `hello.tz`
60
60
 
61
61
  The `--json` flag will make the task emit JSON-encoded Michelson instead of pure Michelson `.tz`
62
62
 
63
+ ## The `taq compile-all` Task
64
+
65
+ Basic usage is:
66
+
67
+ ```shell
68
+ taq compile-all
69
+ ```
70
+
71
+ It works just like the `compile` task but it compiles all main contracts, a.k.a contracts with a `main` function.
72
+
63
73
  ## The `taq test` Task
64
74
 
65
75
  Basic usage is:
package/common.ts CHANGED
@@ -11,23 +11,30 @@ export interface CompileOpts extends ProxyTaskArgs.t {
11
11
  json: boolean;
12
12
  }
13
13
 
14
+ export interface CompileAllOpts extends ProxyTaskArgs.t {
15
+ json: boolean;
16
+ }
17
+
14
18
  export interface TestOpts extends RequestArgs.t {
15
19
  task?: string;
16
20
  sourceFile?: string;
17
21
  }
18
22
 
19
- export type IntersectionOpts = LigoOpts & CompileOpts & TestOpts;
23
+ export type IntersectionOpts = LigoOpts & CompileOpts & CompileAllOpts & TestOpts;
20
24
 
21
- type UnionOpts = LigoOpts | CompileOpts | TestOpts;
25
+ type UnionOpts = LigoOpts | CompileOpts | CompileAllOpts | TestOpts;
22
26
 
23
27
  // Should point to the latest stable version, so it needs to be updated as part of our release process.
24
- const LIGO_DEFAULT_IMAGE = 'ligolang/ligo:0.54.1';
28
+ const LIGO_DEFAULT_IMAGE = 'ligolang/ligo:0.57.0';
25
29
 
26
30
  const LIGO_IMAGE_ENV_VAR = 'TAQ_LIGO_IMAGE';
27
31
 
28
32
  export const getLigoDockerImage = (): string => getDockerImage(LIGO_DEFAULT_IMAGE, LIGO_IMAGE_ENV_VAR);
29
33
 
30
- export const getInputFilename = (parsedArgs: UnionOpts, sourceFile: string): string =>
34
+ export const getInputFilenameAbsPath = (parsedArgs: UnionOpts, sourceFile: string): string =>
35
+ join(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? 'contracts', sourceFile);
36
+
37
+ export const getInputFilenameRelPath = (parsedArgs: UnionOpts, sourceFile: string): string =>
31
38
  join(parsedArgs.config.contractsDir ?? 'contracts', sourceFile);
32
39
 
33
40
  export const emitExternalError = (err: unknown, sourceFile: string): void => {
package/compile-all.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { sendErr, sendJsonRes } from '@taqueria/node-sdk';
2
+ import glob from 'fast-glob';
3
+ import { readFile } from 'fs/promises';
4
+ import { join } from 'path';
5
+ import { CompileAllOpts as Opts, CompileOpts, getInputFilenameAbsPath } from './common';
6
+ import { compileContractWithStorageAndParameter, TableRow } from './compile';
7
+
8
+ const isMainContract = (parsedArgs: Opts, contactFilename: string): Promise<boolean> =>
9
+ readFile(getInputFilenameAbsPath(parsedArgs, contactFilename), 'utf8')
10
+ .then(data => /(const|let|function)\s+main/.test(data));
11
+
12
+ const compileAll = async (parsedArgs: Opts): Promise<void> => {
13
+ let p: Promise<TableRow[]>[] = [];
14
+
15
+ const contractFilenames = await glob(
16
+ ['**/*.ligo', '**/*.religo', '**/*.mligo', '**/*.jsligo'],
17
+ { cwd: join(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? 'contracts'), absolute: false },
18
+ );
19
+
20
+ for (const filename of contractFilenames) {
21
+ if (await isMainContract(parsedArgs, filename)) {
22
+ p.push(compileContractWithStorageAndParameter(parsedArgs as CompileOpts, filename));
23
+ }
24
+ }
25
+
26
+ return Promise.all(p).then(tables => tables.flat()).then(sendJsonRes).catch(err => sendErr(err, false));
27
+ };
28
+
29
+ export default compileAll;
package/compile.ts CHANGED
@@ -1,11 +1,17 @@
1
- import { execCmd, getArch, getArtifactsDir, sendAsyncErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';
1
+ import { execCmd, getArch, getArtifactsDir, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';
2
2
  import { access, readFile, writeFile } from 'fs/promises';
3
3
  import { basename, extname, join } from 'path';
4
- import { CompileOpts as Opts, emitExternalError, getInputFilename, getLigoDockerImage } from './common';
4
+ import {
5
+ CompileOpts as Opts,
6
+ emitExternalError,
7
+ getInputFilenameAbsPath,
8
+ getInputFilenameRelPath,
9
+ getLigoDockerImage,
10
+ } from './common';
5
11
 
6
- type TableRow = { contract: string; artifact: string };
12
+ export type TableRow = { contract: string; artifact: string };
7
13
 
8
- type ExprKind = 'storage' | 'default_storage' | 'parameter';
14
+ export type ExprKind = 'storage' | 'default_storage' | 'parameter';
9
15
 
10
16
  const COMPILE_ERR_MSG: string = 'Not compiled';
11
17
 
@@ -67,7 +73,7 @@ const getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string =>
67
73
  if (!projectDir) throw `No project directory provided`;
68
74
  const baseCmd =
69
75
  `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
70
- const inputFile = getInputFilename(parsedArgs, sourceFile);
76
+ const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
71
77
  const outputFile = `-o ${getOutputContractFilename(parsedArgs, sourceFile)}`;
72
78
  const flags = isOutputFormatJSON(parsedArgs) ? ' --michelson-format json ' : '';
73
79
  const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}`;
@@ -80,7 +86,7 @@ const getCompileExprCmd = (parsedArgs: Opts, sourceFile: string, exprKind: ExprK
80
86
  const compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';
81
87
  const baseCmd =
82
88
  `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
83
- const inputFile = getInputFilename(parsedArgs, sourceFile);
89
+ const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
84
90
  const outputFile = `-o ${getOutputExprFilename(parsedArgs, sourceFile, exprKind, exprName)}`;
85
91
  const flags = isOutputFormatJSON(parsedArgs) ? ' --michelson-format json ' : '';
86
92
  const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile} ${flags}`;
@@ -127,7 +133,7 @@ const compileExpr = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind) =
127
133
  });
128
134
 
129
135
  const getExprNames = (parsedArgs: Opts, sourceFile: string): Promise<string[]> =>
130
- readFile(getInputFilename(parsedArgs, sourceFile), 'utf8')
136
+ readFile(getInputFilenameAbsPath(parsedArgs, sourceFile), 'utf8')
131
137
  .then(data => data.match(/(?<=\n\s*(let|const)\s+)[a-zA-Z0-9_]+/g) ?? []);
132
138
 
133
139
  const compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind): Promise<TableRow[]> =>
@@ -154,7 +160,7 @@ const compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind):
154
160
  // TODO: Just for backwards compatibility. Can be deleted in the future.
155
161
  const tryLegacyStorageNamingConvention = (parsedArgs: Opts, sourceFile: string) => {
156
162
  const storageListFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;
157
- const storageListFilename = getInputFilename(parsedArgs, storageListFile);
163
+ const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
158
164
  return access(storageListFilename).then(() => {
159
165
  sendWarn(
160
166
  `Warning: The naming convention of "<CONTRACT>.storages.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.storageList.<EXTENSION>". Please adjust your storage file names accordingly\n`,
@@ -166,7 +172,7 @@ const tryLegacyStorageNamingConvention = (parsedArgs: Opts, sourceFile: string)
166
172
  // TODO: Just for backwards compatibility. Can be deleted in the future.
167
173
  const tryLegacyParameterNamingConvention = (parsedArgs: Opts, sourceFile: string) => {
168
174
  const parameterListFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;
169
- const parameterListFilename = getInputFilename(parsedArgs, parameterListFile);
175
+ const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
170
176
  return access(parameterListFilename).then(() => {
171
177
  sendWarn(
172
178
  `Warning: The naming convention of "<CONTRACT>.parameters.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.parameterList.<EXTENSION>". Please adjust your parameter file names accordingly\n`,
@@ -206,13 +212,16 @@ const initContentForParameter = (sourceFile: string): string => {
206
212
  return linkToContract + instruction + syntax;
207
213
  };
208
214
 
209
- const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string): Promise<TableRow[]> => {
215
+ export const compileContractWithStorageAndParameter = async (
216
+ parsedArgs: Opts,
217
+ sourceFile: string,
218
+ ): Promise<TableRow[]> => {
210
219
  const contractCompileResult = await compileContract(parsedArgs, sourceFile);
211
220
  if (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];
212
221
 
213
222
  const storageListFile = `${removeExt(sourceFile)}.storageList${extractExt(sourceFile)}`;
214
- const storageListFilename = getInputFilename(parsedArgs, storageListFile);
215
- const storageCompileResult = await access(storageListFilename)
223
+ const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
224
+ const storageCompileResult = await (access(storageListFilename)
216
225
  .then(() => compileExprs(parsedArgs, storageListFile, 'storage'))
217
226
  .catch(() => tryLegacyStorageNamingConvention(parsedArgs, sourceFile))
218
227
  .catch(() => {
@@ -220,11 +229,11 @@ const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFi
220
229
  `Note: storage file associated with "${sourceFile}" can't be found, so "${storageListFile}" has been created for you. Use this file to define all initial storage values for this contract\n`,
221
230
  );
222
231
  writeFile(storageListFilename, initContentForStorage(sourceFile), 'utf8');
223
- });
232
+ }));
224
233
 
225
234
  const parameterListFile = `${removeExt(sourceFile)}.parameterList${extractExt(sourceFile)}`;
226
- const parameterListFilename = getInputFilename(parsedArgs, parameterListFile);
227
- const parameterCompileResult = await access(parameterListFilename)
235
+ const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
236
+ const parameterCompileResult = await (access(parameterListFilename)
228
237
  .then(() => compileExprs(parsedArgs, parameterListFile, 'parameter'))
229
238
  .catch(() => tryLegacyParameterNamingConvention(parsedArgs, sourceFile))
230
239
  .catch(() => {
@@ -232,7 +241,7 @@ const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFi
232
241
  `Note: parameter file associated with "${sourceFile}" can't be found, so "${parameterListFile}" has been created for you. Use this file to define all parameter values for this contract\n`,
233
242
  );
234
243
  writeFile(parameterListFilename, initContentForParameter(sourceFile), 'utf8');
235
- });
244
+ }));
236
245
 
237
246
  let compileResults: TableRow[] = [contractCompileResult];
238
247
  if (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);
@@ -283,7 +292,11 @@ const compile = (parsedArgs: Opts): Promise<void> => {
283
292
  `${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`,
284
293
  );
285
294
  }
286
- return p.then(sendJsonRes).catch(err => sendAsyncErr(err, false));
295
+ return p.then(sendJsonRes).catch(err => sendErr(err, false));
287
296
  };
288
297
 
289
298
  export default compile;
299
+ export const ___TEST___ = {
300
+ getContractNameForExpr,
301
+ getOutputExprFilename,
302
+ };
package/createContract.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { experimental, sendAsyncErr } from '@taqueria/node-sdk';
1
+ import { sendAsyncErr } from '@taqueria/node-sdk';
2
2
  import { RequestArgs } from '@taqueria/node-sdk';
3
3
  import { writeFile } from 'fs/promises';
4
4
  import { jsligo_template, mligo_template, pascaligo_template, religo_template } from './ligo_templates';
@@ -8,10 +8,6 @@ interface Opts extends RequestArgs.t {
8
8
  syntax?: string;
9
9
  }
10
10
 
11
- const registerContract = (arg: Opts, contractName: string) => {
12
- experimental.registerContract(arg, contractName);
13
- };
14
-
15
11
  const getLigoTemplate = async (contractName: string, syntax: string | undefined): Promise<string> => {
16
12
  const matchResult = contractName.match(/\.[^.]+$/);
17
13
  const ext = matchResult ? matchResult[0].substring(1) : null;
@@ -40,8 +36,7 @@ const createContract = (args: RequestArgs.t) => {
40
36
  const syntax = unsafeOpts.syntax;
41
37
  const contractsDir = `${args.config.projectDir}/${args.config.contractsDir}`;
42
38
  return getLigoTemplate(contractName, syntax)
43
- .then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template))
44
- .then(_ => registerContract(unsafeOpts, contractName));
39
+ .then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template));
45
40
  };
46
41
 
47
42
  export default createContract;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+