@0xobelisk/sui-common 1.1.6 → 1.1.8
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/dist/index.d.ts +18 -1
- package/dist/index.js +59 -68
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/codegen/debug.ts +3 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/modules.d.ts +1 -1
- package/src/codegen/types/index.ts +26 -11
- package/src/codegen/utils/config.ts +14 -24
- package/src/codegen/utils/errors.ts +3 -4
- package/src/codegen/utils/format.ts +29 -32
- package/src/codegen/utils/formatAndWrite.ts +22 -19
- package/src/codegen/utils/posixPath.ts +1 -1
- package/src/codegen/utils/renderMove/common.ts +36 -41
- package/src/codegen/utils/renderMove/generateDappKey.ts +12 -15
- package/src/codegen/utils/renderMove/generateDefaultSchema.ts +20 -36
- package/src/codegen/utils/renderMove/generateError.ts +28 -33
- package/src/codegen/utils/renderMove/generateEvent.ts +65 -77
- package/src/codegen/utils/renderMove/generateInit.ts +14 -24
- package/src/codegen/utils/renderMove/generateSchema.ts +160 -197
- package/src/codegen/utils/renderMove/generateSchemaHub.ts +12 -15
- package/src/codegen/utils/renderMove/generateScript.ts +15 -32
- package/src/codegen/utils/renderMove/generateSystem.ts +3 -14
- package/src/codegen/utils/renderMove/generateToml.ts +10 -15
- package/src/codegen/utils/renderMove/schemaGen.ts +39 -47
- package/src/debug.ts +3 -3
- package/src/index.ts +3 -2
- package/src/modules.d.ts +2 -2
- package/src/parseData/index.ts +1 -1
- package/src/parseData/parser/index.ts +42 -42
- package/src/primitives/index.ts +8 -0
|
@@ -1,162 +1,138 @@
|
|
|
1
|
-
import {BaseType, SchemaData, SchemaType} from '../../types';
|
|
1
|
+
import { BaseType, SchemaData, SchemaType } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
getStructAttrsWithType,
|
|
5
|
+
getStructAttrs,
|
|
6
|
+
getStructTypes,
|
|
7
|
+
getStructAttrsQuery,
|
|
8
|
+
containsString
|
|
8
9
|
} from './common';
|
|
9
10
|
|
|
10
11
|
function sortByFirstLetter(arr: string[]): string[] {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
return arr.sort((a, b) => {
|
|
13
|
+
const firstLetterA = a.charAt(0).toLowerCase();
|
|
14
|
+
const firstLetterB = b.charAt(0).toLowerCase();
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (firstLetterA < firstLetterB) {
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
if (firstLetterA > firstLetterB) {
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
});
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function capitalizeAndRemoveUnderscores(input: string): string {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
return input
|
|
28
|
+
.split('_')
|
|
29
|
+
.map((word, index) => {
|
|
30
|
+
return index === 0
|
|
31
|
+
? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
32
|
+
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
33
|
+
})
|
|
34
|
+
.join('');
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function renderSetAttrsFunc(
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
schemaName: string,
|
|
39
|
+
fields: BaseType | Record<string, BaseType>
|
|
39
40
|
): string {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
return Object.entries(fields)
|
|
42
|
+
.map(
|
|
43
|
+
([key, type]) =>
|
|
44
|
+
`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
|
|
44
45
|
self.${key} = ${key};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
}`
|
|
47
|
+
)
|
|
48
|
+
.join('\n');
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export function renderSetFunc(
|
|
51
|
-
|
|
52
|
-
fields: Record<string, string>,
|
|
53
|
-
): string {
|
|
54
|
-
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(
|
|
55
|
-
fields,
|
|
56
|
-
)}) {
|
|
51
|
+
export function renderSetFunc(schemaName: string, fields: Record<string, string>): string {
|
|
52
|
+
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {
|
|
57
53
|
${Object.entries(fields)
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
|
|
55
|
+
.join('\n')}
|
|
60
56
|
}`;
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
export function renderGetAllFunc(
|
|
64
|
-
|
|
65
|
-
fields: Record<string, string>,
|
|
66
|
-
): string {
|
|
67
|
-
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
59
|
+
export function renderGetAllFunc(schemaName: string, fields: Record<string, string>): string {
|
|
60
|
+
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
68
61
|
(${getStructAttrsQuery(fields)})
|
|
69
62
|
}`;
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
export function renderGetAttrsFunc(
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
schemaName: string,
|
|
67
|
+
fields: BaseType | Record<string, BaseType>
|
|
75
68
|
): string {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
key,
|
|
80
|
-
type,
|
|
81
|
-
]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
69
|
+
return Object.entries(fields)
|
|
70
|
+
.map(
|
|
71
|
+
([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
82
72
|
self.${key}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
}`
|
|
74
|
+
)
|
|
75
|
+
.join('\n');
|
|
86
76
|
}
|
|
87
77
|
|
|
88
78
|
function convertToSnakeCase(input: string): string {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
return input
|
|
80
|
+
.replace(/([A-Z])/g, '_$1')
|
|
81
|
+
.toLowerCase()
|
|
82
|
+
.replace(/^_/, '');
|
|
93
83
|
}
|
|
94
84
|
|
|
95
85
|
export async function generateSchemaData(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
projectName: string,
|
|
87
|
+
data: Record<string, SchemaData>,
|
|
88
|
+
path: string
|
|
99
89
|
) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
109
|
-
let code = '';
|
|
90
|
+
console.log('\n📦 Starting Schema Data Generation...');
|
|
91
|
+
for (const key of Object.keys(data)) {
|
|
92
|
+
const name = key;
|
|
93
|
+
const fields = data[key];
|
|
94
|
+
console.log(
|
|
95
|
+
` └─ ${name} ${Array.isArray(fields) ? '(enum)' : '(struct)'}: ${JSON.stringify(fields)}`
|
|
96
|
+
);
|
|
97
|
+
let code = '';
|
|
110
98
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
const enumNames = Object.keys(data)
|
|
100
|
+
.filter((item) => Array.isArray(data[item]))
|
|
101
|
+
.map((item) => item);
|
|
114
102
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const sortByFirstLetterFields = sortByFirstLetter(fields);
|
|
119
|
-
code = `module ${projectName}::${projectName}_${convertToSnakeCase(
|
|
120
|
-
name,
|
|
121
|
-
)} {
|
|
103
|
+
if (Array.isArray(fields)) {
|
|
104
|
+
const sortByFirstLetterFields = sortByFirstLetter(fields);
|
|
105
|
+
code = `module ${projectName}::${projectName}_${convertToSnakeCase(name)} {
|
|
122
106
|
public enum ${name} has copy, drop , store {
|
|
123
107
|
${sortByFirstLetterFields}
|
|
124
108
|
}
|
|
125
109
|
|
|
126
110
|
${sortByFirstLetterFields
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
field,
|
|
130
|
-
)}(): ${name} {
|
|
111
|
+
.map((field: string) => {
|
|
112
|
+
return `public fun new_${convertToSnakeCase(field)}(): ${name} {
|
|
131
113
|
${name}::${field}
|
|
132
114
|
}`;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
name,
|
|
138
|
-
)} {
|
|
115
|
+
})
|
|
116
|
+
.join('')}`;
|
|
117
|
+
} else {
|
|
118
|
+
code = `module ${projectName}::${projectName}_${convertToSnakeCase(name)} {
|
|
139
119
|
use std::ascii::String;
|
|
140
120
|
|
|
141
|
-
${
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.join('\n')
|
|
151
|
-
}
|
|
121
|
+
${Object.keys(data)
|
|
122
|
+
.map((name) => {
|
|
123
|
+
if (containsString(fields, name)) {
|
|
124
|
+
return `use ${projectName}::${projectName}_${convertToSnakeCase(name)}::${name};`;
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
})
|
|
128
|
+
.filter(Boolean)
|
|
129
|
+
.join('\n')}
|
|
152
130
|
|
|
153
131
|
public struct ${name} has copy, drop , store {
|
|
154
132
|
${getStructAttrsWithType(fields)}
|
|
155
133
|
}
|
|
156
134
|
|
|
157
|
-
public fun new(${getStructAttrsWithType(
|
|
158
|
-
fields,
|
|
159
|
-
)}): ${name} {
|
|
135
|
+
public fun new(${getStructAttrsWithType(fields)}): ${name} {
|
|
160
136
|
${name} {
|
|
161
137
|
${getStructAttrs(fields)}
|
|
162
138
|
}
|
|
@@ -167,53 +143,40 @@ export async function generateSchemaData(
|
|
|
167
143
|
${renderSetAttrsFunc(name, fields)}
|
|
168
144
|
${renderSetFunc(name, fields)}
|
|
169
145
|
}`;
|
|
170
|
-
|
|
146
|
+
}
|
|
171
147
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
console.log('✅ Schema Data Generation Complete\n');
|
|
148
|
+
await formatAndWriteMove(
|
|
149
|
+
code,
|
|
150
|
+
`${path}/contracts/${projectName}/sources/codegen/data/${convertToSnakeCase(name)}.move`,
|
|
151
|
+
'formatAndWriteMove'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
181
154
|
}
|
|
182
155
|
|
|
183
|
-
function generateImport(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})
|
|
195
|
-
.join('\n');
|
|
196
|
-
} else {
|
|
197
|
-
return '';
|
|
198
|
-
}
|
|
156
|
+
function generateImport(projectName: string, data: Record<string, SchemaData> | null) {
|
|
157
|
+
if (data != null) {
|
|
158
|
+
const names = Object.keys(data);
|
|
159
|
+
return names
|
|
160
|
+
.map((name) => {
|
|
161
|
+
return `use ${projectName}::${projectName}_${convertToSnakeCase(name)}::${name};`;
|
|
162
|
+
})
|
|
163
|
+
.join('\n');
|
|
164
|
+
} else {
|
|
165
|
+
return '';
|
|
166
|
+
}
|
|
199
167
|
}
|
|
200
168
|
|
|
201
169
|
export async function generateSchemaStructure(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
170
|
+
projectName: string,
|
|
171
|
+
data: Record<string, SchemaData> | null,
|
|
172
|
+
schemas: Record<string, SchemaType>,
|
|
173
|
+
path: string
|
|
206
174
|
) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
` └─ Structure fields: ${
|
|
213
|
-
Object.values(schemas).length
|
|
214
|
-
}`,
|
|
215
|
-
);
|
|
216
|
-
const schemaMoudle = `module ${projectName}::${projectName}_schema {
|
|
175
|
+
console.log('\n🔨 Starting Schema Structure Generation...');
|
|
176
|
+
Object.entries(schemas).forEach(([key, value]) => {
|
|
177
|
+
console.log(` └─ ${key}: ${value}`);
|
|
178
|
+
});
|
|
179
|
+
const schemaMoudle = `module ${projectName}::${projectName}_schema {
|
|
217
180
|
use std::ascii::String;
|
|
218
181
|
use std::ascii::string;
|
|
219
182
|
use sui::package::UpgradeCap;
|
|
@@ -229,8 +192,8 @@ export async function generateSchemaStructure(
|
|
|
229
192
|
public struct Schema has key, store { id: UID }
|
|
230
193
|
|
|
231
194
|
${Object.entries(schemas)
|
|
232
|
-
|
|
233
|
-
|
|
195
|
+
.map(([key, value]) => {
|
|
196
|
+
return `public fun borrow_${key}(self: &Schema) : &${value} {
|
|
234
197
|
storage::borrow_field(&self.id, b"${key}")
|
|
235
198
|
}
|
|
236
199
|
|
|
@@ -238,27 +201,25 @@ export async function generateSchemaStructure(
|
|
|
238
201
|
storage::borrow_mut_field(&mut self.id, b"${key}")
|
|
239
202
|
}
|
|
240
203
|
`;
|
|
241
|
-
|
|
242
|
-
|
|
204
|
+
})
|
|
205
|
+
.join('')}
|
|
243
206
|
|
|
244
207
|
|
|
245
208
|
public(package) fun create(ctx: &mut TxContext): Schema {
|
|
246
209
|
let mut id = object::new(ctx);
|
|
247
210
|
${Object.entries(schemas)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
})
|
|
261
|
-
.join('\n')}
|
|
211
|
+
.map(([key, value]) => {
|
|
212
|
+
let storage_type = '';
|
|
213
|
+
if (value.includes('StorageValue')) {
|
|
214
|
+
storage_type = `storage_value::new(b"${key}", ctx)`;
|
|
215
|
+
} else if (value.includes('StorageMap')) {
|
|
216
|
+
storage_type = `storage_map::new(b"${key}", ctx)`;
|
|
217
|
+
} else if (value.includes('StorageDoubleMap')) {
|
|
218
|
+
storage_type = `storage_double_map::new(b"${key}", ctx)`;
|
|
219
|
+
}
|
|
220
|
+
return `storage::add_field<${value}>(&mut id, b"${key}", ${storage_type});`;
|
|
221
|
+
})
|
|
222
|
+
.join('\n')}
|
|
262
223
|
|
|
263
224
|
Schema { id }
|
|
264
225
|
}
|
|
@@ -276,36 +237,38 @@ export async function generateSchemaStructure(
|
|
|
276
237
|
|
|
277
238
|
// ======================================== View Functions ========================================
|
|
278
239
|
${Object.entries(schemas)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
240
|
+
.map(([key, value]) => {
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
let all_types = value
|
|
243
|
+
.match(/<(.+)>/)[1]
|
|
244
|
+
.split(',')
|
|
245
|
+
.map((type) => type.trim());
|
|
246
|
+
let para_key: string[] = [];
|
|
247
|
+
let para_value = '';
|
|
248
|
+
let borrow_key = '';
|
|
249
|
+
if (value.includes('StorageValue')) {
|
|
250
|
+
para_key = [];
|
|
251
|
+
para_value = `${all_types[0]}`;
|
|
252
|
+
borrow_key = 'get()';
|
|
253
|
+
} else if (value.includes('StorageMap')) {
|
|
254
|
+
para_key = [`key: ${all_types[0]}`];
|
|
255
|
+
para_value = `${all_types[1]}`;
|
|
256
|
+
borrow_key = 'get(key)';
|
|
257
|
+
} else if (value.includes('StorageDoubleMap')) {
|
|
258
|
+
para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`];
|
|
259
|
+
para_value = `${all_types[2]}`;
|
|
260
|
+
borrow_key = 'get(key1, key2)';
|
|
261
|
+
}
|
|
262
|
+
return `public fun get_${key}(self: &Schema, ${para_key}) : &${para_value} {
|
|
299
263
|
self.borrow_${key}().${borrow_key}
|
|
300
|
-
}
|
|
301
|
-
|
|
264
|
+
}`;
|
|
265
|
+
})
|
|
266
|
+
.join('\n')}
|
|
302
267
|
// =========================================================================================================
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
console.log('✅ Schema Structure Generation Complete\n');
|
|
268
|
+
}`;
|
|
269
|
+
await formatAndWriteMove(
|
|
270
|
+
schemaMoudle,
|
|
271
|
+
`${path}/contracts/${projectName}/sources/codegen/schema.move`,
|
|
272
|
+
'formatAndWriteMove'
|
|
273
|
+
);
|
|
310
274
|
}
|
|
311
|
-
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { DubheConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateSchemaHub(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
console.log(
|
|
10
|
-
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`
|
|
11
|
-
);
|
|
4
|
+
export async function generateSchemaHub(config: DubheConfig, srcPrefix: string) {
|
|
5
|
+
console.log('\n🔑 Starting DappKey Generation...');
|
|
6
|
+
console.log(
|
|
7
|
+
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`
|
|
8
|
+
);
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
let code = `module ${config.name}::${config.name}_schema_hub {
|
|
14
11
|
use sui::transfer::public_share_object;
|
|
15
12
|
use sui::dynamic_field as df;
|
|
16
13
|
|
|
@@ -56,10 +53,10 @@ export async function generateSchemaHub(
|
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
`;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
await formatAndWriteMove(
|
|
57
|
+
code,
|
|
58
|
+
`${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`,
|
|
59
|
+
'formatAndWriteMove'
|
|
60
|
+
);
|
|
61
|
+
console.log('✅ DappKey Generation Complete\n');
|
|
65
62
|
}
|
|
@@ -5,40 +5,23 @@ import { capitalizeAndRemoveUnderscores } from './generateSchema';
|
|
|
5
5
|
|
|
6
6
|
import { readFileSync } from 'fs';
|
|
7
7
|
|
|
8
|
-
export async function generateDeployHook(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
console.log('\n📝 Starting Deploy Hook Generation...');
|
|
13
|
-
console.log(
|
|
14
|
-
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;
|
|
18
|
-
if (!existsSync(path)) {
|
|
19
|
-
const code = `module ${config.name}::${config.name}_deploy_hook {
|
|
8
|
+
export async function generateDeployHook(config: DubheConfig, srcPrefix: string) {
|
|
9
|
+
const path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;
|
|
10
|
+
if (!existsSync(path)) {
|
|
11
|
+
const code = `module ${config.name}::${config.name}_deploy_hook {
|
|
20
12
|
use ${config.name}::${config.name}_schema::Schema;
|
|
21
13
|
|
|
22
14
|
public(package) fun run(_schema: &mut Schema, _ctx: &mut TxContext) {
|
|
23
15
|
|
|
24
16
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
path,
|
|
29
|
-
'formatAndWriteMove'
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
console.log('✅ Deploy Hook Generation Complete\n');
|
|
17
|
+
}`;
|
|
18
|
+
await formatAndWriteMove(code, path, 'formatAndWriteMove');
|
|
19
|
+
}
|
|
33
20
|
}
|
|
34
21
|
|
|
35
22
|
export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`${srcPrefix}/contracts/${config.name}/sources/scripts/migrate.move`
|
|
39
|
-
)
|
|
40
|
-
) {
|
|
41
|
-
let code = `module ${config.name}::${config.name}_migrate {
|
|
23
|
+
if (!existsSync(`${srcPrefix}/contracts/${config.name}/sources/scripts/migrate.move`)) {
|
|
24
|
+
let code = `module ${config.name}::${config.name}_migrate {
|
|
42
25
|
const ON_CHAIN_VERSION: u32 = 1;
|
|
43
26
|
|
|
44
27
|
public fun on_chain_version(): u32 {
|
|
@@ -46,10 +29,10 @@ export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
|
46
29
|
}
|
|
47
30
|
}
|
|
48
31
|
`;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
await formatAndWriteMove(
|
|
33
|
+
code,
|
|
34
|
+
`${srcPrefix}/contracts/${config.name}/sources/scripts/migrate.move`,
|
|
35
|
+
'formatAndWriteMove'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
55
38
|
}
|
|
@@ -5,18 +5,7 @@ import fs from 'node:fs/promises';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
|
|
7
7
|
export async function generateSystem(config: DubheConfig, srcPrefix: string) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/systems`
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
!existsSync(
|
|
16
|
-
`${srcPrefix}/contracts/${config.name}/sources/systems`
|
|
17
|
-
)
|
|
18
|
-
) {
|
|
19
|
-
await fs.mkdir(`${srcPrefix}/contracts/${config.name}/sources/systems`, { recursive: true })
|
|
20
|
-
}
|
|
21
|
-
console.log('✅ System Generation Complete\n');
|
|
8
|
+
if (!existsSync(`${srcPrefix}/contracts/${config.name}/sources/systems`)) {
|
|
9
|
+
await fs.mkdir(`${srcPrefix}/contracts/${config.name}/sources/systems`, { recursive: true });
|
|
10
|
+
}
|
|
22
11
|
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { DubheConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateToml(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
) {
|
|
8
|
-
console.log('\n📄 Starting Move.toml Generation...');
|
|
9
|
-
console.log(
|
|
10
|
-
` └─ Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`
|
|
11
|
-
);
|
|
4
|
+
export async function generateToml(config: DubheConfig, srcPrefix: string) {
|
|
5
|
+
console.log('\n📄 Starting Move.toml Generation...');
|
|
6
|
+
console.log(` └─ Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`);
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
let code = `[package]
|
|
14
9
|
name = "${config.name}"
|
|
15
10
|
version = "1.0.0"
|
|
16
11
|
edition = "2024"
|
|
@@ -23,10 +18,10 @@ Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe
|
|
|
23
18
|
sui = "0x2"
|
|
24
19
|
${config.name} = "0x0"
|
|
25
20
|
`;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
await formatAndWriteMove(
|
|
22
|
+
code,
|
|
23
|
+
`${srcPrefix}/contracts/${config.name}/Move.toml`,
|
|
24
|
+
'formatAndWriteMove'
|
|
25
|
+
);
|
|
26
|
+
console.log('✅ Move.toml Generation Complete\n');
|
|
32
27
|
}
|