@moltium/world-cli 0.1.12 → 0.1.14

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.
Files changed (2) hide show
  1. package/dist/index.js +130 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38,6 +38,34 @@ function generateWorldConfig(options) {
38
38
  sqlite: {
39
39
  filename: "./data/world.db"
40
40
  }
41
+ },
42
+ ...options.persistenceType === "postgres" && options.dbConfig && {
43
+ postgres: {
44
+ host: options.dbConfig.host,
45
+ port: options.dbConfig.port,
46
+ database: options.dbConfig.database,
47
+ user: options.dbConfig.user,
48
+ password: options.dbConfig.password
49
+ }
50
+ },
51
+ ...options.persistenceType === "redis" && options.dbConfig && {
52
+ redis: {
53
+ host: options.dbConfig.host,
54
+ port: options.dbConfig.port,
55
+ ...options.dbConfig.password && { password: options.dbConfig.password },
56
+ db: options.dbConfig.db
57
+ }
58
+ },
59
+ ...options.persistenceType === "mongodb" && options.dbConfig && {
60
+ mongodb: {
61
+ url: options.dbConfig.url,
62
+ database: options.dbConfig.database
63
+ }
64
+ },
65
+ ...options.persistenceType === "leveldb" && options.dbConfig && {
66
+ leveldb: {
67
+ location: options.dbConfig.path || options.dbConfig.location || "./data/leveldb"
68
+ }
41
69
  }
42
70
  },
43
71
  blockchain: {
@@ -68,7 +96,7 @@ function generateTokenConfig(tokenConfig) {
68
96
  };
69
97
  }
70
98
  function generateEnvFile(options) {
71
- return `# Monad Network Configuration
99
+ let env = `# Monad Network Configuration
72
100
  MONAD_RPC_URL=https://rpc-testnet.monadinfra.com
73
101
 
74
102
  # Deployer Wallet
@@ -85,6 +113,36 @@ ${options.tokenType === "custom" ? "WORLD_TOKEN_ADDRESS=\n" : ""}
85
113
  # Optional: Monad Block Explorer API Key
86
114
  # MONAD_ETHERSCAN_KEY=
87
115
  `;
116
+ if (options.persistenceType === "postgres") {
117
+ env += `
118
+ # PostgreSQL Configuration
119
+ DB_HOST=${options.dbConfig?.host || "localhost"}
120
+ DB_PORT=${options.dbConfig?.port || "5432"}
121
+ DB_NAME=${options.dbConfig?.database || "moltium_world"}
122
+ DB_USER=${options.dbConfig?.user || "postgres"}
123
+ DB_PASSWORD=${options.dbConfig?.password || ""}
124
+ `;
125
+ } else if (options.persistenceType === "redis") {
126
+ env += `
127
+ # Redis Configuration
128
+ DB_HOST=${options.dbConfig?.host || "localhost"}
129
+ DB_PORT=${options.dbConfig?.port || "6379"}
130
+ DB_PASSWORD=${options.dbConfig?.password || ""}
131
+ DB_NAME=${options.dbConfig?.db || "0"}
132
+ `;
133
+ } else if (options.persistenceType === "mongodb") {
134
+ env += `
135
+ # MongoDB Configuration
136
+ DB_URL=${options.dbConfig?.url || "mongodb://localhost:27017"}
137
+ DB_NAME=${options.dbConfig?.database || "moltium_world"}
138
+ `;
139
+ } else if (options.persistenceType === "leveldb") {
140
+ env += `
141
+ # LevelDB Configuration
142
+ DB_PATH=${options.dbConfig?.path || "./data/leveldb"}
143
+ `;
144
+ }
145
+ return env;
88
146
  }
89
147
 
90
148
  // src/templates/world-template.ts
@@ -101,25 +159,37 @@ async function main() {
101
159
  // Load base configuration from JSON
102
160
  const config = JSON.parse(fs.readFileSync('./world.config.json', 'utf-8')) as WorldConfig;
103
161
 
104
- // Merge blockchain settings from environment variables
162
+ // Merge settings from environment variables
105
163
  if (config.blockchain) {
106
- if (process.env.MONAD_RPC_URL) {
107
- config.blockchain.rpcUrl = process.env.MONAD_RPC_URL;
108
- }
109
- if (process.env.DEPLOYER_PRIVATE_KEY) {
110
- config.blockchain.privateKey = process.env.DEPLOYER_PRIVATE_KEY;
111
- }
112
- if (process.env.ENTRY_FEE_MON) {
113
- config.blockchain.entryFee = parseFloat(process.env.ENTRY_FEE_MON);
114
- }
115
- if (process.env.AGENT_REGISTRY_ADDRESS) {
116
- config.blockchain.agentRegistryAddress = process.env.AGENT_REGISTRY_ADDRESS;
117
- }
118
- if (process.env.WORLD_MEMBERSHIP_ADDRESS) {
119
- config.blockchain.membershipContractAddress = process.env.WORLD_MEMBERSHIP_ADDRESS;
120
- }
121
- if (process.env.WORLD_TOKEN_ADDRESS) {
122
- config.blockchain.worldTokenAddress = process.env.WORLD_TOKEN_ADDRESS;
164
+ if (process.env.MONAD_RPC_URL) config.blockchain.rpcUrl = process.env.MONAD_RPC_URL;
165
+ if (process.env.DEPLOYER_PRIVATE_KEY) config.blockchain.privateKey = process.env.DEPLOYER_PRIVATE_KEY;
166
+ if (process.env.ENTRY_FEE_MON) config.blockchain.entryFee = parseFloat(process.env.ENTRY_FEE_MON);
167
+ if (process.env.AGENT_REGISTRY_ADDRESS) config.blockchain.agentRegistryAddress = process.env.AGENT_REGISTRY_ADDRESS;
168
+ if (process.env.WORLD_MEMBERSHIP_ADDRESS) config.blockchain.membershipContractAddress = process.env.WORLD_MEMBERSHIP_ADDRESS;
169
+ if (process.env.WORLD_TOKEN_ADDRESS) config.blockchain.worldTokenAddress = process.env.WORLD_TOKEN_ADDRESS;
170
+ }
171
+
172
+ if (config.persistence) {
173
+ if (config.persistence.type === 'postgres') {
174
+ if (!config.persistence.postgres) config.persistence.postgres = { host: 'localhost', port: 5432, database: 'moltium_world', user: 'postgres', password: '' };
175
+ if (process.env.DB_HOST) config.persistence.postgres.host = process.env.DB_HOST;
176
+ if (process.env.DB_PORT) config.persistence.postgres.port = parseInt(process.env.DB_PORT);
177
+ if (process.env.DB_NAME) config.persistence.postgres.database = process.env.DB_NAME;
178
+ if (process.env.DB_USER) config.persistence.postgres.user = process.env.DB_USER;
179
+ if (process.env.DB_PASSWORD) config.persistence.postgres.password = process.env.DB_PASSWORD;
180
+ } else if (config.persistence.type === 'redis') {
181
+ if (!config.persistence.redis) config.persistence.redis = { host: 'localhost', port: 6379 };
182
+ if (process.env.DB_HOST) config.persistence.redis.host = process.env.DB_HOST;
183
+ if (process.env.DB_PORT) config.persistence.redis.port = parseInt(process.env.DB_PORT);
184
+ if (process.env.DB_PASSWORD) config.persistence.redis.password = process.env.DB_PASSWORD;
185
+ if (process.env.DB_NAME) config.persistence.redis.db = parseInt(process.env.DB_NAME);
186
+ } else if (config.persistence.type === 'mongodb') {
187
+ if (!config.persistence.mongodb) config.persistence.mongodb = { url: 'mongodb://localhost:27017', database: 'moltium_world' };
188
+ if (process.env.DB_URL) config.persistence.mongodb.url = process.env.DB_URL;
189
+ if (process.env.DB_NAME) config.persistence.mongodb.database = process.env.DB_NAME;
190
+ } else if (config.persistence.type === 'leveldb') {
191
+ if (!config.persistence.leveldb) config.persistence.leveldb = { location: './data/leveldb' };
192
+ if (process.env.DB_PATH) config.persistence.leveldb.location = process.env.DB_PATH;
123
193
  }
124
194
  }
125
195
 
@@ -352,12 +422,42 @@ var initCommand = new Command("init").description("Initialize a new world projec
352
422
  { name: "Memory - In-memory only (development)", value: "memory" },
353
423
  { name: "PostgreSQL - Production-grade SQL", value: "postgres" },
354
424
  { name: "Redis - High-speed in-memory", value: "redis" },
355
- { name: "MongoDB - Document database", value: "mongo" },
425
+ { name: "MongoDB - Document database", value: "mongodb" },
356
426
  { name: "LevelDB - Embedded key-value", value: "leveldb" }
357
427
  ],
358
428
  default: "sqlite"
359
429
  }
360
430
  ]);
431
+ let dbConfig = {};
432
+ if (persistenceAnswers.persistenceType === "postgres") {
433
+ dbConfig = await inquirer.prompt([
434
+ { type: "input", name: "host", message: "PostgreSQL host:", default: "localhost" },
435
+ { type: "input", name: "port", message: "PostgreSQL port:", default: "5432", validate: (v) => !isNaN(Number(v)) || "Must be a number" },
436
+ { type: "input", name: "database", message: "Database name:", default: "moltium_world" },
437
+ { type: "input", name: "user", message: "Database user:", default: "postgres" },
438
+ { type: "password", name: "password", message: "Database password:", mask: "*" }
439
+ ]);
440
+ dbConfig.port = parseInt(dbConfig.port);
441
+ } else if (persistenceAnswers.persistenceType === "redis") {
442
+ dbConfig = await inquirer.prompt([
443
+ { type: "input", name: "host", message: "Redis host:", default: "localhost" },
444
+ { type: "input", name: "port", message: "Redis port:", default: "6379", validate: (v) => !isNaN(Number(v)) || "Must be a number" },
445
+ { type: "password", name: "password", message: "Redis password (leave empty if none):", mask: "*", default: "" },
446
+ { type: "input", name: "db", message: "Redis database number:", default: "0", validate: (v) => !isNaN(Number(v)) || "Must be a number" }
447
+ ]);
448
+ dbConfig.port = parseInt(dbConfig.port);
449
+ dbConfig.db = parseInt(dbConfig.db);
450
+ if (!dbConfig.password) delete dbConfig.password;
451
+ } else if (persistenceAnswers.persistenceType === "mongodb") {
452
+ dbConfig = await inquirer.prompt([
453
+ { type: "input", name: "url", message: "MongoDB connection URL:", default: "mongodb://localhost:27017" },
454
+ { type: "input", name: "database", message: "Database name:", default: "moltium_world" }
455
+ ]);
456
+ } else if (persistenceAnswers.persistenceType === "leveldb") {
457
+ dbConfig = await inquirer.prompt([
458
+ { type: "input", name: "path", message: "LevelDB data path:", default: "./data/leveldb" }
459
+ ]);
460
+ }
361
461
  const entryFeeAnswers = await inquirer.prompt([
362
462
  {
363
463
  type: "input",
@@ -376,7 +476,8 @@ var initCommand = new Command("init").description("Initialize a new world projec
376
476
  const worldConfig = generateWorldConfig({
377
477
  ...answers,
378
478
  ...persistenceAnswers,
379
- ...entryFeeAnswers
479
+ ...entryFeeAnswers,
480
+ dbConfig
380
481
  });
381
482
  await fs.writeFile(
382
483
  path.join(projectDir, "world.config.json"),
@@ -389,7 +490,11 @@ var initCommand = new Command("init").description("Initialize a new world projec
389
490
  JSON.stringify(tokenConfigContent, null, 2)
390
491
  );
391
492
  }
392
- const envContent = generateEnvFile({ tokenType: answers.tokenType });
493
+ const envContent = generateEnvFile({
494
+ tokenType: answers.tokenType,
495
+ persistenceType: persistenceAnswers.persistenceType,
496
+ dbConfig
497
+ });
393
498
  await fs.writeFile(path.join(projectDir, ".env"), envContent);
394
499
  await fs.writeFile(
395
500
  path.join(projectDir, ".gitignore"),
@@ -417,12 +522,12 @@ var initCommand = new Command("init").description("Initialize a new world projec
417
522
  "deploy:contracts": "moltium-world deploy"
418
523
  },
419
524
  dependencies: {
420
- "@moltium/world-core": "^0.1.12",
525
+ "@moltium/world-core": "^0.1.14",
421
526
  dotenv: "^16.4.0",
422
527
  ...persistenceAnswers.persistenceType === "sqlite" ? { "better-sqlite3": "^11.0.0" } : {},
423
528
  ...persistenceAnswers.persistenceType === "redis" ? { "ioredis": "^5.3.0" } : {},
424
529
  ...persistenceAnswers.persistenceType === "postgres" ? { "pg": "^8.12.0" } : {},
425
- ...persistenceAnswers.persistenceType === "mongo" ? { "mongodb": "^6.3.0" } : {},
530
+ ...persistenceAnswers.persistenceType === "mongodb" ? { "mongodb": "^6.3.0" } : {},
426
531
  ...persistenceAnswers.persistenceType === "leveldb" ? { "level": "^8.0.0" } : {}
427
532
  },
428
533
  devDependencies: {
@@ -836,7 +941,7 @@ var deployCommand = new Command4("deploy").description("Deploy smart contracts t
836
941
 
837
942
  // src/index.ts
838
943
  var program = new Command5();
839
- program.name("moltium-world").description("CLI tool for creating and managing Moltium World SDK projects").version("0.1.12");
944
+ program.name("moltium-world").description("CLI tool for creating and managing Moltium World SDK projects").version("0.1.14");
840
945
  program.addCommand(initCommand);
841
946
  program.addCommand(tokenCommand);
842
947
  program.addCommand(startCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltium/world-cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "CLI tool for creating and managing Moltium World SDK projects",
5
5
  "license": "MIT",
6
6
  "keywords": [