intor-cli 0.0.11 → 0.0.13

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "intor-cli",
3
- "version": "0.0.11",
4
- "description": "📟 CLI tool for intor",
3
+ "version": "0.0.13",
4
+ "description": "The Intor CLI",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://github.com/yiming-liao/intor-cli#readme",
7
7
  "repository": {
@@ -39,8 +39,10 @@
39
39
  "intor": "src/cli/index.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@intor/reader-md": "0.1.4",
43
- "@intor/reader-yaml": "0.1.1",
42
+ "@intor/reader-json5": "^0.1.0",
43
+ "@intor/reader-md": "^0.1.4",
44
+ "@intor/reader-toml": "^0.1.0",
45
+ "@intor/reader-yaml": "^0.1.1",
44
46
  "cac": "6.7.14",
45
47
  "fast-glob": "3.3.3",
46
48
  "intor": "2.3.26",
@@ -13,6 +13,10 @@ export function registerGenerateCommand(cli: CAC) {
13
13
  // -----------------------------------------------------------------------
14
14
  // Option
15
15
  // -----------------------------------------------------------------------
16
+ .option(
17
+ "--messages <path>",
18
+ "Explicit messages file for schema generation (bypass runtime loader)",
19
+ )
16
20
  .option(
17
21
  "--ext <ext>",
18
22
  "Enable extra messages file extension (repeatable)",
@@ -32,7 +36,8 @@ export function registerGenerateCommand(cli: CAC) {
32
36
  // Action
33
37
  // -----------------------------------------------------------------------
34
38
  .action(async (options) => {
35
- const { ext, reader, debug } = options as {
39
+ const { messages, ext, reader, debug } = options as {
40
+ messages?: string;
36
41
  ext?: Array<ExtraExt>;
37
42
  reader?: string[];
38
43
  debug?: boolean;
@@ -41,7 +46,12 @@ export function registerGenerateCommand(cli: CAC) {
41
46
  const { exts, customReaders } = normalizeReaderOptions({ ext, reader });
42
47
 
43
48
  try {
44
- await generate({ exts, customReaders, debug });
49
+ await generate({
50
+ messageFilePath: messages,
51
+ exts,
52
+ customReaders,
53
+ debug,
54
+ });
45
55
  } catch (error) {
46
56
  console.error(error);
47
57
  process.exitCode = 1;
@@ -1,11 +1,15 @@
1
1
  import type { ExtraExt } from "../../core/constants";
2
2
  import type { MessagesReader, MessagesReaders } from "intor";
3
+ import { json5Reader } from "@intor/reader-json5";
3
4
  import { mdReader } from "@intor/reader-md";
5
+ import { tomlReader } from "@intor/reader-toml";
4
6
  import { yamlReader } from "@intor/reader-yaml";
5
7
 
6
8
  export const BUILTIN_READERS: Record<ExtraExt, MessagesReader> = {
7
9
  md: mdReader,
8
10
  yaml: yamlReader,
11
+ toml: tomlReader,
12
+ json5: json5Reader,
9
13
  };
10
14
 
11
15
  export const getBuiltInReaders = (
@@ -1,2 +1,2 @@
1
- export const EXTRA_EXTS = ["md", "yaml"] as const;
1
+ export const EXTRA_EXTS = ["md", "yaml", "toml", "json5"] as const;
2
2
  export type ExtraExt = (typeof EXTRA_EXTS)[number];
@@ -1,5 +1,8 @@
1
1
  /* eslint-disable unicorn/no-process-exit */
2
2
  import type { ExtraExt } from "../../core";
3
+ import type { MergeOverrides } from "../../core/collect-messages/types";
4
+ import type { LocaleMessages } from "intor";
5
+ import { readFile } from "node:fs/promises";
3
6
  import path from "node:path";
4
7
  import { buildTypes, buildSchemas, type BuildInput } from "../../build";
5
8
  import {
@@ -16,12 +19,14 @@ import { printOverrides } from "./print-overrides";
16
19
  import { printSummary } from "./print-summary";
17
20
 
18
21
  export interface GenerateOptions {
22
+ messageFilePath?: string;
19
23
  exts?: Array<ExtraExt>;
20
24
  customReaders?: Record<string, string>;
21
25
  debug?: boolean;
22
26
  }
23
27
 
24
28
  export async function generate({
29
+ messageFilePath,
25
30
  exts = [],
26
31
  customReaders,
27
32
  debug,
@@ -30,6 +35,8 @@ export async function generate({
30
35
  spinner.start();
31
36
  const start = performance.now();
32
37
 
38
+ const hasTarget = !!messageFilePath;
39
+
33
40
  try {
34
41
  // -----------------------------------------------------------------------
35
42
  // Discover configs from the current workspace
@@ -53,12 +60,21 @@ export async function generate({
53
60
  print(`${dim("Config:")} ${cyan(config.id)} ${dim(`⚲ ${filePath}`)}`);
54
61
  spinner.start();
55
62
 
56
- const { messages, overrides } = await collectRuntimeMessages(
57
- config,
58
- config.defaultLocale,
59
- exts,
60
- customReaders,
61
- );
63
+ let messages: LocaleMessages;
64
+ let overrides: MergeOverrides[] = [];
65
+ if (!hasTarget) {
66
+ const result = await collectRuntimeMessages(
67
+ config,
68
+ config.defaultLocale,
69
+ exts,
70
+ customReaders,
71
+ );
72
+ messages = result.messages;
73
+ overrides = result.overrides;
74
+ } else {
75
+ const content = await readFile(messageFilePath, "utf8");
76
+ messages = { [config.defaultLocale]: JSON.parse(content) };
77
+ }
62
78
 
63
79
  printOverrides(overrides);
64
80
  const schemas = inferSchemas(messages[config.defaultLocale]);