slicejs-cli 4.2.0 → 4.4.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 (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +260 -257
  3. package/client.js +927 -780
  4. package/commands/Print.js +163 -163
  5. package/commands/Validations.js +92 -92
  6. package/commands/build/build.js +97 -107
  7. package/commands/buildProduction/buildProduction.js +613 -613
  8. package/commands/bundle/bundle.js +251 -239
  9. package/commands/createComponent/VisualComponentTemplate.js +55 -55
  10. package/commands/createComponent/createComponent.js +128 -128
  11. package/commands/deleteComponent/deleteComponent.js +81 -81
  12. package/commands/docs/docs.js +365 -0
  13. package/commands/doctor/doctor.js +677 -563
  14. package/commands/getComponent/getComponent.js +842 -842
  15. package/commands/init/init.js +526 -475
  16. package/commands/lint/lint.js +75 -0
  17. package/commands/lint/types.js +85 -0
  18. package/commands/listComponents/listComponents.js +172 -172
  19. package/commands/seo/check.js +91 -0
  20. package/commands/seo/images.js +586 -0
  21. package/commands/seo/sitemap.js +106 -0
  22. package/commands/seo/support.js +130 -0
  23. package/commands/setup/lint.js +151 -0
  24. package/commands/skill/skill.js +236 -236
  25. package/commands/startServer/startServer.js +240 -240
  26. package/commands/startServer/watchServer.js +66 -66
  27. package/commands/typecheck/typecheck.js +83 -0
  28. package/commands/types/types.js +1378 -1097
  29. package/commands/utils/JsMinifier.js +230 -230
  30. package/commands/utils/LocalCliDelegation.js +78 -53
  31. package/commands/utils/PackageManager.js +148 -148
  32. package/commands/utils/PathHelper.js +87 -75
  33. package/commands/utils/ProjectValidation.js +274 -0
  34. package/commands/utils/SourceDiagnostics.js +201 -201
  35. package/commands/utils/VersionChecker.js +169 -169
  36. package/commands/utils/analyzeSource.js +77 -77
  37. package/commands/utils/bundling/BundleGenerator.js +3748 -3776
  38. package/commands/utils/bundling/DependencyAnalyzer.js +976 -976
  39. package/commands/utils/bundling/ExternalModuleBundler.js +298 -298
  40. package/commands/utils/componentAudit.js +74 -0
  41. package/commands/utils/compressAssets.js +103 -103
  42. package/commands/utils/cssScope.js +83 -0
  43. package/commands/utils/loadConfig.js +31 -31
  44. package/commands/utils/semver.js +66 -0
  45. package/commands/utils/sliceConfigSchema.js +72 -0
  46. package/commands/utils/sliceScripts.js +48 -48
  47. package/commands/utils/updateManager.js +471 -471
  48. package/eslint-config.js +128 -0
  49. package/package.json +19 -13
@@ -0,0 +1,75 @@
1
+ // slice lint — the project's own ESLint, with the shared config available as
2
+ // `slicejs-cli/eslint-config.js`.
3
+ //
4
+ // The CLI does not bundle ESLint: the project declares it, like any other dev
5
+ // tool, and this command is a thin wrapper so `slice lint` works in scripts and
6
+ // CI without remembering the binary name.
7
+
8
+ import path from 'node:path';
9
+ import { spawnSync } from 'node:child_process';
10
+ import { createRequire } from 'node:module';
11
+ import Print from '../Print.js';
12
+ import { refreshGeneratedTypes, reportTypesRefresh } from './types.js';
13
+
14
+ /** Path to the project's eslint binary, or null when it is not installed. */
15
+ export function resolveEslint(projectRoot) {
16
+ try {
17
+ const require = createRequire(path.join(projectRoot, 'package.json'));
18
+ const pkgPath = require.resolve('eslint/package.json');
19
+ return path.join(path.dirname(pkgPath), 'bin', 'eslint.js');
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ /** Refresh declarations unless the caller opted out with `--no-types`. */
26
+ export async function runTypeRefresh(projectRoot, options = {}) {
27
+ if (options.types === false) return null;
28
+ return refreshGeneratedTypes(projectRoot);
29
+ }
30
+
31
+ export default async function lintCommand(options = {}, projectRoot) {
32
+ // One command verifies the project: refresh the declarations the editor reads
33
+ // before running ESLint, so they can never go stale. --no-types opts out.
34
+ if (options.types !== false) {
35
+ try {
36
+ const types = await runTypeRefresh(projectRoot, options);
37
+ if (types) reportTypesRefresh(types, projectRoot);
38
+ } catch (error) {
39
+ Print.error('Could not refresh the generated types:', error.message);
40
+ process.exitCode = 1;
41
+ }
42
+ }
43
+
44
+ const eslint = resolveEslint(projectRoot);
45
+
46
+ if (!eslint) {
47
+ Print.error('ESLint is not installed in this project.');
48
+ Print.info('Install it: npm i -D eslint (or "pnpm add -D eslint")');
49
+ Print.info('Then add eslint.config.js: import slice from "slicejs-cli/eslint-config.js"; export default [...slice];');
50
+ process.exitCode = 1;
51
+ return false;
52
+ }
53
+
54
+ const targets = options.paths?.length ? options.paths : ['.'];
55
+ const args = [eslint, ...(options.fix ? ['--fix'] : []), ...targets];
56
+
57
+ const result = spawnSync(process.execPath, args, {
58
+ cwd: projectRoot,
59
+ stdio: 'inherit',
60
+ env: process.env
61
+ });
62
+
63
+ if (result.error) {
64
+ Print.error('Could not run ESLint:', result.error.message);
65
+ process.exitCode = 1;
66
+ return false;
67
+ }
68
+
69
+ if (result.status !== 0) {
70
+ process.exitCode = result.status || 1;
71
+ return false;
72
+ }
73
+
74
+ return true;
75
+ }
@@ -0,0 +1,85 @@
1
+ // Keeping the generated declarations in sync is part of "lint" from the user's
2
+ // point of view: one command that verifies the project, not two. ESLint itself
3
+ // does not type-check (JS, no tsconfig); what this phase guarantees is that the
4
+ // `.d.ts` the editor reads still matches the props on disk.
5
+
6
+ import fs from 'fs-extra';
7
+ import path from 'node:path';
8
+ import Print from '../Print.js';
9
+ import { generateTypesFile, ensureEditorConfigForTypes } from '../types/types.js';
10
+
11
+ export const DEFAULT_TYPES_OUTPUT = path.join('src', 'slice-build.generated.d.ts');
12
+
13
+ /** A project opts into types by having the file or a script that generates it. */
14
+ export async function usesGeneratedTypes(projectRoot) {
15
+ const packagePath = path.join(projectRoot, 'package.json');
16
+ let scripts = {};
17
+ try {
18
+ scripts = JSON.parse(await fs.readFile(packagePath, 'utf8')).scripts || {};
19
+ } catch { /* no package.json: nothing to configure */ }
20
+
21
+ if (Object.values(scripts).some((command) => /types\s+generate/.test(String(command)))) return true;
22
+ return fs.pathExists(path.join(projectRoot, DEFAULT_TYPES_OUTPUT));
23
+ }
24
+
25
+ /**
26
+ * Regenerate the declarations in place.
27
+ * @returns {Promise<{status: 'created'|'updated'|'unchanged'|'skipped', file?: string, components?: number}>}
28
+ */
29
+ export async function refreshGeneratedTypes(projectRoot, output = DEFAULT_TYPES_OUTPUT) {
30
+ if (!await usesGeneratedTypes(projectRoot)) {
31
+ return { status: 'skipped' };
32
+ }
33
+
34
+ // Types come from the component registry. A repo with a leftover `slice:types`
35
+ // script but no Slice app (the CLI itself, for instance) has nothing to type.
36
+ if (!await fs.pathExists(path.join(projectRoot, 'src', 'Components', 'components.js'))) {
37
+ return { status: 'skipped' };
38
+ }
39
+
40
+ const file = path.isAbsolute(output) ? output : path.join(projectRoot, output);
41
+ const before = await fs.readFile(file, 'utf8').catch(() => null);
42
+
43
+ const result = await generateTypesFile({ projectRoot, outputPath: file });
44
+ const after = await fs.readFile(file, 'utf8').catch(() => null);
45
+
46
+ // Without this the declarations exist but `slice typecheck` has nothing to
47
+ // point tsc at (its error message tells you to run types generate).
48
+ const jsconfig = await ensureEditorConfigForTypes({ projectRoot, outputPath: file });
49
+
50
+ return {
51
+ status: before === null ? 'created' : before === after ? 'unchanged' : 'updated',
52
+ file,
53
+ components: result.componentsProcessed,
54
+ jsconfig: jsconfig.mode,
55
+ jsconfigReason: jsconfig.reason,
56
+ jsconfigError: jsconfig.errorMessage
57
+ };
58
+ }
59
+
60
+ /** Explain what the refresh did, including the jsconfig decisions it took. */
61
+ export function reportTypesRefresh(types, projectRoot) {
62
+ if (types.status === 'created') Print.info(`Generated types: ${path.relative(projectRoot, types.file)}`);
63
+ else if (types.status === 'updated') Print.info(`Updated generated types: ${path.relative(projectRoot, types.file)}`);
64
+ else if (types.status === 'skipped') Print.info('Types: not configured in this project, skipped.');
65
+
66
+ switch (types.jsconfig) {
67
+ case 'created_jsconfig':
68
+ Print.info('Created jsconfig.json for type-checking.');
69
+ break;
70
+ case 'updated_jsconfig':
71
+ Print.info('Updated jsconfig.json for type-checking.');
72
+ break;
73
+ case 'reset_jsconfig':
74
+ Print.warning(`Rewrote jsconfig.json (${types.jsconfigReason || 'unreadable or invalid'}).`);
75
+ break;
76
+ case 'tsconfig_exists':
77
+ Print.info('Using tsconfig.json; the generated declarations are not added to it.');
78
+ break;
79
+ case 'editor_config_error':
80
+ Print.warning('Could not update jsconfig.json:', types.jsconfigError || 'unknown error');
81
+ break;
82
+ default:
83
+ break;
84
+ }
85
+ }
@@ -1,172 +1,172 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import Table from 'cli-table3';
4
- import chalk from 'chalk';
5
- import Print from '../Print.js';
6
- import { getSrcPath, getComponentsJsPath, getConfigPath } from '../utils/PathHelper.js';
7
-
8
- /**
9
- * Loads configuration from sliceConfig.json
10
- * @returns {object} - Configuration object
11
- */
12
- const loadConfig = () => {
13
- try {
14
- const configPath = getConfigPath(import.meta.url);
15
- if (!fs.existsSync(configPath)) {
16
- Print.error('sliceConfig.json not found');
17
- Print.info('Run "slice init" to initialize your project');
18
- return null;
19
- }
20
- const rawData = fs.readFileSync(configPath, 'utf-8');
21
- return JSON.parse(rawData);
22
- } catch (error) {
23
- Print.error(`Failed to load configuration: ${error.message}`);
24
- Print.info('Check that sliceConfig.json is valid JSON');
25
- return null;
26
- }
27
- };
28
-
29
- /**
30
- * Lists files in a given folder, filtering only .js files
31
- * @param {string} folderPath - Path of the folder to read
32
- * @returns {string[]} - List of found files
33
- */
34
- const listComponents = (folderPath) => {
35
- try {
36
- if (!fs.existsSync(folderPath)) {
37
- return [];
38
- }
39
- const result = fs.readdirSync(folderPath);
40
- return result;
41
- } catch (error) {
42
- Print.error(`Failed to read directory ${folderPath}: ${error.message}`);
43
- return [];
44
- }
45
- };
46
-
47
- /**
48
- * Counts files in a component directory
49
- */
50
- const countComponentFiles = (componentPath) => {
51
- try {
52
- if (!fs.existsSync(componentPath)) return 0;
53
- const files = fs.readdirSync(componentPath);
54
- return files.filter(f => fs.statSync(path.join(componentPath, f)).isFile()).length;
55
- } catch {
56
- return 0;
57
- }
58
- };
59
-
60
- /**
61
- * Gets components dynamically from sliceConfig.json
62
- * @returns {object} - Component mapping with their category
63
- */
64
- const getComponents = () => {
65
- const config = loadConfig();
66
- if (!config) return {};
67
-
68
- const folderSuffix = 'src'; // Always use 'src' for development
69
- const componentPaths = config.paths?.components || {};
70
- let allComponents = new Map();
71
-
72
- Object.entries(componentPaths).forEach(([category, { path: folderPath }]) => {
73
- const cleanFolderPath = folderPath ? folderPath.replace(/^[/\\]+/, '') : '';
74
- const fullPath = getSrcPath(import.meta.url, cleanFolderPath);
75
- const files = listComponents(fullPath);
76
-
77
- files.forEach(file => {
78
- const componentPath = path.join(fullPath, file);
79
- if (fs.statSync(componentPath).isDirectory()) {
80
- const fileCount = countComponentFiles(componentPath);
81
- allComponents.set(file, { category, files: fileCount });
82
- }
83
- });
84
- });
85
-
86
- return Object.fromEntries(allComponents);
87
- };
88
-
89
- function listComponentsReal() {
90
- try {
91
- // Get components dynamically
92
- const components = getComponents();
93
-
94
- if (Object.keys(components).length === 0) {
95
- Print.warning('No components found in your project');
96
- Print.info('Create your first component with "slice component create"');
97
- return;
98
- }
99
-
100
- // Create table with cli-table3
101
- const table = new Table({
102
- head: [
103
- chalk.cyan.bold('Component'),
104
- chalk.cyan.bold('Category'),
105
- chalk.cyan.bold('Files')
106
- ],
107
- colWidths: [30, 20, 10],
108
- style: {
109
- head: [],
110
- border: ['gray']
111
- }
112
- });
113
-
114
- // Group by category for better visualization
115
- const byCategory = {};
116
- Object.entries(components).forEach(([name, data]) => {
117
- if (!byCategory[data.category]) {
118
- byCategory[data.category] = [];
119
- }
120
- byCategory[data.category].push({ name, files: data.files });
121
- });
122
-
123
- // Add rows to the table
124
- Object.entries(byCategory).forEach(([category, comps]) => {
125
- comps.forEach((comp, index) => {
126
- if (index === 0) {
127
- // First row of the category
128
- table.push([
129
- chalk.bold(comp.name),
130
- chalk.yellow(category),
131
- comp.files.toString()
132
- ]);
133
- } else {
134
- // Rest of components in the category
135
- table.push([
136
- chalk.bold(comp.name),
137
- chalk.gray('″'), // Ditto mark
138
- comp.files.toString()
139
- ]);
140
- }
141
- });
142
- });
143
-
144
- Print.newLine();
145
- Print.title('📦 Local Components');
146
- Print.newLine();
147
- console.log(table.toString());
148
- Print.newLine();
149
- Print.info(`Total: ${Object.keys(components).length} component${Object.keys(components).length !== 1 ? 's' : ''} found`);
150
-
151
- // Path where components.js will be generated
152
- const outputPath = getComponentsJsPath(import.meta.url);
153
-
154
- // Ensure the directory exists
155
- const outputDir = path.dirname(outputPath);
156
- if (!fs.existsSync(outputDir)) {
157
- fs.mkdirSync(outputDir, { recursive: true });
158
- }
159
-
160
- // Generate components.js file with detected components
161
- const componentsForExport = Object.fromEntries(
162
- Object.entries(components).map(([name, data]) => [name, data.category])
163
- );
164
- fs.writeFileSync(outputPath, `const components = ${JSON.stringify(componentsForExport, null, 2)};\n\nexport default components;\n`);
165
-
166
- } catch (error) {
167
- Print.error(`Failed to list components: ${error.message}`);
168
- Print.info('Make sure your project structure is correct');
169
- }
170
- }
171
-
172
- export default listComponentsReal;
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import Table from 'cli-table3';
4
+ import chalk from 'chalk';
5
+ import Print from '../Print.js';
6
+ import { getSrcPath, getComponentsJsPath, getConfigPath } from '../utils/PathHelper.js';
7
+
8
+ /**
9
+ * Loads configuration from sliceConfig.json
10
+ * @returns {object} - Configuration object
11
+ */
12
+ const loadConfig = () => {
13
+ try {
14
+ const configPath = getConfigPath(import.meta.url);
15
+ if (!fs.existsSync(configPath)) {
16
+ Print.error('sliceConfig.json not found');
17
+ Print.info('Run "slice init" to initialize your project');
18
+ return null;
19
+ }
20
+ const rawData = fs.readFileSync(configPath, 'utf-8');
21
+ return JSON.parse(rawData);
22
+ } catch (error) {
23
+ Print.error(`Failed to load configuration: ${error.message}`);
24
+ Print.info('Check that sliceConfig.json is valid JSON');
25
+ return null;
26
+ }
27
+ };
28
+
29
+ /**
30
+ * Lists files in a given folder, filtering only .js files
31
+ * @param {string} folderPath - Path of the folder to read
32
+ * @returns {string[]} - List of found files
33
+ */
34
+ const listComponents = (folderPath) => {
35
+ try {
36
+ if (!fs.existsSync(folderPath)) {
37
+ return [];
38
+ }
39
+ const result = fs.readdirSync(folderPath);
40
+ return result;
41
+ } catch (error) {
42
+ Print.error(`Failed to read directory ${folderPath}: ${error.message}`);
43
+ return [];
44
+ }
45
+ };
46
+
47
+ /**
48
+ * Counts files in a component directory
49
+ */
50
+ const countComponentFiles = (componentPath) => {
51
+ try {
52
+ if (!fs.existsSync(componentPath)) return 0;
53
+ const files = fs.readdirSync(componentPath);
54
+ return files.filter(f => fs.statSync(path.join(componentPath, f)).isFile()).length;
55
+ } catch {
56
+ return 0;
57
+ }
58
+ };
59
+
60
+ /**
61
+ * Gets components dynamically from sliceConfig.json
62
+ * @returns {object} - Component mapping with their category
63
+ */
64
+ const getComponents = () => {
65
+ const config = loadConfig();
66
+ if (!config) return {};
67
+
68
+ const folderSuffix = 'src'; // Always use 'src' for development
69
+ const componentPaths = config.paths?.components || {};
70
+ let allComponents = new Map();
71
+
72
+ Object.entries(componentPaths).forEach(([category, { path: folderPath }]) => {
73
+ const cleanFolderPath = folderPath ? folderPath.replace(/^[/\\]+/, '') : '';
74
+ const fullPath = getSrcPath(import.meta.url, cleanFolderPath);
75
+ const files = listComponents(fullPath);
76
+
77
+ files.forEach(file => {
78
+ const componentPath = path.join(fullPath, file);
79
+ if (fs.statSync(componentPath).isDirectory()) {
80
+ const fileCount = countComponentFiles(componentPath);
81
+ allComponents.set(file, { category, files: fileCount });
82
+ }
83
+ });
84
+ });
85
+
86
+ return Object.fromEntries(allComponents);
87
+ };
88
+
89
+ function listComponentsReal() {
90
+ try {
91
+ // Get components dynamically
92
+ const components = getComponents();
93
+
94
+ if (Object.keys(components).length === 0) {
95
+ Print.warning('No components found in your project');
96
+ Print.info('Create your first component with "slice component create"');
97
+ return;
98
+ }
99
+
100
+ // Create table with cli-table3
101
+ const table = new Table({
102
+ head: [
103
+ chalk.cyan.bold('Component'),
104
+ chalk.cyan.bold('Category'),
105
+ chalk.cyan.bold('Files')
106
+ ],
107
+ colWidths: [30, 20, 10],
108
+ style: {
109
+ head: [],
110
+ border: ['gray']
111
+ }
112
+ });
113
+
114
+ // Group by category for better visualization
115
+ const byCategory = {};
116
+ Object.entries(components).forEach(([name, data]) => {
117
+ if (!byCategory[data.category]) {
118
+ byCategory[data.category] = [];
119
+ }
120
+ byCategory[data.category].push({ name, files: data.files });
121
+ });
122
+
123
+ // Add rows to the table
124
+ Object.entries(byCategory).forEach(([category, comps]) => {
125
+ comps.forEach((comp, index) => {
126
+ if (index === 0) {
127
+ // First row of the category
128
+ table.push([
129
+ chalk.bold(comp.name),
130
+ chalk.yellow(category),
131
+ comp.files.toString()
132
+ ]);
133
+ } else {
134
+ // Rest of components in the category
135
+ table.push([
136
+ chalk.bold(comp.name),
137
+ chalk.gray('″'), // Ditto mark
138
+ comp.files.toString()
139
+ ]);
140
+ }
141
+ });
142
+ });
143
+
144
+ Print.newLine();
145
+ Print.title('📦 Local Components');
146
+ Print.newLine();
147
+ console.log(table.toString());
148
+ Print.newLine();
149
+ Print.info(`Total: ${Object.keys(components).length} component${Object.keys(components).length !== 1 ? 's' : ''} found`);
150
+
151
+ // Path where components.js will be generated
152
+ const outputPath = getComponentsJsPath(import.meta.url);
153
+
154
+ // Ensure the directory exists
155
+ const outputDir = path.dirname(outputPath);
156
+ if (!fs.existsSync(outputDir)) {
157
+ fs.mkdirSync(outputDir, { recursive: true });
158
+ }
159
+
160
+ // Generate components.js file with detected components
161
+ const componentsForExport = Object.fromEntries(
162
+ Object.entries(components).map(([name, data]) => [name, data.category])
163
+ );
164
+ fs.writeFileSync(outputPath, `const components = ${JSON.stringify(componentsForExport, null, 2)};\n\nexport default components;\n`);
165
+
166
+ } catch (error) {
167
+ Print.error(`Failed to list components: ${error.message}`);
168
+ Print.info('Make sure your project structure is correct');
169
+ }
170
+ }
171
+
172
+ export default listComponentsReal;
@@ -0,0 +1,91 @@
1
+ // slice seo check — the strict, exit-code-1 gate for CI:
2
+ // 1. validates seo.json (same validator the server uses),
3
+ // 2. cross-checks it against routes.js,
4
+ // 3. compares the committed sitemap against what the manifest would produce.
5
+ //
6
+ // `slice doctor` reports the same information in a friendlier table; this one
7
+ // is meant to fail a pipeline.
8
+
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { pathToFileURL } from 'node:url';
12
+ import Print from '../Print.js';
13
+ import {
14
+ MANIFEST_FILE,
15
+ SITEMAP_FILE,
16
+ loadFrameworkSeo,
17
+ loadManifest
18
+ } from './support.js';
19
+
20
+ export async function loadRoutes(projectRoot) {
21
+ const candidates = [
22
+ path.join(projectRoot, 'src', 'routes.js'),
23
+ path.join(projectRoot, 'dist', 'routes.js')
24
+ ];
25
+ for (const candidate of candidates) {
26
+ if (!fs.existsSync(candidate)) continue;
27
+ const module = await import(pathToFileURL(candidate).href);
28
+ const routes = module.default ?? module.routes ?? [];
29
+ return Array.isArray(routes) ? routes : [];
30
+ }
31
+ return [];
32
+ }
33
+
34
+ /** @returns {Promise<{ errors: string[], warnings: string[], sitemap: string }>} */
35
+ export async function checkSeo(options = {}) {
36
+ const { projectRoot } = options;
37
+ const framework = options.framework || await loadFrameworkSeo(projectRoot);
38
+ const manifest = options.manifest || loadManifest(projectRoot).manifest;
39
+
40
+ if (!manifest) {
41
+ return { errors: [`${MANIFEST_FILE} not found in ${projectRoot}`], warnings: [], sitemap: 'missing' };
42
+ }
43
+
44
+ const routes = options.routes || await loadRoutes(projectRoot);
45
+ const { errors, warnings } = framework.validateSeoManifest(manifest, {
46
+ routes,
47
+ publicDir: path.join(projectRoot, 'src', 'public')
48
+ });
49
+
50
+ let sitemap = 'ok';
51
+ if (manifest.sitemap === false) {
52
+ sitemap = 'disabled';
53
+ } else {
54
+ const file = path.join(projectRoot, SITEMAP_FILE);
55
+ if (!fs.existsSync(file)) {
56
+ sitemap = 'missing';
57
+ errors.push(`${SITEMAP_FILE} is missing: run \`slice seo sitemap\``);
58
+ } else {
59
+ const origin = framework.normalizeOrigin(manifest.origin);
60
+ const expected = origin ? framework.buildSitemap({ manifest, origin }) : null;
61
+ if (expected !== null && fs.readFileSync(file, 'utf8') !== expected) {
62
+ sitemap = 'drifted';
63
+ errors.push(`${SITEMAP_FILE} is out of date: run \`slice seo sitemap\``);
64
+ }
65
+ }
66
+ }
67
+
68
+ return { errors, warnings, sitemap, routes: routes.length };
69
+ }
70
+
71
+ export default async function checkCommand(options = {}, projectRoot) {
72
+ try {
73
+ const result = await checkSeo({ projectRoot, ...options });
74
+
75
+ for (const warning of result.warnings) Print.warning(warning);
76
+
77
+ if (result.errors.length) {
78
+ for (const error of result.errors) Print.error(error);
79
+ Print.error(`SEO check failed: ${result.errors.length} problem(s).`);
80
+ process.exitCode = 1;
81
+ return;
82
+ }
83
+
84
+ Print.success(
85
+ `SEO OK: sitemap ${result.sitemap}, ${result.routes} route(s) cross-checked.`
86
+ );
87
+ } catch (error) {
88
+ Print.error('slice seo check failed:', error.message);
89
+ process.exitCode = 1;
90
+ }
91
+ }