@moltium/world-cli 0.1.12 → 0.1.13
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.js +118 -24
- 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
|
+
path: options.dbConfig.path
|
|
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
|
-
|
|
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,31 @@ ${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
|
+
}
|
|
140
|
+
return env;
|
|
88
141
|
}
|
|
89
142
|
|
|
90
143
|
// src/templates/world-template.ts
|
|
@@ -101,25 +154,31 @@ async function main() {
|
|
|
101
154
|
// Load base configuration from JSON
|
|
102
155
|
const config = JSON.parse(fs.readFileSync('./world.config.json', 'utf-8')) as WorldConfig;
|
|
103
156
|
|
|
104
|
-
// Merge
|
|
157
|
+
// Merge settings from environment variables
|
|
105
158
|
if (config.blockchain) {
|
|
106
|
-
if (process.env.MONAD_RPC_URL)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (process.env.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
config.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
config.
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
config.
|
|
159
|
+
if (process.env.MONAD_RPC_URL) config.blockchain.rpcUrl = process.env.MONAD_RPC_URL;
|
|
160
|
+
if (process.env.DEPLOYER_PRIVATE_KEY) config.blockchain.privateKey = process.env.DEPLOYER_PRIVATE_KEY;
|
|
161
|
+
if (process.env.ENTRY_FEE_MON) config.blockchain.entryFee = parseFloat(process.env.ENTRY_FEE_MON);
|
|
162
|
+
if (process.env.AGENT_REGISTRY_ADDRESS) config.blockchain.agentRegistryAddress = process.env.AGENT_REGISTRY_ADDRESS;
|
|
163
|
+
if (process.env.WORLD_MEMBERSHIP_ADDRESS) config.blockchain.membershipContractAddress = process.env.WORLD_MEMBERSHIP_ADDRESS;
|
|
164
|
+
if (process.env.WORLD_TOKEN_ADDRESS) config.blockchain.worldTokenAddress = process.env.WORLD_TOKEN_ADDRESS;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (config.persistence) {
|
|
168
|
+
if (config.persistence.type === 'postgres' && config.persistence.postgres) {
|
|
169
|
+
if (process.env.DB_HOST) config.persistence.postgres.host = process.env.DB_HOST;
|
|
170
|
+
if (process.env.DB_PORT) config.persistence.postgres.port = parseInt(process.env.DB_PORT);
|
|
171
|
+
if (process.env.DB_NAME) config.persistence.postgres.database = process.env.DB_NAME;
|
|
172
|
+
if (process.env.DB_USER) config.persistence.postgres.user = process.env.DB_USER;
|
|
173
|
+
if (process.env.DB_PASSWORD) config.persistence.postgres.password = process.env.DB_PASSWORD;
|
|
174
|
+
} else if (config.persistence.type === 'redis' && config.persistence.redis) {
|
|
175
|
+
if (process.env.DB_HOST) config.persistence.redis.host = process.env.DB_HOST;
|
|
176
|
+
if (process.env.DB_PORT) config.persistence.redis.port = parseInt(process.env.DB_PORT);
|
|
177
|
+
if (process.env.DB_PASSWORD) config.persistence.redis.password = process.env.DB_PASSWORD;
|
|
178
|
+
if (process.env.DB_NAME) config.persistence.redis.db = parseInt(process.env.DB_NAME);
|
|
179
|
+
} else if (config.persistence.type === 'mongodb' && config.persistence.mongodb) {
|
|
180
|
+
if (process.env.DB_URL) config.persistence.mongodb.url = process.env.DB_URL;
|
|
181
|
+
if (process.env.DB_NAME) config.persistence.mongodb.database = process.env.DB_NAME;
|
|
123
182
|
}
|
|
124
183
|
}
|
|
125
184
|
|
|
@@ -352,12 +411,42 @@ var initCommand = new Command("init").description("Initialize a new world projec
|
|
|
352
411
|
{ name: "Memory - In-memory only (development)", value: "memory" },
|
|
353
412
|
{ name: "PostgreSQL - Production-grade SQL", value: "postgres" },
|
|
354
413
|
{ name: "Redis - High-speed in-memory", value: "redis" },
|
|
355
|
-
{ name: "MongoDB - Document database", value: "
|
|
414
|
+
{ name: "MongoDB - Document database", value: "mongodb" },
|
|
356
415
|
{ name: "LevelDB - Embedded key-value", value: "leveldb" }
|
|
357
416
|
],
|
|
358
417
|
default: "sqlite"
|
|
359
418
|
}
|
|
360
419
|
]);
|
|
420
|
+
let dbConfig = {};
|
|
421
|
+
if (persistenceAnswers.persistenceType === "postgres") {
|
|
422
|
+
dbConfig = await inquirer.prompt([
|
|
423
|
+
{ type: "input", name: "host", message: "PostgreSQL host:", default: "localhost" },
|
|
424
|
+
{ type: "input", name: "port", message: "PostgreSQL port:", default: "5432", validate: (v) => !isNaN(Number(v)) || "Must be a number" },
|
|
425
|
+
{ type: "input", name: "database", message: "Database name:", default: "moltium_world" },
|
|
426
|
+
{ type: "input", name: "user", message: "Database user:", default: "postgres" },
|
|
427
|
+
{ type: "password", name: "password", message: "Database password:", mask: "*" }
|
|
428
|
+
]);
|
|
429
|
+
dbConfig.port = parseInt(dbConfig.port);
|
|
430
|
+
} else if (persistenceAnswers.persistenceType === "redis") {
|
|
431
|
+
dbConfig = await inquirer.prompt([
|
|
432
|
+
{ type: "input", name: "host", message: "Redis host:", default: "localhost" },
|
|
433
|
+
{ type: "input", name: "port", message: "Redis port:", default: "6379", validate: (v) => !isNaN(Number(v)) || "Must be a number" },
|
|
434
|
+
{ type: "password", name: "password", message: "Redis password (leave empty if none):", mask: "*", default: "" },
|
|
435
|
+
{ type: "input", name: "db", message: "Redis database number:", default: "0", validate: (v) => !isNaN(Number(v)) || "Must be a number" }
|
|
436
|
+
]);
|
|
437
|
+
dbConfig.port = parseInt(dbConfig.port);
|
|
438
|
+
dbConfig.db = parseInt(dbConfig.db);
|
|
439
|
+
if (!dbConfig.password) delete dbConfig.password;
|
|
440
|
+
} else if (persistenceAnswers.persistenceType === "mongodb") {
|
|
441
|
+
dbConfig = await inquirer.prompt([
|
|
442
|
+
{ type: "input", name: "url", message: "MongoDB connection URL:", default: "mongodb://localhost:27017" },
|
|
443
|
+
{ type: "input", name: "database", message: "Database name:", default: "moltium_world" }
|
|
444
|
+
]);
|
|
445
|
+
} else if (persistenceAnswers.persistenceType === "leveldb") {
|
|
446
|
+
dbConfig = await inquirer.prompt([
|
|
447
|
+
{ type: "input", name: "path", message: "LevelDB data path:", default: "./data/leveldb" }
|
|
448
|
+
]);
|
|
449
|
+
}
|
|
361
450
|
const entryFeeAnswers = await inquirer.prompt([
|
|
362
451
|
{
|
|
363
452
|
type: "input",
|
|
@@ -376,7 +465,8 @@ var initCommand = new Command("init").description("Initialize a new world projec
|
|
|
376
465
|
const worldConfig = generateWorldConfig({
|
|
377
466
|
...answers,
|
|
378
467
|
...persistenceAnswers,
|
|
379
|
-
...entryFeeAnswers
|
|
468
|
+
...entryFeeAnswers,
|
|
469
|
+
dbConfig
|
|
380
470
|
});
|
|
381
471
|
await fs.writeFile(
|
|
382
472
|
path.join(projectDir, "world.config.json"),
|
|
@@ -389,7 +479,11 @@ var initCommand = new Command("init").description("Initialize a new world projec
|
|
|
389
479
|
JSON.stringify(tokenConfigContent, null, 2)
|
|
390
480
|
);
|
|
391
481
|
}
|
|
392
|
-
const envContent = generateEnvFile({
|
|
482
|
+
const envContent = generateEnvFile({
|
|
483
|
+
tokenType: answers.tokenType,
|
|
484
|
+
persistenceType: persistenceAnswers.persistenceType,
|
|
485
|
+
dbConfig
|
|
486
|
+
});
|
|
393
487
|
await fs.writeFile(path.join(projectDir, ".env"), envContent);
|
|
394
488
|
await fs.writeFile(
|
|
395
489
|
path.join(projectDir, ".gitignore"),
|
|
@@ -417,7 +511,7 @@ var initCommand = new Command("init").description("Initialize a new world projec
|
|
|
417
511
|
"deploy:contracts": "moltium-world deploy"
|
|
418
512
|
},
|
|
419
513
|
dependencies: {
|
|
420
|
-
"@moltium/world-core": "^0.1.
|
|
514
|
+
"@moltium/world-core": "^0.1.13",
|
|
421
515
|
dotenv: "^16.4.0",
|
|
422
516
|
...persistenceAnswers.persistenceType === "sqlite" ? { "better-sqlite3": "^11.0.0" } : {},
|
|
423
517
|
...persistenceAnswers.persistenceType === "redis" ? { "ioredis": "^5.3.0" } : {},
|
|
@@ -836,7 +930,7 @@ var deployCommand = new Command4("deploy").description("Deploy smart contracts t
|
|
|
836
930
|
|
|
837
931
|
// src/index.ts
|
|
838
932
|
var program = new Command5();
|
|
839
|
-
program.name("moltium-world").description("CLI tool for creating and managing Moltium World SDK projects").version("0.1.
|
|
933
|
+
program.name("moltium-world").description("CLI tool for creating and managing Moltium World SDK projects").version("0.1.13");
|
|
840
934
|
program.addCommand(initCommand);
|
|
841
935
|
program.addCommand(tokenCommand);
|
|
842
936
|
program.addCommand(startCommand);
|