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.
Files changed (51) hide show
  1. package/client.js +192 -82
  2. package/commands/Print.js +158 -164
  3. package/commands/build/build.js +27 -1
  4. package/commands/buildProduction/buildProduction.js +42 -71
  5. package/commands/bundle/bundle.js +65 -60
  6. package/commands/docs/agents.js +260 -0
  7. package/commands/docs/events.js +365 -0
  8. package/commands/docs/index.js +123 -0
  9. package/commands/doctor/doctor.js +99 -12
  10. package/commands/export/checkExport.js +163 -0
  11. package/commands/export/clientRedirects.js +72 -0
  12. package/commands/export/copyDist.js +180 -0
  13. package/commands/export/export.js +236 -0
  14. package/commands/export/files.js +33 -0
  15. package/commands/export/hosts/cloudflare.js +48 -0
  16. package/commands/export/hosts/github.js +31 -0
  17. package/commands/export/hosts/index.js +69 -0
  18. package/commands/export/hosts/netlify.js +42 -0
  19. package/commands/export/hosts/nginx.js +73 -0
  20. package/commands/export/hosts/none.js +23 -0
  21. package/commands/export/hosts/s3.js +24 -0
  22. package/commands/export/hosts/shared.js +62 -0
  23. package/commands/export/hosts/vercel.js +69 -0
  24. package/commands/export/outDir.js +91 -0
  25. package/commands/export/prerender.js +121 -0
  26. package/commands/getComponent/getComponent.js +44 -40
  27. package/commands/init/init.js +32 -22
  28. package/commands/lint/lint.js +2 -2
  29. package/commands/lint/types.js +1 -1
  30. package/commands/listComponents/listComponents.js +205 -172
  31. package/commands/seo/check.js +7 -4
  32. package/commands/seo/images.js +77 -22
  33. package/commands/seo/sitemap.js +6 -3
  34. package/commands/seo/support.js +62 -0
  35. package/commands/setup/lint.js +1 -1
  36. package/commands/skill/skill.js +2 -2
  37. package/commands/startServer/startServer.js +60 -21
  38. package/commands/startServer/watchServer.js +3 -3
  39. package/commands/translator/check.js +32 -0
  40. package/commands/translator/init.js +125 -0
  41. package/commands/translator/scan.js +444 -0
  42. package/commands/typecheck/typecheck.js +2 -2
  43. package/commands/types/types.js +22 -3
  44. package/commands/utils/VersionChecker.js +14 -14
  45. package/commands/utils/bundling/BundleGenerator.js +45 -27
  46. package/commands/utils/bundling/DependencyAnalyzer.js +1007 -976
  47. package/commands/utils/componentCatalog.js +120 -0
  48. package/commands/utils/publicEnv.js +74 -0
  49. package/commands/utils/sliceConfigSchema.js +34 -0
  50. package/commands/utils/updateManager.js +12 -12
  51. package/package.json +22 -23
@@ -0,0 +1,120 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+
4
+ const cleanCategoryPath = (value) =>
5
+ String(value || '').replace(/^[/\\]+/, '').replace(/[/\\]+$/, '');
6
+
7
+ export function getComponentCategories(config) {
8
+ const entries = Object.entries(config?.paths?.components || {});
9
+ return entries
10
+ .map(([name, meta]) => ({
11
+ name,
12
+ type: meta?.type || 'Visual',
13
+ path: meta?.path || `/Components/${name}`,
14
+ description: typeof meta?.description === 'string' ? meta.description : '',
15
+ }))
16
+ .sort((a, b) => a.name.localeCompare(b.name));
17
+ }
18
+
19
+ export async function loadProjectConfig(projectRoot) {
20
+ const configPath = path.join(projectRoot, 'src', 'sliceConfig.json');
21
+ if (!(await fs.pathExists(configPath))) {
22
+ throw new Error(`sliceConfig.json not found at ${configPath}`);
23
+ }
24
+ return fs.readJson(configPath);
25
+ }
26
+
27
+ export async function scanComponentCatalog({ projectRoot, config }) {
28
+ const categories = [];
29
+
30
+ for (const category of getComponentCategories(config)) {
31
+ const relativePath = path.posix.join('src', cleanCategoryPath(category.path));
32
+ const directory = path.join(projectRoot, 'src', cleanCategoryPath(category.path));
33
+ const components = [];
34
+
35
+ if (await fs.pathExists(directory)) {
36
+ const entries = await fs.readdir(directory, { withFileTypes: true });
37
+ for (const entry of entries) {
38
+ if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
39
+ const componentDir = path.join(directory, entry.name);
40
+ const files = await fs.readdir(componentDir, { withFileTypes: true });
41
+ const fileNames = files
42
+ .filter((file) => file.isFile())
43
+ .map((file) => file.name)
44
+ .sort((a, b) => a.localeCompare(b));
45
+ components.push({
46
+ name: entry.name,
47
+ category: category.name,
48
+ type: category.type,
49
+ directory: componentDir,
50
+ relativePath: path.posix.join(relativePath, entry.name),
51
+ fileCount: fileNames.length,
52
+ files: fileNames,
53
+ readme: fileNames.includes('README.md'),
54
+ spec: fileNames.some((name) => name.endsWith('.spec.js')),
55
+ });
56
+ }
57
+ }
58
+
59
+ components.sort((a, b) => a.name.localeCompare(b.name));
60
+ categories.push({ ...category, relativePath, directory, components });
61
+ }
62
+
63
+ const components = categories.flatMap((category) => category.components);
64
+ return { config, categories, components };
65
+ }
66
+
67
+ export function buildComponentsRegistry(catalog) {
68
+ const registry = {};
69
+ for (const component of catalog.components) registry[component.name] = component.category;
70
+ return Object.fromEntries(Object.entries(registry).sort(([a], [b]) => a.localeCompare(b)));
71
+ }
72
+
73
+ export function serializeComponentsRegistry(catalog) {
74
+ return `const components = ${JSON.stringify(buildComponentsRegistry(catalog), null, 2)};\n\nexport default components;\n`;
75
+ }
76
+
77
+ export async function writeComponentsRegistry(projectRoot, catalog) {
78
+ const outputPath = path.join(projectRoot, 'src', 'Components', 'components.js');
79
+ await fs.ensureDir(path.dirname(outputPath));
80
+ await fs.writeFile(outputPath, serializeComponentsRegistry(catalog), 'utf8');
81
+ return outputPath;
82
+ }
83
+
84
+ export async function syncComponentsRegistry(projectRoot) {
85
+ const config = await loadProjectConfig(projectRoot);
86
+ const catalog = await scanComponentCatalog({ projectRoot, config });
87
+ await writeComponentsRegistry(projectRoot, catalog);
88
+ return catalog;
89
+ }
90
+
91
+ export async function readComponentsRegistry(projectRoot) {
92
+ const registryPath = path.join(projectRoot, 'src', 'Components', 'components.js');
93
+ if (!(await fs.pathExists(registryPath))) return null;
94
+ const source = await fs.readFile(registryPath, 'utf8');
95
+ const match = source.match(/const components = ({[\s\S]*?});/);
96
+ if (!match) return null;
97
+ try {
98
+ return JSON.parse(match[1]);
99
+ } catch {
100
+ return null;
101
+ }
102
+ }
103
+
104
+ export function componentDocCommand(component) {
105
+ // Only the registry-owned categories publish component docs remotely.
106
+ // App categories (Domain, Core, Providers, AppComponents, DataDisplay…) are
107
+ // local and document themselves in a README next to the component.
108
+ if (!['Visual', 'Service'].includes(component.category)) return null;
109
+ const id = component.name
110
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
111
+ .replace(/[_\s]+/g, '-')
112
+ .toLowerCase();
113
+ return `slice docs get components:${id}`;
114
+ }
115
+
116
+ export function componentDocCell(component) {
117
+ if (component.readme) return `[README](./${component.name}/README.md)`;
118
+ const command = componentDocCommand(component);
119
+ return command ? `\`${command}\`` : '—';
120
+ }
@@ -0,0 +1,74 @@
1
+ // commands/utils/publicEnv.js
2
+ //
3
+ // One place for the build-time public environment. `slice build` writes both
4
+ // dist/slice-env.json (shared, auditable) and dist/slice-env.generated.js (the
5
+ // ESM shim the runtime imports). `slice export` copies them and `slice start`
6
+ // serves them as static files; no dynamic env endpoint is needed in production.
7
+ import fs from 'fs-extra';
8
+ import path from 'path';
9
+ import { createRequire } from 'node:module';
10
+ import { pathToFileURL } from 'node:url';
11
+
12
+ let resolverPromise;
13
+
14
+ /**
15
+ * Prefer the framework package export, but fall back to the package file path so
16
+ * an older framework release still works.
17
+ */
18
+ export async function loadPublicEnvResolver() {
19
+ if (!resolverPromise) {
20
+ resolverPromise = (async () => {
21
+ try {
22
+ return await import('slicejs-web-framework/api/framework/publicEnvResolver.js');
23
+ } catch {
24
+ const require = createRequire(import.meta.url);
25
+ const entry = require.resolve('slicejs-web-framework');
26
+ const packageRoot = path.resolve(path.dirname(entry), '..');
27
+ return import(pathToFileURL(path.join(packageRoot, 'api', 'framework', 'publicEnvResolver.js')).href);
28
+ }
29
+ })();
30
+ }
31
+ return resolverPromise;
32
+ }
33
+
34
+ export async function resolvePublicEnvPayload(projectRoot) {
35
+ const { resolvePublicEnv } = await loadPublicEnvResolver();
36
+ return resolvePublicEnv({
37
+ mode: 'production',
38
+ envFilePath: path.join(projectRoot, '.env')
39
+ });
40
+ }
41
+
42
+ /**
43
+ * Writes both env artifacts into `<outDir>` and returns the number of public keys.
44
+ * The JSON is the shared source of truth; the ESM shim exists because native JSON
45
+ * modules are not available in every browser/webview Slice supports.
46
+ */
47
+ export async function writeSliceEnv(outDir, projectRoot) {
48
+ const payload = await resolvePublicEnvPayload(projectRoot);
49
+ await writeSliceEnvPayload(outDir, payload);
50
+ return Object.keys(payload.env || {}).length;
51
+ }
52
+
53
+ export function renderSliceEnvModule(payload) {
54
+ return [
55
+ '// Generated by slice build. Do not edit.',
56
+ `const env = ${JSON.stringify(payload, null, 2)};`,
57
+ 'export default env;',
58
+ ''
59
+ ].join('\n');
60
+ }
61
+
62
+ export async function writeSliceEnvPayload(outDir, payload) {
63
+ await fs.ensureDir(outDir);
64
+ await fs.writeFile(
65
+ path.join(outDir, 'slice-env.json'),
66
+ `${JSON.stringify(payload, null, 2)}\n`,
67
+ 'utf8'
68
+ );
69
+ await fs.writeFile(
70
+ path.join(outDir, 'slice-env.generated.js'),
71
+ renderSliceEnvModule(payload),
72
+ 'utf8'
73
+ );
74
+ }
@@ -43,10 +43,27 @@ export function validateAgainstSchema(value, schema, at = 'sliceConfig') {
43
43
  }
44
44
  }
45
45
 
46
+ if (Object.prototype.hasOwnProperty.call(schema || {}, 'const') && value !== schema.const) {
47
+ issues.push({ path: at, message: `must be ${JSON.stringify(schema.const)}` });
48
+ }
49
+
46
50
  if (Array.isArray(schema?.enum) && !schema.enum.some((option) => option === value)) {
47
51
  issues.push({ path: at, message: `must be one of ${schema.enum.map((option) => JSON.stringify(option)).join(', ')}` });
48
52
  }
49
53
 
54
+ if (typeof value === 'string' && typeof schema?.minLength === 'number' && value.length < schema.minLength) {
55
+ issues.push({ path: at, message: `must be at least ${schema.minLength} character(s)` });
56
+ }
57
+
58
+ if (Array.isArray(value) && schema?.uniqueItems === true) {
59
+ const seen = new Set();
60
+ value.forEach((item, index) => {
61
+ const id = JSON.stringify(item);
62
+ if (seen.has(id)) issues.push({ path: `${at}[${index}]`, message: 'is duplicated (uniqueItems)' });
63
+ seen.add(id);
64
+ });
65
+ }
66
+
50
67
  for (const required of schema?.required || []) {
51
68
  if (value?.[required] === undefined) issues.push({ path: `${at}.${required}`, message: 'is required' });
52
69
  }
@@ -55,12 +72,29 @@ export function validateAgainstSchema(value, schema, at = 'sliceConfig') {
55
72
  for (const [key, child] of Object.entries(schema?.properties || {})) {
56
73
  if (value[key] !== undefined) issues.push(...validateAgainstSchema(value[key], child, `${at}.${key}`));
57
74
  }
75
+ if (schema?.additionalProperties === false) {
76
+ for (const key of Object.keys(value)) {
77
+ if (!Object.prototype.hasOwnProperty.call(schema.properties || {}, key)) {
78
+ issues.push({ path: `${at}.${key}`, message: 'is not a known option' });
79
+ }
80
+ }
81
+ }
58
82
  }
59
83
 
60
84
  if (Array.isArray(value) && schema?.items) {
61
85
  value.forEach((item, index) => issues.push(...validateAgainstSchema(item, schema.items, `${at}[${index}]`)));
62
86
  }
63
87
 
88
+ // Conditional schema (`if`/`then`/`else`), e.g. enabled: true requires defaultLocale.
89
+ if (schema?.if) {
90
+ const condition = validateAgainstSchema(value, schema.if, at);
91
+ if (condition.length === 0 && schema.then) {
92
+ issues.push(...validateAgainstSchema(value, schema.then, at));
93
+ } else if (condition.length > 0 && schema.else) {
94
+ issues.push(...validateAgainstSchema(value, schema.else, at));
95
+ }
96
+ }
97
+
64
98
  return issues;
65
99
  }
66
100
 
@@ -130,16 +130,16 @@ export class UpdateManager {
130
130
  }
131
131
 
132
132
  console.log('');
133
- Print.warning('📦 Available Updates:');
133
+ Print.subtitle('Available updates');
134
134
  console.log('');
135
135
 
136
136
  updateInfo.updates.forEach(pkg => {
137
- console.log(` ${pkg.type === 'cli' ? '🔧' : '⚡'} ${pkg.displayName}`);
137
+ console.log(` ${pkg.displayName}`);
138
138
  console.log(` ${pkg.current} → ${pkg.latest}`);
139
139
  });
140
140
 
141
141
  console.log('');
142
- console.log(' 📚 Changelog: https://github.com/VKneider/slice.js/releases');
142
+ console.log(' Changelog: https://github.com/VKneider/slice.js/releases');
143
143
  console.log('');
144
144
  }
145
145
 
@@ -296,7 +296,7 @@ export class UpdateManager {
296
296
  }
297
297
 
298
298
  if (updateInfo.allCurrent || !updateInfo.hasUpdates) {
299
- Print.success('✅ All components are up to date!');
299
+ Print.success('All components are up to date');
300
300
  // --update-api works even when no package update runs.
301
301
  if (options.updateApi) {
302
302
  await this.updateApiIndexIfNeeded(options);
@@ -318,7 +318,7 @@ export class UpdateManager {
318
318
  // Show plan and confirm installation if not auto-confirmed
319
319
  let plan = await this.buildUpdatePlan(packagesToUpdate);
320
320
  console.log('');
321
- Print.info('🧭 Update plan:');
321
+ Print.subtitle('Update plan');
322
322
  plan.forEach(item => {
323
323
  const where = item.target === 'global' ? 'GLOBAL' : 'PROJECT';
324
324
  console.log(` • ${item.package} → ${where}`);
@@ -341,7 +341,7 @@ export class UpdateManager {
341
341
  packagesToUpdate.push('slicejs-cli');
342
342
  plan = await this.buildUpdatePlan(packagesToUpdate);
343
343
  console.log('');
344
- Print.info('🧭 Updated plan:');
344
+ Print.subtitle('Updated plan');
345
345
  plan.forEach(item => {
346
346
  const where = item.target === 'global' ? 'GLOBAL' : 'PROJECT';
347
347
  console.log(` • ${item.package} → ${where}`);
@@ -373,7 +373,7 @@ export class UpdateManager {
373
373
  }
374
374
 
375
375
  console.log(''); // Line break
376
- Print.info('📥 Installing updates...');
376
+ Print.info('Installing updates...');
377
377
  console.log('');
378
378
 
379
379
  // Install updates
@@ -385,14 +385,14 @@ export class UpdateManager {
385
385
  const failCount = results.filter(r => !r.success).length;
386
386
 
387
387
  if (failCount === 0) {
388
- Print.success(`✅ ${successCount} package(s) updated successfully!`);
388
+ Print.success(`${successCount} package(s) updated`);
389
389
  } else {
390
- Print.warning(`⚠️ ${successCount} successful, ${failCount} failed`);
390
+ Print.warning(`${successCount} succeeded, ${failCount} failed`);
391
391
  }
392
392
 
393
393
  if (successCount > 0) {
394
394
  console.log('');
395
- Print.info('💡 It is recommended to restart the development server if it is running.');
395
+ Print.info('Restart the development server if it is running.');
396
396
  }
397
397
 
398
398
  const frameworkUpdated = results.find(r => r.packageName === 'slicejs-web-framework' && r.success);
@@ -425,7 +425,7 @@ export class UpdateManager {
425
425
  return;
426
426
  }
427
427
 
428
- Print.warning('⚠️ Detected changes in framework api/index.js.');
428
+ Print.warning('Detected changes in framework api/index.js.');
429
429
 
430
430
  // Overwriting api/index.js is opt-in: `--update-api` is the only way
431
431
  // to auto-confirm. `-y/--yes` deliberately does NOT imply it — the
@@ -457,7 +457,7 @@ export class UpdateManager {
457
457
  const backupPath = `${projectApiPath}.bak`;
458
458
  await fs.copy(projectApiPath, backupPath);
459
459
  await fs.writeFile(projectApiPath, frameworkContent, 'utf-8');
460
- Print.success('✅ api/index.js updated from framework template.');
460
+ Print.success('api/index.js updated from the framework template.');
461
461
  Print.info(`Backup created at ${backupPath}`);
462
462
  } catch (error) {
463
463
  Print.error(`Failed to update api/index.js: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "4.4.0",
3
+ "version": "4.6.0",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "bin": {
@@ -19,25 +19,6 @@
19
19
  "type": "git",
20
20
  "url": "https://github.com/vkneider/slicejs-cli.git"
21
21
  },
22
- "scripts": {
23
- "release:check": "node scripts/release-check.mjs",
24
- "slice:browse": "slice browse",
25
- "slice:build": "slice build",
26
- "slice:create": "slice component create",
27
- "slice:delete": "slice component delete",
28
- "slice:dev": "slice dev",
29
- "slice:doctor": "node ./node_modules/slicejs-cli/client.js doctor",
30
- "slice:get": "slice get",
31
- "slice:help": "node ./node_modules/slicejs-cli/client.js --help",
32
- "slice:init": "slice init",
33
- "slice:list": "slice component list",
34
- "slice:start": "slice start",
35
- "slice:sync": "slice sync",
36
- "slice:types": "slice types generate",
37
- "slice:version": "slice version",
38
- "test": "node --test",
39
- "lint": "node ./client.js lint"
40
- },
41
22
  "keywords": [
42
23
  "framework",
43
24
  "web",
@@ -50,7 +31,6 @@
50
31
  ],
51
32
  "author": "vkneider",
52
33
  "type": "module",
53
- "packageManager": "pnpm@11.1.1",
54
34
  "preferGlobal": false,
55
35
  "license": "ISC",
56
36
  "dependencies": {
@@ -68,11 +48,30 @@
68
48
  "html-minifier-terser": "^7.2.0",
69
49
  "inquirer": "^12.4.2",
70
50
  "ora": "^8.2.0",
71
- "slicejs-web-framework": "^4.0.2",
51
+ "slicejs-web-framework": "^4.3.0",
72
52
  "terser": "^5.43.1"
73
53
  },
74
54
  "devDependencies": {
75
55
  "@playwright/test": "^1.60.0",
76
56
  "eslint": "^9.39.5"
57
+ },
58
+ "scripts": {
59
+ "release:check": "node scripts/release-check.mjs",
60
+ "slice:browse": "slice browse",
61
+ "slice:build": "slice build",
62
+ "slice:create": "slice component create",
63
+ "slice:delete": "slice component delete",
64
+ "slice:dev": "slice dev",
65
+ "slice:doctor": "node ./node_modules/slicejs-cli/client.js doctor",
66
+ "slice:get": "slice get",
67
+ "slice:help": "node ./node_modules/slicejs-cli/client.js --help",
68
+ "slice:init": "slice init",
69
+ "slice:list": "slice component list",
70
+ "slice:start": "slice start",
71
+ "slice:sync": "slice sync",
72
+ "slice:types": "slice types generate",
73
+ "slice:version": "slice version",
74
+ "test": "node --test",
75
+ "lint": "node ./client.js lint"
77
76
  }
78
- }
77
+ }