@taqueria/plugin-metadata 0.0.0-pr-985-8196aa14 → 0.14.2
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 +142 -0
- package/_readme.eta +145 -0
- package/index.js +87 -6
- package/index.js.map +1 -1
- package/index.ts +9 -1
- package/package.json +3 -2
- package/src/proxy.ts +102 -5
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Taqueria Metadata Plugin
|
|
2
|
+
|
|
3
|
+
The Taqueria Metadata plugin provides an easy way to create a json file containing `TZIP-16` compliant metadata related to a smart contract
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Taqueria v0.13.0 or later
|
|
8
|
+
- Node.js v16.3 or later
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
To install the metadata plugin on a Taqueria project, navigate to the project folder and run:
|
|
13
|
+
```shell
|
|
14
|
+
taq install @taqueria/plugin-metadata
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
There is no configuration required to run the plugin
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
The Metadata plugin provides an interactive CLI interface that collects basic contract metadata fields as outlined in `TZIP-16` specification, and generates a compliant JSON file that can be uploaded to IPFS
|
|
24
|
+
|
|
25
|
+
The metadata fields collected are:
|
|
26
|
+
|
|
27
|
+
| name | description |
|
|
28
|
+
|:-----------------:|:-------------------------------------:|
|
|
29
|
+
| name | Name of the contract |
|
|
30
|
+
| version | Version of the contract |
|
|
31
|
+
| description | Description of the contract |
|
|
32
|
+
| authors | List of authors |
|
|
33
|
+
| homepage | Homepage associated with the contract |
|
|
34
|
+
| license | Type of license e. g. ISC, MIT |
|
|
35
|
+
| interfaces | List of interfaces |
|
|
36
|
+
|
|
37
|
+
To save time in multi-contract projects, `taq generate-project-metadata` can be run. This will collect project level metadata fields which are then provided as the default values for each subsequent invocation of `taq generate-metadata < contractName >`
|
|
38
|
+
|
|
39
|
+
The plugin exposes two tasks:
|
|
40
|
+
- `taq generate-metadata < contractName >` - Generates `TZIP-16` compliant metadata for a contract in JSON format
|
|
41
|
+
- `taq generate-project-metadata` - Generates project level metadata that is written to `config.json`
|
|
42
|
+
|
|
43
|
+
Contract metadata is output into a JSON file in the `./artifacts` directory, while project metadata is added to `.taq/config.json` as seen here:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
"metadata": {
|
|
47
|
+
"name": "string",
|
|
48
|
+
"projectDescription": "string",
|
|
49
|
+
"authors": [
|
|
50
|
+
"string",
|
|
51
|
+
"string"
|
|
52
|
+
],
|
|
53
|
+
"homepage": "url",
|
|
54
|
+
"license": "string"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Tasks
|
|
59
|
+
|
|
60
|
+
### `taq generate-metadata [contractName]`
|
|
61
|
+
|
|
62
|
+
The `generate-metadata` task starts an interactive interface that collects the relavent fields via CLI prompts and outputs a `TZIP-16` compliant metadata file in JSON format
|
|
63
|
+
|
|
64
|
+
> ### :page_with_curl: Note
|
|
65
|
+
> The contract may, or may not exist yet
|
|
66
|
+
|
|
67
|
+
#### Command Structure
|
|
68
|
+
|
|
69
|
+
```shell
|
|
70
|
+
taq generate-metadata < sourceFile >
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Options
|
|
74
|
+
|
|
75
|
+
The metadata `generate-metadata` task will accept the following required parameters:
|
|
76
|
+
|
|
77
|
+
| name | description |
|
|
78
|
+
|:-------------|--------------------------------------------------------------------|
|
|
79
|
+
| contractName | The contract name (the contract may exist, or not exist) |
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
#### Task Properties
|
|
83
|
+
|
|
84
|
+
| attribute | value |
|
|
85
|
+
|------------|:---------------------------------------:|
|
|
86
|
+
| task | 'generate-metadata' |
|
|
87
|
+
| command | 'generate-metadata [sourceFile]' |
|
|
88
|
+
| aliases | N/A |
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### `taq generate-project-metadata`
|
|
92
|
+
|
|
93
|
+
The `generate-project-metadata` task collects project-level metadata fields which are added to `config.json`. Once generated, these values will be used as defaults when generating contract metadata
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
#### Command Structure
|
|
97
|
+
|
|
98
|
+
```shell
|
|
99
|
+
taq generate-project-metadata
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Options
|
|
103
|
+
|
|
104
|
+
The `generate-project-metadata` task not not have any additional parameters or options
|
|
105
|
+
|
|
106
|
+
#### Task Properties
|
|
107
|
+
|
|
108
|
+
| attribute | value |
|
|
109
|
+
|:----------:|:---------------------------------------:|
|
|
110
|
+
| task | 'generate-project-metadata' |
|
|
111
|
+
| command | 'taq generate-project-metadata' |
|
|
112
|
+
| aliases | N/A |
|
|
113
|
+
|
|
114
|
+
## Behaviour
|
|
115
|
+
|
|
116
|
+
The user flow for each task is outlined below
|
|
117
|
+
|
|
118
|
+
### Generating or updating a metadata file for a contract
|
|
119
|
+
|
|
120
|
+
- Prompt the user for standard metadata fields, providing default values
|
|
121
|
+
- If metadata already exists for a contract, it will use existing values as the default prompt values
|
|
122
|
+
- If contractName is not provided, it will prompt for contractName
|
|
123
|
+
- For a new contract metadata, it will find other contracts metadata and use those for the default values for common fields like authors, license, homepage this eliminates an extra step to define/register project metadata, but project metadata will be used as a priority if available
|
|
124
|
+
|
|
125
|
+
### Generating project metadata
|
|
126
|
+
|
|
127
|
+
- Add the project metadata to .taq config.json
|
|
128
|
+
- Add the project metadata schema
|
|
129
|
+
|
|
130
|
+
### Default Value Priority
|
|
131
|
+
|
|
132
|
+
Summary of priority for default values:
|
|
133
|
+
- 1st Priority: Previous Values
|
|
134
|
+
- 2nd Priority: Project Values
|
|
135
|
+
- 3rd Priority: Existing Contract Metadata Values
|
|
136
|
+
- 4th Priority: Other Contract Values
|
|
137
|
+
|
|
138
|
+
## Plugin Architecture
|
|
139
|
+
|
|
140
|
+
This is a plugin developed for Taqueria built on NodeJS using the Taqueria Node SDK
|
|
141
|
+
|
|
142
|
+
|
package/_readme.eta
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<% if (it.output == "github") { %>
|
|
2
|
+
# Taqueria Metadata Plugin
|
|
3
|
+
<% } %>
|
|
4
|
+
|
|
5
|
+
The Taqueria Metadata plugin provides an easy way to create a json file containing `TZIP-16` compliant metadata related to a smart contract
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Taqueria v0.13.0 or later
|
|
10
|
+
- Node.js v16.3 or later
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
To install the metadata plugin on a Taqueria project, navigate to the project folder and run:
|
|
15
|
+
```shell
|
|
16
|
+
taq install @taqueria/plugin-metadata
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Configuration
|
|
20
|
+
|
|
21
|
+
There is no configuration required to run the plugin
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
The Metadata plugin provides an interactive CLI interface that collects basic contract metadata fields as outlined in `TZIP-16` specification, and generates a compliant JSON file that can be uploaded to IPFS
|
|
26
|
+
|
|
27
|
+
The metadata fields collected are:
|
|
28
|
+
|
|
29
|
+
| name | description |
|
|
30
|
+
|:-----------------:|:-------------------------------------:|
|
|
31
|
+
| name | Name of the contract |
|
|
32
|
+
| version | Version of the contract |
|
|
33
|
+
| description | Description of the contract |
|
|
34
|
+
| authors | List of authors |
|
|
35
|
+
| homepage | Homepage associated with the contract |
|
|
36
|
+
| license | Type of license e. g. ISC, MIT |
|
|
37
|
+
| interfaces | List of interfaces |
|
|
38
|
+
|
|
39
|
+
To save time in multi-contract projects, `taq generate-project-metadata` can be run. This will collect project level metadata fields which are then provided as the default values for each subsequent invocation of `taq generate-metadata < contractName >`
|
|
40
|
+
|
|
41
|
+
The plugin exposes two tasks:
|
|
42
|
+
- `taq generate-metadata < contractName >` - Generates `TZIP-16` compliant metadata for a contract in JSON format
|
|
43
|
+
- `taq generate-project-metadata` - Generates project level metadata that is written to `config.json`
|
|
44
|
+
|
|
45
|
+
Contract metadata is output into a JSON file in the `./artifacts` directory, while project metadata is added to `.taq/config.json` as seen here:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
"metadata": {
|
|
49
|
+
"name": "string",
|
|
50
|
+
"projectDescription": "string",
|
|
51
|
+
"authors": [
|
|
52
|
+
"string",
|
|
53
|
+
"string"
|
|
54
|
+
],
|
|
55
|
+
"homepage": "url",
|
|
56
|
+
"license": "string"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Tasks
|
|
61
|
+
|
|
62
|
+
### `taq generate-metadata [contractName]`
|
|
63
|
+
|
|
64
|
+
The `generate-metadata` task starts an interactive interface that collects the relavent fields via CLI prompts and outputs a `TZIP-16` compliant metadata file in JSON format
|
|
65
|
+
|
|
66
|
+
<%~ it.noteOpenAdmonition %>
|
|
67
|
+
The contract may, or may not exist yet
|
|
68
|
+
<%= it.closeAdmonition %>
|
|
69
|
+
|
|
70
|
+
#### Command Structure
|
|
71
|
+
|
|
72
|
+
```shell
|
|
73
|
+
taq generate-metadata < sourceFile >
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Options
|
|
77
|
+
|
|
78
|
+
The metadata `generate-metadata` task will accept the following required parameters:
|
|
79
|
+
|
|
80
|
+
| name | description |
|
|
81
|
+
|:-------------|--------------------------------------------------------------------|
|
|
82
|
+
| contractName | The contract name (the contract may exist, or not exist) |
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
#### Task Properties
|
|
86
|
+
|
|
87
|
+
| attribute | value |
|
|
88
|
+
|------------|:---------------------------------------:|
|
|
89
|
+
| task | 'generate-metadata' |
|
|
90
|
+
| command | 'generate-metadata [sourceFile]' |
|
|
91
|
+
| aliases | N/A |
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### `taq generate-project-metadata`
|
|
95
|
+
|
|
96
|
+
The `generate-project-metadata` task collects project-level metadata fields which are added to `config.json`. Once generated, these values will be used as defaults when generating contract metadata
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
#### Command Structure
|
|
100
|
+
|
|
101
|
+
```shell
|
|
102
|
+
taq generate-project-metadata
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Options
|
|
106
|
+
|
|
107
|
+
The `generate-project-metadata` task not not have any additional parameters or options
|
|
108
|
+
|
|
109
|
+
#### Task Properties
|
|
110
|
+
|
|
111
|
+
| attribute | value |
|
|
112
|
+
|:----------:|:---------------------------------------:|
|
|
113
|
+
| task | 'generate-project-metadata' |
|
|
114
|
+
| command | 'taq generate-project-metadata' |
|
|
115
|
+
| aliases | N/A |
|
|
116
|
+
|
|
117
|
+
## Behaviour
|
|
118
|
+
|
|
119
|
+
The user flow for each task is outlined below
|
|
120
|
+
|
|
121
|
+
### Generating or updating a metadata file for a contract
|
|
122
|
+
|
|
123
|
+
- Prompt the user for standard metadata fields, providing default values
|
|
124
|
+
- If metadata already exists for a contract, it will use existing values as the default prompt values
|
|
125
|
+
- If contractName is not provided, it will prompt for contractName
|
|
126
|
+
- For a new contract metadata, it will find other contracts metadata and use those for the default values for common fields like authors, license, homepage this eliminates an extra step to define/register project metadata, but project metadata will be used as a priority if available
|
|
127
|
+
|
|
128
|
+
### Generating project metadata
|
|
129
|
+
|
|
130
|
+
- Add the project metadata to .taq config.json
|
|
131
|
+
- Add the project metadata schema
|
|
132
|
+
|
|
133
|
+
### Default Value Priority
|
|
134
|
+
|
|
135
|
+
Summary of priority for default values:
|
|
136
|
+
- 1st Priority: Previous Values
|
|
137
|
+
- 2nd Priority: Project Values
|
|
138
|
+
- 3rd Priority: Existing Contract Metadata Values
|
|
139
|
+
- 4th Priority: Other Contract Values
|
|
140
|
+
|
|
141
|
+
## Plugin Architecture
|
|
142
|
+
|
|
143
|
+
This is a plugin developed for Taqueria built on NodeJS using the Taqueria Node SDK
|
|
144
|
+
|
|
145
|
+
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Plugin as $8CNkB$Plugin, Task as $8CNkB$Task, PositionalArg as $8CNkB$PositionalArg, sendJsonRes as $8CNkB$sendJsonRes, sendAsyncErr as $8CNkB$sendAsyncErr} from "@taqueria/node-sdk";
|
|
1
|
+
import {Plugin as $8CNkB$Plugin, Task as $8CNkB$Task, PositionalArg as $8CNkB$PositionalArg, writeJsonFile as $8CNkB$writeJsonFile, sendRes as $8CNkB$sendRes, sendJsonRes as $8CNkB$sendJsonRes, sendAsyncErr as $8CNkB$sendAsyncErr} from "@taqueria/node-sdk";
|
|
2
2
|
import $8CNkB$fspromises from "fs/promises";
|
|
3
3
|
import $8CNkB$path from "path";
|
|
4
4
|
import $8CNkB$prompts from "prompts";
|
|
@@ -8,7 +8,8 @@ import $8CNkB$prompts from "prompts";
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
const $b297f5d0aa12bc82$var$createContractMetadata = async (contractName,
|
|
11
|
+
const $b297f5d0aa12bc82$var$createContractMetadata = async (contractName, config)=>{
|
|
12
|
+
const contracts = Object.keys(config.contracts ?? {}).map((x)=>(0, $8CNkB$path).basename(x, (0, $8CNkB$path).extname(x)));
|
|
12
13
|
if (!contractName) {
|
|
13
14
|
if (contracts?.length) {
|
|
14
15
|
// Show contract options
|
|
@@ -50,8 +51,15 @@ const $b297f5d0aa12bc82$var$createContractMetadata = async (contractName, contra
|
|
|
50
51
|
};
|
|
51
52
|
let defaultValues = await loadContractMetadata(contractName);
|
|
52
53
|
if (defaultValues) console.log("Existing Metadata:", defaultValues);
|
|
54
|
+
// Load project metadata for defaults
|
|
55
|
+
if (!defaultValues && config.metadata) // console.log('Project Metadata:', defaultValues);
|
|
56
|
+
defaultValues = {
|
|
57
|
+
...config.metadata,
|
|
58
|
+
// use the contractName instead of the projectName as the name default
|
|
59
|
+
name: contractName
|
|
60
|
+
};
|
|
61
|
+
// Load other contracts for defaults
|
|
53
62
|
if (!defaultValues && contracts?.length) {
|
|
54
|
-
// Load other contracts for defaults
|
|
55
63
|
const otherContractMetadata = (await Promise.all(contracts.map(async (x)=>await loadContractMetadata(x)))).filter((x)=>x).map((x)=>x) ?? [];
|
|
56
64
|
defaultValues = {
|
|
57
65
|
authors: otherContractMetadata.map((x)=>x.authors).filter((x)=>x?.length)[0],
|
|
@@ -114,12 +122,72 @@ const $b297f5d0aa12bc82$var$createContractMetadata = async (contractName, contra
|
|
|
114
122
|
]
|
|
115
123
|
};
|
|
116
124
|
};
|
|
125
|
+
const $b297f5d0aa12bc82$var$createProjectMetadata = async (config)=>{
|
|
126
|
+
const defaultValues = config.metadata;
|
|
127
|
+
// Common fields from Tzip-16
|
|
128
|
+
const response = await (0, $8CNkB$prompts)([
|
|
129
|
+
{
|
|
130
|
+
type: `text`,
|
|
131
|
+
name: `name`,
|
|
132
|
+
message: `Enter project name`,
|
|
133
|
+
initial: defaultValues?.name ?? ""
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: `text`,
|
|
137
|
+
name: `description`,
|
|
138
|
+
message: `Enter project description`,
|
|
139
|
+
initial: defaultValues?.projectDescription ?? ""
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "list",
|
|
143
|
+
name: "authors",
|
|
144
|
+
message: "Enter project authors (comma separated)",
|
|
145
|
+
initial: defaultValues?.authors?.join(",") ?? "",
|
|
146
|
+
separator: ","
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: "text",
|
|
150
|
+
name: "homepage",
|
|
151
|
+
message: "Enter project web url",
|
|
152
|
+
initial: defaultValues?.homepage ?? ""
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "text",
|
|
156
|
+
name: "license",
|
|
157
|
+
message: "Enter project license",
|
|
158
|
+
initial: defaultValues?.license ?? "ISC"
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
161
|
+
const projectMetadata = {
|
|
162
|
+
name: response.name,
|
|
163
|
+
projectDescription: response.description,
|
|
164
|
+
authors: response.authors,
|
|
165
|
+
homepage: response.homepage,
|
|
166
|
+
license: response.license
|
|
167
|
+
};
|
|
168
|
+
const updatedConfig = {
|
|
169
|
+
...config,
|
|
170
|
+
metadata: projectMetadata
|
|
171
|
+
};
|
|
172
|
+
await (0, $8CNkB$writeJsonFile)(config.configFile)(updatedConfig);
|
|
173
|
+
return {
|
|
174
|
+
render: "table",
|
|
175
|
+
data: Object.entries(projectMetadata).map(([k, v])=>({
|
|
176
|
+
key: k,
|
|
177
|
+
value: v
|
|
178
|
+
}))
|
|
179
|
+
};
|
|
180
|
+
};
|
|
117
181
|
const $b297f5d0aa12bc82$var$execute = async (opts)=>{
|
|
118
182
|
const { task: task , contractName: contractName , config: config , } = opts;
|
|
119
|
-
|
|
183
|
+
// TAQ BUG: If both tasks start with 'generate' then 'project-metadata' is always selected
|
|
184
|
+
// WORKAROUND: If the 2nd command is changed to generate-project-metadata, it works as expected
|
|
185
|
+
// console.log('execute', { task, contractName, metadata: config.metadata });
|
|
120
186
|
switch(task){
|
|
121
187
|
case "metadata":
|
|
122
|
-
return $b297f5d0aa12bc82$var$createContractMetadata(contractName,
|
|
188
|
+
return $b297f5d0aa12bc82$var$createContractMetadata(contractName, config);
|
|
189
|
+
case "project-metadata":
|
|
190
|
+
return $b297f5d0aa12bc82$var$createProjectMetadata(config);
|
|
123
191
|
default:
|
|
124
192
|
throw new Error(`${task} is not an understood task by the metadata plugin`);
|
|
125
193
|
}
|
|
@@ -128,6 +196,11 @@ var $b297f5d0aa12bc82$export$2e2bcd8739ae039 = async (args)=>{
|
|
|
128
196
|
const opts = args;
|
|
129
197
|
try {
|
|
130
198
|
const resultRaw = await $b297f5d0aa12bc82$var$execute(opts);
|
|
199
|
+
const USE_TEXT_OUTPUT = true;
|
|
200
|
+
if (USE_TEXT_OUTPUT) {
|
|
201
|
+
const message = JSON.stringify(resultRaw.data, null, 2);
|
|
202
|
+
return (0, $8CNkB$sendRes)(message);
|
|
203
|
+
}
|
|
131
204
|
// TODO: Fix deno parsing
|
|
132
205
|
// Without this, `data.reduce is not a function`
|
|
133
206
|
const result = "data" in resultRaw ? resultRaw.data : resultRaw;
|
|
@@ -146,7 +219,7 @@ var $b297f5d0aa12bc82$export$2e2bcd8739ae039 = async (args)=>{
|
|
|
146
219
|
tasks: [
|
|
147
220
|
(0, $8CNkB$Task).create({
|
|
148
221
|
task: "metadata",
|
|
149
|
-
command: "generate
|
|
222
|
+
command: "generate-metadata [contractName]",
|
|
150
223
|
description: "Create contract metadata.",
|
|
151
224
|
aliases: [],
|
|
152
225
|
handler: "proxy",
|
|
@@ -158,6 +231,14 @@ var $b297f5d0aa12bc82$export$2e2bcd8739ae039 = async (args)=>{
|
|
|
158
231
|
}),
|
|
159
232
|
],
|
|
160
233
|
encoding: "none"
|
|
234
|
+
}),
|
|
235
|
+
(0, $8CNkB$Task).create({
|
|
236
|
+
task: "project-metadata",
|
|
237
|
+
command: "generate-project-metadata",
|
|
238
|
+
description: "Create project metadata to be used as defaults for contracts.",
|
|
239
|
+
aliases: [],
|
|
240
|
+
handler: "proxy",
|
|
241
|
+
encoding: "none"
|
|
161
242
|
}),
|
|
162
243
|
],
|
|
163
244
|
proxy: $b297f5d0aa12bc82$export$2e2bcd8739ae039
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;ACAA;;;;AAkBA,MAAM,4CAAsB,GAAG,OAC9B,YAAgC,EAChC,SAA+B,GACF;IAC7B,IAAI,CAAC,YAAY,EAAE;QAClB,IAAI,SAAS,EAAE,MAAM,EAAE;YACtB,wBAAwB;YACxB,2CAA2C;YAE3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,GAChC,MAAM,CAAA,GAAA,cAAO,CAAA,CAAC;gBACf;oBACC,IAAI,EAAE,CAAC,MAAM,CAAC;oBACd,IAAI,EAAE,CAAC,Q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,EAAE;YACN,CAAA,GAAA,WAAI,CAAA,CAAC,MAAM,CAAC;gBACX,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,kCAAkC;gBAC3C,WAAW,EAAE,2BAA2B;gBACxC,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE;oBACZ,CAAA,GAAA,oBAAa,CAAA,CAAC,MAAM,CAAC;wBACpB,WAAW,EAAE,cAAc;wBAC3B,WAAW,EAAE,iBAAiB;wBAC9B,IAAI,EAAE,QAAQ;qBACd,CAAC;iBACF;gBACD,QAAQ,EAAE,MAAM;aAChB,CAAC;SACF;eACD,wCAAK;KACL,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["index.ts","src/proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';\nimport proxy from './src/proxy';\n\nPlugin.create(() => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'metadata',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'metadata',\n\t\t\tcommand: 'generate metadata [contractName]',\n\t\t\tdescription: 'Create contract metadata.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'contractName',\n\t\t\t\t\tdescription: 'Which contract?',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\tencoding: 'none',\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { getContracts, sendAsyncErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport prompts from 'prompts';\n\n// TODO: What should this be, it was removed from the sdk\ntype PluginResponse =\n\t| void\n\t| {\n\t\trender: 'table';\n\t\tdata: unknown[];\n\t};\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\treadonly contractName?: string;\n}\n\nconst createContractMetadata = async (\n\tcontractName: undefined | string,\n\tcontracts: undefined | string[],\n): Promise<PluginResponse> => {\n\tif (!contractName) {\n\t\tif (contracts?.length) {\n\t\t\t// Show contract options\n\t\t\t// console.log('contracts', { contracts });\n\n\t\t\tconst result = contracts.length > 1\n\t\t\t\t? await prompts([\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: `select`,\n\t\t\t\t\t\tname: `contract`,\n\t\t\t\t\t\tmessage: `Pick a contract`,\n\t\t\t\t\t\tchoices: contracts.map(x => ({ title: x, value: x })),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t\t: await prompts([\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: `text`,\n\t\t\t\t\t\tname: `contract`,\n\t\t\t\t\t\tmessage: `Enter a contract name`,\n\t\t\t\t\t\tinitial: contracts[0],\n\t\t\t\t\t},\n\t\t\t\t]) as { contract: string };\n\n\t\t\tcontractName = result.contract;\n\t\t}\n\n\t\tif (!contractName) {\n\t\t\tthrow new Error(`contractName was not provided`);\n\t\t}\n\t}\n\n\tconst destFilePath = path.resolve(process.cwd(), `./artifacts/${contractName}.json`);\n\n\tconst loadContractMetadata = async (otherContractName: string) => {\n\t\ttry {\n\t\t\tconst otherContractFilePath = path.resolve(process.cwd(), `./artifacts/${otherContractName}.json`);\n\t\t\tconst existingContent = await fs.readFile(otherContractFilePath, { encoding: 'utf-8' });\n\t\t\treturn JSON.parse(existingContent) as Partial<typeof contractMetadata>;\n\t\t} catch (err) {\n\t\t\t// ignore missing file\n\t\t\treturn undefined;\n\t\t}\n\t};\n\n\tlet defaultValues = await loadContractMetadata(contractName);\n\tif (defaultValues) {\n\t\tconsole.log('Existing Metadata:', defaultValues);\n\t}\n\n\tif (!defaultValues && contracts?.length) {\n\t\t// Load other contracts for defaults\n\t\tconst otherContractMetadata = (await Promise.all(contracts.map(async x => await loadContractMetadata(x))))\n\t\t\t.filter(x => x).map(x => x!) ?? [];\n\t\tdefaultValues = {\n\t\t\tauthors: otherContractMetadata.map(x => x.authors).filter(x => x?.length)[0],\n\t\t\thomepage: otherContractMetadata.map(x => x.homepage).filter(x => x?.length)[0],\n\t\t\tlicense: otherContractMetadata.map(x => x.license).filter(x => x?.length)[0],\n\t\t};\n\t}\n\n\t// Basic Tzip-16 contract metadata\n\tconst response = await prompts([\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `name`,\n\t\t\tmessage: `Enter contract name`,\n\t\t\tinitial: defaultValues?.name ?? contractName,\n\t\t},\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `description`,\n\t\t\tmessage: `Enter contract description`,\n\t\t\tinitial: defaultValues?.description ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'list',\n\t\t\tname: 'authors',\n\t\t\tmessage: 'Enter contract authors (comma separated)',\n\t\t\tinitial: defaultValues?.authors?.join(',') ?? '',\n\t\t\tseparator: ',',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'homepage',\n\t\t\tmessage: 'Enter contract web url',\n\t\t\tinitial: defaultValues?.homepage ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'license',\n\t\t\tmessage: 'Enter contract license',\n\t\t\tinitial: defaultValues?.license ?? 'ISC',\n\t\t},\n\t\t// TODO: errors - mapping of error codes to human readable error messages\n\t\t// TODO: views - off-chain views\n\t\t// TODO: select optional interfaces and answer additional prompts\n\t]) as {\n\t\tname: string;\n\t\tdescription: string;\n\t\tauthors: string[];\n\t\tlicense: string;\n\t\thomepage: string;\n\t};\n\n\tconst contractMetadata = {\n\t\tname: response.name,\n\t\tversion: 'v1.0.0',\n\t\tdescription: response.description,\n\t\tauthors: response.authors,\n\t\thomepage: response.homepage,\n\t\tlicense: response.license,\n\t\tinterfaces: [\n\t\t\t'TZIP-016',\n\t\t],\n\t};\n\tawait fs.writeFile(destFilePath, JSON.stringify(contractMetadata, null, 2));\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: [\n\t\t\t{\n\t\t\t\tcontractName,\n\t\t\t},\n\t\t],\n\t};\n};\n\nconst execute = async (opts: Opts): Promise<PluginResponse> => {\n\tconst {\n\t\ttask,\n\t\tcontractName,\n\t\tconfig,\n\t} = opts;\n\n\tconst contracts = Object.keys(config.contracts ?? {}).map(x => path.basename(x, path.extname(x)));\n\n\tswitch (task) {\n\t\tcase 'metadata':\n\t\t\treturn createContractMetadata(contractName, contracts);\n\t\tdefault:\n\t\t\tthrow new Error(`${task} is not an understood task by the metadata plugin`);\n\t}\n};\n\nexport default async (args: RequestArgs.ProxyRequestArgs): Promise<PluginResponse> => {\n\tconst opts = args as Opts;\n\n\ttry {\n\t\tconst resultRaw = await execute(opts) as Record<string, unknown>;\n\t\t// TODO: Fix deno parsing\n\t\t// Without this, `data.reduce is not a function`\n\t\tconst result = ('data' in resultRaw) ? resultRaw.data : resultRaw;\n\t\treturn sendJsonRes(result);\n\t} catch (err) {\n\t\tconst error = err as Error;\n\t\tif (error.message) {\n\t\t\treturn sendAsyncErr(error.message);\n\t\t}\n\t}\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"/"}
|
|
1
|
+
{"mappings":";;;;;AAAA;ACAA;;;;AAmBA,MAAM,4CAAsB,GAAG,OAC9B,YAAgC,EAChC,MAAc,GACe;IAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA,CAAC,GAAI,CAAA,GAAA,WAAI,CAAA,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAA,GAAA,WAAI,CAAA,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,AAAC;IAElG,IAAI,CAAC,YAAY,EAAE;QAClB,IAAI,SAAS,EAAE,MAAM,EAAE;YACtB,wBAAwB;YACxB,2CAA2C;YAE3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,GAChC,MAAM,CAAA,GAAA,cAAO,CAAA,C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,EAAE,2BAA2B;gBACpC,WAAW,EAAE,+DAA+D;gBAC5E,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,MAAM;aAChB,CAAC;SACF;eACD,wCAAK;KACL,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["index.ts","src/proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';\nimport proxy from './src/proxy';\n\nPlugin.create(() => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'metadata',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'metadata',\n\t\t\tcommand: 'generate-metadata [contractName]',\n\t\t\tdescription: 'Create contract metadata.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'contractName',\n\t\t\t\t\tdescription: 'Which contract?',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\tencoding: 'none',\n\t\t}),\n\t\tTask.create({\n\t\t\ttask: 'project-metadata',\n\t\t\tcommand: 'generate-project-metadata',\n\t\t\tdescription: 'Create project metadata to be used as defaults for contracts.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'none',\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { getContracts, sendAsyncErr, sendJsonRes, sendRes, writeJsonFile } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport prompts from 'prompts';\n\n// TODO: What should this be, it was removed from the sdk\ntype PluginResponse =\n\t| void\n\t| {\n\t\trender: 'table';\n\t\tdata: unknown[];\n\t};\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\treadonly contractName?: string;\n}\ntype Config = Opts['config'];\n\nconst createContractMetadata = async (\n\tcontractName: undefined | string,\n\tconfig: Config,\n): Promise<PluginResponse> => {\n\tconst contracts = Object.keys(config.contracts ?? {}).map(x => path.basename(x, path.extname(x)));\n\n\tif (!contractName) {\n\t\tif (contracts?.length) {\n\t\t\t// Show contract options\n\t\t\t// console.log('contracts', { contracts });\n\n\t\t\tconst result = contracts.length > 1\n\t\t\t\t? await prompts([\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: `select`,\n\t\t\t\t\t\tname: `contract`,\n\t\t\t\t\t\tmessage: `Pick a contract`,\n\t\t\t\t\t\tchoices: contracts.map(x => ({ title: x, value: x })),\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t\t: await prompts([\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: `text`,\n\t\t\t\t\t\tname: `contract`,\n\t\t\t\t\t\tmessage: `Enter a contract name`,\n\t\t\t\t\t\tinitial: contracts[0],\n\t\t\t\t\t},\n\t\t\t\t]) as { contract: string };\n\n\t\t\tcontractName = result.contract;\n\t\t}\n\n\t\tif (!contractName) {\n\t\t\tthrow new Error(`contractName was not provided`);\n\t\t}\n\t}\n\n\tconst destFilePath = path.resolve(process.cwd(), `./artifacts/${contractName}.json`);\n\n\tconst loadContractMetadata = async (otherContractName: string) => {\n\t\ttry {\n\t\t\tconst otherContractFilePath = path.resolve(process.cwd(), `./artifacts/${otherContractName}.json`);\n\t\t\tconst existingContent = await fs.readFile(otherContractFilePath, { encoding: 'utf-8' });\n\t\t\treturn JSON.parse(existingContent) as Partial<typeof contractMetadata>;\n\t\t} catch (err) {\n\t\t\t// ignore missing file\n\t\t\treturn undefined;\n\t\t}\n\t};\n\n\tlet defaultValues = await loadContractMetadata(contractName);\n\tif (defaultValues) {\n\t\tconsole.log('Existing Metadata:', defaultValues);\n\t}\n\n\t// Load project metadata for defaults\n\tif (!defaultValues && config.metadata) {\n\t\t// console.log('Project Metadata:', defaultValues);\n\t\tdefaultValues = {\n\t\t\t...config.metadata,\n\t\t\t// use the contractName instead of the projectName as the name default\n\t\t\tname: contractName,\n\t\t};\n\t}\n\n\t// Load other contracts for defaults\n\tif (!defaultValues && contracts?.length) {\n\t\tconst otherContractMetadata = (await Promise.all(contracts.map(async x => await loadContractMetadata(x))))\n\t\t\t.filter(x => x).map(x => x!) ?? [];\n\t\tdefaultValues = {\n\t\t\tauthors: otherContractMetadata.map(x => x.authors).filter(x => x?.length)[0],\n\t\t\thomepage: otherContractMetadata.map(x => x.homepage).filter(x => x?.length)[0],\n\t\t\tlicense: otherContractMetadata.map(x => x.license).filter(x => x?.length)[0],\n\t\t};\n\t}\n\n\t// Basic Tzip-16 contract metadata\n\tconst response = await prompts([\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `name`,\n\t\t\tmessage: `Enter contract name`,\n\t\t\tinitial: defaultValues?.name ?? contractName,\n\t\t},\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `description`,\n\t\t\tmessage: `Enter contract description`,\n\t\t\tinitial: defaultValues?.description ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'list',\n\t\t\tname: 'authors',\n\t\t\tmessage: 'Enter contract authors (comma separated)',\n\t\t\tinitial: defaultValues?.authors?.join(',') ?? '',\n\t\t\tseparator: ',',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'homepage',\n\t\t\tmessage: 'Enter contract web url',\n\t\t\tinitial: defaultValues?.homepage ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'license',\n\t\t\tmessage: 'Enter contract license',\n\t\t\tinitial: defaultValues?.license ?? 'ISC',\n\t\t},\n\t\t// TODO: errors - mapping of error codes to human readable error messages\n\t\t// TODO: views - off-chain views\n\t\t// TODO: select optional interfaces and answer additional prompts\n\t]) as {\n\t\tname: string;\n\t\tdescription: string;\n\t\tauthors: string[];\n\t\tlicense: string;\n\t\thomepage: string;\n\t};\n\n\tconst contractMetadata = {\n\t\tname: response.name,\n\t\tversion: 'v1.0.0',\n\t\tdescription: response.description,\n\t\tauthors: response.authors,\n\t\thomepage: response.homepage,\n\t\tlicense: response.license,\n\t\tinterfaces: [\n\t\t\t'TZIP-016',\n\t\t],\n\t};\n\tawait fs.writeFile(destFilePath, JSON.stringify(contractMetadata, null, 2));\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: [\n\t\t\t{\n\t\t\t\tcontractName,\n\t\t\t},\n\t\t],\n\t};\n};\n\ntype ProjectMetadata = {\n\tname: string;\n\tprojectDescription: string;\n\tauthors: string[];\n\tlicense: string;\n\thomepage: string;\n};\nconst createProjectMetadata = async (\n\tconfig: Config,\n): Promise<PluginResponse> => {\n\tconst defaultValues = config.metadata;\n\n\t// Common fields from Tzip-16\n\tconst response = await prompts([\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `name`,\n\t\t\tmessage: `Enter project name`,\n\t\t\tinitial: defaultValues?.name ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: `text`,\n\t\t\tname: `description`,\n\t\t\tmessage: `Enter project description`,\n\t\t\tinitial: defaultValues?.projectDescription ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'list',\n\t\t\tname: 'authors',\n\t\t\tmessage: 'Enter project authors (comma separated)',\n\t\t\tinitial: defaultValues?.authors?.join(',') ?? '',\n\t\t\tseparator: ',',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'homepage',\n\t\t\tmessage: 'Enter project web url',\n\t\t\tinitial: defaultValues?.homepage ?? '',\n\t\t},\n\t\t{\n\t\t\ttype: 'text',\n\t\t\tname: 'license',\n\t\t\tmessage: 'Enter project license',\n\t\t\tinitial: defaultValues?.license ?? 'ISC',\n\t\t},\n\t]) as {\n\t\tname: string;\n\t\tdescription: string;\n\t\tauthors: string[];\n\t\thomepage: string;\n\t\tlicense: string;\n\t};\n\n\tconst projectMetadata: ProjectMetadata = {\n\t\tname: response.name,\n\t\tprojectDescription: response.description,\n\t\tauthors: response.authors,\n\t\thomepage: response.homepage,\n\t\tlicense: response.license,\n\t};\n\n\tconst updatedConfig = {\n\t\t...config,\n\t\tmetadata: projectMetadata,\n\t};\n\tawait writeJsonFile(config.configFile)(updatedConfig);\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: Object.entries(projectMetadata).map(([k, v]) => ({ key: k, value: v })),\n\t};\n};\n\nconst execute = async (opts: Opts): Promise<PluginResponse> => {\n\tconst {\n\t\ttask,\n\t\tcontractName,\n\t\tconfig,\n\t} = opts;\n\n\t// TAQ BUG: If both tasks start with 'generate' then 'project-metadata' is always selected\n\t// WORKAROUND: If the 2nd command is changed to generate-project-metadata, it works as expected\n\t// console.log('execute', { task, contractName, metadata: config.metadata });\n\n\tswitch (task) {\n\t\tcase 'metadata':\n\t\t\treturn createContractMetadata(contractName, config as (typeof config & { metadata?: ProjectMetadata }));\n\t\tcase 'project-metadata':\n\t\t\treturn createProjectMetadata(config as (typeof config & { metadata?: ProjectMetadata }));\n\t\tdefault:\n\t\t\tthrow new Error(`${task} is not an understood task by the metadata plugin`);\n\t}\n};\n\nexport default async (args: RequestArgs.ProxyRequestArgs): Promise<PluginResponse> => {\n\tconst opts = args as Opts;\n\n\ttry {\n\t\tconst resultRaw = await execute(opts) as Record<string, unknown>;\n\n\t\tconst USE_TEXT_OUTPUT = true;\n\t\tif (USE_TEXT_OUTPUT) {\n\t\t\tconst message = JSON.stringify(resultRaw.data, null, 2);\n\t\t\treturn sendRes(message);\n\t\t}\n\n\t\t// TODO: Fix deno parsing\n\t\t// Without this, `data.reduce is not a function`\n\t\tconst result = ('data' in resultRaw) ? resultRaw.data : resultRaw;\n\t\treturn sendJsonRes(result);\n\t} catch (err) {\n\t\tconst error = err as Error;\n\t\tif (error.message) {\n\t\t\treturn sendAsyncErr(error.message);\n\t\t}\n\t}\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"/"}
|
package/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ Plugin.create(() => ({
|
|
|
8
8
|
tasks: [
|
|
9
9
|
Task.create({
|
|
10
10
|
task: 'metadata',
|
|
11
|
-
command: 'generate
|
|
11
|
+
command: 'generate-metadata [contractName]',
|
|
12
12
|
description: 'Create contract metadata.',
|
|
13
13
|
aliases: [],
|
|
14
14
|
handler: 'proxy',
|
|
@@ -21,6 +21,14 @@ Plugin.create(() => ({
|
|
|
21
21
|
],
|
|
22
22
|
encoding: 'none',
|
|
23
23
|
}),
|
|
24
|
+
Task.create({
|
|
25
|
+
task: 'project-metadata',
|
|
26
|
+
command: 'generate-project-metadata',
|
|
27
|
+
description: 'Create project metadata to be used as defaults for contracts.',
|
|
28
|
+
aliases: [],
|
|
29
|
+
handler: 'proxy',
|
|
30
|
+
encoding: 'none',
|
|
31
|
+
}),
|
|
24
32
|
],
|
|
25
33
|
proxy,
|
|
26
34
|
}), process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taqueria/plugin-metadata",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "A plugin for Taqueria providing metadata creation and validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"taqueria",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"directory": "taqueria-plugin-metadata"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@taqueria/node-sdk": "^0.
|
|
34
|
+
"@taqueria/node-sdk": "^0.14.2",
|
|
35
|
+
"@taqueria/protocol": "^0.14.2",
|
|
35
36
|
"prompts": "^2.4.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
package/src/proxy.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getContracts, sendAsyncErr, sendJsonRes } from '@taqueria/node-sdk';
|
|
1
|
+
import { getContracts, sendAsyncErr, sendJsonRes, sendRes, writeJsonFile } from '@taqueria/node-sdk';
|
|
2
2
|
import { RequestArgs } from '@taqueria/node-sdk/types';
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
4
|
import path from 'path';
|
|
@@ -15,11 +15,14 @@ type PluginResponse =
|
|
|
15
15
|
interface Opts extends RequestArgs.ProxyRequestArgs {
|
|
16
16
|
readonly contractName?: string;
|
|
17
17
|
}
|
|
18
|
+
type Config = Opts['config'];
|
|
18
19
|
|
|
19
20
|
const createContractMetadata = async (
|
|
20
21
|
contractName: undefined | string,
|
|
21
|
-
|
|
22
|
+
config: Config,
|
|
22
23
|
): Promise<PluginResponse> => {
|
|
24
|
+
const contracts = Object.keys(config.contracts ?? {}).map(x => path.basename(x, path.extname(x)));
|
|
25
|
+
|
|
23
26
|
if (!contractName) {
|
|
24
27
|
if (contracts?.length) {
|
|
25
28
|
// Show contract options
|
|
@@ -69,8 +72,18 @@ const createContractMetadata = async (
|
|
|
69
72
|
console.log('Existing Metadata:', defaultValues);
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
// Load project metadata for defaults
|
|
76
|
+
if (!defaultValues && config.metadata) {
|
|
77
|
+
// console.log('Project Metadata:', defaultValues);
|
|
78
|
+
defaultValues = {
|
|
79
|
+
...config.metadata,
|
|
80
|
+
// use the contractName instead of the projectName as the name default
|
|
81
|
+
name: contractName,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Load other contracts for defaults
|
|
72
86
|
if (!defaultValues && contracts?.length) {
|
|
73
|
-
// Load other contracts for defaults
|
|
74
87
|
const otherContractMetadata = (await Promise.all(contracts.map(async x => await loadContractMetadata(x))))
|
|
75
88
|
.filter(x => x).map(x => x!) ?? [];
|
|
76
89
|
defaultValues = {
|
|
@@ -147,6 +160,79 @@ const createContractMetadata = async (
|
|
|
147
160
|
};
|
|
148
161
|
};
|
|
149
162
|
|
|
163
|
+
type ProjectMetadata = {
|
|
164
|
+
name: string;
|
|
165
|
+
projectDescription: string;
|
|
166
|
+
authors: string[];
|
|
167
|
+
license: string;
|
|
168
|
+
homepage: string;
|
|
169
|
+
};
|
|
170
|
+
const createProjectMetadata = async (
|
|
171
|
+
config: Config,
|
|
172
|
+
): Promise<PluginResponse> => {
|
|
173
|
+
const defaultValues = config.metadata;
|
|
174
|
+
|
|
175
|
+
// Common fields from Tzip-16
|
|
176
|
+
const response = await prompts([
|
|
177
|
+
{
|
|
178
|
+
type: `text`,
|
|
179
|
+
name: `name`,
|
|
180
|
+
message: `Enter project name`,
|
|
181
|
+
initial: defaultValues?.name ?? '',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: `text`,
|
|
185
|
+
name: `description`,
|
|
186
|
+
message: `Enter project description`,
|
|
187
|
+
initial: defaultValues?.projectDescription ?? '',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
type: 'list',
|
|
191
|
+
name: 'authors',
|
|
192
|
+
message: 'Enter project authors (comma separated)',
|
|
193
|
+
initial: defaultValues?.authors?.join(',') ?? '',
|
|
194
|
+
separator: ',',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
type: 'text',
|
|
198
|
+
name: 'homepage',
|
|
199
|
+
message: 'Enter project web url',
|
|
200
|
+
initial: defaultValues?.homepage ?? '',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
type: 'text',
|
|
204
|
+
name: 'license',
|
|
205
|
+
message: 'Enter project license',
|
|
206
|
+
initial: defaultValues?.license ?? 'ISC',
|
|
207
|
+
},
|
|
208
|
+
]) as {
|
|
209
|
+
name: string;
|
|
210
|
+
description: string;
|
|
211
|
+
authors: string[];
|
|
212
|
+
homepage: string;
|
|
213
|
+
license: string;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const projectMetadata: ProjectMetadata = {
|
|
217
|
+
name: response.name,
|
|
218
|
+
projectDescription: response.description,
|
|
219
|
+
authors: response.authors,
|
|
220
|
+
homepage: response.homepage,
|
|
221
|
+
license: response.license,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const updatedConfig = {
|
|
225
|
+
...config,
|
|
226
|
+
metadata: projectMetadata,
|
|
227
|
+
};
|
|
228
|
+
await writeJsonFile(config.configFile)(updatedConfig);
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
render: 'table',
|
|
232
|
+
data: Object.entries(projectMetadata).map(([k, v]) => ({ key: k, value: v })),
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
150
236
|
const execute = async (opts: Opts): Promise<PluginResponse> => {
|
|
151
237
|
const {
|
|
152
238
|
task,
|
|
@@ -154,11 +240,15 @@ const execute = async (opts: Opts): Promise<PluginResponse> => {
|
|
|
154
240
|
config,
|
|
155
241
|
} = opts;
|
|
156
242
|
|
|
157
|
-
|
|
243
|
+
// TAQ BUG: If both tasks start with 'generate' then 'project-metadata' is always selected
|
|
244
|
+
// WORKAROUND: If the 2nd command is changed to generate-project-metadata, it works as expected
|
|
245
|
+
// console.log('execute', { task, contractName, metadata: config.metadata });
|
|
158
246
|
|
|
159
247
|
switch (task) {
|
|
160
248
|
case 'metadata':
|
|
161
|
-
return createContractMetadata(contractName,
|
|
249
|
+
return createContractMetadata(contractName, config as (typeof config & { metadata?: ProjectMetadata }));
|
|
250
|
+
case 'project-metadata':
|
|
251
|
+
return createProjectMetadata(config as (typeof config & { metadata?: ProjectMetadata }));
|
|
162
252
|
default:
|
|
163
253
|
throw new Error(`${task} is not an understood task by the metadata plugin`);
|
|
164
254
|
}
|
|
@@ -169,6 +259,13 @@ export default async (args: RequestArgs.ProxyRequestArgs): Promise<PluginRespons
|
|
|
169
259
|
|
|
170
260
|
try {
|
|
171
261
|
const resultRaw = await execute(opts) as Record<string, unknown>;
|
|
262
|
+
|
|
263
|
+
const USE_TEXT_OUTPUT = true;
|
|
264
|
+
if (USE_TEXT_OUTPUT) {
|
|
265
|
+
const message = JSON.stringify(resultRaw.data, null, 2);
|
|
266
|
+
return sendRes(message);
|
|
267
|
+
}
|
|
268
|
+
|
|
172
269
|
// TODO: Fix deno parsing
|
|
173
270
|
// Without this, `data.reduce is not a function`
|
|
174
271
|
const result = ('data' in resultRaw) ? resultRaw.data : resultRaw;
|