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/client.js
CHANGED
|
@@ -12,6 +12,8 @@ import runDiagnostics from "./commands/doctor/doctor.js";
|
|
|
12
12
|
import seoCheck from "./commands/seo/check.js";
|
|
13
13
|
import seoSitemap from "./commands/seo/sitemap.js";
|
|
14
14
|
import seoImages from "./commands/seo/images.js";
|
|
15
|
+
import translatorCheck from "./commands/translator/check.js";
|
|
16
|
+
import translatorInit from "./commands/translator/init.js";
|
|
15
17
|
import versionChecker from "./commands/utils/VersionChecker.js";
|
|
16
18
|
import updateManager from "./commands/utils/updateManager.js";
|
|
17
19
|
import fs from "fs";
|
|
@@ -22,12 +24,27 @@ import { loadConfigSync as sharedLoadConfigSync } from "./commands/utils/loadCon
|
|
|
22
24
|
import { spawnSync } from "node:child_process";
|
|
23
25
|
import validations from "./commands/Validations.js";
|
|
24
26
|
import Print from "./commands/Print.js";
|
|
25
|
-
import build from './commands/build/build.js';
|
|
26
|
-
import
|
|
27
|
-
import
|
|
27
|
+
import build from './commands/build/build.js';
|
|
28
|
+
import exportStatic from './commands/export/export.js';
|
|
29
|
+
import lintCommand from './commands/lint/lint.js';
|
|
30
|
+
import typecheckCommand from './commands/typecheck/typecheck.js';
|
|
28
31
|
import setupLintCommand from './commands/setup/lint.js';
|
|
29
32
|
import { runGenerateTypes } from './commands/types/types.js';
|
|
30
33
|
import { runDocsGet, runDocsList, runDocsSearch } from './commands/docs/docs.js';
|
|
34
|
+
import { checkDocs, generateDocs, hasDocumentationScaffold } from './commands/docs/index.js';
|
|
35
|
+
|
|
36
|
+
async function syncAgentDocs() {
|
|
37
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
38
|
+
if (!(await hasDocumentationScaffold(projectRoot))) return;
|
|
39
|
+
try {
|
|
40
|
+
await generateDocs({
|
|
41
|
+
projectRoot,
|
|
42
|
+
target: 'agents',
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
Print.warning(`Could not update AGENTS.md: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
31
48
|
import { cleanBundles, bundleInfo } from './commands/bundle/bundle.js';
|
|
32
49
|
import {
|
|
33
50
|
isLocalDelegationDisabled,
|
|
@@ -67,7 +84,6 @@ function parsePort(value) {
|
|
|
67
84
|
async function withNodeEnv(env, fn) {
|
|
68
85
|
const prevEnv = process.env.NODE_ENV;
|
|
69
86
|
process.env.NODE_ENV = env;
|
|
70
|
-
listComponents();
|
|
71
87
|
try {
|
|
72
88
|
return await fn();
|
|
73
89
|
} finally {
|
|
@@ -99,7 +115,7 @@ async function runWithVersionCheck(commandFunction, ...args) {
|
|
|
99
115
|
return result;
|
|
100
116
|
} catch (error) {
|
|
101
117
|
Print.error(`Command execution: ${error.message}`);
|
|
102
|
-
|
|
118
|
+
Print.stack(error);
|
|
103
119
|
// A command that threw must not report success. This used to swallow the
|
|
104
120
|
// error and return normally, so `slice build` printed a red failure and
|
|
105
121
|
// still exited 0 — CI read that as a passing build and shipped it.
|
|
@@ -151,15 +167,15 @@ try {
|
|
|
151
167
|
const pkgPath = path.join(__dirname, "./package.json");
|
|
152
168
|
const pkgRaw = fs.readFileSync(pkgPath, "utf-8");
|
|
153
169
|
const pkg = JSON.parse(pkgRaw);
|
|
154
|
-
sliceClient.version(pkg.version).description("
|
|
170
|
+
sliceClient.name("slice").version(pkg.version).description("Build, run and maintain Slice.js projects");
|
|
155
171
|
} catch {
|
|
156
|
-
sliceClient.version("0.0.0").description("
|
|
172
|
+
sliceClient.name("slice").version("0.0.0").description("Build, run and maintain Slice.js projects");
|
|
157
173
|
}
|
|
158
174
|
|
|
159
175
|
// INIT COMMAND
|
|
160
176
|
sliceClient
|
|
161
177
|
.command("init")
|
|
162
|
-
.description("
|
|
178
|
+
.description("Create a new Slice.js project")
|
|
163
179
|
.argument("[name]", "Project name (defaults to my-slice-app)")
|
|
164
180
|
.option("-y, --yes", "Skip prompts")
|
|
165
181
|
.option("--pm <packageManager>", "Package manager to use (pnpm or npm). Auto-detected when omitted")
|
|
@@ -275,7 +291,7 @@ sliceClient
|
|
|
275
291
|
|
|
276
292
|
// BUILD COMMAND
|
|
277
293
|
const buildCommand = sliceClient.command("build")
|
|
278
|
-
.description("Build
|
|
294
|
+
.description("Build for production")
|
|
279
295
|
.action(async (options) => {
|
|
280
296
|
await withNodeEnv('production', () => runWithVersionCheck(async () => {
|
|
281
297
|
// build() reports failure by returning false (degraded files, missing
|
|
@@ -319,10 +335,38 @@ buildCommand
|
|
|
319
335
|
.option("--compress", "Precompress dist assets to .gz and .br (brotli) for static serving")
|
|
320
336
|
.option("--skip-clean", "Skip cleaning dist before build");
|
|
321
337
|
|
|
338
|
+
// EXPORT COMMAND - STATIC HOST PACKAGE (experimental)
|
|
339
|
+
sliceClient
|
|
340
|
+
.command("export")
|
|
341
|
+
.description("Package the production build for a static host (experimental)")
|
|
342
|
+
.option("-o, --out <dir>", "Output directory", "dist-static")
|
|
343
|
+
.option("--from-dist", "Reuse dist/ instead of running a build")
|
|
344
|
+
.option("--host <name>", "Host rules: cloudflare, netlify, vercel, nginx, github, s3, none (default: cloudflare)")
|
|
345
|
+
.option("--seo <file>", "SEO manifest (auto-detected: seo.json / public/seo.json)")
|
|
346
|
+
.option("--origin <url>", "Canonical origin override for prerendered pages")
|
|
347
|
+
.option("--images <file>", "Social card manifest (auto-detected: public/og/manifest.json)")
|
|
348
|
+
.option("--no-prerender", "Only the SPA shell and host rules")
|
|
349
|
+
.option("--spa", "Serve unknown routes with index.html (SPA fallback)")
|
|
350
|
+
.option("--keep-components", "Keep /Components in the export (component source is fetchable)")
|
|
351
|
+
.option("--check", "Validate an existing export without writing")
|
|
352
|
+
.option("--dry-run", "Report what would be written without writing")
|
|
353
|
+
.option("--sourcemap", "Emit source maps (not recommended for a public export)")
|
|
354
|
+
.option("--hash-filenames", "Add a content hash to bundle filenames")
|
|
355
|
+
.option("--compress", "Precompress dist assets (delegated to build)")
|
|
356
|
+
.option("--no-minify", "Disable minification (enabled by default)")
|
|
357
|
+
.option("--no-obfuscate", "Disable obfuscation (enabled by default)")
|
|
358
|
+
.action(async (options) => {
|
|
359
|
+
await withNodeEnv('production', () => runWithVersionCheck(async () => {
|
|
360
|
+
const ok = await exportStatic(options);
|
|
361
|
+
if (ok === false) process.exitCode = 1;
|
|
362
|
+
return ok;
|
|
363
|
+
}));
|
|
364
|
+
});
|
|
365
|
+
|
|
322
366
|
// DEV COMMAND (DEVELOPMENT)
|
|
323
367
|
sliceClient
|
|
324
368
|
.command("dev")
|
|
325
|
-
.description("Start development server
|
|
369
|
+
.description("Start the development server")
|
|
326
370
|
.option("-p, --port <port>", "Port for development server")
|
|
327
371
|
.option("--no-hmr", "Disable hot module reload (enabled by default)")
|
|
328
372
|
.action(async (options) => {
|
|
@@ -338,7 +382,7 @@ sliceClient
|
|
|
338
382
|
// START COMMAND - PRODUCTION MODE
|
|
339
383
|
sliceClient
|
|
340
384
|
.command("start")
|
|
341
|
-
.description("Serve production
|
|
385
|
+
.description("Serve the production build")
|
|
342
386
|
.option("-p, --port <port>", "Port for server")
|
|
343
387
|
.action(async (options) => {
|
|
344
388
|
await withNodeEnv('production', () => runWithVersionCheck(async () => {
|
|
@@ -350,13 +394,13 @@ sliceClient
|
|
|
350
394
|
});
|
|
351
395
|
|
|
352
396
|
// COMPONENT COMMAND GROUP - For local component management
|
|
353
|
-
const componentCommand = sliceClient.command("component").alias("comp").description("Manage
|
|
397
|
+
const componentCommand = sliceClient.command("component").alias("comp").description("Manage project components");
|
|
354
398
|
|
|
355
399
|
// CREATE LOCAL COMPONENT
|
|
356
400
|
componentCommand
|
|
357
401
|
.command("create [name]")
|
|
358
402
|
.alias("new")
|
|
359
|
-
.description("Create a
|
|
403
|
+
.description("Create a component")
|
|
360
404
|
.option("-c, --category <category>", "Component category (e.g. Visual, Service, AppComponents). Skips the prompt when provided.")
|
|
361
405
|
.action(async (name, options) => {
|
|
362
406
|
await runWithVersionCheck(async () => {
|
|
@@ -408,8 +452,8 @@ componentCommand
|
|
|
408
452
|
const result = createComponent(componentName, category);
|
|
409
453
|
if (result) {
|
|
410
454
|
Print.success(`Component '${componentName}' created successfully in category '${category}'`);
|
|
411
|
-
|
|
412
|
-
|
|
455
|
+
listComponents({ category });
|
|
456
|
+
await syncAgentDocs();
|
|
413
457
|
}
|
|
414
458
|
});
|
|
415
459
|
});
|
|
@@ -418,10 +462,13 @@ componentCommand
|
|
|
418
462
|
componentCommand
|
|
419
463
|
.command("list")
|
|
420
464
|
.alias("ls")
|
|
421
|
-
.description("List
|
|
422
|
-
.
|
|
465
|
+
.description("List local components")
|
|
466
|
+
.option("-a, --all", "List every component, not just a category summary")
|
|
467
|
+
.option("-c, --category <category>", "Only one category")
|
|
468
|
+
.option("--json", "Print machine-readable JSON")
|
|
469
|
+
.action(async (options) => {
|
|
423
470
|
await runWithVersionCheck(() => {
|
|
424
|
-
listComponents();
|
|
471
|
+
listComponents(options);
|
|
425
472
|
return Promise.resolve();
|
|
426
473
|
});
|
|
427
474
|
});
|
|
@@ -430,7 +477,7 @@ componentCommand
|
|
|
430
477
|
componentCommand
|
|
431
478
|
.command("delete [name]")
|
|
432
479
|
.alias("remove")
|
|
433
|
-
.description("Delete a component
|
|
480
|
+
.description("Delete a component")
|
|
434
481
|
.option("-c, --category <category>", "Component category. Skips the category prompt when provided.")
|
|
435
482
|
.option("-y, --yes", "Skip the confirmation prompt (for non-interactive use)")
|
|
436
483
|
.action(async (name, options) => {
|
|
@@ -521,8 +568,8 @@ componentCommand
|
|
|
521
568
|
// deleteComponent validates the name/category and that the component exists.
|
|
522
569
|
if (deleteComponent(componentName, category)) {
|
|
523
570
|
Print.success(`Component ${componentName} deleted successfully`);
|
|
524
|
-
|
|
525
|
-
|
|
571
|
+
listComponents({ category });
|
|
572
|
+
await syncAgentDocs();
|
|
526
573
|
}
|
|
527
574
|
} catch (error) {
|
|
528
575
|
Print.error(`Deleting component: ${error.message}`);
|
|
@@ -531,10 +578,10 @@ componentCommand
|
|
|
531
578
|
});
|
|
532
579
|
|
|
533
580
|
// REGISTRY COMMAND GROUP - For component registry operations
|
|
534
|
-
const registryCommand = sliceClient.command("registry").alias("reg").description("Manage components
|
|
581
|
+
const registryCommand = sliceClient.command("registry").alias("reg").description("Manage registry components");
|
|
535
582
|
|
|
536
583
|
// SKILL COMMAND GROUP - Claude Code skill fetched from the docs repo
|
|
537
|
-
const skillCommand = sliceClient.command("skill").description("Manage the
|
|
584
|
+
const skillCommand = sliceClient.command("skill").description("Manage the developer skill");
|
|
538
585
|
|
|
539
586
|
skillCommand
|
|
540
587
|
.command("add")
|
|
@@ -548,7 +595,7 @@ skillCommand
|
|
|
548
595
|
});
|
|
549
596
|
|
|
550
597
|
// DOCUMENTATION COMMAND GROUP - Framework and Slice.js Components docs
|
|
551
|
-
const docsCommand = sliceClient.command("docs").description("Search and
|
|
598
|
+
const docsCommand = sliceClient.command("docs").description("Search docs and generate project documentation");
|
|
552
599
|
|
|
553
600
|
docsCommand
|
|
554
601
|
.command("list")
|
|
@@ -586,6 +633,33 @@ docsCommand
|
|
|
586
633
|
});
|
|
587
634
|
});
|
|
588
635
|
|
|
636
|
+
docsCommand
|
|
637
|
+
.command("generate [target]")
|
|
638
|
+
.description("Generate project documentation: all, agents, types, or events")
|
|
639
|
+
.option("-o, --output <path>", "Custom types output path", "src/slice-build.generated.d.ts")
|
|
640
|
+
.action(async (target, options) => {
|
|
641
|
+
await runWithVersionCheck(async () => {
|
|
642
|
+
await generateDocs({
|
|
643
|
+
projectRoot: getProjectRoot(import.meta.url),
|
|
644
|
+
target: target || 'all',
|
|
645
|
+
outputPath: options.output,
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
docsCommand
|
|
651
|
+
.command("check [target]")
|
|
652
|
+
.description("Check generated project documentation for drift: all, agents, types, or events")
|
|
653
|
+
.action(async (target) => {
|
|
654
|
+
await runWithVersionCheck(async () => {
|
|
655
|
+
const result = await checkDocs({
|
|
656
|
+
projectRoot: getProjectRoot(import.meta.url),
|
|
657
|
+
target: target || 'all',
|
|
658
|
+
});
|
|
659
|
+
if (!result.ok) process.exitCode = 1;
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
|
|
589
663
|
skillCommand
|
|
590
664
|
.command("update")
|
|
591
665
|
.description("Update the installed skill to the latest compatible version")
|
|
@@ -605,7 +679,7 @@ skillCommand
|
|
|
605
679
|
});
|
|
606
680
|
|
|
607
681
|
// TYPES COMMAND GROUP - TypeScript declarations from static props
|
|
608
|
-
const typesCommand = sliceClient.command("types").description("Generate TypeScript declarations
|
|
682
|
+
const typesCommand = sliceClient.command("types").description("Generate TypeScript declarations");
|
|
609
683
|
|
|
610
684
|
typesCommand
|
|
611
685
|
.command("generate")
|
|
@@ -628,7 +702,7 @@ typesCommand
|
|
|
628
702
|
// GET COMPONENTS FROM REGISTRY
|
|
629
703
|
registryCommand
|
|
630
704
|
.command("get [components...]")
|
|
631
|
-
.description("
|
|
705
|
+
.description("Install components from the registry")
|
|
632
706
|
.option("-f, --force", "Force overwrite existing components")
|
|
633
707
|
.option("-s, --service", "Install Service components instead of Visual")
|
|
634
708
|
.option("--no-deps", "Do not resolve and install component dependencies")
|
|
@@ -639,6 +713,7 @@ registryCommand
|
|
|
639
713
|
service: options.service,
|
|
640
714
|
deps: options.deps
|
|
641
715
|
});
|
|
716
|
+
await syncAgentDocs();
|
|
642
717
|
});
|
|
643
718
|
});
|
|
644
719
|
|
|
@@ -646,7 +721,7 @@ registryCommand
|
|
|
646
721
|
registryCommand
|
|
647
722
|
.command("list")
|
|
648
723
|
.alias("ls")
|
|
649
|
-
.description("List
|
|
724
|
+
.description("List registry components")
|
|
650
725
|
.action(async () => {
|
|
651
726
|
await runWithVersionCheck(async () => {
|
|
652
727
|
await listRemoteComponents();
|
|
@@ -656,20 +731,21 @@ registryCommand
|
|
|
656
731
|
// SYNC COMPONENTS FROM REGISTRY
|
|
657
732
|
registryCommand
|
|
658
733
|
.command("sync")
|
|
659
|
-
.description("Update
|
|
734
|
+
.description("Update installed components")
|
|
660
735
|
.option("-f, --force", "Force update without confirmation")
|
|
661
736
|
.action(async (options) => {
|
|
662
737
|
await runWithVersionCheck(async () => {
|
|
663
738
|
await syncComponents({
|
|
664
739
|
force: options.force
|
|
665
740
|
});
|
|
741
|
+
await syncAgentDocs();
|
|
666
742
|
});
|
|
667
743
|
});
|
|
668
744
|
|
|
669
745
|
// SHORTCUTS - Top-level convenient commands
|
|
670
746
|
sliceClient
|
|
671
747
|
.command("get [components...]")
|
|
672
|
-
.description("
|
|
748
|
+
.description("Install components from the registry")
|
|
673
749
|
.option("-f, --force", "Force overwrite existing components")
|
|
674
750
|
.option("-s, --service", "Install Service components instead of Visual")
|
|
675
751
|
.option("--no-deps", "Do not resolve and install component dependencies")
|
|
@@ -688,12 +764,13 @@ sliceClient
|
|
|
688
764
|
service: options.service,
|
|
689
765
|
deps: options.deps
|
|
690
766
|
});
|
|
767
|
+
await syncAgentDocs();
|
|
691
768
|
});
|
|
692
769
|
});
|
|
693
770
|
|
|
694
771
|
sliceClient
|
|
695
772
|
.command("browse")
|
|
696
|
-
.description("
|
|
773
|
+
.description("Browse registry components")
|
|
697
774
|
.action(async () => {
|
|
698
775
|
await runWithVersionCheck(async () => {
|
|
699
776
|
await listRemoteComponents();
|
|
@@ -702,23 +779,27 @@ sliceClient
|
|
|
702
779
|
|
|
703
780
|
sliceClient
|
|
704
781
|
.command("sync")
|
|
705
|
-
.description("
|
|
782
|
+
.description("Update installed components")
|
|
706
783
|
.option("-f, --force", "Force update without confirmation")
|
|
707
784
|
.action(async (options) => {
|
|
708
785
|
await runWithVersionCheck(async () => {
|
|
709
786
|
await syncComponents({
|
|
710
787
|
force: options.force
|
|
711
788
|
});
|
|
789
|
+
await syncAgentDocs();
|
|
712
790
|
});
|
|
713
791
|
});
|
|
714
792
|
|
|
715
793
|
// LIST COMMAND - Quick shortcut for listing local components
|
|
716
794
|
sliceClient
|
|
717
795
|
.command("list")
|
|
718
|
-
.description("
|
|
719
|
-
.
|
|
796
|
+
.description("List local components")
|
|
797
|
+
.option("-a, --all", "List every component, not just a category summary")
|
|
798
|
+
.option("-c, --category <category>", "Only one category")
|
|
799
|
+
.option("--json", "Print machine-readable JSON")
|
|
800
|
+
.action(async (options) => {
|
|
720
801
|
await runWithVersionCheck(() => {
|
|
721
|
-
listComponents();
|
|
802
|
+
listComponents(options);
|
|
722
803
|
return Promise.resolve();
|
|
723
804
|
});
|
|
724
805
|
});
|
|
@@ -727,59 +808,59 @@ sliceClient
|
|
|
727
808
|
sliceClient
|
|
728
809
|
.command("doctor")
|
|
729
810
|
.alias("diagnose")
|
|
730
|
-
.description("
|
|
811
|
+
.description("Check project health")
|
|
731
812
|
.action(async () => {
|
|
732
813
|
await runWithVersionCheck(async () => {
|
|
733
814
|
await runDiagnostics();
|
|
734
815
|
});
|
|
735
816
|
});
|
|
736
817
|
|
|
737
|
-
// LINT COMMAND - runs the project's ESLint, with the shared config available
|
|
738
|
-
// as `slicejs-cli/eslint-config.js`. The CLI does not bundle ESLint itself.
|
|
739
|
-
sliceClient
|
|
740
|
-
.command("lint [paths...]")
|
|
741
|
-
.description("Run ESLint in this project")
|
|
742
|
-
.option("--fix", "Apply automatic fixes")
|
|
743
|
-
.option("--no-types", "Do not refresh the generated declarations")
|
|
744
|
-
.action(async (paths, options) => {
|
|
745
|
-
await runWithVersionCheck(async () => {
|
|
746
|
-
await lintCommand({ paths, fix: options.fix, types: options.types }, getProjectRoot(import.meta.url));
|
|
747
|
-
});
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
const setupCommand = sliceClient
|
|
751
|
-
.command("setup")
|
|
752
|
-
.description("Add optional tooling to an existing project");
|
|
753
|
-
|
|
754
|
-
setupCommand
|
|
755
|
-
.command("lint")
|
|
756
|
-
.description("Install ESLint and add the shared Slice config")
|
|
757
|
-
.option("--dry-run", "Show what would change, write nothing")
|
|
758
|
-
.option("--with-types", "Also install TypeScript and add a typecheck script")
|
|
759
|
-
.action(async (options) => {
|
|
760
|
-
await runWithVersionCheck(async () => {
|
|
761
|
-
await setupLintCommand(options, getProjectRoot(import.meta.url));
|
|
762
|
-
});
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
// TYPECHECK COMMAND - the compiler step. ESLint does not type-check; this runs
|
|
766
|
-
// the project tsc over the jsconfig that `slice types generate` maintains.
|
|
767
|
-
sliceClient
|
|
768
|
-
.command("typecheck")
|
|
769
|
-
.description("Type-check the project with its own TypeScript (jsconfig.json)")
|
|
770
|
-
.option("-p, --project <path>", "Config file (default: jsconfig.json, then tsconfig.json)")
|
|
771
|
-
.option("--no-types", "Do not refresh the generated declarations")
|
|
772
|
-
.action(async (options) => {
|
|
773
|
-
await runWithVersionCheck(async () => {
|
|
774
|
-
await typecheckCommand(options, getProjectRoot(import.meta.url));
|
|
775
|
-
});
|
|
776
|
-
});
|
|
777
|
-
|
|
818
|
+
// LINT COMMAND - runs the project's ESLint, with the shared config available
|
|
819
|
+
// as `slicejs-cli/eslint-config.js`. The CLI does not bundle ESLint itself.
|
|
820
|
+
sliceClient
|
|
821
|
+
.command("lint [paths...]")
|
|
822
|
+
.description("Run ESLint in this project")
|
|
823
|
+
.option("--fix", "Apply automatic fixes")
|
|
824
|
+
.option("--no-types", "Do not refresh the generated declarations")
|
|
825
|
+
.action(async (paths, options) => {
|
|
826
|
+
await runWithVersionCheck(async () => {
|
|
827
|
+
await lintCommand({ paths, fix: options.fix, types: options.types }, getProjectRoot(import.meta.url));
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
const setupCommand = sliceClient
|
|
832
|
+
.command("setup")
|
|
833
|
+
.description("Add optional tooling to an existing project");
|
|
834
|
+
|
|
835
|
+
setupCommand
|
|
836
|
+
.command("lint")
|
|
837
|
+
.description("Install ESLint and add the shared Slice config")
|
|
838
|
+
.option("--dry-run", "Show what would change, write nothing")
|
|
839
|
+
.option("--with-types", "Also install TypeScript and add a typecheck script")
|
|
840
|
+
.action(async (options) => {
|
|
841
|
+
await runWithVersionCheck(async () => {
|
|
842
|
+
await setupLintCommand(options, getProjectRoot(import.meta.url));
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
// TYPECHECK COMMAND - the compiler step. ESLint does not type-check; this runs
|
|
847
|
+
// the project tsc over the jsconfig that `slice types generate` maintains.
|
|
848
|
+
sliceClient
|
|
849
|
+
.command("typecheck")
|
|
850
|
+
.description("Type-check the project with its own TypeScript (jsconfig.json)")
|
|
851
|
+
.option("-p, --project <path>", "Config file (default: jsconfig.json, then tsconfig.json)")
|
|
852
|
+
.option("--no-types", "Do not refresh the generated declarations")
|
|
853
|
+
.action(async (options) => {
|
|
854
|
+
await runWithVersionCheck(async () => {
|
|
855
|
+
await typecheckCommand(options, getProjectRoot(import.meta.url));
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
|
|
778
859
|
// SEO COMMANDS — the artifacts are committed, so they are written on demand and
|
|
779
860
|
// guarded in CI rather than generated at request time.
|
|
780
861
|
const seoCommand = sliceClient
|
|
781
862
|
.command("seo")
|
|
782
|
-
.description("SEO helpers
|
|
863
|
+
.description("SEO helpers");
|
|
783
864
|
|
|
784
865
|
seoCommand
|
|
785
866
|
.command("sitemap")
|
|
@@ -819,17 +900,46 @@ seoCommand
|
|
|
819
900
|
});
|
|
820
901
|
});
|
|
821
902
|
|
|
903
|
+
// TRANSLATOR COMMANDS - dictionaries, data-t templates and key() props.
|
|
904
|
+
const translatorCommand = sliceClient
|
|
905
|
+
.command("translator")
|
|
906
|
+
.alias("i18n")
|
|
907
|
+
.description("Translator helpers");
|
|
908
|
+
|
|
909
|
+
translatorCommand
|
|
910
|
+
.command("init")
|
|
911
|
+
.description("Add the translator block to sliceConfig.json and create src/locales/<locale>.json")
|
|
912
|
+
.option("--locales <list>", "comma-separated locales", "en")
|
|
913
|
+
.option("--default <locale>", "default locale (default: the first of --locales)")
|
|
914
|
+
.option("--path <path>", "dictionary folder served by the app", "/locales")
|
|
915
|
+
.option("--dry-run", "show what would change, write nothing")
|
|
916
|
+
.action(async (options) => {
|
|
917
|
+
await runWithVersionCheck(async () => {
|
|
918
|
+
await translatorInit(options, getProjectRoot(import.meta.url));
|
|
919
|
+
});
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
translatorCommand
|
|
923
|
+
.command("check")
|
|
924
|
+
.description("Verify every data-t / slice.t() key exists in every locale")
|
|
925
|
+
.option("--unused", "also report dictionary keys no template or call uses")
|
|
926
|
+
.action(async (options) => {
|
|
927
|
+
await runWithVersionCheck(async () => {
|
|
928
|
+
await translatorCheck(options, getProjectRoot(import.meta.url));
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
|
|
822
932
|
// POSTINSTALL COMMAND - Configure npm scripts in existing project
|
|
823
933
|
sliceClient
|
|
824
934
|
.command("postinstall")
|
|
825
|
-
.description("
|
|
935
|
+
.description("Add Slice scripts to package.json")
|
|
826
936
|
.action(() => {
|
|
827
937
|
const pnpmHome = process.env.PNPM_HOME;
|
|
828
938
|
const cliEntryPath = fileURLToPath(import.meta.url);
|
|
829
939
|
const isGlobal = process.env.npm_config_global === 'true'
|
|
830
940
|
|| (pnpmHome && cliEntryPath.startsWith(pnpmHome));
|
|
831
941
|
if (isGlobal) {
|
|
832
|
-
console.log('
|
|
942
|
+
console.log('Global installation of slicejs-cli detected.');
|
|
833
943
|
console.log(' We strongly recommend using a local installation to avoid version mismatches.');
|
|
834
944
|
console.log(` Uninstall global: ${pnpmHome ? 'pnpm remove -g slicejs-cli' : 'npm uninstall -g slicejs-cli'}`);
|
|
835
945
|
return;
|
|
@@ -864,10 +974,10 @@ sliceClient
|
|
|
864
974
|
}
|
|
865
975
|
|
|
866
976
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf-8');
|
|
867
|
-
console.log(
|
|
977
|
+
console.log(`slicejs-cli installed successfully. Added ${addedCount} package scripts to package.json.`);
|
|
868
978
|
console.log(` Run: ${runScriptCommand(packageManager, 'slice:dev')}`);
|
|
869
979
|
} catch (err) {
|
|
870
|
-
console.log('
|
|
980
|
+
console.log('slicejs-cli installed successfully.');
|
|
871
981
|
console.log(' Could not auto-configure scripts:', err.message);
|
|
872
982
|
console.log(` Configure scripts manually and run: ${runScriptCommand(packageManager, 'slice:dev')}`);
|
|
873
983
|
}
|
|
@@ -938,7 +1048,7 @@ program.on('command:*', () => {
|
|
|
938
1048
|
});
|
|
939
1049
|
|
|
940
1050
|
// HELP Command
|
|
941
|
-
const helpCommand = sliceClient.command("help").description("Display help
|
|
1051
|
+
const helpCommand = sliceClient.command("help").description("Display CLI help").action(() => {
|
|
942
1052
|
sliceClient.outputHelp();
|
|
943
1053
|
});
|
|
944
1054
|
|