@taqueria/plugin-smartpy-legacy 0.37.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Taqueria SmartPy Plugin
2
+
3
+ The SmartPy plugin provides tasks to work with SmartPy smart contracts written in the legacy syntax (up to SmartPy v0.16) such as compiling and testing.
4
+
5
+ ## Requirements
6
+
7
+ - Taqueria v0.26.0 or later
8
+ - Node.js v16.16 or later. (v17.x.x or later is not supported)
9
+ - Docker v20.10.12 or later
10
+ - Python 3 and pdoc
11
+
12
+ ## Installation
13
+
14
+ To install the SmartPy plugin on a Taqueria project, navigate to the project folder and run:
15
+
16
+ ```shell
17
+ taq install @taqueria/plugin-smartpy-legacy
18
+ ```
19
+
20
+ > ### :page_with_curl: Note
21
+ > To override the SmartPy version used by the plugin, create an environmental variable `TAQ_SMARTPY_VERSION` and set it appropriately, e.g. `v0.16.0`
22
+
23
+ ## The `taq compile` Task
24
+
25
+ Basic usage is:
26
+
27
+ ```shell
28
+ taq compile <contractName>
29
+ ```
30
+
31
+ > ### :warning: CAUTION
32
+ > The `compile` task is implemented by more than one compiler plugin (SmartPy, Archetype, SmartPy). If more than one of these plugins are installed on a project, you need to use the `--plugin smartpy` flag to specify a particular compiler
33
+
34
+ ### Basic description
35
+ The SmartPy plugin exposes a `compile` task in Taqueria which can target one SmartPy contract in the `contracts` folder and compile it to a Michelson `.tz` file output to the `artifacts` folder
36
+
37
+ ### A frictionless smart contract development workflow
38
+ We provide a smooth SmartPy workflow for our SmartPy plugin by making it easier to get started and maintain the contracts. You can get started by simply performing `taq compile my_contract.py` then `taq deploy my_contract.tz` (or `taq deploy my_contract.tz --env testing` to deploy to ghostnet) and now you've deployed a contract originally written in SmartPy
39
+
40
+ To benefit from this workflow, users will have to define all compilation and expression compilation targets in their main SmartPy contract file and the `compile` task will compile them all and copy the relevant artifacts (contract, storage, and expression files) to the `artifacts` folder. All other artifacts will be stored under `artifacts/.smartpy`
41
+
42
+ Compilation targets in SmartPy produce both the contract and its storage Michelson files. We will name them using the following naming convention: `<CONTRACT_NAME>.storage.<COMPILATION_TARGET_NAME>.tz`. But the first of these is special and will be called: `<CONTRACT_NAME>.default_storage.tz` (the `deploy` task of the Taquito plugin will deem this as the default initial storage value)
43
+
44
+ Expression compilation targets in SmartPy produce only the expression Michelson files (can be useful as parameter values used to invoke entrypoints with the `transfer` task of the Taquito plugin). We will name these generated `.tz` files using the following naming convention: `<CONTRACT_NAME>.expression.<COMPILATION_TARGET_NAME>.tz`
45
+
46
+ ### Options
47
+
48
+ The `--json` flag will make the task emit JSON-encoded Michelson instead of pure Michelson `.tz`
49
+
50
+ ## The `taq compile-all` Task
51
+
52
+ Basic usage is:
53
+
54
+ ```shell
55
+ taq compile-all
56
+ ```
57
+
58
+ It works just like the `compile` task but it compiles all contracts with at least one SmartPy compilation target.
59
+
60
+ ## The `taq test` Task
61
+
62
+ Basic usage is:
63
+
64
+ ```shell
65
+ taq test <fileName>
66
+ ```
67
+
68
+ ### Basic description
69
+ This task tests the SmartPy source code and reports either a failure or success
70
+
71
+ ## Plugin Architecture
72
+
73
+ This is a plugin developed for Taqueria built on NodeJS using the Taqueria Node SDK and distributed via NPM
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+
package/index.js ADDED
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
+ mod
19
+ ));
20
+
21
+ // index.ts
22
+ var import_node_sdk6 = require("@taqueria/node-sdk");
23
+
24
+ // main.ts
25
+ var import_node_sdk5 = require("@taqueria/node-sdk");
26
+
27
+ // compile.ts
28
+ var import_node_sdk2 = require("@taqueria/node-sdk");
29
+ var import_promises2 = require("fs/promises");
30
+ var import_path2 = require("path");
31
+
32
+ // common.ts
33
+ var import_node_sdk = require("@taqueria/node-sdk");
34
+ var import_promises = require("fs/promises");
35
+ var import_path = require("path");
36
+ var SMARTPY_DEFAULT_VERSION = "v0.16.0";
37
+ var SMARTPY_VERSION_ENV_VAR = "TAQ_SMARTPY_VERSION";
38
+ var SMARTPY_ARTIFACTS_DIR = ".smartpy";
39
+ var smartpyVersionToInstallerMap = {
40
+ "v0.16.0": "https://smartpy.io/releases/20221215-8f134ebb649f5a7b37c44fca8f336f970f523565/cli/install.sh"
41
+ };
42
+ var getSmartpyVersion = () => {
43
+ const userDefinedSmartpyVersion = process.env[SMARTPY_VERSION_ENV_VAR];
44
+ if (userDefinedSmartpyVersion) {
45
+ if (/v0\.1[4-6]\./.test(userDefinedSmartpyVersion)) {
46
+ return userDefinedSmartpyVersion;
47
+ } else {
48
+ (0, import_node_sdk.sendWarn)(
49
+ `Version ${userDefinedSmartpyVersion} is not supported by Taqueria yet. The supported versions are [${Object.keys(smartpyVersionToInstallerMap)}]. Will default to ${SMARTPY_DEFAULT_VERSION}`
50
+ );
51
+ return SMARTPY_DEFAULT_VERSION;
52
+ }
53
+ } else {
54
+ return SMARTPY_DEFAULT_VERSION;
55
+ }
56
+ };
57
+ var getPathToSmartPyCliDir = () => `${process.env.HOME}/smartpy-cli-${getSmartpyVersion()}`;
58
+ var getSmartPyCli = () => `${getPathToSmartPyCliDir()}/SmartPy.sh`;
59
+ var getSmartPyInstallerCmd = (projectDir) => {
60
+ const trimmedProjectdir = projectDir.replace(/\/$/, "");
61
+ const installer = (0, import_path.join)(__dirname, "install.sh");
62
+ const install = `bash ${installer} --yes --prefix ${getPathToSmartPyCliDir()} --project ${trimmedProjectdir};`;
63
+ return install;
64
+ };
65
+ var addPyExtensionIfMissing = (sourceFile) => /\.py$/.test(sourceFile) ? sourceFile : `${sourceFile}.py`;
66
+ var extractExt = (path) => {
67
+ const matchResult = path.match(/\.py$/);
68
+ return matchResult ? matchResult[0] : "";
69
+ };
70
+ var removeExt = (path) => {
71
+ const extRegex = new RegExp(extractExt(path));
72
+ return path.replace(extRegex, "");
73
+ };
74
+ var getInputFilename = (parsedArgs, sourceFile) => (0, import_path.join)(parsedArgs.config.projectDir, (0, import_node_sdk.getContractsDir)(parsedArgs), sourceFile);
75
+ var getCompilationTargetsDirname = (parsedArgs, sourceFile) => (0, import_path.join)(parsedArgs.config.projectDir, (0, import_node_sdk.getArtifactsDir)(parsedArgs), SMARTPY_ARTIFACTS_DIR, removeExt(sourceFile));
76
+ var installSmartPyCliIfNotExist = (projectDir) => (0, import_promises.access)(getSmartPyCli()).catch(() => {
77
+ (0, import_node_sdk.sendWarn)("SmartPy CLI not found. Installing it now...");
78
+ return (0, import_node_sdk.execCmd)(getSmartPyInstallerCmd(projectDir)).then(({ stderr }) => {
79
+ if (stderr.length > 0)
80
+ (0, import_node_sdk.sendWarn)(stderr);
81
+ });
82
+ });
83
+ var emitExternalError = (err, sourceFile) => {
84
+ (0, import_node_sdk.sendErr)(`
85
+ === Error messages for ${sourceFile} ===`);
86
+ err instanceof Error ? (0, import_node_sdk.sendErr)(err.message.replace(/Command failed.+?\n/, "")) : (0, import_node_sdk.sendErr)(err);
87
+ (0, import_node_sdk.sendErr)(`
88
+ ===`);
89
+ };
90
+
91
+ // compile.ts
92
+ var COMPILE_ERR_MSG = "Not compiled";
93
+ var isOutputFormatJSON = (parsedArgs) => parsedArgs.json;
94
+ var getOutputContractFilename = (parsedArgs, sourceFile) => {
95
+ const outputFile = (0, import_path2.basename)(sourceFile, (0, import_path2.extname)(sourceFile));
96
+ const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
97
+ return (0, import_path2.join)(parsedArgs.config.projectDir, (0, import_node_sdk2.getArtifactsDir)(parsedArgs), `${outputFile}${ext}`);
98
+ };
99
+ var getOutputStorageFilename = (parsedArgs, sourceFile, compilationTargetName, isDefaultStorage) => {
100
+ const outputFile = (0, import_path2.basename)(sourceFile, (0, import_path2.extname)(sourceFile));
101
+ const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
102
+ const storageName = isDefaultStorage ? `${outputFile}.default_storage${ext}` : `${outputFile}.storage.${compilationTargetName}${ext}`;
103
+ return (0, import_path2.join)(parsedArgs.config.projectDir, (0, import_node_sdk2.getArtifactsDir)(parsedArgs), storageName);
104
+ };
105
+ var getOutputExprFilename = (parsedArgs, sourceFile, compilationTargetName) => {
106
+ const outputFile = (0, import_path2.basename)(sourceFile, (0, import_path2.extname)(sourceFile));
107
+ const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
108
+ const exprName = `${outputFile}.expression.${compilationTargetName}${ext}`;
109
+ return (0, import_path2.join)(parsedArgs.config.projectDir, (0, import_node_sdk2.getArtifactsDir)(parsedArgs), exprName);
110
+ };
111
+ var getCompilationTargetNames = (parsedArgs, sourceFile) => (0, import_promises2.readFile)(getInputFilename(parsedArgs, sourceFile), "utf8").then((data) => ({
112
+ compTargetNames: data.match(/(?<=add_compilation_target\s*\(\s*['"])[^'"]+(?=['"])/g) ?? [],
113
+ exprCompTargetNames: data.match(/(?<=add_expression_compilation_target\s*\(\s*['"])[^'"]+(?=['"])/g) ?? []
114
+ }));
115
+ var copyArtifactsForFirstCompTarget = async (parsedArgs, sourceFile, compTargetNames) => {
116
+ if (compTargetNames.length === 0)
117
+ return [];
118
+ const firstCompTargetName = compTargetNames.slice(0, 1)[0];
119
+ const dstContractPath = getOutputContractFilename(parsedArgs, sourceFile);
120
+ await (0, import_promises2.copyFile)(
121
+ (0, import_path2.join)(
122
+ getCompilationTargetsDirname(parsedArgs, sourceFile),
123
+ firstCompTargetName,
124
+ isOutputFormatJSON(parsedArgs) ? "step_000_cont_0_contract.json" : "step_000_cont_0_contract.tz"
125
+ ),
126
+ dstContractPath
127
+ );
128
+ const dstDefaultStoragePath = getOutputStorageFilename(parsedArgs, sourceFile, firstCompTargetName, true);
129
+ await (0, import_promises2.copyFile)(
130
+ (0, import_path2.join)(
131
+ getCompilationTargetsDirname(parsedArgs, sourceFile),
132
+ firstCompTargetName,
133
+ isOutputFormatJSON(parsedArgs) ? "step_000_cont_0_storage.json" : "step_000_cont_0_storage.tz"
134
+ ),
135
+ dstDefaultStoragePath
136
+ );
137
+ return [dstContractPath, dstDefaultStoragePath];
138
+ };
139
+ var copyArtifactsForRestCompTargets = async (parsedArgs, sourceFile, compTargetNames) => {
140
+ if (compTargetNames.length === 0)
141
+ return [];
142
+ const restCompTargetNames = compTargetNames.slice(1, compTargetNames.length);
143
+ const dstStoragePaths = await Promise.all(restCompTargetNames.map(async (compTargetName) => {
144
+ const dstStoragePath = getOutputStorageFilename(parsedArgs, sourceFile, compTargetName, false);
145
+ await (0, import_promises2.copyFile)(
146
+ (0, import_path2.join)(
147
+ getCompilationTargetsDirname(parsedArgs, sourceFile),
148
+ compTargetName,
149
+ isOutputFormatJSON(parsedArgs) ? "step_000_cont_0_storage.json" : "step_000_cont_0_storage.tz"
150
+ ),
151
+ dstStoragePath
152
+ );
153
+ return dstStoragePath;
154
+ }));
155
+ return dstStoragePaths;
156
+ };
157
+ var copyArtifactsForExprCompTargets = async (parsedArgs, sourceFile, exprCompTargetNames) => {
158
+ if (exprCompTargetNames.length === 0)
159
+ return [];
160
+ const dstExprPaths = await Promise.all(exprCompTargetNames.map(async (compTargetName) => {
161
+ const dstExprPath = getOutputExprFilename(parsedArgs, sourceFile, compTargetName);
162
+ await (0, import_promises2.copyFile)(
163
+ (0, import_path2.join)(
164
+ getCompilationTargetsDirname(parsedArgs, sourceFile),
165
+ compTargetName,
166
+ isOutputFormatJSON(parsedArgs) ? "step_000_expression.json" : "step_000_expression.tz"
167
+ ),
168
+ dstExprPath
169
+ );
170
+ return dstExprPath;
171
+ }));
172
+ return dstExprPaths;
173
+ };
174
+ var copyRelevantArtifactsForCompTargets = (parsedArgs, sourceFile) => async ({ compTargetNames, exprCompTargetNames }) => {
175
+ if (compTargetNames.length === 0 && exprCompTargetNames.length === 0)
176
+ return "No compilation targets defined";
177
+ const dstContractAndDefaultStoragePaths = await copyArtifactsForFirstCompTarget(
178
+ parsedArgs,
179
+ sourceFile,
180
+ compTargetNames
181
+ );
182
+ const dstStoragePaths = await copyArtifactsForRestCompTargets(
183
+ parsedArgs,
184
+ sourceFile,
185
+ compTargetNames
186
+ );
187
+ const dstExpressionPaths = await copyArtifactsForExprCompTargets(
188
+ parsedArgs,
189
+ sourceFile,
190
+ exprCompTargetNames
191
+ );
192
+ return dstContractAndDefaultStoragePaths.concat(dstStoragePaths).concat(dstExpressionPaths).join("\n");
193
+ };
194
+ var getCompileContractCmd = (parsedArgs, sourceFile) => {
195
+ const outputDir = getCompilationTargetsDirname(parsedArgs, sourceFile);
196
+ const booleanFlags = " --html --purge ";
197
+ return `${getSmartPyCli()} compile ${getInputFilename(parsedArgs, sourceFile)} ${outputDir} ${booleanFlags}`;
198
+ };
199
+ var compileContract = (parsedArgs, sourceFile) => (0, import_node_sdk2.getArch)().then(() => installSmartPyCliIfNotExist(parsedArgs.projectDir)).then(() => getCompileContractCmd(parsedArgs, sourceFile)).then(import_node_sdk2.execCmd).then(({ stderr }) => {
200
+ if (stderr.length > 0)
201
+ (0, import_node_sdk2.sendWarn)(stderr);
202
+ }).then(() => getCompilationTargetNames(parsedArgs, sourceFile)).then(copyRelevantArtifactsForCompTargets(parsedArgs, sourceFile)).then((relevantArtifacts) => ({
203
+ contract: sourceFile,
204
+ artifact: relevantArtifacts
205
+ })).catch((err) => {
206
+ emitExternalError(err, sourceFile);
207
+ return {
208
+ contract: sourceFile,
209
+ artifact: COMPILE_ERR_MSG
210
+ };
211
+ });
212
+ var compile = (parsedArgs) => compileContract(parsedArgs, addPyExtensionIfMissing(parsedArgs.sourceFile)).then((result) => [result]).then(import_node_sdk2.sendJsonRes).catch((err) => (0, import_node_sdk2.sendAsyncErr)(err, false));
213
+ var compile_default = compile;
214
+
215
+ // compileAll.ts
216
+ var import_node_sdk3 = require("@taqueria/node-sdk");
217
+ var import_fast_glob = __toESM(require("fast-glob"));
218
+ var import_promises3 = require("fs/promises");
219
+ var import_path3 = require("path");
220
+ var contractHasCompTarget = (parsedArgs, contactFilename) => (0, import_promises3.readFile)(getInputFilename(parsedArgs, contactFilename), "utf8").then((data) => /add_(expression_)?compilation_target\s*\(\s*['"][^'"]+['"]/.test(data));
221
+ var compileAll = async (parsedArgs) => {
222
+ let p = [];
223
+ const contractFilenames = await (0, import_fast_glob.default)(
224
+ ["**/*.py"],
225
+ { cwd: (0, import_path3.join)(parsedArgs.config.projectDir, (0, import_node_sdk3.getContractsDir)(parsedArgs)), absolute: false }
226
+ );
227
+ for (const filename of contractFilenames) {
228
+ if (await contractHasCompTarget(parsedArgs, filename)) {
229
+ p.push(compileContract(parsedArgs, filename));
230
+ }
231
+ }
232
+ return Promise.all(p).then(import_node_sdk3.sendJsonRes).catch((err) => (0, import_node_sdk3.sendAsyncErr)(err, false));
233
+ };
234
+ var compileAll_default = compileAll;
235
+
236
+ // test.ts
237
+ var import_node_sdk4 = require("@taqueria/node-sdk");
238
+ var getTestContractCmd = (parsedArgs, sourceFile) => {
239
+ const outputDir = getCompilationTargetsDirname(parsedArgs, sourceFile);
240
+ const booleanFlags = " --html --purge ";
241
+ return `${getSmartPyCli()} test ${getInputFilename(parsedArgs, sourceFile)} ${outputDir} ${booleanFlags}`;
242
+ };
243
+ var testContract = (parsedArgs, sourceFile) => (0, import_node_sdk4.getArch)().then(() => installSmartPyCliIfNotExist(parsedArgs.projectDir)).then(() => getTestContractCmd(parsedArgs, sourceFile)).then(import_node_sdk4.execCmd).then(({ stdout, stderr }) => {
244
+ if (stderr.length > 0)
245
+ (0, import_node_sdk4.sendWarn)(stderr);
246
+ const result = "\u{1F389} All tests passed \u{1F389}";
247
+ return {
248
+ contract: sourceFile,
249
+ testResults: stdout.length > 0 ? `${stdout}
250
+ ${result}` : result
251
+ };
252
+ }).catch((err) => {
253
+ emitExternalError(err, sourceFile);
254
+ return {
255
+ contract: sourceFile,
256
+ testResults: "Some tests failed :("
257
+ };
258
+ });
259
+ var test = (parsedArgs) => {
260
+ const sourceFile = addPyExtensionIfMissing(parsedArgs.sourceFile);
261
+ return testContract(parsedArgs, sourceFile).then((result) => [result]).then(import_node_sdk4.sendJsonRes).catch(
262
+ (err) => (0, import_node_sdk4.sendAsyncErr)(err, false)
263
+ );
264
+ };
265
+ var test_default = test;
266
+
267
+ // main.ts
268
+ var main = (parsedArgs) => {
269
+ const unsafeArgs = parsedArgs;
270
+ switch (unsafeArgs.task) {
271
+ case "compile":
272
+ return compile_default(unsafeArgs);
273
+ case "compile-all":
274
+ return compileAll_default(unsafeArgs);
275
+ case "test":
276
+ return test_default(unsafeArgs);
277
+ default:
278
+ return (0, import_node_sdk5.sendAsyncErr)(`${unsafeArgs.task} is not an understood task by the SmartPy plugin`);
279
+ }
280
+ };
281
+ var main_default = main;
282
+
283
+ // index.ts
284
+ import_node_sdk6.Plugin.create((i18n) => ({
285
+ alias: "smartpy",
286
+ schema: "1.0",
287
+ version: "0.1",
288
+ tasks: [
289
+ import_node_sdk6.Task.create({
290
+ task: "compile",
291
+ command: "compile <sourceFile>",
292
+ aliases: ["c", "compile-smartpy"],
293
+ description: "Compile a smart contract written in a SmartPy syntax to Michelson code, along with its associated storage values, per compilation targets, and some expressions per expression compilation targets",
294
+ handler: "proxy",
295
+ encoding: "json",
296
+ options: [
297
+ import_node_sdk6.Option.create({
298
+ flag: "json",
299
+ boolean: true,
300
+ description: "Emit JSON-encoded Michelson"
301
+ })
302
+ ]
303
+ }),
304
+ import_node_sdk6.Task.create({
305
+ task: "compile-all",
306
+ command: "compile-all",
307
+ description: "Compile all SmartPy smart contracts with at least one SmartPy compilation target to Michelson code, along with their associated storage values, per compilation targets, and some expressions per expression compilation targets",
308
+ handler: "proxy",
309
+ encoding: "json",
310
+ options: [
311
+ import_node_sdk6.Option.create({
312
+ flag: "json",
313
+ boolean: true,
314
+ description: "Emit JSON-encoded Michelson"
315
+ })
316
+ ]
317
+ }),
318
+ import_node_sdk6.Task.create({
319
+ task: "test",
320
+ command: "test <sourceFile>",
321
+ description: "Test a smart contract written in SmartPy",
322
+ handler: "proxy",
323
+ encoding: "json"
324
+ })
325
+ ],
326
+ proxy: main_default
327
+ }), process.argv);
328
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts","main.ts","compile.ts","common.ts","compileAll.ts","test.ts"],"sourcesContent":["import { Option, Plugin, Task } from '@taqueria/node-sdk';\nimport main from './main';\n\nPlugin.create(i18n => ({\n\talias: 'smartpy',\n\tschema: '1.0',\n\tversion: '0.1',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile <sourceFile>',\n\t\t\taliases: ['c', 'compile-smartpy'],\n\t\t\tdescription:\n\t\t\t\t'Compile a smart contract written in a SmartPy syntax to Michelson code, along with its associated storage values, per compilation targets, and some expressions per expression compilation targets',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'json',\n\t\t\t\t\tboolean: true,\n\t\t\t\t\tdescription: 'Emit JSON-encoded Michelson',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tTask.create({\n\t\t\ttask: 'compile-all',\n\t\t\tcommand: 'compile-all',\n\t\t\tdescription:\n\t\t\t\t'Compile all SmartPy smart contracts with at least one SmartPy compilation target to Michelson code, along with their associated storage values, per compilation targets, and some expressions per expression compilation targets',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'json',\n\t\t\t\t\tboolean: true,\n\t\t\t\t\tdescription: 'Emit JSON-encoded Michelson',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test <sourceFile>',\n\t\t\tdescription: 'Test a smart contract written in SmartPy',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t],\n\tproxy: main,\n}), process.argv);\n","import { RequestArgs, sendAsyncErr } from '@taqueria/node-sdk';\nimport { IntersectionOpts as Opts } from './common';\nimport compile from './compile';\nimport compileAll from './compileAll';\nimport test from './test';\n\nconst main = (parsedArgs: RequestArgs.t): Promise<void> => {\n\tconst unsafeArgs = parsedArgs as Opts;\n\tswitch (unsafeArgs.task) {\n\t\tcase 'compile':\n\t\t\treturn compile(unsafeArgs);\n\t\tcase 'compile-all':\n\t\t\treturn compileAll(unsafeArgs);\n\t\tcase 'test':\n\t\t\treturn test(unsafeArgs);\n\t\tdefault:\n\t\t\treturn sendAsyncErr(`${unsafeArgs.task} is not an understood task by the SmartPy plugin`);\n\t}\n};\n\nexport default main;\n","import { execCmd, getArch, getArtifactsDir, sendAsyncErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport { copyFile, readFile } from 'fs/promises';\nimport { basename, extname, join } from 'path';\nimport {\n\taddPyExtensionIfMissing,\n\tCompileOpts as Opts,\n\temitExternalError,\n\tgetCompilationTargetsDirname,\n\tgetInputFilename,\n\tgetSmartPyCli,\n\tinstallSmartPyCliIfNotExist,\n} from './common';\n\nexport type TableRow = { contract: string; artifact: string };\n\nconst COMPILE_ERR_MSG: string = 'Not compiled';\n\nconst isOutputFormatJSON = (parsedArgs: Opts): boolean => parsedArgs.json;\n\nconst getOutputContractFilename = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\tconst ext = isOutputFormatJSON(parsedArgs) ? '.json' : '.tz';\n\treturn join(parsedArgs.config.projectDir, getArtifactsDir(parsedArgs), `${outputFile}${ext}`);\n};\n\nconst getOutputStorageFilename = (\n\tparsedArgs: Opts,\n\tsourceFile: string,\n\tcompilationTargetName: string,\n\tisDefaultStorage: boolean,\n): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\tconst ext = isOutputFormatJSON(parsedArgs) ? '.json' : '.tz';\n\tconst storageName = isDefaultStorage\n\t\t? `${outputFile}.default_storage${ext}`\n\t\t: `${outputFile}.storage.${compilationTargetName}${ext}`;\n\treturn join(parsedArgs.config.projectDir, getArtifactsDir(parsedArgs), storageName);\n};\n\nconst getOutputExprFilename = (parsedArgs: Opts, sourceFile: string, compilationTargetName: string): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\tconst ext = isOutputFormatJSON(parsedArgs) ? '.json' : '.tz';\n\tconst exprName = `${outputFile}.expression.${compilationTargetName}${ext}`;\n\treturn join(parsedArgs.config.projectDir, getArtifactsDir(parsedArgs), exprName);\n};\n\nconst getCompilationTargetNames = (\n\tparsedArgs: Opts,\n\tsourceFile: string,\n): Promise<{ compTargetNames: string[]; exprCompTargetNames: string[] }> =>\n\treadFile(getInputFilename(parsedArgs, sourceFile), 'utf8')\n\t\t.then(data => ({\n\t\t\tcompTargetNames: data.match(/(?<=add_compilation_target\\s*\\(\\s*['\"])[^'\"]+(?=['\"])/g) ?? [],\n\t\t\texprCompTargetNames: data.match(/(?<=add_expression_compilation_target\\s*\\(\\s*['\"])[^'\"]+(?=['\"])/g) ?? [],\n\t\t}));\n\nconst copyArtifactsForFirstCompTarget = async (\n\tparsedArgs: Opts,\n\tsourceFile: string,\n\tcompTargetNames: string[],\n): Promise<string[]> => {\n\tif (compTargetNames.length === 0) return [];\n\tconst firstCompTargetName = compTargetNames.slice(0, 1)[0];\n\n\tconst dstContractPath = getOutputContractFilename(parsedArgs, sourceFile);\n\tawait copyFile(\n\t\tjoin(\n\t\t\tgetCompilationTargetsDirname(parsedArgs, sourceFile),\n\t\t\tfirstCompTargetName,\n\t\t\tisOutputFormatJSON(parsedArgs) ? 'step_000_cont_0_contract.json' : 'step_000_cont_0_contract.tz',\n\t\t),\n\t\tdstContractPath,\n\t);\n\n\tconst dstDefaultStoragePath = getOutputStorageFilename(parsedArgs, sourceFile, firstCompTargetName, true);\n\tawait copyFile(\n\t\tjoin(\n\t\t\tgetCompilationTargetsDirname(parsedArgs, sourceFile),\n\t\t\tfirstCompTargetName,\n\t\t\tisOutputFormatJSON(parsedArgs) ? 'step_000_cont_0_storage.json' : 'step_000_cont_0_storage.tz',\n\t\t),\n\t\tdstDefaultStoragePath,\n\t);\n\n\treturn [dstContractPath, dstDefaultStoragePath];\n};\n\nconst copyArtifactsForRestCompTargets = async (\n\tparsedArgs: Opts,\n\tsourceFile: string,\n\tcompTargetNames: string[],\n): Promise<string[]> => {\n\tif (compTargetNames.length === 0) return [];\n\tconst restCompTargetNames = compTargetNames.slice(1, compTargetNames.length);\n\n\tconst dstStoragePaths = await Promise.all(restCompTargetNames.map(async compTargetName => {\n\t\tconst dstStoragePath = getOutputStorageFilename(parsedArgs, sourceFile, compTargetName, false);\n\t\tawait copyFile(\n\t\t\tjoin(\n\t\t\t\tgetCompilationTargetsDirname(parsedArgs, sourceFile),\n\t\t\t\tcompTargetName,\n\t\t\t\tisOutputFormatJSON(parsedArgs) ? 'step_000_cont_0_storage.json' : 'step_000_cont_0_storage.tz',\n\t\t\t),\n\t\t\tdstStoragePath,\n\t\t);\n\t\treturn dstStoragePath;\n\t}));\n\n\treturn dstStoragePaths;\n};\n\nconst copyArtifactsForExprCompTargets = async (\n\tparsedArgs: Opts,\n\tsourceFile: string,\n\texprCompTargetNames: string[],\n): Promise<string[]> => {\n\tif (exprCompTargetNames.length === 0) return [];\n\n\tconst dstExprPaths = await Promise.all(exprCompTargetNames.map(async compTargetName => {\n\t\tconst dstExprPath = getOutputExprFilename(parsedArgs, sourceFile, compTargetName);\n\t\tawait copyFile(\n\t\t\tjoin(\n\t\t\t\tgetCompilationTargetsDirname(parsedArgs, sourceFile),\n\t\t\t\tcompTargetName,\n\t\t\t\tisOutputFormatJSON(parsedArgs) ? 'step_000_expression.json' : 'step_000_expression.tz',\n\t\t\t),\n\t\t\tdstExprPath,\n\t\t);\n\t\treturn dstExprPath;\n\t}));\n\n\treturn dstExprPaths;\n};\n\nconst copyRelevantArtifactsForCompTargets = (parsedArgs: Opts, sourceFile: string) =>\n\tasync (\n\t\t{ compTargetNames, exprCompTargetNames }: { compTargetNames: string[]; exprCompTargetNames: string[] },\n\t): Promise<string> => {\n\t\tif (compTargetNames.length === 0 && exprCompTargetNames.length === 0) return 'No compilation targets defined';\n\n\t\tconst dstContractAndDefaultStoragePaths = await copyArtifactsForFirstCompTarget(\n\t\t\tparsedArgs,\n\t\t\tsourceFile,\n\t\t\tcompTargetNames,\n\t\t);\n\n\t\tconst dstStoragePaths = await copyArtifactsForRestCompTargets(\n\t\t\tparsedArgs,\n\t\t\tsourceFile,\n\t\t\tcompTargetNames,\n\t\t);\n\n\t\tconst dstExpressionPaths = await copyArtifactsForExprCompTargets(\n\t\t\tparsedArgs,\n\t\t\tsourceFile,\n\t\t\texprCompTargetNames,\n\t\t);\n\n\t\treturn dstContractAndDefaultStoragePaths.concat(dstStoragePaths).concat(dstExpressionPaths).join('\\n');\n\t};\n\nconst getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputDir = getCompilationTargetsDirname(parsedArgs, sourceFile);\n\tconst booleanFlags = ' --html --purge ';\n\treturn `${getSmartPyCli()} compile ${getInputFilename(parsedArgs, sourceFile)} ${outputDir} ${booleanFlags}`;\n};\n\nexport const compileContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => installSmartPyCliIfNotExist(parsedArgs.projectDir))\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})\n\t\t.then(() => getCompilationTargetNames(parsedArgs, sourceFile))\n\t\t.then(copyRelevantArtifactsForCompTargets(parsedArgs, sourceFile))\n\t\t.then(relevantArtifacts => ({\n\t\t\tcontract: sourceFile,\n\t\t\tartifact: relevantArtifacts,\n\t\t}))\n\t\t.catch(err => {\n\t\t\temitExternalError(err, sourceFile);\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 compile = (parsedArgs: Opts): Promise<void> =>\n\tcompileContract(parsedArgs, addPyExtensionIfMissing(parsedArgs.sourceFile))\n\t\t.then(result => [result])\n\t\t.then(sendJsonRes)\n\t\t.catch(err => sendAsyncErr(err, false));\n\nexport default compile;\n","import { execCmd, getArtifactsDir, getContractsDir, sendErr, sendWarn } from '@taqueria/node-sdk';\nimport { ProxyTaskArgs } from '@taqueria/node-sdk/types';\nimport { access, copyFile, readdir, stat } from 'fs/promises';\nimport { join } from 'path';\n\nexport interface CompileOpts extends ProxyTaskArgs.t {\n\tsourceFile: string;\n\tjson: boolean;\n}\n\nexport interface CompileAllOpts extends ProxyTaskArgs.t {\n\tjson: boolean;\n}\n\nexport interface TestOpts extends ProxyTaskArgs.t {\n\tsourceFile: string;\n}\n\nexport type IntersectionOpts = CompileOpts & CompileAllOpts & TestOpts;\n\ntype UnionOpts = CompileOpts | CompileAllOpts | TestOpts;\n\n// Should point to the latest stable version, so it needs to be updated as part of our release process.\nconst SMARTPY_DEFAULT_VERSION = 'v0.16.0';\n\nconst SMARTPY_VERSION_ENV_VAR = 'TAQ_SMARTPY_VERSION';\n\nconst SMARTPY_ARTIFACTS_DIR = '.smartpy';\n\nconst smartpyVersionToInstallerMap: { [k: string]: string } = {\n\t'v0.16.0': 'https://smartpy.io/releases/20221215-8f134ebb649f5a7b37c44fca8f336f970f523565/cli/install.sh',\n};\n\nconst getSmartpyVersion = (): string => {\n\tconst userDefinedSmartpyVersion = process.env[SMARTPY_VERSION_ENV_VAR];\n\tif (userDefinedSmartpyVersion) {\n\t\tif (/v0\\.1[4-6]\\./.test(userDefinedSmartpyVersion)) {\n\t\t\treturn userDefinedSmartpyVersion;\n\t\t} else {\n\t\t\tsendWarn(\n\t\t\t\t`Version ${userDefinedSmartpyVersion} is not supported by Taqueria yet. The supported versions are [${\n\t\t\t\t\tObject.keys(smartpyVersionToInstallerMap)\n\t\t\t\t}]. Will default to ${SMARTPY_DEFAULT_VERSION}`,\n\t\t\t);\n\t\t\treturn SMARTPY_DEFAULT_VERSION;\n\t\t}\n\t} else {\n\t\treturn SMARTPY_DEFAULT_VERSION;\n\t}\n};\n\nconst getPathToSmartPyCliDir = (): string => `${process.env.HOME}/smartpy-cli-${getSmartpyVersion()}`;\n\nexport const getSmartPyCli = (): string => `${getPathToSmartPyCliDir()}/SmartPy.sh`;\n\nconst getSmartPyInstallerCmd = (projectDir: string): string => {\n\tconst trimmedProjectdir = projectDir.replace(/\\/$/, '');\n\tconst installer = join(__dirname, 'install.sh');\n\tconst install = `bash ${installer} --yes --prefix ${getPathToSmartPyCliDir()} --project ${trimmedProjectdir};`;\n\treturn install;\n};\n\nexport const addPyExtensionIfMissing = (sourceFile: string): string =>\n\t/\\.py$/.test(sourceFile) ? sourceFile : `${sourceFile}.py`;\n\nconst extractExt = (path: string): string => {\n\tconst matchResult = path.match(/\\.py$/);\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\nexport const getInputFilename = (parsedArgs: UnionOpts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.projectDir, getContractsDir(parsedArgs), sourceFile);\n\nexport const getCompilationTargetsDirname = (parsedArgs: UnionOpts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.projectDir, getArtifactsDir(parsedArgs), SMARTPY_ARTIFACTS_DIR, removeExt(sourceFile));\n\nexport const installSmartPyCliIfNotExist = (projectDir: string) =>\n\taccess(getSmartPyCli())\n\t\t.catch(() => {\n\t\t\tsendWarn('SmartPy CLI not found. Installing it now...');\n\t\t\treturn execCmd(getSmartPyInstallerCmd(projectDir))\n\t\t\t\t.then(({ stderr }) => {\n\t\t\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\t\t});\n\t\t});\n\nexport const emitExternalError = (err: unknown, sourceFile: string): void => {\n\tsendErr(`\\n=== Error messages for ${sourceFile} ===`);\n\terr instanceof Error ? sendErr(err.message.replace(/Command failed.+?\\n/, '')) : sendErr(err as any);\n\tsendErr(`\\n===`);\n};\n","import { getContractsDir, sendAsyncErr, sendJsonRes } from '@taqueria/node-sdk';\nimport glob from 'fast-glob';\nimport { readFile } from 'fs/promises';\nimport { join } from 'path';\nimport { CompileAllOpts as Opts, CompileOpts, getInputFilename } from './common';\nimport { compileContract, TableRow } from './compile';\n\nconst contractHasCompTarget = (parsedArgs: Opts, contactFilename: string): Promise<boolean> =>\n\treadFile(getInputFilename(parsedArgs, contactFilename), 'utf8')\n\t\t.then(data => /add_(expression_)?compilation_target\\s*\\(\\s*['\"][^'\"]+['\"]/.test(data));\n\nconst compileAll = async (parsedArgs: Opts): Promise<void> => {\n\tlet p: Promise<TableRow>[] = [];\n\n\tconst contractFilenames = await glob(\n\t\t['**/*.py'],\n\t\t{ cwd: join(parsedArgs.config.projectDir, getContractsDir(parsedArgs)), absolute: false },\n\t);\n\n\tfor (const filename of contractFilenames) {\n\t\tif (await contractHasCompTarget(parsedArgs, filename)) {\n\t\t\tp.push(compileContract(parsedArgs as CompileOpts, filename));\n\t\t}\n\t}\n\n\treturn Promise.all(p).then(sendJsonRes).catch(err => sendAsyncErr(err, false));\n};\n\nexport default compileAll;\n","import { execCmd, getArch, sendAsyncErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport {\n\taddPyExtensionIfMissing,\n\temitExternalError,\n\tgetCompilationTargetsDirname,\n\tgetInputFilename,\n\tgetSmartPyCli,\n\tinstallSmartPyCliIfNotExist,\n\tTestOpts as Opts,\n} from './common';\n\ntype TableRow = { contract: string; testResults: string };\n\nconst getTestContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputDir = getCompilationTargetsDirname(parsedArgs, sourceFile);\n\tconst booleanFlags = ' --html --purge ';\n\treturn `${getSmartPyCli()} test ${getInputFilename(parsedArgs, sourceFile)} ${outputDir} ${booleanFlags}`;\n};\n\nconst testContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => installSmartPyCliIfNotExist(parsedArgs.projectDir))\n\t\t.then(() => getTestContractCmd(parsedArgs, sourceFile))\n\t\t.then(execCmd)\n\t\t.then(({ stdout, stderr }) => {\n\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\tconst result = '🎉 All tests passed 🎉';\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\ttestResults: stdout.length > 0 ? `${stdout}\\n${result}` : result,\n\t\t\t};\n\t\t})\n\t\t.catch(err => {\n\t\t\temitExternalError(err, sourceFile);\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\ttestResults: 'Some tests failed :(',\n\t\t\t};\n\t\t});\n\nconst test = (parsedArgs: Opts): Promise<void> => {\n\tconst sourceFile = addPyExtensionIfMissing(parsedArgs.sourceFile);\n\treturn testContract(parsedArgs, sourceFile).then(result => [result]).then(sendJsonRes).catch(err =>\n\t\tsendAsyncErr(err, false)\n\t);\n};\n\nexport default test;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAqC;;;ACArC,IAAAC,mBAA0C;;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AAAA,EAC1F;AACD;AAEA,IAAO,eAAQ;;;ADjBf,wBAAO,OAAO,WAAS;AAAA,EACtB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,IACN,sBAAK,OAAO;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,CAAC,KAAK,iBAAiB;AAAA,MAChC,aACC;AAAA,MACD,SAAS;AAAA,MACT,UAAU;AAAA,MACV,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,IACD,sBAAK,OAAO;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,aACC;AAAA,MACD,SAAS;AAAA,MACT,UAAU;AAAA,MACV,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,IACD,sBAAK,OAAO;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,aAAa;AAAA,MACb,SAAS;AAAA,MACT,UAAU;AAAA,IACX,CAAC;AAAA,EACF;AAAA,EACA,OAAO;AACR,IAAI,QAAQ,IAAI;","names":["import_node_sdk","import_node_sdk","import_node_sdk","import_promises","import_path","import_node_sdk","import_promises","import_path","glob","import_node_sdk"]}