@kosdev-code/kos-ui-cli 2.0.45 → 2.0.46

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.
@@ -1,150 +0,0 @@
1
- // utils/dev-config.mjs
2
- import { existsSync, readFileSync } from "fs";
3
- import path from "path";
4
-
5
- /**
6
- * Read the development configuration from root .kos.json
7
- *
8
- * @returns {Object|null} Development config or null if not found
9
- */
10
- export function getDevConfig() {
11
- const workspaceRoot = process.cwd();
12
- const kosJsonPath = path.join(workspaceRoot, '.kos.json');
13
-
14
- if (!existsSync(kosJsonPath)) {
15
- return null;
16
- }
17
-
18
- try {
19
- const content = readFileSync(kosJsonPath, 'utf-8');
20
- const config = JSON.parse(content);
21
-
22
- if (config.type !== 'root') {
23
- return null;
24
- }
25
-
26
- if (!config.development || !config.development.hosts) {
27
- return null;
28
- }
29
-
30
- return config.development;
31
- } catch (error) {
32
- console.error(`[kos-cli] Error reading .kos.json: ${error.message}`);
33
- return null;
34
- }
35
- }
36
-
37
- /**
38
- * Find a host configuration by name
39
- *
40
- * @param {string} hostName - Name of the host to find
41
- * @returns {Object|null} Host config or null if not found
42
- */
43
- export function getHost(hostName) {
44
- const devConfig = getDevConfig();
45
-
46
- if (!devConfig) {
47
- return null;
48
- }
49
-
50
- return devConfig.hosts.find(h => h.name === hostName) || null;
51
- }
52
-
53
- /**
54
- * Get all available hosts
55
- *
56
- * @returns {Array} Array of host configurations
57
- */
58
- export function getAllHosts() {
59
- const devConfig = getDevConfig();
60
-
61
- if (!devConfig) {
62
- return [];
63
- }
64
-
65
- return devConfig.hosts || [];
66
- }
67
-
68
- /**
69
- * Filter plugins based on options
70
- *
71
- * @param {Array} hostPlugins - Array of plugin configs from host
72
- * @param {Object} options - Filter options
73
- * @param {Array} options.plugins - Specific plugin aliases to include
74
- * @param {Array} options.disable - Plugin aliases to exclude
75
- * @returns {Array} Filtered array of plugin configurations
76
- */
77
- export function filterPlugins(hostPlugins, options = {}) {
78
- let plugins = hostPlugins.filter(p => p.enabled);
79
-
80
- // If specific plugins requested, override enabled flag
81
- if (options.plugins && options.plugins.length > 0) {
82
- plugins = hostPlugins.filter(p => options.plugins.includes(p.alias));
83
- }
84
-
85
- // Apply disable list
86
- if (options.disable && options.disable.length > 0) {
87
- plugins = plugins.filter(p => !options.disable.includes(p.alias));
88
- }
89
-
90
- return plugins;
91
- }
92
-
93
- /**
94
- * Check if a project exists in the workspace
95
- *
96
- * @param {string} projectName - Name of the project
97
- * @returns {boolean} True if project exists
98
- */
99
- export function checkProjectExists(projectName) {
100
- const workspaceRoot = process.cwd();
101
-
102
- // Check common project locations
103
- const appPath = path.join(workspaceRoot, 'apps', projectName, 'project.json');
104
- const libPath = path.join(workspaceRoot, 'libs', projectName, 'project.json');
105
- const pluginPath = path.join(workspaceRoot, 'plugins', projectName, 'project.json');
106
- const packagesPath = path.join(workspaceRoot, 'packages', projectName, 'project.json');
107
-
108
- return existsSync(appPath) ||
109
- existsSync(libPath) ||
110
- existsSync(pluginPath) ||
111
- existsSync(packagesPath);
112
- }
113
-
114
- /**
115
- * Validate development configuration
116
- *
117
- * @returns {Object} Validation result with isValid and errors
118
- */
119
- export function validateDevConfig() {
120
- const devConfig = getDevConfig();
121
- const errors = [];
122
-
123
- if (!devConfig) {
124
- errors.push('.kos.json missing or does not contain development configuration');
125
- return { isValid: false, errors };
126
- }
127
-
128
- if (!Array.isArray(devConfig.hosts) || devConfig.hosts.length === 0) {
129
- errors.push('No hosts defined in development configuration');
130
- return { isValid: false, errors };
131
- }
132
-
133
- // Validate each host
134
- devConfig.hosts.forEach((host, idx) => {
135
- if (!host.name) {
136
- errors.push(`Host at index ${idx} missing required 'name' field`);
137
- }
138
- if (!host.project) {
139
- errors.push(`Host at index ${idx} missing required 'project' field`);
140
- }
141
- if (!host.port) {
142
- errors.push(`Host at index ${idx} missing required 'port' field`);
143
- }
144
- if (!Array.isArray(host.plugins)) {
145
- errors.push(`Host '${host.name}' missing 'plugins' array`);
146
- }
147
- });
148
-
149
- return { isValid: errors.length === 0, errors };
150
- }