slicejs-cli 4.4.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 +192 -82
- 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 +99 -12
- 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 +44 -40
- 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 +7 -4
- package/commands/seo/images.js +77 -22
- package/commands/seo/sitemap.js +6 -3
- package/commands/seo/support.js +62 -0
- 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 +32 -0
- package/commands/translator/init.js +125 -0
- package/commands/translator/scan.js +444 -0
- 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 +1007 -976
- package/commands/utils/componentCatalog.js +120 -0
- package/commands/utils/publicEnv.js +74 -0
- package/commands/utils/sliceConfigSchema.js +34 -0
- package/commands/utils/updateManager.js +12 -12
- package/package.json +22 -23
package/commands/init/init.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import Print from '../Print.js';
|
|
6
|
+
import { generateDocs } from '../docs/index.js';
|
|
6
7
|
import { getProjectRoot, getApiPath, getSrcPath, getPath } from '../utils/PathHelper.js';
|
|
7
8
|
import { execSync } from 'child_process';
|
|
8
9
|
import {
|
|
@@ -104,6 +105,9 @@ node_modules/
|
|
|
104
105
|
# Production build output (slice build)
|
|
105
106
|
dist/
|
|
106
107
|
|
|
108
|
+
# Static export output (slice export)
|
|
109
|
+
dist-static/
|
|
110
|
+
|
|
107
111
|
# Local environment overrides
|
|
108
112
|
.env
|
|
109
113
|
.env.*
|
|
@@ -241,7 +245,7 @@ export default async function initializeProject(options = {}) {
|
|
|
241
245
|
fwSpinner.warn('Install did not run; using the slicejs-web-framework already in this project');
|
|
242
246
|
} else {
|
|
243
247
|
fwSpinner.fail('Failed to install slicejs-web-framework');
|
|
244
|
-
Print.error(
|
|
248
|
+
Print.error(`slice init: ${err.message}`);
|
|
245
249
|
const retry = installCommand(packageManager, latestVersion ? `slicejs-web-framework@${latestVersion}` : 'slicejs-web-framework');
|
|
246
250
|
Print.info(`Retry with: ${retry}`);
|
|
247
251
|
return;
|
|
@@ -283,8 +287,8 @@ export default async function initializeProject(options = {}) {
|
|
|
283
287
|
if (fs.existsSync(path.join(destinationApi, 'index.js'))) throw new Error(`api/index.js already exists: ${path.join(destinationApi, 'index.js')}`);
|
|
284
288
|
if (fs.existsSync(destinationSrc)) throw new Error(`The "src" directory already exists: ${destinationSrc}`);
|
|
285
289
|
} catch (error) {
|
|
286
|
-
Print.error(
|
|
287
|
-
|
|
290
|
+
Print.error(`Validating destination directories: ${error.message}`);
|
|
291
|
+
Print.stack(error);
|
|
288
292
|
return;
|
|
289
293
|
}
|
|
290
294
|
|
|
@@ -299,7 +303,7 @@ export default async function initializeProject(options = {}) {
|
|
|
299
303
|
} catch (error) {
|
|
300
304
|
apiSpinner.fail('Error creating api/index.js');
|
|
301
305
|
Print.error(error.message);
|
|
302
|
-
|
|
306
|
+
Print.stack(error);
|
|
303
307
|
return;
|
|
304
308
|
}
|
|
305
309
|
|
|
@@ -351,7 +355,7 @@ export default async function initializeProject(options = {}) {
|
|
|
351
355
|
} catch (error) {
|
|
352
356
|
srcSpinner.fail('Error creating source structure');
|
|
353
357
|
Print.error(error.message);
|
|
354
|
-
|
|
358
|
+
Print.stack(error);
|
|
355
359
|
return;
|
|
356
360
|
}
|
|
357
361
|
|
|
@@ -484,38 +488,44 @@ export default async function initializeProject(options = {}) {
|
|
|
484
488
|
}
|
|
485
489
|
|
|
486
490
|
await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), 'utf8');
|
|
487
|
-
pkgSpinner.succeed('Package scripts configured
|
|
488
|
-
|
|
489
|
-
Print.title('New recommended commands:');
|
|
490
|
-
console.log(` ${packageManager} run dev - Start development server`);
|
|
491
|
-
console.log(` ${packageManager} run get - Install components`);
|
|
492
|
-
console.log(` ${packageManager} run browse - Browse components`);
|
|
491
|
+
pkgSpinner.succeed('Package scripts configured');
|
|
493
492
|
} catch (error) {
|
|
494
493
|
pkgSpinner.fail('Failed to configure npm scripts');
|
|
495
494
|
Print.error(error.message);
|
|
496
|
-
|
|
495
|
+
Print.stack(error);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// 5. SEED THE AGENT DOCUMENTATION
|
|
499
|
+
const docsSpinner = ora('Documenting the project for agents...').start();
|
|
500
|
+
try {
|
|
501
|
+
await generateDocs({ projectRoot, target: 'all' });
|
|
502
|
+
docsSpinner.succeed('AGENTS.md, category guides, types and event docs created');
|
|
503
|
+
} catch (error) {
|
|
504
|
+
docsSpinner.warn('Project created, but the agent docs could not be generated');
|
|
505
|
+
Print.error(`Documentation error: ${error.message}`);
|
|
497
506
|
}
|
|
498
507
|
|
|
499
508
|
const projectName = path.basename(process.cwd());
|
|
500
509
|
|
|
501
510
|
const failedCount = [...visualResults, ...serviceResults].filter(r => !r.success).length;
|
|
502
511
|
if (failedCount > 0) {
|
|
503
|
-
|
|
512
|
+
const suffix = failedCount === 1 ? '' : 's';
|
|
513
|
+
Print.warning(`${failedCount} component${suffix} failed to install. Retry with "${packageManager} run get -- <name>".`);
|
|
504
514
|
}
|
|
505
515
|
|
|
506
|
-
Print.success(`Project initialized
|
|
516
|
+
Print.success(`Project initialized in ${projectName}/`);
|
|
507
517
|
Print.newLine();
|
|
508
|
-
Print.title('Next steps
|
|
518
|
+
Print.title('Next steps');
|
|
509
519
|
console.log(` cd ${projectName}`);
|
|
510
|
-
console.log(` ${packageManager} run dev
|
|
511
|
-
console.log(` ${packageManager} run browse
|
|
512
|
-
console.log(` ${packageManager} run get -- Button
|
|
513
|
-
console.log(` ${packageManager} run sync
|
|
514
|
-
console.log(
|
|
520
|
+
console.log(` ${packageManager} run dev Start the development server`);
|
|
521
|
+
console.log(` ${packageManager} run browse Browse registry components`);
|
|
522
|
+
console.log(` ${packageManager} run get -- Button Add a component`);
|
|
523
|
+
console.log(` ${packageManager} run sync Update installed components`);
|
|
524
|
+
console.log(' npx slicejs-cli setup lint --with-types ESLint, type checking and generated types');
|
|
515
525
|
|
|
516
526
|
} catch (error) {
|
|
517
|
-
Print.error(
|
|
518
|
-
|
|
527
|
+
Print.error(`Unexpected error initializing project: ${error.message}`);
|
|
528
|
+
Print.stack(error);
|
|
519
529
|
}
|
|
520
530
|
}
|
|
521
531
|
|
package/commands/lint/lint.js
CHANGED
|
@@ -36,7 +36,7 @@ export default async function lintCommand(options = {}, projectRoot) {
|
|
|
36
36
|
const types = await runTypeRefresh(projectRoot, options);
|
|
37
37
|
if (types) reportTypesRefresh(types, projectRoot);
|
|
38
38
|
} catch (error) {
|
|
39
|
-
Print.error(
|
|
39
|
+
Print.error(`Could not refresh the generated types: ${error.message}`);
|
|
40
40
|
process.exitCode = 1;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -61,7 +61,7 @@ export default async function lintCommand(options = {}, projectRoot) {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
if (result.error) {
|
|
64
|
-
Print.error(
|
|
64
|
+
Print.error(`Could not run ESLint: ${result.error.message}`);
|
|
65
65
|
process.exitCode = 1;
|
|
66
66
|
return false;
|
|
67
67
|
}
|
package/commands/lint/types.js
CHANGED
|
@@ -77,7 +77,7 @@ export function reportTypesRefresh(types, projectRoot) {
|
|
|
77
77
|
Print.info('Using tsconfig.json; the generated declarations are not added to it.');
|
|
78
78
|
break;
|
|
79
79
|
case 'editor_config_error':
|
|
80
|
-
Print.warning(
|
|
80
|
+
Print.warning(`Could not update jsconfig.json: ${types.jsconfigError || 'unknown error'}`);
|
|
81
81
|
break;
|
|
82
82
|
default:
|
|
83
83
|
break;
|
|
@@ -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
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
MANIFEST_FILE,
|
|
15
15
|
SITEMAP_FILE,
|
|
16
16
|
loadFrameworkSeo,
|
|
17
|
-
loadManifest
|
|
17
|
+
loadManifest,
|
|
18
|
+
loadSeoTranslator
|
|
18
19
|
} from './support.js';
|
|
19
20
|
|
|
20
21
|
export async function loadRoutes(projectRoot) {
|
|
@@ -42,9 +43,11 @@ export async function checkSeo(options = {}) {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const routes = options.routes || await loadRoutes(projectRoot);
|
|
46
|
+
const translator = options.translator ?? await loadSeoTranslator(projectRoot, framework);
|
|
45
47
|
const { errors, warnings } = framework.validateSeoManifest(manifest, {
|
|
46
48
|
routes,
|
|
47
|
-
publicDir: path.join(projectRoot, 'src', 'public')
|
|
49
|
+
publicDir: path.join(projectRoot, 'src', 'public'),
|
|
50
|
+
translator
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
let sitemap = 'ok';
|
|
@@ -57,7 +60,7 @@ export async function checkSeo(options = {}) {
|
|
|
57
60
|
errors.push(`${SITEMAP_FILE} is missing: run \`slice seo sitemap\``);
|
|
58
61
|
} else {
|
|
59
62
|
const origin = framework.normalizeOrigin(manifest.origin);
|
|
60
|
-
const expected = origin ? framework.buildSitemap({ manifest, origin }) : null;
|
|
63
|
+
const expected = origin ? framework.buildSitemap({ manifest, origin, translator }) : null;
|
|
61
64
|
if (expected !== null && fs.readFileSync(file, 'utf8') !== expected) {
|
|
62
65
|
sitemap = 'drifted';
|
|
63
66
|
errors.push(`${SITEMAP_FILE} is out of date: run \`slice seo sitemap\``);
|
|
@@ -85,7 +88,7 @@ export default async function checkCommand(options = {}, projectRoot) {
|
|
|
85
88
|
`SEO OK: sitemap ${result.sitemap}, ${result.routes} route(s) cross-checked.`
|
|
86
89
|
);
|
|
87
90
|
} catch (error) {
|
|
88
|
-
Print.error(
|
|
91
|
+
Print.error(`slice seo check failed: ${error.message}`);
|
|
89
92
|
process.exitCode = 1;
|
|
90
93
|
}
|
|
91
94
|
}
|