slicejs-cli 4.5.0 â 4.6.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.
- package/client.js +162 -83
- package/commands/Print.js +158 -164
- package/commands/build/build.js +27 -1
- package/commands/buildProduction/buildProduction.js +42 -71
- package/commands/bundle/bundle.js +65 -60
- package/commands/docs/agents.js +260 -0
- package/commands/docs/events.js +365 -0
- package/commands/docs/index.js +123 -0
- package/commands/doctor/doctor.js +43 -9
- package/commands/export/checkExport.js +163 -0
- package/commands/export/clientRedirects.js +72 -0
- package/commands/export/copyDist.js +180 -0
- package/commands/export/export.js +236 -0
- package/commands/export/files.js +33 -0
- package/commands/export/hosts/cloudflare.js +48 -0
- package/commands/export/hosts/github.js +31 -0
- package/commands/export/hosts/index.js +69 -0
- package/commands/export/hosts/netlify.js +42 -0
- package/commands/export/hosts/nginx.js +73 -0
- package/commands/export/hosts/none.js +23 -0
- package/commands/export/hosts/s3.js +24 -0
- package/commands/export/hosts/shared.js +62 -0
- package/commands/export/hosts/vercel.js +69 -0
- package/commands/export/outDir.js +91 -0
- package/commands/export/prerender.js +121 -0
- package/commands/getComponent/getComponent.js +39 -34
- package/commands/init/init.js +32 -22
- package/commands/lint/lint.js +2 -2
- package/commands/lint/types.js +1 -1
- package/commands/listComponents/listComponents.js +205 -172
- package/commands/seo/check.js +1 -1
- package/commands/seo/images.js +1 -1
- package/commands/seo/sitemap.js +1 -1
- package/commands/setup/lint.js +1 -1
- package/commands/skill/skill.js +2 -2
- package/commands/startServer/startServer.js +60 -21
- package/commands/startServer/watchServer.js +3 -3
- package/commands/translator/check.js +1 -1
- package/commands/translator/init.js +1 -1
- package/commands/typecheck/typecheck.js +2 -2
- package/commands/types/types.js +22 -3
- package/commands/utils/VersionChecker.js +14 -14
- package/commands/utils/bundling/BundleGenerator.js +45 -27
- package/commands/utils/bundling/DependencyAnalyzer.js +38 -17
- package/commands/utils/componentCatalog.js +120 -0
- package/commands/utils/publicEnv.js +74 -0
- package/commands/utils/updateManager.js +12 -12
- package/package.json +22 -23
|
@@ -1,172 +1,205 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import Print from '../Print.js';
|
|
5
|
+
import { getSrcPath, getComponentsJsPath, getConfigPath } from '../utils/PathHelper.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Loads configuration from sliceConfig.json
|
|
9
|
+
* @returns {object|null}
|
|
10
|
+
*/
|
|
11
|
+
const loadConfig = () => {
|
|
12
|
+
try {
|
|
13
|
+
const configPath = getConfigPath(import.meta.url);
|
|
14
|
+
if (!fs.existsSync(configPath)) {
|
|
15
|
+
Print.error('sliceConfig.json not found');
|
|
16
|
+
Print.info('Run "slice init" to initialize your project');
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
20
|
+
} catch (error) {
|
|
21
|
+
Print.error(`Failed to load configuration: ${error.message}`);
|
|
22
|
+
Print.info('Check that sliceConfig.json is valid JSON');
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const listDirectories = (folderPath) => {
|
|
28
|
+
try {
|
|
29
|
+
if (!fs.existsSync(folderPath)) return [];
|
|
30
|
+
return fs.readdirSync(folderPath);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
Print.error(`Failed to read directory ${folderPath}: ${error.message}`);
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const countFiles = (componentPath) => {
|
|
38
|
+
try {
|
|
39
|
+
if (!fs.existsSync(componentPath)) return 0;
|
|
40
|
+
return fs.readdirSync(componentPath).filter((file) =>
|
|
41
|
+
fs.statSync(path.join(componentPath, file)).isFile()
|
|
42
|
+
).length;
|
|
43
|
+
} catch {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Scans sliceConfig.paths.components and returns the live component catalog.
|
|
50
|
+
* @returns {Record<string, {category: string, files: number}>}
|
|
51
|
+
*/
|
|
52
|
+
const getComponents = () => {
|
|
53
|
+
const config = loadConfig();
|
|
54
|
+
if (!config) return {};
|
|
55
|
+
|
|
56
|
+
const components = new Map();
|
|
57
|
+
for (const [category, meta] of Object.entries(config.paths?.components || {})) {
|
|
58
|
+
const cleanPath = meta?.path ? meta.path.replace(/^[/\\]+/, '') : '';
|
|
59
|
+
const fullPath = getSrcPath(import.meta.url, cleanPath);
|
|
60
|
+
for (const entry of listDirectories(fullPath)) {
|
|
61
|
+
const componentPath = path.join(fullPath, entry);
|
|
62
|
+
if (fs.existsSync(componentPath) && fs.statSync(componentPath).isDirectory()) {
|
|
63
|
+
components.set(entry, { category, files: countFiles(componentPath) });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Object.fromEntries(
|
|
69
|
+
Object.entries(Object.fromEntries(components)).sort(([a], [b]) => a.localeCompare(b))
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function writeRegistry(components) {
|
|
74
|
+
const outputPath = getComponentsJsPath(import.meta.url);
|
|
75
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
76
|
+
const registry = Object.fromEntries(
|
|
77
|
+
Object.entries(components).map(([name, data]) => [name, data.category])
|
|
78
|
+
);
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
outputPath,
|
|
81
|
+
`const components = ${JSON.stringify(registry, null, 2)};\n\nexport default components;\n`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function groupByCategory(components) {
|
|
86
|
+
const grouped = new Map();
|
|
87
|
+
for (const [name, data] of Object.entries(components)) {
|
|
88
|
+
if (!grouped.has(data.category)) grouped.set(data.category, []);
|
|
89
|
+
grouped.get(data.category).push(name);
|
|
90
|
+
}
|
|
91
|
+
return new Map(
|
|
92
|
+
[...grouped.entries()]
|
|
93
|
+
.map(([category, names]) => [category, names.sort((a, b) => a.localeCompare(b))])
|
|
94
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function wrapNames(names, indent = ' ') {
|
|
99
|
+
const width = Math.max(40, (process.stdout.columns || 80) - indent.length);
|
|
100
|
+
const lines = [];
|
|
101
|
+
let current = '';
|
|
102
|
+
for (const name of names) {
|
|
103
|
+
const next = current ? `${current}, ${name}` : name;
|
|
104
|
+
if (next.length > width && current) {
|
|
105
|
+
lines.push(current);
|
|
106
|
+
current = name;
|
|
107
|
+
} else {
|
|
108
|
+
current = next;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (current) lines.push(current);
|
|
112
|
+
return lines.map((line) => `${indent}${line}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function printCompact(components, grouped) {
|
|
116
|
+
const names = Object.keys(components);
|
|
117
|
+
if (names.length === 0) {
|
|
118
|
+
Print.warning('No components found in your project');
|
|
119
|
+
Print.info('Create your first component with "slice component create"');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Print.newLine();
|
|
124
|
+
console.log(chalk.bold('Local components'));
|
|
125
|
+
Print.newLine();
|
|
126
|
+
|
|
127
|
+
for (const [category, categoryNames] of grouped) {
|
|
128
|
+
const sample = categoryNames.slice(0, 4).join(', ');
|
|
129
|
+
const more = categoryNames.length > 4 ? ` +${categoryNames.length - 4} more` : '';
|
|
130
|
+
console.log(
|
|
131
|
+
` ${chalk.cyan.bold(category.padEnd(16))} ${chalk.gray(String(categoryNames.length).padStart(3))} ${chalk.white(sample)}${chalk.gray(more)}`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Print.newLine();
|
|
136
|
+
Print.info(`Total: ${names.length} component${names.length === 1 ? '' : 's'} in ${grouped.size} categor${grouped.size === 1 ? 'y' : 'ies'}`);
|
|
137
|
+
Print.info('Use "slice component list --all" for every component, or --category <name> to narrow it.');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function printAll(components, grouped) {
|
|
141
|
+
const names = Object.keys(components);
|
|
142
|
+
if (names.length === 0) {
|
|
143
|
+
Print.warning('No components found in your project');
|
|
144
|
+
Print.info('Create your first component with "slice component create"');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Print.newLine();
|
|
149
|
+
console.log(chalk.bold('Local components'));
|
|
150
|
+
for (const [category, categoryNames] of grouped) {
|
|
151
|
+
Print.newLine();
|
|
152
|
+
console.log(` ${chalk.cyan.bold(category)} ${chalk.gray(`(${categoryNames.length})`)}`);
|
|
153
|
+
for (const line of wrapNames(categoryNames)) console.log(chalk.white(line));
|
|
154
|
+
}
|
|
155
|
+
Print.newLine();
|
|
156
|
+
Print.info(`Total: ${names.length} component${names.length === 1 ? '' : 's'} in ${grouped.size} categor${grouped.size === 1 ? 'y' : 'ies'}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function printJson(components, grouped) {
|
|
160
|
+
const payload = {
|
|
161
|
+
total: Object.keys(components).length,
|
|
162
|
+
categories: [...grouped.entries()].map(([name, componentsInCategory]) => ({
|
|
163
|
+
name,
|
|
164
|
+
count: componentsInCategory.length,
|
|
165
|
+
components: componentsInCategory,
|
|
166
|
+
})),
|
|
167
|
+
};
|
|
168
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Lists local components and rewrites components.js.
|
|
173
|
+
*
|
|
174
|
+
* Default output is a compact category summary; `--all` lists every component.
|
|
175
|
+
* The long cli-table is gone on purpose: real apps have dozens/hundreds of
|
|
176
|
+
* components and a table becomes noise.
|
|
177
|
+
*
|
|
178
|
+
* @param {{ all?: boolean, category?: string, json?: boolean }} [options]
|
|
179
|
+
*/
|
|
180
|
+
function listComponentsReal(options = {}) {
|
|
181
|
+
try {
|
|
182
|
+
const components = getComponents();
|
|
183
|
+
writeRegistry(components);
|
|
184
|
+
|
|
185
|
+
const filter = options.category
|
|
186
|
+
? Object.entries(components).filter(([, data]) => data.category.toLowerCase() === String(options.category).toLowerCase())
|
|
187
|
+
: Object.entries(components);
|
|
188
|
+
const filtered = Object.fromEntries(filter);
|
|
189
|
+
const grouped = groupByCategory(filtered);
|
|
190
|
+
|
|
191
|
+
if (options.json) {
|
|
192
|
+
printJson(filtered, grouped);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (options.all) printAll(filtered, grouped);
|
|
197
|
+
else printCompact(filtered, grouped);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
Print.error(`Failed to list components: ${error.message}`);
|
|
200
|
+
Print.info('Make sure your project structure is correct');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { getComponents };
|
|
205
|
+
export default listComponentsReal;
|
package/commands/seo/check.js
CHANGED
|
@@ -88,7 +88,7 @@ export default async function checkCommand(options = {}, projectRoot) {
|
|
|
88
88
|
`SEO OK: sitemap ${result.sitemap}, ${result.routes} route(s) cross-checked.`
|
|
89
89
|
);
|
|
90
90
|
} catch (error) {
|
|
91
|
-
Print.error(
|
|
91
|
+
Print.error(`slice seo check failed: ${error.message}`);
|
|
92
92
|
process.exitCode = 1;
|
|
93
93
|
}
|
|
94
94
|
}
|
package/commands/seo/images.js
CHANGED
|
@@ -635,7 +635,7 @@ export default async function imagesCommand(options = {}, projectRoot) {
|
|
|
635
635
|
process.exitCode = 1;
|
|
636
636
|
}
|
|
637
637
|
} catch (error) {
|
|
638
|
-
Print.error(
|
|
638
|
+
Print.error(`slice seo images failed: ${error.message}`);
|
|
639
639
|
process.exitCode = 1;
|
|
640
640
|
}
|
|
641
641
|
}
|
package/commands/seo/sitemap.js
CHANGED
|
@@ -103,7 +103,7 @@ export default async function sitemapCommand(options = {}, projectRoot) {
|
|
|
103
103
|
process.exitCode = 1;
|
|
104
104
|
}
|
|
105
105
|
} catch (error) {
|
|
106
|
-
Print.error(
|
|
106
|
+
Print.error(`slice seo sitemap failed: ${error.message}`);
|
|
107
107
|
process.exitCode = 1;
|
|
108
108
|
}
|
|
109
109
|
}
|
package/commands/setup/lint.js
CHANGED
|
@@ -120,7 +120,7 @@ export default async function setupLintCommand(options = {}, projectRoot) {
|
|
|
120
120
|
try {
|
|
121
121
|
result = await setupLint({ projectRoot, dryRun, withTypes: Boolean(options.withTypes) });
|
|
122
122
|
} catch (error) {
|
|
123
|
-
Print.error(
|
|
123
|
+
Print.error(`slice setup lint: ${error.message}`);
|
|
124
124
|
process.exitCode = 1;
|
|
125
125
|
return false;
|
|
126
126
|
}
|
package/commands/skill/skill.js
CHANGED
|
@@ -180,7 +180,7 @@ async function addSkill(options = {}) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
Print.success(`Skill '${manifest.name}' v${manifest.version} installed at ${manifest.installPath}/`);
|
|
183
|
-
Print.info("Reload
|
|
183
|
+
Print.info("Reload your agent session (Claude Code, OpenCode, âĻ) to pick up the skill.");
|
|
184
184
|
return true;
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -213,7 +213,7 @@ async function statusSkill() {
|
|
|
213
213
|
const installDir = path.join(projectRoot, manifest.installPath);
|
|
214
214
|
const localVersion = readLocalVersion(installDir);
|
|
215
215
|
|
|
216
|
-
Print.title("Slice.js
|
|
216
|
+
Print.title("Slice.js developer skill");
|
|
217
217
|
console.log(` name: ${manifest.name}`);
|
|
218
218
|
console.log(` latest: v${manifest.version} (targets ${manifest.targets})`);
|
|
219
219
|
console.log(` installed: ${localVersion ? "v" + localVersion : "not installed"}`);
|
|
@@ -6,9 +6,11 @@ import { spawn } from 'child_process';
|
|
|
6
6
|
import { createServer } from 'net';
|
|
7
7
|
import setupWatcher, { stopWatcher } from './watchServer.js';
|
|
8
8
|
import Print from '../Print.js';
|
|
9
|
-
import { getApiPath, getSrcPath, getDistPath, getPath } from '../utils/PathHelper.js';
|
|
9
|
+
import { getApiPath, getSrcPath, getDistPath, getPath, getProjectRoot } from '../utils/PathHelper.js';
|
|
10
10
|
import { loadConfigSync } from '../utils/loadConfig.js';
|
|
11
11
|
import build from '../build/build.js';
|
|
12
|
+
import { generateDocs, hasDocumentationScaffold } from '../docs/index.js';
|
|
13
|
+
import { syncComponentsRegistry } from '../utils/componentCatalog.js';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Checks if a port is available
|
|
@@ -91,26 +93,46 @@ function startNodeServer(port, mode) {
|
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
let serverStarted = false;
|
|
94
|
-
let
|
|
96
|
+
let readyAnnounced = false;
|
|
97
|
+
let stdoutBuffer = '';
|
|
98
|
+
|
|
99
|
+
const isReadyLine = (line) =>
|
|
100
|
+
line.includes('Server running') ||
|
|
101
|
+
line.includes('listening on') ||
|
|
102
|
+
line.includes('Started on') ||
|
|
103
|
+
line.includes(`port ${port}`);
|
|
104
|
+
|
|
105
|
+
// The framework announces readiness on stdout. The CLI already prints the
|
|
106
|
+
// READY block, so the announcing line is consumed instead of forwarded;
|
|
107
|
+
// everything else the server logs still reaches the terminal.
|
|
108
|
+
const forwardLine = (line) => {
|
|
109
|
+
if (isReadyLine(line)) {
|
|
110
|
+
if (!readyAnnounced) {
|
|
111
|
+
readyAnnounced = true;
|
|
112
|
+
serverStarted = true;
|
|
113
|
+
Print.serverReady(port);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
process.stdout.write(line);
|
|
118
|
+
};
|
|
95
119
|
|
|
96
|
-
// Capture output
|
|
120
|
+
// Capture output line by line so a readiness message split across chunks is
|
|
121
|
+
// still detected and suppressed exactly once.
|
|
97
122
|
serverProcess.stdout.on('data', (data) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
output.includes('Server running') ||
|
|
104
|
-
output.includes('listening on') ||
|
|
105
|
-
output.includes('Started on') ||
|
|
106
|
-
output.includes(`port ${port}`)
|
|
107
|
-
)) {
|
|
108
|
-
serverStarted = true;
|
|
109
|
-
Print.serverReady(port);
|
|
123
|
+
stdoutBuffer += data.toString();
|
|
124
|
+
let newline;
|
|
125
|
+
while ((newline = stdoutBuffer.indexOf('\n')) !== -1) {
|
|
126
|
+
forwardLine(stdoutBuffer.slice(0, newline + 1));
|
|
127
|
+
stdoutBuffer = stdoutBuffer.slice(newline + 1);
|
|
110
128
|
}
|
|
129
|
+
});
|
|
111
130
|
|
|
112
|
-
|
|
113
|
-
|
|
131
|
+
serverProcess.stdout.on('end', () => {
|
|
132
|
+
if (stdoutBuffer) {
|
|
133
|
+
forwardLine(stdoutBuffer);
|
|
134
|
+
stdoutBuffer = '';
|
|
135
|
+
}
|
|
114
136
|
});
|
|
115
137
|
|
|
116
138
|
serverProcess.stderr.on('data', (data) => {
|
|
@@ -135,6 +157,7 @@ function startNodeServer(port, mode) {
|
|
|
135
157
|
setTimeout(() => {
|
|
136
158
|
if (!serverStarted) {
|
|
137
159
|
serverStarted = true;
|
|
160
|
+
readyAnnounced = true;
|
|
138
161
|
Print.serverReady(port);
|
|
139
162
|
}
|
|
140
163
|
resolve(serverProcess);
|
|
@@ -166,7 +189,7 @@ export default async function startServer(options = {}) {
|
|
|
166
189
|
const { mode = 'development', port = defaultPort, watch = false } = options;
|
|
167
190
|
|
|
168
191
|
try {
|
|
169
|
-
Print.title(
|
|
192
|
+
Print.title(`Starting Slice.js ${mode} server`);
|
|
170
193
|
Print.newLine();
|
|
171
194
|
|
|
172
195
|
// Verify project structure
|
|
@@ -174,6 +197,22 @@ export default async function startServer(options = {}) {
|
|
|
174
197
|
throw new Error('Project structure not found. Run "slice init" first.');
|
|
175
198
|
}
|
|
176
199
|
|
|
200
|
+
// Keep the generated documentation current while developing. The build
|
|
201
|
+
// command checks it instead of writing, so CI catches a stale commit.
|
|
202
|
+
// Hand-written AGENTS.md files are left alone until the project opts in.
|
|
203
|
+
if (mode === 'development' && watch) {
|
|
204
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
205
|
+
try {
|
|
206
|
+
// Keep components.js current without printing the component catalog.
|
|
207
|
+
await syncComponentsRegistry(projectRoot);
|
|
208
|
+
if (await hasDocumentationScaffold(projectRoot)) {
|
|
209
|
+
await generateDocs({ projectRoot, target: 'all' });
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
Print.warning(`Could not generate project docs: ${error.message}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
177
216
|
let actualPort = await isPortAvailable(port) ? port : port + 1; // Try one more port
|
|
178
217
|
if(actualPort !== port) {
|
|
179
218
|
// Check if the fallback is available
|
|
@@ -181,10 +220,10 @@ export default async function startServer(options = {}) {
|
|
|
181
220
|
if(!fallbackAvailable) {
|
|
182
221
|
throw new Error(`Ports ${port} and ${actualPort} are in use.`);
|
|
183
222
|
}
|
|
184
|
-
Print.info(
|
|
223
|
+
Print.info(`Port ${port} is busy; using ${actualPort}.`);
|
|
185
224
|
}
|
|
186
225
|
|
|
187
|
-
Print.serverStatus('checking', `Port ${actualPort} available
|
|
226
|
+
Print.serverStatus('checking', `Port ${actualPort} available`);
|
|
188
227
|
Print.newLine();
|
|
189
228
|
|
|
190
229
|
if (mode === 'production') {
|
|
@@ -218,7 +257,7 @@ export default async function startServer(options = {}) {
|
|
|
218
257
|
await new Promise(r => setTimeout(r, 500));
|
|
219
258
|
|
|
220
259
|
try {
|
|
221
|
-
Print.info('
|
|
260
|
+
Print.info('File changed. Restarting server...');
|
|
222
261
|
|
|
223
262
|
currentServerProcess = await startNodeServer(actualPort, mode);
|
|
224
263
|
} catch (e) {
|
|
@@ -8,7 +8,7 @@ import Print from '../Print.js';
|
|
|
8
8
|
* @returns {FSWatcher} - Chokidar watcher
|
|
9
9
|
*/
|
|
10
10
|
export default function setupWatcher(serverProcess, onRestart) {
|
|
11
|
-
Print.info('Watch mode enabled
|
|
11
|
+
Print.info('Watch mode enabled; monitoring changes');
|
|
12
12
|
Print.newLine();
|
|
13
13
|
|
|
14
14
|
const watcher = chokidar.watch(['api/**/*'], {
|
|
@@ -33,7 +33,7 @@ export default function setupWatcher(serverProcess, onRestart) {
|
|
|
33
33
|
clearTimeout(reloadTimeout);
|
|
34
34
|
reloadTimeout = setTimeout(() => {
|
|
35
35
|
if (onRestart) {
|
|
36
|
-
console.log(chalk.yellow('
|
|
36
|
+
console.log(chalk.yellow('API change detected. Restarting server...'));
|
|
37
37
|
onRestart(changedPath);
|
|
38
38
|
}
|
|
39
39
|
}, 500);
|
|
@@ -47,7 +47,7 @@ export default function setupWatcher(serverProcess, onRestart) {
|
|
|
47
47
|
Print.error(`Watcher error: ${error.message}`);
|
|
48
48
|
})
|
|
49
49
|
.on('ready', () => {
|
|
50
|
-
console.log(chalk.gray('
|
|
50
|
+
console.log(chalk.gray('Watching for changes...'));
|
|
51
51
|
Print.newLine();
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -26,7 +26,7 @@ export default async function checkCommand(options = {}, projectRoot) {
|
|
|
26
26
|
`${result.contentCount ? `, ${result.contentCount} content document(s)` : ''}).`
|
|
27
27
|
);
|
|
28
28
|
} catch (error) {
|
|
29
|
-
Print.error(
|
|
29
|
+
Print.error(`slice translator check failed: ${error.message}`);
|
|
30
30
|
process.exitCode = 1;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -119,7 +119,7 @@ export default async function initCommand(options = {}, projectRoot) {
|
|
|
119
119
|
Print.info('Dictionaries live in that folder; templates use data-t="key" and code uses slice.t("key").');
|
|
120
120
|
Print.info('Next: `slice translator check`.');
|
|
121
121
|
} catch (error) {
|
|
122
|
-
Print.error(
|
|
122
|
+
Print.error(`slice translator init failed: ${error.message}`);
|
|
123
123
|
process.exitCode = 1;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -42,7 +42,7 @@ export default async function typecheckCommand(options = {}, projectRoot) {
|
|
|
42
42
|
const types = await runTypeRefresh(projectRoot, options);
|
|
43
43
|
if (types) reportTypesRefresh(types, projectRoot);
|
|
44
44
|
} catch (error) {
|
|
45
|
-
Print.warning(
|
|
45
|
+
Print.warning(`Could not refresh the generated types: ${error.message}`);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -69,7 +69,7 @@ export default async function typecheckCommand(options = {}, projectRoot) {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
if (result.error) {
|
|
72
|
-
Print.error(
|
|
72
|
+
Print.error(`Could not run tsc: ${result.error.message}`);
|
|
73
73
|
process.exitCode = 1;
|
|
74
74
|
return false;
|
|
75
75
|
}
|