@vira-ui/cli 1.1.0 → 1.1.1
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 +25 -17
- 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.1.
|
|
94
|
+
.version("1.1.1");
|
|
95
95
|
const SUPPORTED_TEMPLATES = ["frontend", "fullstack", "kanban"];
|
|
96
96
|
/**
|
|
97
97
|
* Инициализация проекта в текущей директории
|
|
@@ -283,15 +283,6 @@ make
|
|
|
283
283
|
await generateGoHandler(name, options.dir);
|
|
284
284
|
console.log(chalk_1.default.green(`✓ handler ${name} created in ${options.dir}`));
|
|
285
285
|
});
|
|
286
|
-
make
|
|
287
|
-
.command("model")
|
|
288
|
-
.description("Create Go model struct")
|
|
289
|
-
.argument("<name>", "Model name (e.g. User)")
|
|
290
|
-
.option("-d, --dir <directory>", "Target directory", path.join("backend", "internal", "models"))
|
|
291
|
-
.action(async (name, options) => {
|
|
292
|
-
await generateGoModel(name, options.dir);
|
|
293
|
-
console.log(chalk_1.default.green(`✓ model ${name} created in ${options.dir}`));
|
|
294
|
-
});
|
|
295
286
|
make
|
|
296
287
|
.command("migration")
|
|
297
288
|
.description("Create SQL migration (up/down)")
|
|
@@ -1643,6 +1634,21 @@ async function generateCRUDHandler(name, dir, modelName) {
|
|
|
1643
1634
|
const model = modelName || capitalize(name);
|
|
1644
1635
|
const targetDir = path.join(process.cwd(), dir);
|
|
1645
1636
|
await fs.ensureDir(targetDir);
|
|
1637
|
+
// Попытка определить модуль из go.mod
|
|
1638
|
+
let modulePath = "your-project/backend";
|
|
1639
|
+
try {
|
|
1640
|
+
const goModPath = path.join(process.cwd(), dir, "..", "..", "go.mod");
|
|
1641
|
+
if (await fs.pathExists(goModPath)) {
|
|
1642
|
+
const goModContent = await fs.readFile(goModPath, "utf8");
|
|
1643
|
+
const moduleMatch = goModContent.match(/^module\\s+(.+)$/m);
|
|
1644
|
+
if (moduleMatch) {
|
|
1645
|
+
modulePath = moduleMatch[1];
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
catch (e) {
|
|
1650
|
+
// Игнорируем ошибки, используем дефолтный путь
|
|
1651
|
+
}
|
|
1646
1652
|
const handlerCode = `package handlers
|
|
1647
1653
|
|
|
1648
1654
|
import (
|
|
@@ -1653,6 +1659,8 @@ import (
|
|
|
1653
1659
|
"github.com/gorilla/mux"
|
|
1654
1660
|
"github.com/go-playground/validator/v10"
|
|
1655
1661
|
"github.com/google/uuid"
|
|
1662
|
+
|
|
1663
|
+
"${modulePath}/internal/models"
|
|
1656
1664
|
)
|
|
1657
1665
|
|
|
1658
1666
|
var validate = validator.New()
|
|
@@ -1666,7 +1674,7 @@ type PaginationParams struct {
|
|
|
1666
1674
|
|
|
1667
1675
|
// 🎯 Production-ready: List response with pagination
|
|
1668
1676
|
type ${handlerName}ListResponse struct {
|
|
1669
|
-
Items []
|
|
1677
|
+
Items []models.${model} \`json:"items"\`
|
|
1670
1678
|
Total int \`json:"total"\`
|
|
1671
1679
|
Limit int \`json:"limit"\`
|
|
1672
1680
|
Offset int \`json:"offset"\`
|
|
@@ -1679,8 +1687,8 @@ type ${handlerName}Event struct {
|
|
|
1679
1687
|
Type string \`json:"type"\` // created, updated, deleted
|
|
1680
1688
|
EntityID string \`json:"entity_id"\`
|
|
1681
1689
|
UserID string \`json:"user_id,omitempty"\`
|
|
1682
|
-
OldValue
|
|
1683
|
-
NewValue
|
|
1690
|
+
OldValue *models.${model} \`json:"old_value,omitempty"\`
|
|
1691
|
+
NewValue *models.${model} \`json:"new_value,omitempty"\`
|
|
1684
1692
|
Timestamp time.Time \`json:"timestamp"\`
|
|
1685
1693
|
}
|
|
1686
1694
|
|
|
@@ -1729,7 +1737,7 @@ func List${handlerName}(w http.ResponseWriter, r *http.Request) {
|
|
|
1729
1737
|
// }
|
|
1730
1738
|
|
|
1731
1739
|
response := ${handlerName}ListResponse{
|
|
1732
|
-
Items: []
|
|
1740
|
+
Items: []models.${model}{},
|
|
1733
1741
|
Total: 0,
|
|
1734
1742
|
Limit: limit,
|
|
1735
1743
|
Offset: offset,
|
|
@@ -1763,7 +1771,7 @@ func Get${handlerName}(w http.ResponseWriter, r *http.Request) {
|
|
|
1763
1771
|
// return
|
|
1764
1772
|
// }
|
|
1765
1773
|
|
|
1766
|
-
item :=
|
|
1774
|
+
item := models.${model}{ID: id}
|
|
1767
1775
|
|
|
1768
1776
|
// 🎯 Production-ready: Cache detail (TTL 5min)
|
|
1769
1777
|
// redis.Set(cacheKey, item, 5*time.Minute)
|
|
@@ -1773,7 +1781,7 @@ func Get${handlerName}(w http.ResponseWriter, r *http.Request) {
|
|
|
1773
1781
|
|
|
1774
1782
|
// Create${handlerName} handles POST /${safeName}
|
|
1775
1783
|
func Create${handlerName}(w http.ResponseWriter, r *http.Request) {
|
|
1776
|
-
var input
|
|
1784
|
+
var input models.${model}
|
|
1777
1785
|
|
|
1778
1786
|
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
|
1779
1787
|
http.Error(w, "Invalid JSON", http.StatusBadRequest)
|
|
@@ -1831,7 +1839,7 @@ func Update${handlerName}(w http.ResponseWriter, r *http.Request) {
|
|
|
1831
1839
|
vars := mux.Vars(r)
|
|
1832
1840
|
id := vars["id"]
|
|
1833
1841
|
|
|
1834
|
-
var input
|
|
1842
|
+
var input models.${model}
|
|
1835
1843
|
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
|
1836
1844
|
http.Error(w, "Invalid JSON", http.StatusBadRequest)
|
|
1837
1845
|
return
|