@taqueria/plugin-archetype 0.6.2 → 0.7.0-rc1
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/archetype_template.ts +9 -0
- package/compile.ts +5 -12
- package/createContract.ts +28 -0
- package/index.js +46 -30
- package/index.js.map +1 -1
- package/index.ts +15 -11
- package/package.json +2 -2
package/compile.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { execCmd, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';
|
|
2
|
-
import {
|
|
3
|
-
import glob from 'fast-glob';
|
|
4
|
-
import { readFile } from 'fs/promises';
|
|
1
|
+
import { execCmd, getContracts, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';
|
|
2
|
+
import { RequestArgs, TaqError } from '@taqueria/node-sdk/types';
|
|
5
3
|
import { basename, extname, join } from 'path';
|
|
6
4
|
|
|
7
5
|
interface Opts extends RequestArgs.t {
|
|
@@ -51,12 +49,8 @@ const compileContract = (opts: Opts) =>
|
|
|
51
49
|
});
|
|
52
50
|
});
|
|
53
51
|
|
|
54
|
-
const compileAll = (opts: Opts): Promise<{ contract: string; artifact: string }[]> =>
|
|
55
|
-
|
|
56
|
-
return glob(
|
|
57
|
-
['**/*.arl'],
|
|
58
|
-
{ cwd: opts.config.contractsDir, absolute: false },
|
|
59
|
-
)
|
|
52
|
+
const compileAll = (opts: Opts): Promise<{ contract: string; artifact: string }[]> =>
|
|
53
|
+
Promise.all(getContracts(/\.arl$/, opts.config))
|
|
60
54
|
.then(entries => entries.map(compileContract(opts)))
|
|
61
55
|
.then(processes =>
|
|
62
56
|
processes.length > 0
|
|
@@ -64,9 +58,8 @@ const compileAll = (opts: Opts): Promise<{ contract: string; artifact: string }[
|
|
|
64
58
|
: [{ contract: 'None found', artifact: 'N/A' }]
|
|
65
59
|
)
|
|
66
60
|
.then(promises => Promise.all(promises));
|
|
67
|
-
};
|
|
68
61
|
|
|
69
|
-
const compile = <T>(parsedArgs: Opts)
|
|
62
|
+
const compile = <T>(parsedArgs: Opts) => {
|
|
70
63
|
const p = parsedArgs.sourceFile
|
|
71
64
|
? compileContract(parsedArgs)(parsedArgs.sourceFile)
|
|
72
65
|
.then(result => [result])
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { experimental, sendAsyncErr } from '@taqueria/node-sdk';
|
|
2
|
+
import * as RequestArgs from '@taqueria/protocol/RequestArgs';
|
|
3
|
+
import { writeFile } from 'fs/promises';
|
|
4
|
+
import { arl_template } from './archetype_template';
|
|
5
|
+
|
|
6
|
+
interface Opts extends RequestArgs.t {
|
|
7
|
+
sourceFileName?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const registerContract = (arg: Opts, contractName: string) => {
|
|
11
|
+
experimental.registerContract(arg, contractName);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const validateExtension = async (contractName: string) => {
|
|
15
|
+
const matchResult = contractName.match(/\.arl$/);
|
|
16
|
+
if (matchResult) return;
|
|
17
|
+
return sendAsyncErr(`"${contractName}" doesn't have extension "arl".`);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createContract = (arg: Opts) => {
|
|
21
|
+
const contractName = arg.sourceFileName as string;
|
|
22
|
+
const contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;
|
|
23
|
+
return validateExtension(contractName)
|
|
24
|
+
.then(_ => writeFile(`${contractsDir}/${contractName}`, arl_template))
|
|
25
|
+
.then(_ => registerContract(arg, contractName));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default createContract;
|
package/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
var $dTHpf$taquerianodesdk = require("@taqueria/node-sdk");
|
|
2
|
-
var $dTHpf$fastglob = require("fast-glob");
|
|
3
2
|
var $dTHpf$path = require("path");
|
|
4
|
-
|
|
5
|
-
function $parcel$interopDefault(a) {
|
|
6
|
-
return a && a.__esModule ? a.default : a;
|
|
7
|
-
}
|
|
3
|
+
var $dTHpf$fspromises = require("fs/promises");
|
|
8
4
|
|
|
9
5
|
|
|
10
6
|
|
|
@@ -40,20 +36,12 @@ const $bb055a91efa18df7$var$compileContract = (opts)=>(sourceFile)=>// const sou
|
|
|
40
36
|
artifact: "Not compiled"
|
|
41
37
|
});
|
|
42
38
|
});
|
|
43
|
-
const $bb055a91efa18df7$var$compileAll = (opts)=>
|
|
44
|
-
// TODO: Fetch list of files from SDK
|
|
45
|
-
return (0, ($parcel$interopDefault($dTHpf$fastglob)))([
|
|
46
|
-
"**/*.arl"
|
|
47
|
-
], {
|
|
48
|
-
cwd: opts.config.contractsDir,
|
|
49
|
-
absolute: false
|
|
50
|
-
}).then((entries)=>entries.map($bb055a91efa18df7$var$compileContract(opts))).then((processes)=>processes.length > 0 ? processes : [
|
|
39
|
+
const $bb055a91efa18df7$var$compileAll = (opts)=>Promise.all((0, $dTHpf$taquerianodesdk.getContracts)(/\.arl$/, opts.config)).then((entries)=>entries.map($bb055a91efa18df7$var$compileContract(opts))).then((processes)=>processes.length > 0 ? processes : [
|
|
51
40
|
{
|
|
52
41
|
contract: "None found",
|
|
53
42
|
artifact: "N/A"
|
|
54
43
|
}
|
|
55
44
|
]).then((promises)=>Promise.all(promises));
|
|
56
|
-
};
|
|
57
45
|
const $bb055a91efa18df7$var$compile = (parsedArgs)=>{
|
|
58
46
|
const p = parsedArgs.sourceFile ? $bb055a91efa18df7$var$compileContract(parsedArgs)(parsedArgs.sourceFile).then((result)=>[
|
|
59
47
|
result
|
|
@@ -66,6 +54,35 @@ const $bb055a91efa18df7$var$compile = (parsedArgs)=>{
|
|
|
66
54
|
var $bb055a91efa18df7$export$2e2bcd8739ae039 = $bb055a91efa18df7$var$compile;
|
|
67
55
|
|
|
68
56
|
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const $94ea212fa0656741$export$fc3df5870c3ce31c = `
|
|
60
|
+
archetype hello
|
|
61
|
+
|
|
62
|
+
variable msg : string = "Hello"
|
|
63
|
+
|
|
64
|
+
entry input(name : string) {
|
|
65
|
+
msg += " " + name
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const $decf18aeaad317ec$var$registerContract = (arg, contractName)=>{
|
|
71
|
+
(0, $dTHpf$taquerianodesdk.experimental).registerContract(arg, contractName);
|
|
72
|
+
};
|
|
73
|
+
const $decf18aeaad317ec$var$validateExtension = async (contractName)=>{
|
|
74
|
+
const matchResult = contractName.match(/\.arl$/);
|
|
75
|
+
if (matchResult) return;
|
|
76
|
+
return (0, $dTHpf$taquerianodesdk.sendAsyncErr)(`"${contractName}" doesn't have extension "arl".`);
|
|
77
|
+
};
|
|
78
|
+
const $decf18aeaad317ec$var$createContract = (arg)=>{
|
|
79
|
+
const contractName = arg.sourceFileName;
|
|
80
|
+
const contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;
|
|
81
|
+
return $decf18aeaad317ec$var$validateExtension(contractName).then((_)=>(0, $dTHpf$fspromises.writeFile)(`${contractsDir}/${contractName}`, (0, $94ea212fa0656741$export$fc3df5870c3ce31c))).then((_)=>$decf18aeaad317ec$var$registerContract(arg, contractName));
|
|
82
|
+
};
|
|
83
|
+
var $decf18aeaad317ec$export$2e2bcd8739ae039 = $decf18aeaad317ec$var$createContract;
|
|
84
|
+
|
|
85
|
+
|
|
69
86
|
(0, $dTHpf$taquerianodesdk.Plugin).create((i18n)=>({
|
|
70
87
|
schema: "1.0",
|
|
71
88
|
version: "0.1",
|
|
@@ -84,22 +101,21 @@ var $bb055a91efa18df7$export$2e2bcd8739ae039 = $bb055a91efa18df7$var$compile;
|
|
|
84
101
|
encoding: "json"
|
|
85
102
|
}),
|
|
86
103
|
],
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}),
|
|
104
|
+
templates: [
|
|
105
|
+
(0, $dTHpf$taquerianodesdk.Template).create({
|
|
106
|
+
template: "archetypeContract",
|
|
107
|
+
command: "archetypeContract <sourceFileName>",
|
|
108
|
+
description: "Create a Archetype contract with boilerplate code",
|
|
109
|
+
positionals: [
|
|
110
|
+
(0, $dTHpf$taquerianodesdk.PositionalArg).create({
|
|
111
|
+
placeholder: "sourceFileName",
|
|
112
|
+
type: "string",
|
|
113
|
+
description: "The name of the Archetype contract to generate"
|
|
114
|
+
}),
|
|
115
|
+
],
|
|
116
|
+
handler: (0, $decf18aeaad317ec$export$2e2bcd8739ae039)
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
103
119
|
proxy: (0, $bb055a91efa18df7$export$2e2bcd8739ae039)
|
|
104
120
|
}), process.argv);
|
|
105
121
|
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;AAAA;ACAA;;AAQA,MAAM,sCAAgB,GAAG,CAAC,IAAU,GACnC,CAAC,UAAkB,GAAK;QACvB,MAAM,SAAS,GAAG,CAAA,GAAA,oBAAQ,CAAA,CAAC,UAAU,EAAE,CAAA,GAAA,mBAAO,CAAA,CAAC,UAAU,CAAC,CAAC,AAAC;QAC5D,OAAO,CAAA,GAAA,gBAAI,CAAA,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KAC1D,AAAC;AAEH,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,C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ACN,CAAA,GAAA,2BAAI,CAAA,CAAC,MAAM,CAAC;gBACX,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,sBAAsB;gBAC/B,OAAO,EAAE;oBAAC,GAAG;oBAAE,mBAAmB;iBAAC;gBACnC,WAAW,EAAE,0EAA0E;gBACvF,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,MAAM;aAChB,CAAC;SACF;QACD,SAAS,EAAE;YACV,CAAA,GAAA,+BAAQ,CAAA,CAAC,MAAM,CAAC;gBACf,QAAQ,EAAE,mBAAmB;gBAC7B,OAAO,EAAE,oCAAoC;gBAC7C,WAAW,EAAE,mDAAmD;gBAChE,WAAW,EAAE;oBACZ,CAAA,GAAA,oCAAa,CAAA,CAAC,MAAM,CAAC;wBACpB,WAAW,EAAE,gBAAgB;wBAC7B,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,gDAAgD;qBAC7D,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-archetype/index.ts","taqueria-plugin-archetype/compile.ts","taqueria-plugin-archetype/createContract.ts","taqueria-plugin-archetype/archetype_template.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: 'archetype',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile [sourceFile]',\n\t\t\taliases: ['c', 'compile-archetype'],\n\t\t\tdescription: 'Compile a smart contract written in a Archetype syntax to Michelson code',\n\t\t\toptions: [],\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: 'archetypeContract',\n\t\t\tcommand: 'archetypeContract <sourceFileName>',\n\t\t\tdescription: 'Create a Archetype 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 Archetype contract to generate',\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, getContracts, sendAsyncErr, sendErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { RequestArgs, TaqError } from '@taqueria/node-sdk/types';\nimport { basename, extname, join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFile?: string;\n}\n\nconst getInputFilename = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst inputFile = basename(sourceFile, extname(sourceFile));\n\t\treturn join(opts.config.contractsDir, `${inputFile}.arl`);\n\t};\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 getCompileCommand = (opts: Opts) =>\n\t(sourceFile: string) => {\n\t\tconst { projectDir } = opts;\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 -u $(id -u):$(id -g) -w /project completium/archetype:1.2.12 ${inputFile}`;\n\t\tconst outFile = `-o ${getContractArtifactFilename(opts)(sourceFile)}`;\n\t\tconst cmd = `${baseCommand} ${outFile}`;\n\t\treturn cmd;\n\t};\n\nconst compileContract = (opts: Opts) =>\n\t(sourceFile: string): Promise<{ contract: string; artifact: string }> =>\n\t\t// const sourceAbspath = join(opts.contractsDir, sourceFile)\n\t\texecCmd(getCompileCommand(opts)(sourceFile))\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 = (opts: Opts): Promise<{ contract: string; artifact: string }[]> =>\n\tPromise.all(getContracts(/\\.arl$/, opts.config))\n\t\t.then(entries => entries.map(compileContract(opts)))\n\t\t.then(processes =>\n\t\t\tprocesses.length > 0\n\t\t\t\t? processes\n\t\t\t\t: [{ contract: 'None found', artifact: 'N/A' }]\n\t\t)\n\t\t.then(promises => Promise.all(promises));\n\nconst compile = <T>(parsedArgs: Opts) => {\n\tconst p = parsedArgs.sourceFile\n\t\t? compileContract(parsedArgs)(parsedArgs.sourceFile)\n\t\t\t.then(result => [result])\n\t\t: compileAll(parsedArgs)\n\t\t\t.then(results => {\n\t\t\t\tif (results.length === 0) sendErr('No contracts found to compile.');\n\t\t\t\treturn results;\n\t\t\t});\n\n\treturn p\n\t\t.then(sendJsonRes)\n\t\t.catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n","import { experimental, sendAsyncErr } from '@taqueria/node-sdk';\nimport * as RequestArgs from '@taqueria/protocol/RequestArgs';\nimport { writeFile } from 'fs/promises';\nimport { arl_template } from './archetype_template';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFileName?: string;\n}\n\nconst registerContract = (arg: Opts, contractName: string) => {\n\texperimental.registerContract(arg, contractName);\n};\n\nconst validateExtension = async (contractName: string) => {\n\tconst matchResult = contractName.match(/\\.arl$/);\n\tif (matchResult) return;\n\treturn sendAsyncErr(`\"${contractName}\" doesn't have extension \"arl\".`);\n};\n\nconst createContract = (arg: Opts) => {\n\tconst contractName = arg.sourceFileName as string;\n\tconst contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;\n\treturn validateExtension(contractName)\n\t\t.then(_ => writeFile(`${contractsDir}/${contractName}`, arl_template))\n\t\t.then(_ => registerContract(arg, contractName));\n};\n\nexport default createContract;\n","export const arl_template = `\narchetype hello\n\nvariable msg : string = \"Hello\"\n\nentry input(name : string) {\n msg += \" \" + name\n}\n`;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Option, Plugin, Task } from '@taqueria/node-sdk';
|
|
1
|
+
import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';
|
|
2
2
|
import compile from './compile';
|
|
3
|
+
import createContract from './createContract';
|
|
3
4
|
|
|
4
5
|
Plugin.create(i18n => ({
|
|
5
6
|
schema: '1.0',
|
|
@@ -16,17 +17,20 @@ Plugin.create(i18n => ({
|
|
|
16
17
|
encoding: 'json',
|
|
17
18
|
}),
|
|
18
19
|
],
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
templates: [
|
|
21
|
+
Template.create({
|
|
22
|
+
template: 'archetypeContract',
|
|
23
|
+
command: 'archetypeContract <sourceFileName>',
|
|
24
|
+
description: 'Create a Archetype contract with boilerplate code',
|
|
25
|
+
positionals: [
|
|
26
|
+
PositionalArg.create({
|
|
27
|
+
placeholder: 'sourceFileName',
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'The name of the Archetype contract to generate',
|
|
30
|
+
}),
|
|
24
31
|
],
|
|
32
|
+
handler: createContract,
|
|
25
33
|
}),
|
|
26
|
-
|
|
27
|
-
Promise.resolve({
|
|
28
|
-
status: 'success',
|
|
29
|
-
output: 'Archetype was found in /usr/bin/archetype', // TODO this should use i18n
|
|
30
|
-
}),
|
|
34
|
+
],
|
|
31
35
|
proxy: compile,
|
|
32
36
|
}), process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taqueria/plugin-archetype",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-rc1",
|
|
4
4
|
"description": "A taqueria plugin for compiling Archetype smart contracts",
|
|
5
5
|
"targets": {
|
|
6
6
|
"default": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/ecadlabs/taqueria#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@taqueria/node-sdk": "^0.
|
|
43
|
+
"@taqueria/node-sdk": "^0.7.0-rc1",
|
|
44
44
|
"fast-glob": "^3.2.11"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|