@vira-ui/cli 1.0.2 → 1.1.0

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 +51 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -91,7 +91,7 @@ const program = new commander_1.Command();
91
91
  program
92
92
  .name("vira")
93
93
  .description("ViraJS CLI - Create projects and generate code")
94
- .version("1.0.1");
94
+ .version("1.1.0");
95
95
  const SUPPORTED_TEMPLATES = ["frontend", "fullstack", "kanban"];
96
96
  /**
97
97
  * Инициализация проекта в текущей директории
@@ -310,6 +310,16 @@ make
310
310
  await generateEventHandler(name, options.dir);
311
311
  console.log(chalk_1.default.green(`✓ event handler ${name} created in ${options.dir}`));
312
312
  });
313
+ make
314
+ .command("model")
315
+ .description("Create a Go model struct")
316
+ .argument("<name>", "Model name (e.g. Client)")
317
+ .option("-d, --dir <directory>", "Target directory", path.join("backend", "internal", "models"))
318
+ .option("-f, --fields <fields>", "Comma-separated field definitions (e.g. 'name:string,email:string,phone:string')")
319
+ .action(async (name, options) => {
320
+ await generateGoModel(name, options.dir, options.fields || undefined);
321
+ console.log(chalk_1.default.green(`✓ Go model ${name} created in ${options.dir}`));
322
+ });
313
323
  make
314
324
  .command("crud")
315
325
  .description("Create CRUD handlers for a resource")
@@ -1184,7 +1194,7 @@ export function ${name}Page() {
1184
1194
  /**
1185
1195
  * Генерация модели
1186
1196
  */
1187
- async function generateModel(name, dir) {
1197
+ async function generateModel(name, dir, fields) {
1188
1198
  const modelPath = path.join(process.cwd(), dir, "models", `${name}.ts`);
1189
1199
  await fs.ensureDir(path.dirname(modelPath));
1190
1200
  const modelCode = `import { defineModel } from '@vira-ui/core';
@@ -1521,21 +1531,42 @@ func ${handlerName}(w http.ResponseWriter, r *http.Request) {
1521
1531
  /**
1522
1532
  * Go model scaffold
1523
1533
  */
1524
- async function generateGoModel(name, dir) {
1534
+ async function generateGoModel(name, dir, fields) {
1525
1535
  const modelName = capitalize(name);
1526
1536
  const targetDir = path.join(process.cwd(), dir);
1527
1537
  await fs.ensureDir(targetDir);
1538
+ // Парсим поля если указаны
1539
+ let fieldsCode = "";
1540
+ if (fields) {
1541
+ const fieldList = fields.split(",").map(f => f.trim());
1542
+ fieldsCode = fieldList.map(field => {
1543
+ const [fieldName, fieldType] = field.split(":").map(s => s.trim());
1544
+ const goType = mapTypeScriptToGo(fieldType || "string");
1545
+ return ` ${capitalize(fieldName)} ${goType} \`db:"${fieldName.toLowerCase()}" json:"${fieldName.toLowerCase()}"\``;
1546
+ }).join("\n");
1547
+ // Добавляем стандартные поля если их нет
1548
+ if (!fieldList.some(f => f.toLowerCase().includes("id"))) {
1549
+ fieldsCode = ` ID string \`db:"id" json:"id"\`
1550
+ ${fieldsCode}
1551
+ CreatedAt time.Time \`db:"created_at" json:"created_at"\`
1552
+ UpdatedAt time.Time \`db:"updated_at" json:"updated_at"\``;
1553
+ }
1554
+ }
1555
+ else {
1556
+ // Дефолтные поля для типичной модели
1557
+ fieldsCode = ` ID string \`db:"id" json:"id"\`
1558
+ CreatedAt time.Time \`db:"created_at" json:"created_at"\`
1559
+ UpdatedAt time.Time \`db:"updated_at" json:"updated_at"\``;
1560
+ }
1528
1561
  const modelCode = `package models
1529
1562
 
1530
1563
  import "time"
1531
1564
 
1532
1565
  type ${modelName} struct {
1533
- ID string \`db:"id"\`
1534
- CreatedAt time.Time \`db:"created_at"\`
1535
- UpdatedAt time.Time \`db:"updated_at"\`
1566
+ ${fieldsCode}
1536
1567
  }
1537
1568
  `;
1538
- await fs.writeFile(path.join(targetDir, `${modelName}.go`), modelCode);
1569
+ await fs.writeFile(path.join(targetDir, `${modelName.toLowerCase()}.go`), modelCode);
1539
1570
  }
1540
1571
  /**
1541
1572
  * SQL migration scaffold (timestamped up/down)
@@ -1583,6 +1614,19 @@ function capitalize(value) {
1583
1614
  return value;
1584
1615
  return value.charAt(0).toUpperCase() + value.slice(1);
1585
1616
  }
1617
+ /**
1618
+ * Маппинг TypeScript типов в Go типы
1619
+ */
1620
+ function mapTypeScriptToGo(tsType) {
1621
+ const mapping = {
1622
+ "string": "string",
1623
+ "number": "int",
1624
+ "boolean": "bool",
1625
+ "Date": "time.Time",
1626
+ "date": "time.Time",
1627
+ };
1628
+ return mapping[tsType.toLowerCase()] || "string";
1629
+ }
1586
1630
  function toPascal(value) {
1587
1631
  return value
1588
1632
  .split(/[^a-zA-Z0-9]+/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vira-ui/cli",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "CLI tool for ViraJS project generation",
5
5
  "author": "Vira Team",
6
6
  "license": "MIT",