@0xobelisk/sui-common 0.5.15 → 0.5.16

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 CHANGED
@@ -44,9 +44,9 @@ type ObeliskConfig = {
44
44
  };
45
45
  type MoveType = "string" | "vector<string>" | "String" | "vector<String>" | "address" | "bool" | "u8" | "u64" | "u128" | "vector<address>" | "vector<bool>" | "vector<u8>" | "vector<vector<u8>>" | "vector<u64>" | "vector<u128>";
46
46
 
47
- declare function worldgen(config: ObeliskConfig, srcPrefix?: string): Promise<void>;
47
+ declare function schemaGen(config: ObeliskConfig, srcPrefix?: string, network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet', frameworkId?: string): Promise<void>;
48
48
 
49
49
  declare function loadConfig(configPath?: string): Promise<unknown>;
50
50
  declare function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean): Promise<string>;
51
51
 
52
- export { BaseType, BaseValueType, MoveType, ObeliskConfig, SchemaData, SchemaType, StorageDataType, StorageMapType, formatAndWriteMove, formatAndWriteTypescript, formatMove, formatTypescript, loadConfig, posixPath, resolveConfigPath, worldgen };
52
+ export { BaseType, BaseValueType, MoveType, ObeliskConfig, SchemaData, SchemaType, StorageDataType, StorageMapType, formatAndWriteMove, formatAndWriteTypescript, formatMove, formatTypescript, loadConfig, posixPath, resolveConfigPath, schemaGen };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import y from"prettier";import I from"prettier-plugin-move-js";async function h(e,t){let r;t&&(r=await y.resolveConfig(t));try{return y.format(e,{plugins:[I],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...r})}catch(o){let n;return o instanceof Error?n=o.message:n=o,console.log(`Error during output formatting: ${n}`),e}}async function S(e){return y.format(e,{parser:"typescript"})}import $ from"node:fs/promises";import A from"node:path";import v from"debug";var f=v("obelisk:common"),U=v("obelisk:common");f.log=console.debug.bind(console);U.log=console.error.bind(console);var g=f.extend("codegen"),B=f.extend("codegen");g.log=console.debug.bind(console);B.log=console.error.bind(console);async function c(e,t,r){let o=await h(e),n=` // Copyright (c) Obelisk Labs, Inc.
1
+ import y from"prettier";import K from"prettier-plugin-move-js";async function h(e,t){let o;t&&(o=await y.resolveConfig(t));try{return y.format(e,{plugins:[K],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...o})}catch(r){let n;return r instanceof Error?n=r.message:n=r,console.log(`Error during output formatting: ${n}`),e}}async function w(e){return y.format(e,{parser:"typescript"})}import $ from"node:fs/promises";import A from"node:path";import v from"debug";var g=v("obelisk:common"),I=v("obelisk:common");g.log=console.debug.bind(console);I.log=console.error.bind(console);var f=g.extend("codegen"),U=g.extend("codegen");f.log=console.debug.bind(console);U.log=console.error.bind(console);async function c(e,t,o){let r=await h(e),n=` // Copyright (c) Obelisk Labs, Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
  #[allow(unused_use)]
4
4
 
@@ -6,10 +6,13 @@ import y from"prettier";import I from"prettier-plugin-move-js";async function h(
6
6
 
7
7
  `,s=`#[allow(lint(share_owned))]
8
8
 
9
- `,i=n+o;t.includes(".toml")||t.includes("system")?i=o:t.includes("deploy_hook")&&(i=s+o),await $.mkdir(A.dirname(t),{recursive:!0}),await $.writeFile(t,i),g(`${r}: ${t}`)}async function ue(e,t,r){let o=await S(e);await $.mkdir(A.dirname(t),{recursive:!0}),await $.writeFile(t,o),g(`${r}: ${t}`)}function de(e){return e.replace(/\\/g,"/")}import{existsSync as k}from"fs";import l from"fs";function _(e){l.existsSync(e)&&(l.readdirSync(e).forEach(t=>{let r=`${e}/${t}`;l.lstatSync(r).isDirectory()?_(r):l.unlinkSync(r)}),l.rmdirSync(e))}function T(e){return Object.entries(e).map(([t,r])=>`${t}`).join(",")}function M(e){return typeof e=="string"?e:`(${Object.entries(e).map(([t,r])=>`${r}`)})`}function d(e){return Object.entries(e).map(([t,r])=>`${t}: ${r}`)}function C(e,t){return typeof e=="string"?[`${t}self.value`]:Object.entries(e).map(([r,o])=>`${t}self.${r}`)}import{existsSync as K}from"fs";async function j(e,t){e.systems.map(async r=>{if(!K(`${t}/contracts/${e.name}/sources/system/${r}.move`)){let o=`module ${e.name}::${r}_system {
9
+ `,a=n+r;t.includes(".toml")||t.includes("system")?a=r:t.includes("deploy_hook")&&(a=s+r),await $.mkdir(A.dirname(t),{recursive:!0}),await $.writeFile(t,a),f(`${o}: ${t}`)}async function ue(e,t,o){let r=await w(e);await $.mkdir(A.dirname(t),{recursive:!0}),await $.writeFile(t,r),f(`${o}: ${t}`)}function ge(e){return e.replace(/\\/g,"/")}import{existsSync as k}from"fs";import u from"fs";function _(e){u.existsSync(e)&&(u.readdirSync(e).forEach(t=>{let o=`${e}/${t}`;u.lstatSync(o).isDirectory()?_(o):u.unlinkSync(o)}),u.rmdirSync(e))}function C(e){return Object.entries(e).map(([t,o])=>`${t}`).join(",")}function D(e){return typeof e=="string"?e:`(${Object.entries(e).map(([t,o])=>`${o}`)})`}function d(e){return Object.entries(e).map(([t,o])=>`${t}: ${o}`)}function M(e,t){return typeof e=="string"?[`${t}self.value`]:Object.entries(e).map(([o,r])=>`${t}self.${o}`)}import{existsSync as L}from"fs";async function T(e,t){console.log(`
10
+ \u2699\uFE0F Starting System Generation...`),e.systems.map(async o=>{if(console.log(` \u251C\u2500 Generating system: ${o}`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/system/${o}.move`),!L(`${t}/contracts/${e.name}/sources/system/${o}.move`)){let r=`module ${e.name}::${o}_system {
10
11
 
11
12
  }
12
- `;await c(o,`${t}/contracts/${e.name}/sources/system/${r}.move`,"formatAndWriteMove")}})}async function D(e,t){let r=`[package]
13
+ `;await c(r,`${t}/contracts/${e.name}/sources/system/${o}.move`,"formatAndWriteMove")}}),console.log(`\u2705 System Generation Complete
14
+ `)}async function O(e,t,o){console.log(`
15
+ \u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let r=`[package]
13
16
  name = "${e.name}"
14
17
  version = "0.0.1"
15
18
  edition = "2024.beta"
@@ -19,30 +22,32 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
19
22
  Obelisk = { git = "https://github.com/0xobelisk/obelisk-engine.git", subdir = "packages/obelisk-framework", rev = "main" }
20
23
 
21
24
  [addresses]
22
- sui = "0x2"
23
- obelisk = "0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256"
25
+ sui = "0x2"
26
+ obelisk = "${o}"
24
27
  ${e.name} = "0x0"
25
- `;await c(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove")}function m(e){return e.split("_").map((t,r)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function L(e,t){return Object.entries(t).map(([r,o])=>`public(package) fun set_${r}(self: &mut ${e}, ${r}: ${o}) {
26
- self.${r} = ${r};
28
+ `;await c(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
29
+ `)}function m(e){return e.split("_").map((t,o)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function V(e,t){return Object.entries(t).map(([o,r])=>`public(package) fun set_${o}(self: &mut ${e}, ${o}: ${r}) {
30
+ self.${o} = ${o};
27
31
  }`).join(`
28
- `)}function V(e,t){return`public(package) fun set(self: &mut ${e}, ${d(t)}) {
29
- ${Object.entries(t).map(([r])=>`self.${r} = ${r};`).join(`
32
+ `)}function B(e,t){return`public(package) fun set(self: &mut ${e}, ${d(t)}) {
33
+ ${Object.entries(t).map(([o])=>`self.${o} = ${o};`).join(`
30
34
  `)}
31
- }`}function z(e,t){return`public fun get(self: &${e}): ${M(t)} {
32
- (${C(t,"")})
33
- }`}function N(e,t){return Object.entries(t).map(([r,o])=>`public fun get_${r}(self: &${e}): ${o} {
34
- self.${r}
35
+ }`}function H(e,t){return`public fun get(self: &${e}): ${D(t)} {
36
+ (${M(t,"")})
37
+ }`}function z(e,t){return Object.entries(t).map(([o,r])=>`public fun get_${o}(self: &${e}): ${r} {
38
+ self.${o}
35
39
  }`).join(`
36
- `)}function u(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function O(e,t,r){for(let o in t){let n=t[o];if(n.data)for(let s of n.data){let i="",p=n.data.filter(a=>Array.isArray(a.fields)).map(a=>a.name);Array.isArray(s.fields)?i=`module ${e}::${o}_${u(s.name)} {
40
+ `)}function l(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function j(e,t,o){console.log(`
41
+ \u{1F4E6} Starting Schema Data Generation...`);for(let r in t){let n=t[r];if(n.data){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.data){console.log(` \u2514\u2500 Generating ${s.name} ${Array.isArray(s.fields)?"(enum)":"(struct)"}`);let a="",p=n.data.filter(i=>Array.isArray(i.fields)).map(i=>i.name);Array.isArray(s.fields)?a=`module ${e}::${r}_${l(s.name)} {
37
42
  public enum ${s.name} has copy, drop , store {
38
43
  ${s.fields}
39
44
  }
40
45
 
41
- ${s.fields.map(a=>`public fun new_${u(a)}(): ${s.name} {
42
- ${s.name}::${a}
43
- }`).join("")}`:i=`module ${e}::${o}_${u(s.name)} {
46
+ ${s.fields.map(i=>`public fun new_${l(i)}(): ${s.name} {
47
+ ${s.name}::${i}
48
+ }`).join("")}`:a=`module ${e}::${r}_${l(s.name)} {
44
49
  use std::ascii::String;
45
- ${p.map(a=>`use ${e}::${o}_${u(a)}::${a};`).join(`
50
+ ${p.map(i=>`use ${e}::${r}_${l(i)}::${i};`).join(`
46
51
  `)}
47
52
 
48
53
  public struct ${s.name} has copy, drop , store {
@@ -51,16 +56,18 @@ ${e.name} = "0x0"
51
56
 
52
57
  public fun new(${d(s.fields)}): ${s.name} {
53
58
  ${s.name} {
54
- ${T(s.fields)}
59
+ ${C(s.fields)}
55
60
  }
56
61
  }
57
62
 
63
+ ${H(s.name,s.fields)}
58
64
  ${z(s.name,s.fields)}
59
- ${N(s.name,s.fields)}
60
- ${L(s.name,s.fields)}
61
65
  ${V(s.name,s.fields)}
62
- }`,await c(i,`${r}/contracts/${e}/sources/codegen/schemas/${o}_${u(s.name)}.move`,"formatAndWriteMove")}}}function G(e,t,r){return r.data?r.data.map(o=>`use ${e}::${t}_${u(o.name)}::${o.name};`).join(`
63
- `):""}async function W(e,t,r){for(let o in t){console.log(`Schema: ${o}`);let n=t[o],s=`module ${e}::${o}_schema {
66
+ ${B(s.name,s.fields)}
67
+ }`,await c(a,`${o}/contracts/${e}/sources/codegen/schemas/${r}_${l(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Data Generation Complete
68
+ `)}function N(e,t,o){return o.data?o.data.map(r=>`use ${e}::${t}_${l(r.name)}::${r.name};`).join(`
69
+ `):""}async function W(e,t,o){console.log(`
70
+ \u{1F528} Starting Schema Structure Generation...`);for(let r in t){console.log(` \u251C\u2500 Generating schema: ${r}`),console.log(` \u251C\u2500 Output path: ${o}/contracts/${e}/sources/codegen/schemas/${r}.move`),console.log(` \u2514\u2500 Structure fields: ${Object.keys(t[r].structure).length}`);let n=t[r],s=`module ${e}::${r}_schema {
64
71
  use std::ascii::String;
65
72
  use std::type_name;
66
73
  use obelisk::dapps_system;
@@ -69,36 +76,38 @@ ${e.name} = "0x0"
69
76
  use obelisk::storage_map::{Self, StorageMap};
70
77
  use obelisk::storage_double_map::{Self, StorageDoubleMap};
71
78
  use ${e}::dapp_key::DappKey;
72
- ${G(e,o,n)}
79
+ ${N(e,r,n)}
73
80
 
74
- public struct ${m(o)} has key, store {
81
+ public struct ${m(r)} has key, store {
75
82
  id: UID,
76
83
  ${d(n.structure)}
77
84
  }
78
85
 
79
- ${Object.entries(n.structure).map(([i,p])=>`public fun borrow_${i}(self: &${m(o)}) : &${p} {
80
- &self.${i}
86
+ ${Object.entries(n.structure).map(([a,p])=>`public fun borrow_${a}(self: &${m(r)}) : &${p} {
87
+ &self.${a}
81
88
  }
82
89
 
83
- public(package) fun borrow_mut_${i}(self: &mut ${m(o)}): &mut ${p} {
84
- &mut self.${i}
90
+ public(package) fun borrow_mut_${a}(self: &mut ${m(r)}): &mut ${p} {
91
+ &mut self.${a}
85
92
  }
86
93
  `).join("")}
87
94
 
88
- public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${m(o)} {
95
+ public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${m(r)} {
89
96
  let package_id = dapps_system::current_package_id<DappKey>();
90
97
  assert!(dapps.borrow_metadata().contains_key(package_id), 0);
91
98
  assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
92
- let schema = type_name::get<${m(o)}>().into_string();
99
+ let schema = type_name::get<${m(r)}>().into_string();
93
100
  assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
94
- dapps_system::add_schema<${m(o)}>(dapps, package_id, ctx);
95
- ${m(o)} {
101
+ dapps_system::add_schema<${m(r)}>(dapps, package_id, ctx);
102
+ ${m(r)} {
96
103
  id: object::new(ctx),
97
- ${Object.entries(n.structure).map(([i,p])=>{let a="";return p.includes("StorageValue")?a="storage_value::new()":p.includes("StorageMap")?a="storage_map::new()":p.includes("StorageDoubleMap")&&(a="storage_double_map::new()"),`${i}: ${a},`}).join(" ")}
104
+ ${Object.entries(n.structure).map(([a,p])=>{let i="";return p.includes("StorageValue")?i="storage_value::new()":p.includes("StorageMap")?i="storage_map::new()":p.includes("StorageDoubleMap")&&(i="storage_double_map::new()"),`${a}: ${i},`}).join(" ")}
98
105
  }
99
106
  }
100
107
 
101
- }`;await c(s,`${r}/contracts/${e}/sources/codegen/schemas/${o}.move`,"formatAndWriteMove")}}import{existsSync as H}from"fs";async function R(e,t){if(!H(`${t}/contracts/${e.name}/sources/script/deploy_hook.move`)){let r=`module ${e.name}::deploy_hook {
108
+ }`;await c(s,`${o}/contracts/${e}/sources/codegen/schemas/${r}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
109
+ `)}import{existsSync as Q}from"fs";async function G(e,t){if(console.log(`
110
+ \u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/script/deploy_hook.move`),!Q(`${t}/contracts/${e.name}/sources/script/deploy_hook.move`)){let o=`module ${e.name}::deploy_hook {
102
111
  use obelisk::dapps_schema::Dapps;
103
112
  use obelisk::dapps_system;
104
113
  use ${e.name}::dapp_key::DappKey;
@@ -123,13 +132,13 @@ ${e.name} = "0x0"
123
132
  clock,
124
133
  ctx
125
134
  );
126
- ${Object.keys(e.schemas).map(o=>`let ${o} = ${e.name}::${o}_schema::register(dapps, ctx);`).join(`
135
+ ${Object.keys(e.schemas).map(r=>`let ${r} = ${e.name}::${r}_schema::register(dapps, ctx);`).join(`
127
136
  `)}
128
137
  // Logic that needs to be automated once the contract is deployed
129
138
 
130
139
 
131
140
  // Share the dapp object with the public
132
- ${Object.keys(e.schemas).map(o=>`public_share_object(${o});`).join(`
141
+ ${Object.keys(e.schemas).map(r=>`public_share_object(${r});`).join(`
133
142
  `)}
134
143
  }
135
144
 
@@ -150,13 +159,19 @@ ${e.name} = "0x0"
150
159
  (scenario, dapps)
151
160
  }
152
161
  }
153
- `;await c(r,`${t}/contracts/${e.name}/sources/script/deploy_hook.move`,"formatAndWriteMove")}}async function E(e,t){let r=`module ${e.name}::dapp_key {
154
- /// Authorization token for the app.
155
- public struct DappKey has drop {}
162
+ `;await c(o,`${t}/contracts/${e.name}/sources/script/deploy_hook.move`,"formatAndWriteMove")}console.log(`\u2705 Deploy Hook Generation Complete
163
+ `)}async function R(e,t){console.log(`
164
+ \u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/dapp_key.move`);let o=`module ${e.name}::dapp_key {
165
+ /// Authorization token for the app.
166
+ public struct DappKey has drop {}
156
167
 
157
- public(package) fun new(): DappKey {
158
- DappKey { }
159
- }
168
+ public(package) fun new(): DappKey {
169
+ DappKey { }
170
+ }
160
171
  }
161
- `;await c(r,`${t}/contracts/${e.name}/sources/codegen/dapp_key.move`,"formatAndWriteMove")}async function Be(e,t){let r="";t===void 0?r=process.cwd():r=t,k(`${r}/contracts/${e.name}`)&&_(`${r}/contracts/${e.name}/sources/codegen`),k(`${r}/contracts/${e.name}/Move.toml`)||await D(e,r),k(`${r}/contracts/${e.name}/sources/script/deploy_hook.move`)||await R(e,r),await j(e,r),await O(e.name,e.schemas,r),await W(e.name,e.schemas,r),await E(e,r)}import{findUp as Q}from"find-up";import x from"path";import X from"esbuild";var b=class extends Error{name="NotInsideProjectError";message="You are not inside a Obelisk project"};import{rmSync as Y}from"fs";import{pathToFileURL as Z}from"url";import q from"os";var J=["obelisk.config.js","obelisk.config.mjs","obelisk.config.ts","obelisk.config.mts"],w="obelisk.config.example.mjs";async function Ye(e){e=await F(e);try{return await X.build({entryPoints:[e],format:"esm",outfile:w,platform:"node",bundle:!0,packages:"external"}),e=await F(w,!0),(await import(e+`?update=${Date.now()}`)).obeliskConfig}finally{Y(w,{force:!0})}}async function F(e,t){return e===void 0?e=await P():x.isAbsolute(e)||(e=x.join(process.cwd(),e),e=x.normalize(e)),t&&q.platform()==="win32"?Z(e).href:e}async function P(){let e=await Q(J);if(e===void 0)throw new b;return e}export{c as formatAndWriteMove,ue as formatAndWriteTypescript,h as formatMove,S as formatTypescript,Ye as loadConfig,de as posixPath,F as resolveConfigPath,Be as worldgen};
172
+ `;await c(o,`${t}/contracts/${e.name}/sources/codegen/dapp_key.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
173
+ `)}function E(e){switch(e){case"testnet":return"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256";case"localnet":return"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256";default:return"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256"}}async function Ue(e,t,o,r){console.log(`
174
+ \u{1F680} Starting Schema Generation Process...`),console.log("\u{1F4CB} Project Configuration:"),console.log(` \u251C\u2500 Name: ${e.name}`),console.log(` \u251C\u2500 Description: ${e.description||"No description provided"}`),console.log(` \u251C\u2500 Network: ${o||"testnet"}`),console.log(` \u2514\u2500 Framework ID: ${r||E(o??"testnet")}
175
+ `);let n=t??process.cwd();r=r||E(o??"testnet"),k(`${n}/contracts/${e.name}`)&&_(`${n}/contracts/${e.name}/sources/codegen`),k(`${n}/contracts/${e.name}/Move.toml`)||await O(e,n,r),k(`${n}/contracts/${e.name}/sources/script/deploy_hook.move`)||await G(e,n),await T(e,n),await j(e.name,e.schemas,n),await W(e.name,e.schemas,n),await R(e,n),console.log(`\u2705 Schema Generation Process Complete!
176
+ `)}import{findUp as X}from"find-up";import x from"path";import Y from"esbuild";var b=class extends Error{name="NotInsideProjectError";message="You are not inside a Obelisk project"};import{rmSync as Z}from"fs";import{pathToFileURL as q}from"url";import J from"os";var P=["obelisk.config.js","obelisk.config.mjs","obelisk.config.ts","obelisk.config.mts"],S="obelisk.config.example.mjs";async function Ze(e){e=await F(e);try{return await Y.build({entryPoints:[e],format:"esm",outfile:S,platform:"node",bundle:!0,packages:"external"}),e=await F(S,!0),(await import(e+`?update=${Date.now()}`)).obeliskConfig}finally{Z(S,{force:!0})}}async function F(e,t){return e===void 0?e=await ee():x.isAbsolute(e)||(e=x.join(process.cwd(),e),e=x.normalize(e)),t&&J.platform()==="win32"?q(e).href:e}async function ee(){let e=await X(P);if(e===void 0)throw new b;return e}export{c as formatAndWriteMove,ue as formatAndWriteTypescript,h as formatMove,w as formatTypescript,Ze as loadConfig,ge as posixPath,F as resolveConfigPath,Ue as schemaGen};
162
177
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/codegen/utils/format.ts","../src/codegen/utils/formatAndWrite.ts","../src/debug.ts","../src/codegen/debug.ts","../src/codegen/utils/posixPath.ts","../src/codegen/utils/renderMove/worldgen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts"],"sourcesContent":["import prettier from 'prettier';\nimport prettierPluginMove from 'prettier-plugin-move-js';\n\nexport async function formatMove(\n\tcontent: string,\n\tprettierConfigPath?: string\n): Promise<string> {\n\tlet config;\n\tif (prettierConfigPath) {\n\t\tconfig = await prettier.resolveConfig(prettierConfigPath);\n\t}\n\ttry {\n\t\treturn prettier.format(content, {\n\t\t\tplugins: [prettierPluginMove],\n\t\t\tparser: 'move-parse',\n\t\t\tprintWidth: 120,\n\t\t\tsemi: true,\n\t\t\ttabWidth: 2,\n\t\t\tuseTabs: false,\n\t\t\tbracketSpacing: true,\n\t\t\t...config,\n\t\t});\n\t} catch (error) {\n\t\tlet message;\n\t\tif (error instanceof Error) {\n\t\t\tmessage = error.message;\n\t\t} else {\n\t\t\tmessage = error;\n\t\t}\n\t\tconsole.log(`Error during output formatting: ${message}`);\n\t\treturn content;\n\t}\n}\n\nexport async function formatTypescript(content: string): Promise<string> {\n\treturn prettier.format(content, {\n\t\tparser: 'typescript',\n\t});\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatMove, formatTypescript } from \"./format\";\nimport { debug } from \"../debug\";\n\nexport async function formatAndWriteMove(\n output: string,\n fullOutputPath: string,\n logPrefix?: string\n): Promise<void> {\n const formattedOutput = await formatMove(output);\n let schemaPrefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let deployHookPrefix = `#[allow(lint(share_owned))]\n \n `\n\n let code = schemaPrefix + formattedOutput\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"deploy_hook\")) {\n code = deployHookPrefix + formattedOutput\n }\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n await fs.writeFile(fullOutputPath, code);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n\n/**\n * Formats typescript code using prettier and write it to a file\n * @param output typescript code\n * @param fullOutputPath full path to the output file\n * @param logPrefix prefix for debug logs\n */\nexport async function formatAndWriteTypescript(\n output: string,\n fullOutputPath: string,\n logPrefix: string,\n): Promise<void> {\n const formattedOutput = await formatTypescript(output);\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n\n await fs.writeFile(fullOutputPath, formattedOutput);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"obelisk:common\");\nexport const error = createDebug(\"obelisk:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"codegen\");\nexport const error = parentDebug.extend(\"codegen\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","/**\n * Explicitly normalize a given path to a posix path (using `/` as separator).\n * This should be used for generating Solidity files that will be consumed by solc,\n * because solc expects `/` as path separator, but path.join produces `\\` if the user is on windows.\n */\nexport function posixPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n","import { SchemaType, ObeliskConfig } from \"../../types\";\nimport { rmdirSync, existsSync } from \"fs\";\nimport { deleteFolderRecursive } from \"./common\";\nimport { generateSystem } from \"./generateSystem\";\nimport { generateToml } from \"./generateToml\";\nimport {generateSchemaData, generateSchemaStructure} from \"./generateSchema\";\nimport {generateDeployHook, generateMigrate} from \"./generateScript\";\nimport {generateDappKey} from \"./generateDappKey\";\n\nexport async function worldgen(config: ObeliskConfig, srcPrefix?: string) {\n let path = \"\";\n if (srcPrefix === undefined) {\n path = process.cwd();\n } else {\n path = srcPrefix;\n }\n\n if (existsSync(`${path}/contracts/${config.name}`)) {\n deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n await generateToml(config, path);\n }\n\n if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {\n await generateDeployHook(config, path);\n }\n\n await generateSystem(config, path);\n await generateSchemaData(config.name, config.schemas, path);\n await generateSchemaStructure(config.name, config.schemas, path);\n await generateDappKey(config, path);\n}\n","import { BaseType, SchemaType, BaseValueType, MoveType } from \"../../types\";\nimport fs from \"fs\";\n\nexport function deleteFolderRecursive(path: string) {\n if (fs.existsSync(path)) {\n fs.readdirSync(path).forEach((file) => {\n const curPath = `${path}/${file}`;\n if (fs.lstatSync(curPath).isDirectory()) {\n deleteFolderRecursive(curPath);\n } else {\n fs.unlinkSync(curPath);\n }\n });\n fs.rmdirSync(path);\n }\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n return input.charAt(0).toUpperCase() + input.slice(1);\n}\n\n/**\n *\n * @param values\n * @param prefixArgs\n * @return [ name, age, birth_time ]\n */\nexport function getStructAttrs(\n values: Record<string, string> | string,\n): string {\n return Object.entries(values).map(([key, _]) => `${key}`).join(\",\");\n}\n\nfunction isAddress(str: string): boolean {\n const regex = /^0x[a-fA-F0-9]+$/;\n return regex.test(str);\n}\n\n/**\n *\n * @param values\n * @return ( bool , u64 , u64)\n */\n// export function getStructTypes(values: SchemaType): string {\nexport function getStructTypes(\n values: MoveType | Record<string, MoveType>\n): string {\n return typeof values === \"string\"\n ? values\n : `(${Object.entries(values).map(([_, type]) => `${type}`)})`;\n}\n\n/**\n *\n * @param values\n * @return Attributes and types of the struct. [ name: string, age: u64 ]\n */\nexport function getStructAttrsWithType(\n values: Record<string, string>\n): string[] {\n return Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @param prefixArgs\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n values: MoveType | Record<string, MoveType>,\n prefixArgs: string\n): string[] {\n return typeof values === \"string\"\n ? [`${prefixArgs}self.value`]\n : Object.entries(values).map(\n ([key, _]) => `${prefixArgs}self.${key}`\n );\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateSystem(config: ObeliskConfig, srcPrefix: string) {\n config.systems.map(async (systemName) => {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`\n )\n ) {\n let code = `module ${config.name}::${systemName}_system {\n\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,\n \"formatAndWriteMove\"\n );\n }\n });\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(config: ObeliskConfig, srcPrefix: string) {\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.31.1\" }\nObelisk = { git = \"https://github.com/0xobelisk/obelisk-engine.git\", subdir = \"packages/obelisk-framework\", rev = \"main\" }\n\n[addresses]\nsui = \"0x2\"\nobelisk = \"0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256\"\n${config.name} = \"0x0\"\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/Move.toml`,\n\t\t'formatAndWriteMove'\n\t);\n}\n","import {\n BaseType, SchemaType,\n} from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport {\n getStructAttrsWithType,\n getStructAttrs,\n getStructTypes, getStructAttrsQuery,\n} from \"./common\";\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n return input\n .split('_')\n .map((word, index) => {\n return index === 0\n ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n })\n .join('');\n}\n\nexport function renderSetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) =>\n `public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`\n ).join(\"\\n\");\n}\n\nexport function renderSetFunc(\n schemaName: string,\n fields: Record<string, string>\n): string {\n return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {\n ${Object.entries(fields)\n .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n .join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields, \"\")})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n schemaName: string,\n fields: BaseType | Record<string, BaseType>\n): string {\n return Object.entries(fields)\n .map(\n ([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`\n ).join(\"\\n\");\n}\n\nfunction convertToSnakeCase(input: string): string {\n return input\n .replace(/([A-Z])/g, '_$1')\n .toLowerCase()\n .replace(/^_/, '');\n}\n\nexport async function generateSchemaData(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n const schema = schemas[schemaName];\n if (schema.data) {\n for (const item of schema.data) {\n let code = \"\";\n\n const enumNames = schema.data\n .filter(item => Array.isArray(item.fields))\n .map(item => item.name);\n\n if (Array.isArray(item.fields)) {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields.map((field: string) => {\n return `public fun new_${convertToSnakeCase(field)}(): ${item.name} {\n ${item.name}::${field}\n }`\n }).join(\"\")\n }`\n } else {\n code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {\n use std::ascii::String;\n ${enumNames.map(name => `use ${projectName}::${schemaName}_${convertToSnakeCase(name)}::${name};`).join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(item.fields)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n }\n\n await formatAndWriteMove(\n code,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(item.name)}.move`,\n \"formatAndWriteMove\"\n );\n }\n }\n }\n}\n\nfunction generateImport(projectName: string, schemaName: string, schema: SchemaType) {\n if (schema.data) {\n return schema.data.map(item => {\n return `use ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}::${item.name};`\n }).join('\\n');\n } else {\n return \"\"\n }\n}\n\nexport async function generateSchemaStructure(projectName: string, schemas: Record<string, SchemaType>, path: string) {\n for (const schemaName in schemas) {\n console.log(`Schema: ${schemaName}`);\n const schema = schemas[schemaName];\n const schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::type_name;\n use obelisk::dapps_system;\n use obelisk::dapps_schema::Dapps;\n use obelisk::storage_value::{Self, StorageValue};\n use obelisk::storage_map::{Self, StorageMap};\n use obelisk::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(schemaName)} has key, store {\n id: UID,\n ${getStructAttrsWithType(schema.structure)}\n } \n \n ${Object.entries(schema.structure).map(([key, value]) => {\n return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : &${value} {\n &self.${key}\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(schemaName)}): &mut ${value} {\n &mut self.${key}\n }\n `\n }).join('')} \n \n public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(schemaName)} {\n let package_id = dapps_system::current_package_id<DappKey>();\n assert!(dapps.borrow_metadata().contains_key(package_id), 0);\n assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);\n let schema = type_name::get<${capitalizeAndRemoveUnderscores(schemaName)}>().into_string();\n assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);\n dapps_system::add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(dapps, package_id, ctx);\n ${capitalizeAndRemoveUnderscores(schemaName)} {\n id: object::new(ctx),\n ${Object.entries(schema.structure).map(([key, value]) => {\n let storage_type = \"\"\n if (value.includes(\"StorageValue\")) {\n storage_type = `storage_value::new()`\n } else if (value.includes(\"StorageMap\")) {\n storage_type = `storage_map::new()`\n } else if (value.includes(\"StorageDoubleMap\")) {\n storage_type = `storage_double_map::new()`\n }\n return `${key}: ${storage_type},`\n }).join(' ')\n }\n }\n }\n \n }`;\n await formatAndWriteMove(\n schemaMoudle,\n `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n \"formatAndWriteMove\"\n );\n }\n}","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\nimport { existsSync } from \"fs\";\n\nexport async function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n )\n ) {\n let code = `module ${config.name}::deploy_hook {\n use obelisk::dapps_schema::Dapps;\n use obelisk::dapps_system;\n use ${config.name}::dapp_key::DappKey;\n use std::ascii;\n use sui::clock::Clock;\n use sui::transfer::public_share_object;\n #[test_only]\n use obelisk::dapps_schema;\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to obelisk.\n dapps_system::register<DappKey>(\n dapps,\n ascii::string(b\"${config.name}\"),\n ascii::string(b\"${config.description}\"),\n clock,\n ctx\n );\n ${Object.keys(config.schemas).map(schemaName => {\n return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`\n }).join(\"\\n\")}\n // Logic that needs to be automated once the contract is deployed\n\n\n // Share the dapp object with the public\n ${Object.keys(config.schemas).map(schemaName => {\n return `public_share_object(${schemaName});`\n }).join(\"\\n\")}\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n run(&mut dapps, &clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, dapps)\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\nexport function generateMigrate(config: ObeliskConfig, srcPrefix: string) {\n if (\n !existsSync(\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n )\n ) {\n let code = `module ${config.name}::migrate {\n use obelisk::world::{World, AdminCap};\n\n /// Not the right admin for this world\n const ENotAdmin: u64 = 0;\n const EWrongVersion: u64 = 1;\n const ENotUpgrade: u64 = 2;\n const VERSION: u64 = 1;\n\n public entry fun run(world: &mut World, admin_cap: &AdminCap) {\n assert!(world.admin() == object::id(admin_cap), ENotAdmin);\n assert!(world.version() < VERSION, ENotUpgrade);\n *obelisk::world::mut_version(world, admin_cap) = VERSION;\n }\n\n public fun assert_version(world: &World){\n assert!(world.version() == VERSION, EWrongVersion);\n }\n}\n`;\n formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n \"formatAndWriteMove\"\n );\n }\n}\n\n","import { ObeliskConfig } from \"../../types\";\nimport { formatAndWriteMove } from \"../formatAndWrite\";\n\nexport async function generateDappKey(config: ObeliskConfig, srcPrefix: string) {\n let code = `module ${config.name}::dapp_key {\n /// Authorization token for the app.\n public struct DappKey has drop {}\n\n public(package) fun new(): DappKey {\n DappKey { }\n }\n}\n`;\n await formatAndWriteMove(\n code,\n `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n \"formatAndWriteMove\"\n );\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"obelisk.config.js\",\n \"obelisk.config.mjs\",\n \"obelisk.config.ts\",\n \"obelisk.config.mts\",\n];\nconst TEMP_CONFIG = \"obelisk.config.example.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).obeliskConfig;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(\n configPath: string | undefined,\n toFileURL?: boolean\n) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\"\n ? pathToFileURL(configPath).href\n : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n","\nexport class NotInsideProjectError extends Error {\nname = \"NotInsideProjectError\";\nmessage = \"You are not inside a Obelisk project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,0BAE/B,eAAsBC,EACrBC,EACAC,EACkB,CAClB,IAAIC,EACAD,IACHC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAEzD,GAAI,CACH,OAAOJ,EAAS,OAAOG,EAAS,CAC/B,QAAS,CAACF,CAAkB,EAC5B,OAAQ,aACR,WAAY,IACZ,KAAM,GACN,SAAU,EACV,QAAS,GACT,eAAgB,GAChB,GAAGI,CACJ,CAAC,CACF,OAASC,EAAP,CACD,IAAIC,EACJ,OAAID,aAAiB,MACpBC,EAAUD,EAAM,QAEhBC,EAAUD,EAEX,QAAQ,IAAI,mCAAmCC,GAAS,EACjDJ,CACR,CACD,CAEA,eAAsBK,EAAiBL,EAAkC,CACxE,OAAOH,EAAS,OAAOG,EAAS,CAC/B,OAAQ,YACT,CAAC,CACF,CCtCA,OAAOM,MAAQ,mBACf,OAAOC,MAAU,YCDjB,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,gBAAgB,EACpCE,EAAQF,EAAY,gBAAgB,EAGjDC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAGtCC,EAAM,IAAM,QAAQ,MA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,EAAO,QAASE,CAAI,EAC/D,MAAMQ,EAAgBV,EAAQE,CAAI,CACpC,COjCA,OAAS,UAAAS,MAAc,UACvB,OAAOC,MAAU,OACjB,OAAOC,MAAa,UCDb,IAAMC,EAAN,cAAoC,KAAM,CACjD,KAAO,wBACP,QAAU,sCACV,EDAA,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,KAGf,IAAMC,EAAc,CAClB,oBACA,qBACA,oBACA,oBACF,EACMC,EAAc,6BAEpB,eAAsBC,GAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAME,EAAQ,MAAM,CAClB,YAAa,CAACF,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,aAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EACpBD,EACAG,EACA,CACA,OAAIH,IAAe,OACjBA,EAAa,MAAMI,EAAkB,EAEhCC,EAAK,WAAWL,CAAU,IAC7BA,EAAaK,EAAK,KAAK,QAAQ,IAAI,EAAGL,CAAU,EAChDA,EAAaK,EAAK,UAAUL,CAAU,GAMnCG,GAAaP,EAAG,SAAS,IAAM,QAClCD,EAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOV,CAAW,EAC7C,GAAIS,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["prettier","prettierPluginMove","formatMove","content","prettierConfigPath","config","error","message","formatTypescript","fs","path","createDebug","debug","error","debug","error","formatAndWriteMove","output","fullOutputPath","logPrefix","formattedOutput","formatMove","schemaPrefix","deployHookPrefix","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","prefixArgs","existsSync","generateSystem","config","srcPrefix","systemName","code","formatAndWriteMove","generateToml","config","srcPrefix","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemaMoudle","value","storage_type","existsSync","generateDeployHook","config","srcPrefix","code","schemaName","formatAndWriteMove","generateDappKey","config","srcPrefix","code","formatAndWriteMove","worldgen","config","srcPrefix","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSystem","generateSchemaData","generateSchemaStructure","generateDappKey","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
1
+ {"version":3,"sources":["../src/codegen/utils/format.ts","../src/codegen/utils/formatAndWrite.ts","../src/debug.ts","../src/codegen/debug.ts","../src/codegen/utils/posixPath.ts","../src/codegen/utils/renderMove/schemaGen.ts","../src/codegen/utils/renderMove/common.ts","../src/codegen/utils/renderMove/generateSystem.ts","../src/codegen/utils/renderMove/generateToml.ts","../src/codegen/utils/renderMove/generateSchema.ts","../src/codegen/utils/renderMove/generateScript.ts","../src/codegen/utils/renderMove/generateDappKey.ts","../src/codegen/utils/config.ts","../src/codegen/utils/errors.ts"],"sourcesContent":["import prettier from 'prettier';\nimport prettierPluginMove from 'prettier-plugin-move-js';\n\nexport async function formatMove(\n\tcontent: string,\n\tprettierConfigPath?: string\n): Promise<string> {\n\tlet config;\n\tif (prettierConfigPath) {\n\t\tconfig = await prettier.resolveConfig(prettierConfigPath);\n\t}\n\ttry {\n\t\treturn prettier.format(content, {\n\t\t\tplugins: [prettierPluginMove],\n\t\t\tparser: 'move-parse',\n\t\t\tprintWidth: 120,\n\t\t\tsemi: true,\n\t\t\ttabWidth: 2,\n\t\t\tuseTabs: false,\n\t\t\tbracketSpacing: true,\n\t\t\t...config,\n\t\t});\n\t} catch (error) {\n\t\tlet message;\n\t\tif (error instanceof Error) {\n\t\t\tmessage = error.message;\n\t\t} else {\n\t\t\tmessage = error;\n\t\t}\n\t\tconsole.log(`Error during output formatting: ${message}`);\n\t\treturn content;\n\t}\n}\n\nexport async function formatTypescript(content: string): Promise<string> {\n\treturn prettier.format(content, {\n\t\tparser: 'typescript',\n\t});\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatMove, formatTypescript } from \"./format\";\nimport { debug } from \"../debug\";\n\nexport async function formatAndWriteMove(\n output: string,\n fullOutputPath: string,\n logPrefix?: string\n): Promise<void> {\n const formattedOutput = await formatMove(output);\n let schemaPrefix =\n` // Copyright (c) Obelisk Labs, Inc.\n // SPDX-License-Identifier: MIT\n #[allow(unused_use)]\n \n /* Autogenerated file. Do not edit manually. */\n \n `\n\n let deployHookPrefix = `#[allow(lint(share_owned))]\n \n `\n\n let code = schemaPrefix + formattedOutput\n\n if (fullOutputPath.includes(\".toml\") || fullOutputPath.includes(\"system\")) {\n code = formattedOutput\n } else if (fullOutputPath.includes(\"deploy_hook\")) {\n code = deployHookPrefix + formattedOutput\n }\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n await fs.writeFile(fullOutputPath, code);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n\n/**\n * Formats typescript code using prettier and write it to a file\n * @param output typescript code\n * @param fullOutputPath full path to the output file\n * @param logPrefix prefix for debug logs\n */\nexport async function formatAndWriteTypescript(\n output: string,\n fullOutputPath: string,\n logPrefix: string,\n): Promise<void> {\n const formattedOutput = await formatTypescript(output);\n\n await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });\n\n await fs.writeFile(fullOutputPath, formattedOutput);\n debug(`${logPrefix}: ${fullOutputPath}`);\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"obelisk:common\");\nexport const error = createDebug(\"obelisk:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"codegen\");\nexport const error = parentDebug.extend(\"codegen\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","/**\n * Explicitly normalize a given path to a posix path (using `/` as separator).\n * This should be used for generating Solidity files that will be consumed by solc,\n * because solc expects `/` as path separator, but path.join produces `\\` if the user is on windows.\n */\nexport function posixPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n","import { SchemaType, ObeliskConfig } from '../../types';\nimport { rmdirSync, existsSync } from 'fs';\nimport { deleteFolderRecursive } from './common';\nimport { generateSystem } from './generateSystem';\nimport { generateToml } from './generateToml';\nimport { generateSchemaData, generateSchemaStructure } from './generateSchema';\nimport { generateDeployHook, generateMigrate } from './generateScript';\nimport { generateDappKey } from './generateDappKey';\n\nfunction matchFrameworkId(\n\tnetwork: 'mainnet' | 'testnet' | 'devnet' | 'localnet'\n): string {\n\tswitch (network) {\n\t\tcase 'testnet':\n\t\t\treturn '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';\n\t\tcase 'localnet':\n\t\t\treturn '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';\n\t\tdefault:\n\t\t\treturn '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';\n\t}\n}\n\nexport async function schemaGen(\n\tconfig: ObeliskConfig,\n\tsrcPrefix?: string,\n\tnetwork?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',\n\tframeworkId?: string\n) {\n\tconsole.log('\\nšŸš€ Starting Schema Generation Process...');\n\tconsole.log('šŸ“‹ Project Configuration:');\n\tconsole.log(` ā”œā”€ Name: ${config.name}`);\n\tconsole.log(\n\t\t` ā”œā”€ Description: ${config.description || 'No description provided'}`\n\t);\n\tconsole.log(` ā”œā”€ Network: ${network || 'testnet'}`);\n\tconsole.log(\n\t\t` └─ Framework ID: ${\n\t\t\tframeworkId || matchFrameworkId(network ?? 'testnet')\n\t\t}\\n`\n\t);\n\n\tconst path = srcPrefix ?? process.cwd();\n\n\tframeworkId = frameworkId || matchFrameworkId(network ?? 'testnet');\n\n\tif (existsSync(`${path}/contracts/${config.name}`)) {\n\t\tdeleteFolderRecursive(\n\t\t\t`${path}/contracts/${config.name}/sources/codegen`\n\t\t);\n\t}\n\n\tif (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {\n\t\tawait generateToml(config, path, frameworkId);\n\t}\n\n\tif (\n\t\t!existsSync(\n\t\t\t`${path}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t\t)\n\t) {\n\t\tawait generateDeployHook(config, path);\n\t}\n\n\tawait generateSystem(config, path);\n\tawait generateSchemaData(config.name, config.schemas, path);\n\tawait generateSchemaStructure(config.name, config.schemas, path);\n\tawait generateDappKey(config, path);\n\tconsole.log('āœ… Schema Generation Process Complete!\\n');\n}\n","import { MoveType } from '../../types';\nimport fs from 'fs';\n\nexport function deleteFolderRecursive(path: string) {\n\tif (fs.existsSync(path)) {\n\t\tfs.readdirSync(path).forEach(file => {\n\t\t\tconst curPath = `${path}/${file}`;\n\t\t\tif (fs.lstatSync(curPath).isDirectory()) {\n\t\t\t\tdeleteFolderRecursive(curPath);\n\t\t\t} else {\n\t\t\t\tfs.unlinkSync(curPath);\n\t\t\t}\n\t\t});\n\t\tfs.rmdirSync(path);\n\t}\n}\n\nexport function capitalizeFirstLetter(input: string): string {\n\treturn input.charAt(0).toUpperCase() + input.slice(1);\n}\n\n/**\n *\n * @param values\n * @param prefixArgs\n * @return [ name, age, birth_time ]\n */\nexport function getStructAttrs(\n\tvalues: Record<string, string> | string\n): string {\n\treturn Object.entries(values)\n\t\t.map(([key, _]) => `${key}`)\n\t\t.join(',');\n}\n\nfunction isAddress(str: string): boolean {\n\tconst regex = /^0x[a-fA-F0-9]+$/;\n\treturn regex.test(str);\n}\n\n/**\n *\n * @param values\n * @return ( bool , u64 , u64)\n */\n// export function getStructTypes(values: SchemaType): string {\nexport function getStructTypes(\n\tvalues: MoveType | Record<string, MoveType>\n): string {\n\treturn typeof values === 'string'\n\t\t? values\n\t\t: `(${Object.entries(values).map(([_, type]) => `${type}`)})`;\n}\n\n/**\n *\n * @param values\n * @return Attributes and types of the struct. [ name: string, age: u64 ]\n */\nexport function getStructAttrsWithType(\n\tvalues: Record<string, string>\n): string[] {\n\treturn Object.entries(values).map(([key, type]) => `${key}: ${type}`);\n}\n\n/**\n * @param values\n * @param prefixArgs\n * @return [ data.name, data.age ]\n */\nexport function getStructAttrsQuery(\n\tvalues: MoveType | Record<string, MoveType>,\n\tprefixArgs: string\n): string[] {\n\treturn typeof values === 'string'\n\t\t? [`${prefixArgs}self.value`]\n\t\t: Object.entries(values).map(([key, _]) => `${prefixArgs}self.${key}`);\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\n\nexport async function generateSystem(config: ObeliskConfig, srcPrefix: string) {\n\tconsole.log('\\nāš™ļø Starting System Generation...');\n\tconfig.systems.map(async systemName => {\n\t\tconsole.log(` ā”œā”€ Generating system: ${systemName}`);\n\t\tconsole.log(\n\t\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`\n\t\t);\n\n\t\tif (\n\t\t\t!existsSync(\n\t\t\t\t`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`\n\t\t\t)\n\t\t) {\n\t\t\tlet code = `module ${config.name}::${systemName}_system {\n\n}\n`;\n\t\t\tawait formatAndWriteMove(\n\t\t\t\tcode,\n\t\t\t\t`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,\n\t\t\t\t'formatAndWriteMove'\n\t\t\t);\n\t\t}\n\t});\n\tconsole.log('āœ… System Generation Complete\\n');\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateToml(\n\tconfig: ObeliskConfig,\n\tsrcPrefix: string,\n\tframeworkId: string\n) {\n\tconsole.log('\\nšŸ“„ Starting Move.toml Generation...');\n\tconsole.log(\n\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`\n\t);\n\n\tlet code = `[package]\nname = \"${config.name}\"\nversion = \"0.0.1\"\nedition = \"2024.beta\"\n\n[dependencies]\nSui = { git = \"https://github.com/MystenLabs/sui.git\", subdir = \"crates/sui-framework/packages/sui-framework\", rev = \"mainnet-v1.31.1\" }\nObelisk = { git = \"https://github.com/0xobelisk/obelisk-engine.git\", subdir = \"packages/obelisk-framework\", rev = \"main\" }\n\n[addresses]\nsui = \"0x2\"\nobelisk = \"${frameworkId}\"\n${config.name} = \"0x0\"\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/Move.toml`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('āœ… Move.toml Generation Complete\\n');\n}\n","import { BaseType, SchemaType } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport {\n\tgetStructAttrsWithType,\n\tgetStructAttrs,\n\tgetStructTypes,\n\tgetStructAttrsQuery,\n} from './common';\n\nfunction capitalizeAndRemoveUnderscores(input: string): string {\n\treturn input\n\t\t.split('_')\n\t\t.map((word, index) => {\n\t\t\treturn index === 0\n\t\t\t\t? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n\t\t\t\t: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n\t\t})\n\t\t.join('');\n}\n\nexport function renderSetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([key, type]) =>\n\t\t\t\t`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {\n self.${key} = ${key};\n }`\n\t\t)\n\t\t.join('\\n');\n}\n\nexport function renderSetFunc(\n\tschemaName: string,\n\tfields: Record<string, string>\n): string {\n\treturn `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(\n\t\tfields\n\t)}) {\n ${Object.entries(fields)\n\t\t\t\t.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)\n\t\t\t\t.join('\\n')}\n }`;\n}\n\nexport function renderGetAllFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>\n): string {\n\treturn `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {\n (${getStructAttrsQuery(fields, '')})\n }`;\n}\n\nexport function renderGetAttrsFunc(\n\tschemaName: string,\n\tfields: BaseType | Record<string, BaseType>\n): string {\n\treturn Object.entries(fields)\n\t\t.map(\n\t\t\t([\n\t\t\t\tkey,\n\t\t\t\ttype,\n\t\t\t]) => `public fun get_${key}(self: &${schemaName}): ${type} {\n self.${key}\n }`\n\t\t)\n\t\t.join('\\n');\n}\n\nfunction convertToSnakeCase(input: string): string {\n\treturn input\n\t\t.replace(/([A-Z])/g, '_$1')\n\t\t.toLowerCase()\n\t\t.replace(/^_/, '');\n}\n\nexport async function generateSchemaData(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string\n) {\n\tconsole.log('\\nšŸ“¦ Starting Schema Data Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconst schema = schemas[schemaName];\n\t\tif (schema.data) {\n\t\t\tconsole.log(` ā”œā”€ Processing schema: ${schemaName}`);\n\t\t\tfor (const item of schema.data) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t` └─ Generating ${item.name} ${\n\t\t\t\t\t\tArray.isArray(item.fields) ? '(enum)' : '(struct)'\n\t\t\t\t\t}`\n\t\t\t\t);\n\t\t\t\tlet code = '';\n\n\t\t\t\tconst enumNames = schema.data\n\t\t\t\t\t.filter(item => Array.isArray(item.fields))\n\t\t\t\t\t.map(item => item.name);\n\n\t\t\t\tif (Array.isArray(item.fields)) {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)} {\n public enum ${item.name} has copy, drop , store {\n ${item.fields}\n }\n \n ${item.fields\n\t\t\t\t\t\t\t.map((field: string) => {\n\t\t\t\t\t\t\t\treturn `public fun new_${convertToSnakeCase(\n\t\t\t\t\t\t\t\t\tfield\n\t\t\t\t\t\t\t\t)}(): ${item.name} {\n ${item.name}::${field}\n }`;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')}`;\n\t\t\t\t} else {\n\t\t\t\t\tcode = `module ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)} {\n use std::ascii::String;\n ${enumNames\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\tname =>\n\t\t\t\t\t\t\t\t\t\t`use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\t\t)}::${name};`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join('\\n')}\n\n public struct ${item.name} has copy, drop , store {\n ${getStructAttrsWithType(item.fields)}\n }\n \n public fun new(${getStructAttrsWithType(\n\t\t\t\t\t\t\t\titem.fields\n\t\t\t\t\t\t\t)}): ${item.name} {\n ${item.name} {\n ${getStructAttrs(item.fields)}\n }\n }\n \n ${renderGetAllFunc(item.name, item.fields)}\n ${renderGetAttrsFunc(item.name, item.fields)}\n ${renderSetAttrsFunc(item.name, item.fields)}\n ${renderSetFunc(item.name, item.fields)}\n }`;\n\t\t\t\t}\n\n\t\t\t\tawait formatAndWriteMove(\n\t\t\t\t\tcode,\n\t\t\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(\n\t\t\t\t\t\titem.name\n\t\t\t\t\t)}.move`,\n\t\t\t\t\t'formatAndWriteMove'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconsole.log('āœ… Schema Data Generation Complete\\n');\n}\n\nfunction generateImport(\n\tprojectName: string,\n\tschemaName: string,\n\tschema: SchemaType\n) {\n\tif (schema.data) {\n\t\treturn schema.data\n\t\t\t.map(item => {\n\t\t\t\treturn `use ${projectName}::${schemaName}_${convertToSnakeCase(\n\t\t\t\t\titem.name\n\t\t\t\t)}::${item.name};`;\n\t\t\t})\n\t\t\t.join('\\n');\n\t} else {\n\t\treturn '';\n\t}\n}\n\nexport async function generateSchemaStructure(\n\tprojectName: string,\n\tschemas: Record<string, SchemaType>,\n\tpath: string\n) {\n\tconsole.log('\\nšŸ”Ø Starting Schema Structure Generation...');\n\tfor (const schemaName in schemas) {\n\t\tconsole.log(` ā”œā”€ Generating schema: ${schemaName}`);\n\t\tconsole.log(\n\t\t\t` ā”œā”€ Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`\n\t\t);\n\t\tconsole.log(\n\t\t\t` └─ Structure fields: ${\n\t\t\t\tObject.keys(schemas[schemaName].structure).length\n\t\t\t}`\n\t\t);\n\t\tconst schema = schemas[schemaName];\n\t\tconst schemaMoudle = `module ${projectName}::${schemaName}_schema {\n use std::ascii::String;\n use std::type_name;\n use obelisk::dapps_system;\n use obelisk::dapps_schema::Dapps;\n use obelisk::storage_value::{Self, StorageValue};\n use obelisk::storage_map::{Self, StorageMap};\n use obelisk::storage_double_map::{Self, StorageDoubleMap};\n use ${projectName}::dapp_key::DappKey;\n ${generateImport(projectName, schemaName, schema)}\n\n public struct ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)} has key, store {\n id: UID,\n ${getStructAttrsWithType(schema.structure)}\n } \n \n ${Object.entries(schema.structure)\n\t\t\t\t\t\t\t.map(([key, value]) => {\n\t\t\t\t\t\t\t\treturn `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\t\t\t\tschemaName\n\t\t\t\t\t\t\t\t)}) : &${value} {\n &self.${key}\n }\n \n public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)}): &mut ${value} {\n &mut self.${key}\n }\n `;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')} \n \n public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\tschemaName\n\t\t\t\t\t)} {\n let package_id = dapps_system::current_package_id<DappKey>();\n assert!(dapps.borrow_metadata().contains_key(package_id), 0);\n assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);\n let schema = type_name::get<${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\t\tschemaName\n\t\t\t\t\t\t)}>().into_string();\n assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);\n dapps_system::add_schema<${capitalizeAndRemoveUnderscores(\n\t\t\t\t\t\t\tschemaName\n\t\t\t\t\t\t)}>(dapps, package_id, ctx);\n ${capitalizeAndRemoveUnderscores(schemaName)} {\n id: object::new(ctx),\n ${Object.entries(schema.structure)\n\t\t\t\t\t\t\t\t.map(([key, value]) => {\n\t\t\t\t\t\t\t\t\tlet storage_type = '';\n\t\t\t\t\t\t\t\t\tif (value.includes('StorageValue')) {\n\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_value::new()`;\n\t\t\t\t\t\t\t\t\t} else if (value.includes('StorageMap')) {\n\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_map::new()`;\n\t\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\t\tvalue.includes('StorageDoubleMap')\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tstorage_type = `storage_double_map::new()`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn `${key}: ${storage_type},`;\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t.join(' ')}\n }\n }\n \n }`;\n\t\tawait formatAndWriteMove(\n\t\t\tschemaMoudle,\n\t\t\t`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n\tconsole.log('āœ… Schema Structure Generation Complete\\n');\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\nimport { existsSync } from 'fs';\n\nexport async function generateDeployHook(\n\tconfig: ObeliskConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nšŸ“ Starting Deploy Hook Generation...');\n\tconsole.log(\n\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t);\n\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::deploy_hook {\n use obelisk::dapps_schema::Dapps;\n use obelisk::dapps_system;\n use ${config.name}::dapp_key::DappKey;\n use std::ascii;\n use sui::clock::Clock;\n use sui::transfer::public_share_object;\n #[test_only]\n use obelisk::dapps_schema;\n #[test_only]\n use sui::clock;\n #[test_only]\n use sui::test_scenario;\n #[test_only]\n use sui::test_scenario::Scenario;\n\n public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {\n // Register the dapp to obelisk.\n dapps_system::register<DappKey>(\n dapps,\n ascii::string(b\"${config.name}\"),\n ascii::string(b\"${config.description}\"),\n clock,\n ctx\n );\n ${Object.keys(config.schemas)\n\t\t\t.map(schemaName => {\n\t\t\t\treturn `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`;\n\t\t\t})\n\t\t\t.join('\\n')}\n // Logic that needs to be automated once the contract is deployed\n\n\n // Share the dapp object with the public\n ${Object.keys(config.schemas)\n\t\t\t.map(schemaName => {\n\t\t\t\treturn `public_share_object(${schemaName});`;\n\t\t\t})\n\t\t\t.join('\\n')}\n }\n\n #[test_only]\n public fun deploy_hook_for_testing(): (Scenario, Dapps) {\n let mut scenario = test_scenario::begin(@0xA);\n {\n let ctx = test_scenario::ctx(&mut scenario);\n dapps_schema::init_dapps_for_testing(ctx);\n test_scenario::next_tx(&mut scenario,@0xA);\n };\n let mut dapps = test_scenario::take_shared<Dapps>(&scenario);\n let ctx = test_scenario::ctx(&mut scenario);\n let clock = clock::create_for_testing(ctx);\n run(&mut dapps, &clock, ctx);\n clock::destroy_for_testing(clock);\n test_scenario::next_tx(&mut scenario,@0xA);\n (scenario, dapps)\n }\n}\n`;\n\t\tawait formatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n\tconsole.log('āœ… Deploy Hook Generation Complete\\n');\n}\n\nexport function generateMigrate(config: ObeliskConfig, srcPrefix: string) {\n\tif (\n\t\t!existsSync(\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`\n\t\t)\n\t) {\n\t\tlet code = `module ${config.name}::migrate {\n use obelisk::world::{World, AdminCap};\n\n /// Not the right admin for this world\n const ENotAdmin: u64 = 0;\n const EWrongVersion: u64 = 1;\n const ENotUpgrade: u64 = 2;\n const VERSION: u64 = 1;\n\n public entry fun run(world: &mut World, admin_cap: &AdminCap) {\n assert!(world.admin() == object::id(admin_cap), ENotAdmin);\n assert!(world.version() < VERSION, ENotUpgrade);\n *obelisk::world::mut_version(world, admin_cap) = VERSION;\n }\n\n public fun assert_version(world: &World){\n assert!(world.version() == VERSION, EWrongVersion);\n }\n}\n`;\n\t\tformatAndWriteMove(\n\t\t\tcode,\n\t\t\t`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,\n\t\t\t'formatAndWriteMove'\n\t\t);\n\t}\n}\n","import { ObeliskConfig } from '../../types';\nimport { formatAndWriteMove } from '../formatAndWrite';\n\nexport async function generateDappKey(\n\tconfig: ObeliskConfig,\n\tsrcPrefix: string\n) {\n\tconsole.log('\\nšŸ”‘ Starting DappKey Generation...');\n\tconsole.log(\n\t\t` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`\n\t);\n\n\tlet code = `module ${config.name}::dapp_key {\n\\t/// Authorization token for the app.\n\\tpublic struct DappKey has drop {}\n\n\\tpublic(package) fun new(): DappKey {\n\\t\\tDappKey { }\n\\t}\n}\n`;\n\tawait formatAndWriteMove(\n\t\tcode,\n\t\t`${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,\n\t\t'formatAndWriteMove'\n\t);\n\tconsole.log('āœ… DappKey Generation Complete\\n');\n}\n","import { findUp } from \"find-up\";\nimport path from \"path\";\nimport esbuild from \"esbuild\";\nimport { NotInsideProjectError } from \"./errors\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\n \"obelisk.config.js\",\n \"obelisk.config.mjs\",\n \"obelisk.config.ts\",\n \"obelisk.config.mts\",\n];\nconst TEMP_CONFIG = \"obelisk.config.example.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).obeliskConfig;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(\n configPath: string | undefined,\n toFileURL?: boolean\n) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\"\n ? pathToFileURL(configPath).href\n : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n","\nexport class NotInsideProjectError extends Error {\nname = \"NotInsideProjectError\";\nmessage = \"You are not inside a Obelisk project\";\n}"],"mappings":"AAAA,OAAOA,MAAc,WACrB,OAAOC,MAAwB,0BAE/B,eAAsBC,EACrBC,EACAC,EACkB,CAClB,IAAIC,EACAD,IACHC,EAAS,MAAML,EAAS,cAAcI,CAAkB,GAEzD,GAAI,CACH,OAAOJ,EAAS,OAAOG,EAAS,CAC/B,QAAS,CAACF,CAAkB,EAC5B,OAAQ,aACR,WAAY,IACZ,KAAM,GACN,SAAU,EACV,QAAS,GACT,eAAgB,GAChB,GAAGI,CACJ,CAAC,CACF,OAASC,EAAP,CACD,IAAIC,EACJ,OAAID,aAAiB,MACpBC,EAAUD,EAAM,QAEhBC,EAAUD,EAEX,QAAQ,IAAI,mCAAmCC,GAAS,EACjDJ,CACR,CACD,CAEA,eAAsBK,EAAiBL,EAAkC,CACxE,OAAOH,EAAS,OAAOG,EAAS,CAC/B,OAAQ,YACT,CAAC,CACF,CCtCA,OAAOM,MAAQ,mBACf,OAAOC,MAAU,YCDjB,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,gBAAgB,EACpCE,EAAQF,EAAY,gBAAgB,EAGjDC,EAAM,IAAM,QAAQ,MA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A,EAAO,QAASG,CAAI,EAC/D,MAAMQ,EAAgBX,EAAQG,CAAI,EAClC,QAAQ,IAAI;AAAA,CAAyC,CACtD,COpEA,OAAS,UAAAS,MAAc,UACvB,OAAOC,MAAU,OACjB,OAAOC,MAAa,UCDb,IAAMC,EAAN,cAAoC,KAAM,CACjD,KAAO,wBACP,QAAU,sCACV,EDAA,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,KAGf,IAAMC,EAAc,CAClB,oBACA,qBACA,oBACA,oBACF,EACMC,EAAc,6BAEpB,eAAsBC,GAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAME,EAAQ,MAAM,CAClB,YAAa,CAACF,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,aAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EACpBD,EACAG,EACA,CACA,OAAIH,IAAe,OACjBA,EAAa,MAAMI,GAAkB,EAEhCC,EAAK,WAAWL,CAAU,IAC7BA,EAAaK,EAAK,KAAK,QAAQ,IAAI,EAAGL,CAAU,EAChDA,EAAaK,EAAK,UAAUL,CAAU,GAMnCG,GAAaP,EAAG,SAAS,IAAM,QAClCD,EAAcK,CAAU,EAAE,KAC1BA,CACN,CAEA,eAAeI,IAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOV,CAAW,EAC7C,GAAIS,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["prettier","prettierPluginMove","formatMove","content","prettierConfigPath","config","error","message","formatTypescript","fs","path","createDebug","debug","error","debug","error","formatAndWriteMove","output","fullOutputPath","logPrefix","formattedOutput","formatMove","schemaPrefix","deployHookPrefix","code","fs","path","debug","formatAndWriteTypescript","formatTypescript","posixPath","path","existsSync","fs","deleteFolderRecursive","path","file","curPath","getStructAttrs","values","key","_","getStructTypes","values","_","type","getStructAttrsWithType","key","getStructAttrsQuery","prefixArgs","existsSync","generateSystem","config","srcPrefix","systemName","code","formatAndWriteMove","generateToml","config","srcPrefix","frameworkId","code","formatAndWriteMove","capitalizeAndRemoveUnderscores","input","word","index","renderSetAttrsFunc","schemaName","fields","key","type","renderSetFunc","getStructAttrsWithType","fieldName","renderGetAllFunc","getStructTypes","getStructAttrsQuery","renderGetAttrsFunc","convertToSnakeCase","generateSchemaData","projectName","schemas","path","schema","item","code","enumNames","field","name","getStructAttrs","formatAndWriteMove","generateImport","generateSchemaStructure","schemaMoudle","value","storage_type","existsSync","generateDeployHook","config","srcPrefix","code","schemaName","formatAndWriteMove","generateDappKey","config","srcPrefix","code","formatAndWriteMove","matchFrameworkId","network","schemaGen","config","srcPrefix","frameworkId","path","existsSync","deleteFolderRecursive","generateToml","generateDeployHook","generateSystem","generateSchemaData","generateSchemaStructure","generateDappKey","findUp","path","esbuild","NotInsideProjectError","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","esbuild","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/sui-common",
3
- "version": "0.5.15",
3
+ "version": "0.5.16",
4
4
  "description": "Common low level logic shared between packages",
5
5
  "keywords": [
6
6
  "sui",
@@ -1,5 +1,5 @@
1
- export * from "./format";
2
- export * from "./formatAndWrite";
3
- export * from "./posixPath";
4
- export * from "./renderMove/worldgen";
5
- export * from "./config";
1
+ export * from './format';
2
+ export * from './formatAndWrite';
3
+ export * from './posixPath';
4
+ export * from './renderMove/schemaGen';
5
+ export * from './config';
@@ -1,22 +1,22 @@
1
- import { BaseType, SchemaType, BaseValueType, MoveType } from "../../types";
2
- import fs from "fs";
1
+ import { MoveType } from '../../types';
2
+ import fs from 'fs';
3
3
 
4
4
  export function deleteFolderRecursive(path: string) {
5
- if (fs.existsSync(path)) {
6
- fs.readdirSync(path).forEach((file) => {
7
- const curPath = `${path}/${file}`;
8
- if (fs.lstatSync(curPath).isDirectory()) {
9
- deleteFolderRecursive(curPath);
10
- } else {
11
- fs.unlinkSync(curPath);
12
- }
13
- });
14
- fs.rmdirSync(path);
15
- }
5
+ if (fs.existsSync(path)) {
6
+ fs.readdirSync(path).forEach(file => {
7
+ const curPath = `${path}/${file}`;
8
+ if (fs.lstatSync(curPath).isDirectory()) {
9
+ deleteFolderRecursive(curPath);
10
+ } else {
11
+ fs.unlinkSync(curPath);
12
+ }
13
+ });
14
+ fs.rmdirSync(path);
15
+ }
16
16
  }
17
17
 
18
18
  export function capitalizeFirstLetter(input: string): string {
19
- return input.charAt(0).toUpperCase() + input.slice(1);
19
+ return input.charAt(0).toUpperCase() + input.slice(1);
20
20
  }
21
21
 
22
22
  /**
@@ -26,14 +26,16 @@ export function capitalizeFirstLetter(input: string): string {
26
26
  * @return [ name, age, birth_time ]
27
27
  */
28
28
  export function getStructAttrs(
29
- values: Record<string, string> | string,
29
+ values: Record<string, string> | string
30
30
  ): string {
31
- return Object.entries(values).map(([key, _]) => `${key}`).join(",");
31
+ return Object.entries(values)
32
+ .map(([key, _]) => `${key}`)
33
+ .join(',');
32
34
  }
33
35
 
34
36
  function isAddress(str: string): boolean {
35
- const regex = /^0x[a-fA-F0-9]+$/;
36
- return regex.test(str);
37
+ const regex = /^0x[a-fA-F0-9]+$/;
38
+ return regex.test(str);
37
39
  }
38
40
 
39
41
  /**
@@ -43,11 +45,11 @@ function isAddress(str: string): boolean {
43
45
  */
44
46
  // export function getStructTypes(values: SchemaType): string {
45
47
  export function getStructTypes(
46
- values: MoveType | Record<string, MoveType>
48
+ values: MoveType | Record<string, MoveType>
47
49
  ): string {
48
- return typeof values === "string"
49
- ? values
50
- : `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
50
+ return typeof values === 'string'
51
+ ? values
52
+ : `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
51
53
  }
52
54
 
53
55
  /**
@@ -56,9 +58,9 @@ export function getStructTypes(
56
58
  * @return Attributes and types of the struct. [ name: string, age: u64 ]
57
59
  */
58
60
  export function getStructAttrsWithType(
59
- values: Record<string, string>
61
+ values: Record<string, string>
60
62
  ): string[] {
61
- return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
63
+ return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
62
64
  }
63
65
 
64
66
  /**
@@ -67,12 +69,10 @@ export function getStructAttrsWithType(
67
69
  * @return [ data.name, data.age ]
68
70
  */
69
71
  export function getStructAttrsQuery(
70
- values: MoveType | Record<string, MoveType>,
71
- prefixArgs: string
72
+ values: MoveType | Record<string, MoveType>,
73
+ prefixArgs: string
72
74
  ): string[] {
73
- return typeof values === "string"
74
- ? [`${prefixArgs}self.value`]
75
- : Object.entries(values).map(
76
- ([key, _]) => `${prefixArgs}self.${key}`
77
- );
78
- }
75
+ return typeof values === 'string'
76
+ ? [`${prefixArgs}self.value`]
77
+ : Object.entries(values).map(([key, _]) => `${prefixArgs}self.${key}`);
78
+ }
@@ -1,19 +1,28 @@
1
- import { ObeliskConfig } from "../../types";
2
- import { formatAndWriteMove } from "../formatAndWrite";
1
+ import { ObeliskConfig } from '../../types';
2
+ import { formatAndWriteMove } from '../formatAndWrite';
3
3
 
4
- export async function generateDappKey(config: ObeliskConfig, srcPrefix: string) {
5
- let code = `module ${config.name}::dapp_key {
6
- /// Authorization token for the app.
7
- public struct DappKey has drop {}
4
+ export async function generateDappKey(
5
+ config: ObeliskConfig,
6
+ srcPrefix: string
7
+ ) {
8
+ console.log('\nšŸ”‘ Starting DappKey Generation...');
9
+ console.log(
10
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
11
+ );
8
12
 
9
- public(package) fun new(): DappKey {
10
- DappKey { }
11
- }
13
+ let code = `module ${config.name}::dapp_key {
14
+ \t/// Authorization token for the app.
15
+ \tpublic struct DappKey has drop {}
16
+
17
+ \tpublic(package) fun new(): DappKey {
18
+ \t\tDappKey { }
19
+ \t}
12
20
  }
13
21
  `;
14
- await formatAndWriteMove(
15
- code,
16
- `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
17
- "formatAndWriteMove"
18
- );
22
+ await formatAndWriteMove(
23
+ code,
24
+ `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
25
+ 'formatAndWriteMove'
26
+ );
27
+ console.log('āœ… DappKey Generation Complete\n');
19
28
  }
@@ -1,109 +1,142 @@
1
+ import { BaseType, SchemaType } from '../../types';
2
+ import { formatAndWriteMove } from '../formatAndWrite';
1
3
  import {
2
- BaseType, SchemaType,
3
- } from "../../types";
4
- import { formatAndWriteMove } from "../formatAndWrite";
5
- import {
6
- getStructAttrsWithType,
7
- getStructAttrs,
8
- getStructTypes, getStructAttrsQuery,
9
- } from "./common";
4
+ getStructAttrsWithType,
5
+ getStructAttrs,
6
+ getStructTypes,
7
+ getStructAttrsQuery,
8
+ } from './common';
10
9
 
11
10
  function capitalizeAndRemoveUnderscores(input: string): string {
12
- return input
13
- .split('_')
14
- .map((word, index) => {
15
- return index === 0
16
- ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
17
- : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
18
- })
19
- .join('');
11
+ return input
12
+ .split('_')
13
+ .map((word, index) => {
14
+ return index === 0
15
+ ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
16
+ : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
17
+ })
18
+ .join('');
20
19
  }
21
20
 
22
21
  export function renderSetAttrsFunc(
23
- schemaName: string,
24
- fields: BaseType | Record<string, BaseType>
22
+ schemaName: string,
23
+ fields: BaseType | Record<string, BaseType>
25
24
  ): string {
26
- return Object.entries(fields)
27
- .map(
28
- ([key, type]) =>
29
- `public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
25
+ return Object.entries(fields)
26
+ .map(
27
+ ([key, type]) =>
28
+ `public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
30
29
  self.${key} = ${key};
31
30
  }`
32
- ).join("\n");
31
+ )
32
+ .join('\n');
33
33
  }
34
34
 
35
35
  export function renderSetFunc(
36
- schemaName: string,
37
- fields: Record<string, string>
36
+ schemaName: string,
37
+ fields: Record<string, string>
38
38
  ): string {
39
- return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {
39
+ return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(
40
+ fields
41
+ )}) {
40
42
  ${Object.entries(fields)
41
- .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
42
- .join('\n')}
43
+ .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
44
+ .join('\n')}
43
45
  }`;
44
46
  }
45
47
 
46
48
  export function renderGetAllFunc(
47
- schemaName: string,
48
- fields: BaseType | Record<string, BaseType>
49
+ schemaName: string,
50
+ fields: BaseType | Record<string, BaseType>
49
51
  ): string {
50
- return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
51
- (${getStructAttrsQuery(fields, "")})
52
+ return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
53
+ (${getStructAttrsQuery(fields, '')})
52
54
  }`;
53
55
  }
54
56
 
55
57
  export function renderGetAttrsFunc(
56
- schemaName: string,
57
- fields: BaseType | Record<string, BaseType>
58
+ schemaName: string,
59
+ fields: BaseType | Record<string, BaseType>
58
60
  ): string {
59
- return Object.entries(fields)
60
- .map(
61
- ([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {
61
+ return Object.entries(fields)
62
+ .map(
63
+ ([
64
+ key,
65
+ type,
66
+ ]) => `public fun get_${key}(self: &${schemaName}): ${type} {
62
67
  self.${key}
63
68
  }`
64
- ).join("\n");
69
+ )
70
+ .join('\n');
65
71
  }
66
72
 
67
73
  function convertToSnakeCase(input: string): string {
68
- return input
69
- .replace(/([A-Z])/g, '_$1')
70
- .toLowerCase()
71
- .replace(/^_/, '');
74
+ return input
75
+ .replace(/([A-Z])/g, '_$1')
76
+ .toLowerCase()
77
+ .replace(/^_/, '');
72
78
  }
73
79
 
74
- export async function generateSchemaData(projectName: string, schemas: Record<string, SchemaType>, path: string) {
75
- for (const schemaName in schemas) {
76
- const schema = schemas[schemaName];
77
- if (schema.data) {
78
- for (const item of schema.data) {
79
- let code = "";
80
+ export async function generateSchemaData(
81
+ projectName: string,
82
+ schemas: Record<string, SchemaType>,
83
+ path: string
84
+ ) {
85
+ console.log('\nšŸ“¦ Starting Schema Data Generation...');
86
+ for (const schemaName in schemas) {
87
+ const schema = schemas[schemaName];
88
+ if (schema.data) {
89
+ console.log(` ā”œā”€ Processing schema: ${schemaName}`);
90
+ for (const item of schema.data) {
91
+ console.log(
92
+ ` └─ Generating ${item.name} ${
93
+ Array.isArray(item.fields) ? '(enum)' : '(struct)'
94
+ }`
95
+ );
96
+ let code = '';
80
97
 
81
- const enumNames = schema.data
82
- .filter(item => Array.isArray(item.fields))
83
- .map(item => item.name);
98
+ const enumNames = schema.data
99
+ .filter(item => Array.isArray(item.fields))
100
+ .map(item => item.name);
84
101
 
85
- if (Array.isArray(item.fields)) {
86
- code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {
102
+ if (Array.isArray(item.fields)) {
103
+ code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
104
+ item.name
105
+ )} {
87
106
  public enum ${item.name} has copy, drop , store {
88
107
  ${item.fields}
89
108
  }
90
109
 
91
- ${item.fields.map((field: string) => {
92
- return `public fun new_${convertToSnakeCase(field)}(): ${item.name} {
110
+ ${item.fields
111
+ .map((field: string) => {
112
+ return `public fun new_${convertToSnakeCase(
113
+ field
114
+ )}(): ${item.name} {
93
115
  ${item.name}::${field}
94
- }`
95
- }).join("")
96
- }`
97
- } else {
98
- code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {
116
+ }`;
117
+ })
118
+ .join('')}`;
119
+ } else {
120
+ code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
121
+ item.name
122
+ )} {
99
123
  use std::ascii::String;
100
- ${enumNames.map(name => `use ${projectName}::${schemaName}_${convertToSnakeCase(name)}::${name};`).join('\n')}
124
+ ${enumNames
125
+ .map(
126
+ name =>
127
+ `use ${projectName}::${schemaName}_${convertToSnakeCase(
128
+ name
129
+ )}::${name};`
130
+ )
131
+ .join('\n')}
101
132
 
102
133
  public struct ${item.name} has copy, drop , store {
103
134
  ${getStructAttrsWithType(item.fields)}
104
135
  }
105
136
 
106
- public fun new(${getStructAttrsWithType(item.fields)}): ${item.name} {
137
+ public fun new(${getStructAttrsWithType(
138
+ item.fields
139
+ )}): ${item.name} {
107
140
  ${item.name} {
108
141
  ${getStructAttrs(item.fields)}
109
142
  }
@@ -114,33 +147,57 @@ export async function generateSchemaData(projectName: string, schemas: Record<st
114
147
  ${renderSetAttrsFunc(item.name, item.fields)}
115
148
  ${renderSetFunc(item.name, item.fields)}
116
149
  }`;
117
- }
150
+ }
118
151
 
119
- await formatAndWriteMove(
120
- code,
121
- `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(item.name)}.move`,
122
- "formatAndWriteMove"
123
- );
124
- }
125
- }
126
- }
152
+ await formatAndWriteMove(
153
+ code,
154
+ `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(
155
+ item.name
156
+ )}.move`,
157
+ 'formatAndWriteMove'
158
+ );
159
+ }
160
+ }
161
+ }
162
+ console.log('āœ… Schema Data Generation Complete\n');
127
163
  }
128
164
 
129
- function generateImport(projectName: string, schemaName: string, schema: SchemaType) {
130
- if (schema.data) {
131
- return schema.data.map(item => {
132
- return `use ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}::${item.name};`
133
- }).join('\n');
134
- } else {
135
- return ""
136
- }
165
+ function generateImport(
166
+ projectName: string,
167
+ schemaName: string,
168
+ schema: SchemaType
169
+ ) {
170
+ if (schema.data) {
171
+ return schema.data
172
+ .map(item => {
173
+ return `use ${projectName}::${schemaName}_${convertToSnakeCase(
174
+ item.name
175
+ )}::${item.name};`;
176
+ })
177
+ .join('\n');
178
+ } else {
179
+ return '';
180
+ }
137
181
  }
138
182
 
139
- export async function generateSchemaStructure(projectName: string, schemas: Record<string, SchemaType>, path: string) {
140
- for (const schemaName in schemas) {
141
- console.log(`Schema: ${schemaName}`);
142
- const schema = schemas[schemaName];
143
- const schemaMoudle = `module ${projectName}::${schemaName}_schema {
183
+ export async function generateSchemaStructure(
184
+ projectName: string,
185
+ schemas: Record<string, SchemaType>,
186
+ path: string
187
+ ) {
188
+ console.log('\nšŸ”Ø Starting Schema Structure Generation...');
189
+ for (const schemaName in schemas) {
190
+ console.log(` ā”œā”€ Generating schema: ${schemaName}`);
191
+ console.log(
192
+ ` ā”œā”€ Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`
193
+ );
194
+ console.log(
195
+ ` └─ Structure fields: ${
196
+ Object.keys(schemas[schemaName].structure).length
197
+ }`
198
+ );
199
+ const schema = schemas[schemaName];
200
+ const schemaMoudle = `module ${projectName}::${schemaName}_schema {
144
201
  use std::ascii::String;
145
202
  use std::type_name;
146
203
  use obelisk::dapps_system;
@@ -151,51 +208,69 @@ export async function generateSchemaStructure(projectName: string, schemas: Reco
151
208
  use ${projectName}::dapp_key::DappKey;
152
209
  ${generateImport(projectName, schemaName, schema)}
153
210
 
154
- public struct ${capitalizeAndRemoveUnderscores(schemaName)} has key, store {
211
+ public struct ${capitalizeAndRemoveUnderscores(
212
+ schemaName
213
+ )} has key, store {
155
214
  id: UID,
156
215
  ${getStructAttrsWithType(schema.structure)}
157
216
  }
158
217
 
159
- ${Object.entries(schema.structure).map(([key, value]) => {
160
- return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : &${value} {
218
+ ${Object.entries(schema.structure)
219
+ .map(([key, value]) => {
220
+ return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
221
+ schemaName
222
+ )}) : &${value} {
161
223
  &self.${key}
162
224
  }
163
225
 
164
- public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(schemaName)}): &mut ${value} {
226
+ public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
227
+ schemaName
228
+ )}): &mut ${value} {
165
229
  &mut self.${key}
166
230
  }
167
- `
168
- }).join('')}
231
+ `;
232
+ })
233
+ .join('')}
169
234
 
170
- public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(schemaName)} {
235
+ public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
236
+ schemaName
237
+ )} {
171
238
  let package_id = dapps_system::current_package_id<DappKey>();
172
239
  assert!(dapps.borrow_metadata().contains_key(package_id), 0);
173
240
  assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
174
- let schema = type_name::get<${capitalizeAndRemoveUnderscores(schemaName)}>().into_string();
241
+ let schema = type_name::get<${capitalizeAndRemoveUnderscores(
242
+ schemaName
243
+ )}>().into_string();
175
244
  assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
176
- dapps_system::add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(dapps, package_id, ctx);
245
+ dapps_system::add_schema<${capitalizeAndRemoveUnderscores(
246
+ schemaName
247
+ )}>(dapps, package_id, ctx);
177
248
  ${capitalizeAndRemoveUnderscores(schemaName)} {
178
249
  id: object::new(ctx),
179
- ${Object.entries(schema.structure).map(([key, value]) => {
180
- let storage_type = ""
181
- if (value.includes("StorageValue")) {
182
- storage_type = `storage_value::new()`
183
- } else if (value.includes("StorageMap")) {
184
- storage_type = `storage_map::new()`
185
- } else if (value.includes("StorageDoubleMap")) {
186
- storage_type = `storage_double_map::new()`
187
- }
188
- return `${key}: ${storage_type},`
189
- }).join(' ')
190
- }
250
+ ${Object.entries(schema.structure)
251
+ .map(([key, value]) => {
252
+ let storage_type = '';
253
+ if (value.includes('StorageValue')) {
254
+ storage_type = `storage_value::new()`;
255
+ } else if (value.includes('StorageMap')) {
256
+ storage_type = `storage_map::new()`;
257
+ } else if (
258
+ value.includes('StorageDoubleMap')
259
+ ) {
260
+ storage_type = `storage_double_map::new()`;
261
+ }
262
+ return `${key}: ${storage_type},`;
263
+ })
264
+ .join(' ')}
191
265
  }
192
266
  }
193
267
 
194
268
  }`;
195
- await formatAndWriteMove(
196
- schemaMoudle,
197
- `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
198
- "formatAndWriteMove"
199
- );
200
- }
201
- }
269
+ await formatAndWriteMove(
270
+ schemaMoudle,
271
+ `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
272
+ 'formatAndWriteMove'
273
+ );
274
+ }
275
+ console.log('āœ… Schema Structure Generation Complete\n');
276
+ }
@@ -1,14 +1,22 @@
1
- import { ObeliskConfig } from "../../types";
2
- import { formatAndWriteMove } from "../formatAndWrite";
3
- import { existsSync } from "fs";
1
+ import { ObeliskConfig } from '../../types';
2
+ import { formatAndWriteMove } from '../formatAndWrite';
3
+ import { existsSync } from 'fs';
4
4
 
5
- export async function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {
6
- if (
7
- !existsSync(
8
- `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
9
- )
10
- ) {
11
- let code = `module ${config.name}::deploy_hook {
5
+ export async function generateDeployHook(
6
+ config: ObeliskConfig,
7
+ srcPrefix: string
8
+ ) {
9
+ console.log('\nšŸ“ Starting Deploy Hook Generation...');
10
+ console.log(
11
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
12
+ );
13
+
14
+ if (
15
+ !existsSync(
16
+ `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
17
+ )
18
+ ) {
19
+ let code = `module ${config.name}::deploy_hook {
12
20
  use obelisk::dapps_schema::Dapps;
13
21
  use obelisk::dapps_system;
14
22
  use ${config.name}::dapp_key::DappKey;
@@ -33,16 +41,20 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
33
41
  clock,
34
42
  ctx
35
43
  );
36
- ${Object.keys(config.schemas).map(schemaName => {
37
- return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`
38
- }).join("\n")}
44
+ ${Object.keys(config.schemas)
45
+ .map(schemaName => {
46
+ return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`;
47
+ })
48
+ .join('\n')}
39
49
  // Logic that needs to be automated once the contract is deployed
40
50
 
41
51
 
42
52
  // Share the dapp object with the public
43
- ${Object.keys(config.schemas).map(schemaName => {
44
- return `public_share_object(${schemaName});`
45
- }).join("\n")}
53
+ ${Object.keys(config.schemas)
54
+ .map(schemaName => {
55
+ return `public_share_object(${schemaName});`;
56
+ })
57
+ .join('\n')}
46
58
  }
47
59
 
48
60
  #[test_only]
@@ -63,21 +75,22 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
63
75
  }
64
76
  }
65
77
  `;
66
- await formatAndWriteMove(
67
- code,
68
- `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,
69
- "formatAndWriteMove"
70
- );
71
- }
78
+ await formatAndWriteMove(
79
+ code,
80
+ `${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,
81
+ 'formatAndWriteMove'
82
+ );
83
+ }
84
+ console.log('āœ… Deploy Hook Generation Complete\n');
72
85
  }
73
86
 
74
87
  export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
75
- if (
76
- !existsSync(
77
- `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`
78
- )
79
- ) {
80
- let code = `module ${config.name}::migrate {
88
+ if (
89
+ !existsSync(
90
+ `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`
91
+ )
92
+ ) {
93
+ let code = `module ${config.name}::migrate {
81
94
  use obelisk::world::{World, AdminCap};
82
95
 
83
96
  /// Not the right admin for this world
@@ -97,11 +110,10 @@ export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
97
110
  }
98
111
  }
99
112
  `;
100
- formatAndWriteMove(
101
- code,
102
- `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,
103
- "formatAndWriteMove"
104
- );
105
- }
113
+ formatAndWriteMove(
114
+ code,
115
+ `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,
116
+ 'formatAndWriteMove'
117
+ );
118
+ }
106
119
  }
107
-
@@ -1,23 +1,30 @@
1
- import { ObeliskConfig } from "../../types";
2
- import { formatAndWriteMove } from "../formatAndWrite";
3
- import { existsSync } from "fs";
1
+ import { ObeliskConfig } from '../../types';
2
+ import { formatAndWriteMove } from '../formatAndWrite';
3
+ import { existsSync } from 'fs';
4
4
 
5
5
  export async function generateSystem(config: ObeliskConfig, srcPrefix: string) {
6
- config.systems.map(async (systemName) => {
7
- if (
8
- !existsSync(
9
- `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
10
- )
11
- ) {
12
- let code = `module ${config.name}::${systemName}_system {
6
+ console.log('\nāš™ļø Starting System Generation...');
7
+ config.systems.map(async systemName => {
8
+ console.log(` ā”œā”€ Generating system: ${systemName}`);
9
+ console.log(
10
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
11
+ );
12
+
13
+ if (
14
+ !existsSync(
15
+ `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
16
+ )
17
+ ) {
18
+ let code = `module ${config.name}::${systemName}_system {
13
19
 
14
20
  }
15
21
  `;
16
- await formatAndWriteMove(
17
- code,
18
- `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
19
- "formatAndWriteMove"
20
- );
21
- }
22
- });
22
+ await formatAndWriteMove(
23
+ code,
24
+ `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
25
+ 'formatAndWriteMove'
26
+ );
27
+ }
28
+ });
29
+ console.log('āœ… System Generation Complete\n');
23
30
  }
@@ -1,7 +1,16 @@
1
1
  import { ObeliskConfig } from '../../types';
2
2
  import { formatAndWriteMove } from '../formatAndWrite';
3
3
 
4
- export async function generateToml(config: ObeliskConfig, srcPrefix: string) {
4
+ export async function generateToml(
5
+ config: ObeliskConfig,
6
+ srcPrefix: string,
7
+ frameworkId: string
8
+ ) {
9
+ console.log('\nšŸ“„ Starting Move.toml Generation...');
10
+ console.log(
11
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`
12
+ );
13
+
5
14
  let code = `[package]
6
15
  name = "${config.name}"
7
16
  version = "0.0.1"
@@ -12,8 +21,8 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
12
21
  Obelisk = { git = "https://github.com/0xobelisk/obelisk-engine.git", subdir = "packages/obelisk-framework", rev = "main" }
13
22
 
14
23
  [addresses]
15
- sui = "0x2"
16
- obelisk = "0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256"
24
+ sui = "0x2"
25
+ obelisk = "${frameworkId}"
17
26
  ${config.name} = "0x0"
18
27
  `;
19
28
  await formatAndWriteMove(
@@ -21,4 +30,5 @@ ${config.name} = "0x0"
21
30
  `${srcPrefix}/contracts/${config.name}/Move.toml`,
22
31
  'formatAndWriteMove'
23
32
  );
33
+ console.log('āœ… Move.toml Generation Complete\n');
24
34
  }
@@ -0,0 +1,69 @@
1
+ import { SchemaType, ObeliskConfig } from '../../types';
2
+ import { rmdirSync, existsSync } from 'fs';
3
+ import { deleteFolderRecursive } from './common';
4
+ import { generateSystem } from './generateSystem';
5
+ import { generateToml } from './generateToml';
6
+ import { generateSchemaData, generateSchemaStructure } from './generateSchema';
7
+ import { generateDeployHook, generateMigrate } from './generateScript';
8
+ import { generateDappKey } from './generateDappKey';
9
+
10
+ function matchFrameworkId(
11
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
12
+ ): string {
13
+ switch (network) {
14
+ case 'testnet':
15
+ return '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';
16
+ case 'localnet':
17
+ return '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';
18
+ default:
19
+ return '0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256';
20
+ }
21
+ }
22
+
23
+ export async function schemaGen(
24
+ config: ObeliskConfig,
25
+ srcPrefix?: string,
26
+ network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
27
+ frameworkId?: string
28
+ ) {
29
+ console.log('\nšŸš€ Starting Schema Generation Process...');
30
+ console.log('šŸ“‹ Project Configuration:');
31
+ console.log(` ā”œā”€ Name: ${config.name}`);
32
+ console.log(
33
+ ` ā”œā”€ Description: ${config.description || 'No description provided'}`
34
+ );
35
+ console.log(` ā”œā”€ Network: ${network || 'testnet'}`);
36
+ console.log(
37
+ ` └─ Framework ID: ${
38
+ frameworkId || matchFrameworkId(network ?? 'testnet')
39
+ }\n`
40
+ );
41
+
42
+ const path = srcPrefix ?? process.cwd();
43
+
44
+ frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');
45
+
46
+ if (existsSync(`${path}/contracts/${config.name}`)) {
47
+ deleteFolderRecursive(
48
+ `${path}/contracts/${config.name}/sources/codegen`
49
+ );
50
+ }
51
+
52
+ if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
53
+ await generateToml(config, path, frameworkId);
54
+ }
55
+
56
+ if (
57
+ !existsSync(
58
+ `${path}/contracts/${config.name}/sources/script/deploy_hook.move`
59
+ )
60
+ ) {
61
+ await generateDeployHook(config, path);
62
+ }
63
+
64
+ await generateSystem(config, path);
65
+ await generateSchemaData(config.name, config.schemas, path);
66
+ await generateSchemaStructure(config.name, config.schemas, path);
67
+ await generateDappKey(config, path);
68
+ console.log('āœ… Schema Generation Process Complete!\n');
69
+ }
@@ -1,34 +0,0 @@
1
- import { SchemaType, ObeliskConfig } from "../../types";
2
- import { rmdirSync, existsSync } from "fs";
3
- import { deleteFolderRecursive } from "./common";
4
- import { generateSystem } from "./generateSystem";
5
- import { generateToml } from "./generateToml";
6
- import {generateSchemaData, generateSchemaStructure} from "./generateSchema";
7
- import {generateDeployHook, generateMigrate} from "./generateScript";
8
- import {generateDappKey} from "./generateDappKey";
9
-
10
- export async function worldgen(config: ObeliskConfig, srcPrefix?: string) {
11
- let path = "";
12
- if (srcPrefix === undefined) {
13
- path = process.cwd();
14
- } else {
15
- path = srcPrefix;
16
- }
17
-
18
- if (existsSync(`${path}/contracts/${config.name}`)) {
19
- deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);
20
- }
21
-
22
- if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
23
- await generateToml(config, path);
24
- }
25
-
26
- if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {
27
- await generateDeployHook(config, path);
28
- }
29
-
30
- await generateSystem(config, path);
31
- await generateSchemaData(config.name, config.schemas, path);
32
- await generateSchemaStructure(config.name, config.schemas, path);
33
- await generateDappKey(config, path);
34
- }