@worldware/msg-cli 0.4.0 → 0.5.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/README.md CHANGED
@@ -79,7 +79,7 @@ msg init -i
79
79
  Create a new MsgProject file in the i18n projects directory. Requires `package.json` with `directories.i18n` and `directories.l10n` (run `msg init` first).
80
80
 
81
81
  ```bash
82
- msg create project <projectName> [source] [targets...] [--extend <name>]
82
+ msg create project <projectName> [source] [targets...] [--extend <name>] [--format <MF1|MF2|NONE>]
83
83
  ```
84
84
 
85
85
  | Argument | Required | Description |
@@ -93,17 +93,24 @@ msg create project <projectName> [source] [targets...] [--extend <name>]
93
93
  | Flag | Short | Description |
94
94
  |------------|-------|--------------------------------|
95
95
  | `--extend` | `-e` | Extend an existing project. |
96
+ | `--format` | `-f` | Default message format: `MF1`, `MF2`, or `NONE` (default `MF2`). When omitted with `--extend`, inherits the base project's format. |
96
97
  | `--help` | `-h` | Show help for create project. |
97
98
 
98
99
  **Examples:**
99
100
 
100
101
  ```bash
101
- # Create project myApp with source en and targets fr, de
102
+ # Create project myApp with source en and targets fr, de (format defaults to MF2)
102
103
  msg create project myApp en fr de
103
104
 
104
- # Extend an existing project (inherits source and targets from base)
105
+ # Create with MessageFormat 1 as the project default
106
+ msg create project myApp en fr -f MF1
107
+
108
+ # Extend an existing project (inherits source, targets, and format from base)
105
109
  msg create project extendedApp --extend base
106
110
 
111
+ # Extend and override format
112
+ msg create project extendedApp --extend base --format NONE
113
+
107
114
  # Extend and add/override locales
108
115
  msg create project extendedApp en de --extend base
109
116
 
@@ -115,10 +122,11 @@ msg create project -h
115
122
 
116
123
  - Writes the file to `i18n/projects/<projectName>.js` (always `.js`).
117
124
  - Uses ES module or CommonJS export syntax based on `package.json` `"type"` or presence of `tsconfig.json`.
125
+ - Always includes `format` on `project` settings in the generated file (`MF2` by default).
118
126
  - Generates a translation loader that imports from `l10n/translations` using the relative path from `i18n/projects` (from `directories` in package.json).
119
127
  - Includes `pseudoLocale: 'en-XA'` by default (or inherits from the base project when extending), for use with msg's `getTranslation(pseudoLocale)` pseudolocalization support.
120
- - With `--extend <name>`, merges target locales and pseudoLocale from the existing project. If `source` and `targets` are omitted, they are inherited from the base project.
121
- - Errors if the project name already exists, package.json is missing or invalid, or required directories are not configured.
128
+ - With `--extend <name>`, merges target locales and pseudoLocale from the existing project. If `source` and `targets` are omitted, they are inherited from the base project. If `--format` is omitted, format is inherited from the base project when set.
129
+ - Errors if the project name already exists, package.json is missing or invalid, required directories are not configured, or `--format` is not one of `MF1` / `MF2` / `NONE`.
122
130
 
123
131
  ### create resource
124
132
 
@@ -156,7 +164,7 @@ msg create resource myProject messages --edit
156
164
 
157
165
  - Writes the file to `i18n/resources/<title>.msg.js` (always `.js`, including TypeScript projects).
158
166
  - Uses ES module or CommonJS syntax based on `package.json` `"type"` or presence of `tsconfig.json`.
159
- - Imports the project via the `#i18n/projects/<projectName>` alias (added by `msg init`).
167
+ - Imports the project via the `#i18n/projects/<projectName>.js` alias (added by `msg init`).
160
168
  - Sets `lang` from the project's `sourceLocale` and `dir` to `rtl` for Arabic/Hebrew, `ltr` otherwise.
161
169
  - Exports a named `resource` plus an async `getMessages()` helper that returns `resource.getTranslation(getLang())`, so the resource can be pre-translated for the runtime locale.
162
170
  - Includes sample messages added via chainable `.add()`. Validates that the generated file is importable.
@@ -166,7 +174,7 @@ msg create resource myProject messages --edit
166
174
 
167
175
  ```javascript
168
176
  import { MsgResource, getLang } from '@worldware/msg';
169
- import project from '#i18n/projects/myProject';
177
+ import project from '#i18n/projects/myProject.js';
170
178
 
171
179
  export const resource = MsgResource.create({ /* title, attributes, notes */ }, project);
172
180
 
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-MGHC4AYZ.mjs";
10
10
  import {
11
11
  dynamicImportFromUrl
12
- } from "./chunk-JQKAEOL7.mjs";
12
+ } from "./chunk-PO2Z7EWJ.mjs";
13
13
 
14
14
  // src/lib/import-helpers.ts
15
15
  import { MsgResource } from "@worldware/msg";
@@ -80,7 +80,7 @@ function generateMsgResourceContent(params) {
80
80
  const langStr = `'${escapeSingleQuoted(sourceLocale)}'`;
81
81
  const dirStr = `'${dir}'`;
82
82
  const resourceNote = `This is the ${escapeSingleQuoted(title)} resource.`;
83
- const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}`;
83
+ const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}.js`;
84
84
  const createAndAdd = `MsgResource.create({
85
85
  title: ${titleStr},
86
86
  attributes: {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dynamicImportFromUrl
3
- } from "./chunk-JQKAEOL7.mjs";
3
+ } from "./chunk-PO2Z7EWJ.mjs";
4
4
  import {
5
5
  loadPackageJsonForMsg
6
6
  } from "./chunk-F7XZRKP7.mjs";
@@ -9,6 +9,13 @@ import {
9
9
  import { existsSync, mkdirSync, writeFileSync } from "fs";
10
10
  import { dirname, join, relative } from "path";
11
11
  import { pathToFileURL } from "url";
12
+ import { MSG_DEFAULT_FORMAT } from "@worldware/msg";
13
+ var CREATE_PROJECT_FORMATS = ["MF1", "MF2", "NONE"];
14
+ function resolveCreateProjectFormat(flagFormat, base) {
15
+ if (flagFormat) return flagFormat;
16
+ const inherited = base?.project?.format ?? base?.format;
17
+ return inherited ?? MSG_DEFAULT_FORMAT;
18
+ }
12
19
  function calculateRelativePath(projectsDir, translationsDir) {
13
20
  const rel = relative(projectsDir, translationsDir);
14
21
  return rel.startsWith(".") ? rel : `./${rel}`;
@@ -43,6 +50,8 @@ function loadPackageJsonForCreateProject(cwd) {
43
50
  }
44
51
 
45
52
  export {
53
+ CREATE_PROJECT_FORMATS,
54
+ resolveCreateProjectFormat,
46
55
  calculateRelativePath,
47
56
  importMsgProjectFile,
48
57
  writeMsgProjectFile,
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-MGHC4AYZ.mjs";
11
11
  import {
12
12
  dynamicImportFromUrl
13
- } from "./chunk-JQKAEOL7.mjs";
13
+ } from "./chunk-PO2Z7EWJ.mjs";
14
14
 
15
15
  // src/lib/export-helpers.ts
16
16
  import { MSG_DEFAULT_FORMAT } from "@worldware/msg";
@@ -31,6 +31,7 @@ var import_path3 = require("path");
31
31
  var import_fs2 = require("fs");
32
32
  var import_path2 = require("path");
33
33
  var import_url2 = require("url");
34
+ var import_msg = require("@worldware/msg");
34
35
 
35
36
  // src/lib/create-resource-helpers.ts
36
37
  var import_module = require("module");
@@ -124,6 +125,12 @@ async function dynamicImportFromUrl(url) {
124
125
  }
125
126
 
126
127
  // src/lib/create-project-helpers.ts
128
+ var CREATE_PROJECT_FORMATS = ["MF1", "MF2", "NONE"];
129
+ function resolveCreateProjectFormat(flagFormat, base) {
130
+ if (flagFormat) return flagFormat;
131
+ const inherited = base?.project?.format ?? base?.format;
132
+ return inherited ?? import_msg.MSG_DEFAULT_FORMAT;
133
+ }
127
134
  function calculateRelativePath(projectsDir, translationsDir) {
128
135
  const rel = (0, import_path2.relative)(projectsDir, translationsDir);
129
136
  return rel.startsWith(".") ? rel : `./${rel}`;
@@ -161,6 +168,12 @@ function loadPackageJsonForCreateProject(cwd) {
161
168
  var CreateProject = class _CreateProject extends import_core.Command {
162
169
  static description = "Create a new MsgProject file in the projects directory (i18n/projects)";
163
170
  static strict = false;
171
+ static examples = [
172
+ "<%= config.bin %> <%= command.id %> myApp en fr de",
173
+ "<%= config.bin %> <%= command.id %> myApp en fr -f MF1",
174
+ "<%= config.bin %> <%= command.id %> extendedApp --extend base",
175
+ "<%= config.bin %> <%= command.id %> extendedApp --extend base --format NONE"
176
+ ];
164
177
  static args = {
165
178
  projectName: import_core.Args.string({
166
179
  required: false,
@@ -180,7 +193,13 @@ var CreateProject = class _CreateProject extends import_core.Command {
180
193
  extend: import_core.Flags.string({
181
194
  char: "e",
182
195
  description: "Extend an existing project"
183
- })
196
+ }),
197
+ format: import_core.Flags.option({
198
+ char: "f",
199
+ description: "Default message format for the project (MF1, MF2, or NONE)",
200
+ options: CREATE_PROJECT_FORMATS
201
+ // No default: omission must be distinguishable from an explicit MF2 for --extend inheritance.
202
+ })()
184
203
  };
185
204
  async run() {
186
205
  const { argv, flags } = await this.parse(_CreateProject);
@@ -224,12 +243,15 @@ var CreateProject = class _CreateProject extends import_core.Command {
224
243
  let targetLocales = {};
225
244
  let pseudoLocale = "en-XA";
226
245
  let resolvedSource = source?.trim();
246
+ let baseProject;
227
247
  const hasUserSourceAndTargets = Boolean(resolvedSource && targets?.length && targets.some((t) => t?.trim()));
228
- if (flags.extend) {
229
- const base = await importMsgProjectFile(projectsDir, flags.extend);
248
+ if (useExtend) {
249
+ const extendName = flags.extend.trim();
250
+ const base = await importMsgProjectFile(projectsDir, extendName);
230
251
  if (!base) {
231
- this.error(`Project '${flags.extend}' could not be found to extend.`, { exit: 1 });
252
+ this.error(`Project '${extendName}' could not be found to extend.`, { exit: 1 });
232
253
  }
254
+ baseProject = base;
233
255
  if (base.locales?.targetLocales && typeof base.locales.targetLocales === "object") {
234
256
  targetLocales = { ...base.locales.targetLocales };
235
257
  }
@@ -249,6 +271,7 @@ var CreateProject = class _CreateProject extends import_core.Command {
249
271
  if (t?.trim()) targetLocales[t.trim()] = [t.trim()];
250
272
  }
251
273
  }
274
+ const format = resolveCreateProjectFormat(flags.format, baseProject);
252
275
  const loaderPathLine = "const path = `${TRANSLATION_IMPORT_PATH}/${project}/${language}/${title}.json`;";
253
276
  const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded.`, error);";
254
277
  const loaderBody = `${loaderPathLine}
@@ -265,6 +288,7 @@ var CreateProject = class _CreateProject extends import_core.Command {
265
288
  };
266
289
  }`;
267
290
  const importPath = relPath.replace(/\\/g, "/");
291
+ const projectSettings = `project: { name: ${JSON.stringify(projectName)}, version: 1, format: ${JSON.stringify(format)} }`;
268
292
  const content = isEsm ? `import { MsgProject } from '@worldware/msg';
269
293
 
270
294
  const TRANSLATION_IMPORT_PATH = ${JSON.stringify(importPath)};
@@ -273,7 +297,7 @@ const loader = async (project, title, language) => {
273
297
  };
274
298
 
275
299
  export default MsgProject.create({
276
- project: { name: ${JSON.stringify(projectName)}, version: 1 },
300
+ ${projectSettings},
277
301
  locales: {
278
302
  sourceLocale: ${JSON.stringify(resolvedSource)},
279
303
  pseudoLocale: ${JSON.stringify(pseudoLocale)},
@@ -289,7 +313,7 @@ const loader = async (project, title, language) => {
289
313
  };
290
314
 
291
315
  module.exports = MsgProject.create({
292
- project: { name: ${JSON.stringify(projectName)}, version: 1 },
316
+ ${projectSettings},
293
317
  locales: {
294
318
  sourceLocale: ${JSON.stringify(resolvedSource)},
295
319
  pseudoLocale: ${JSON.stringify(pseudoLocale)},
@@ -7,6 +7,7 @@ import { Command } from '@oclif/core';
7
7
  declare class CreateProject extends Command {
8
8
  static description: string;
9
9
  static strict: boolean;
10
+ static examples: string[];
10
11
  static args: {
11
12
  projectName: _oclif_core_lib_interfaces_parser_js.Arg<string | undefined, Record<string, unknown>>;
12
13
  source: _oclif_core_lib_interfaces_parser_js.Arg<string | undefined, Record<string, unknown>>;
@@ -15,6 +16,7 @@ declare class CreateProject extends Command {
15
16
  static flags: {
16
17
  help: _oclif_core_lib_interfaces_parser_js.BooleanFlag<void>;
17
18
  extend: _oclif_core_lib_interfaces_parser_js.OptionFlag<string | undefined, _oclif_core_lib_interfaces_parser_js.CustomOptions>;
19
+ format: _oclif_core_lib_interfaces_parser_js.OptionFlag<"MF1" | "MF2" | "NONE" | undefined, _oclif_core_lib_interfaces_parser_js.CustomOptions>;
18
20
  };
19
21
  run(): Promise<void>;
20
22
  }
@@ -7,6 +7,7 @@ import { Command } from '@oclif/core';
7
7
  declare class CreateProject extends Command {
8
8
  static description: string;
9
9
  static strict: boolean;
10
+ static examples: string[];
10
11
  static args: {
11
12
  projectName: _oclif_core_lib_interfaces_parser_js.Arg<string | undefined, Record<string, unknown>>;
12
13
  source: _oclif_core_lib_interfaces_parser_js.Arg<string | undefined, Record<string, unknown>>;
@@ -15,6 +16,7 @@ declare class CreateProject extends Command {
15
16
  static flags: {
16
17
  help: _oclif_core_lib_interfaces_parser_js.BooleanFlag<void>;
17
18
  extend: _oclif_core_lib_interfaces_parser_js.OptionFlag<string | undefined, _oclif_core_lib_interfaces_parser_js.CustomOptions>;
19
+ format: _oclif_core_lib_interfaces_parser_js.OptionFlag<"MF1" | "MF2" | "NONE" | undefined, _oclif_core_lib_interfaces_parser_js.CustomOptions>;
18
20
  };
19
21
  run(): Promise<void>;
20
22
  }
@@ -1,10 +1,12 @@
1
1
  import {
2
+ CREATE_PROJECT_FORMATS,
2
3
  calculateRelativePath,
3
4
  importMsgProjectFile,
4
5
  loadPackageJsonForCreateProject,
6
+ resolveCreateProjectFormat,
5
7
  writeMsgProjectFile
6
- } from "../../chunk-5VZRQBSH.mjs";
7
- import "../../chunk-JQKAEOL7.mjs";
8
+ } from "../../chunk-QOEKYM6W.mjs";
9
+ import "../../chunk-PO2Z7EWJ.mjs";
8
10
  import {
9
11
  findPackageJsonPath
10
12
  } from "../../chunk-F7XZRKP7.mjs";
@@ -16,6 +18,12 @@ import { join } from "path";
16
18
  var CreateProject = class _CreateProject extends Command {
17
19
  static description = "Create a new MsgProject file in the projects directory (i18n/projects)";
18
20
  static strict = false;
21
+ static examples = [
22
+ "<%= config.bin %> <%= command.id %> myApp en fr de",
23
+ "<%= config.bin %> <%= command.id %> myApp en fr -f MF1",
24
+ "<%= config.bin %> <%= command.id %> extendedApp --extend base",
25
+ "<%= config.bin %> <%= command.id %> extendedApp --extend base --format NONE"
26
+ ];
19
27
  static args = {
20
28
  projectName: Args.string({
21
29
  required: false,
@@ -35,7 +43,13 @@ var CreateProject = class _CreateProject extends Command {
35
43
  extend: Flags.string({
36
44
  char: "e",
37
45
  description: "Extend an existing project"
38
- })
46
+ }),
47
+ format: Flags.option({
48
+ char: "f",
49
+ description: "Default message format for the project (MF1, MF2, or NONE)",
50
+ options: CREATE_PROJECT_FORMATS
51
+ // No default: omission must be distinguishable from an explicit MF2 for --extend inheritance.
52
+ })()
39
53
  };
40
54
  async run() {
41
55
  const { argv, flags } = await this.parse(_CreateProject);
@@ -79,12 +93,15 @@ var CreateProject = class _CreateProject extends Command {
79
93
  let targetLocales = {};
80
94
  let pseudoLocale = "en-XA";
81
95
  let resolvedSource = source?.trim();
96
+ let baseProject;
82
97
  const hasUserSourceAndTargets = Boolean(resolvedSource && targets?.length && targets.some((t) => t?.trim()));
83
- if (flags.extend) {
84
- const base = await importMsgProjectFile(projectsDir, flags.extend);
98
+ if (useExtend) {
99
+ const extendName = flags.extend.trim();
100
+ const base = await importMsgProjectFile(projectsDir, extendName);
85
101
  if (!base) {
86
- this.error(`Project '${flags.extend}' could not be found to extend.`, { exit: 1 });
102
+ this.error(`Project '${extendName}' could not be found to extend.`, { exit: 1 });
87
103
  }
104
+ baseProject = base;
88
105
  if (base.locales?.targetLocales && typeof base.locales.targetLocales === "object") {
89
106
  targetLocales = { ...base.locales.targetLocales };
90
107
  }
@@ -104,6 +121,7 @@ var CreateProject = class _CreateProject extends Command {
104
121
  if (t?.trim()) targetLocales[t.trim()] = [t.trim()];
105
122
  }
106
123
  }
124
+ const format = resolveCreateProjectFormat(flags.format, baseProject);
107
125
  const loaderPathLine = "const path = `${TRANSLATION_IMPORT_PATH}/${project}/${language}/${title}.json`;";
108
126
  const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded.`, error);";
109
127
  const loaderBody = `${loaderPathLine}
@@ -120,6 +138,7 @@ var CreateProject = class _CreateProject extends Command {
120
138
  };
121
139
  }`;
122
140
  const importPath = relPath.replace(/\\/g, "/");
141
+ const projectSettings = `project: { name: ${JSON.stringify(projectName)}, version: 1, format: ${JSON.stringify(format)} }`;
123
142
  const content = isEsm ? `import { MsgProject } from '@worldware/msg';
124
143
 
125
144
  const TRANSLATION_IMPORT_PATH = ${JSON.stringify(importPath)};
@@ -128,7 +147,7 @@ const loader = async (project, title, language) => {
128
147
  };
129
148
 
130
149
  export default MsgProject.create({
131
- project: { name: ${JSON.stringify(projectName)}, version: 1 },
150
+ ${projectSettings},
132
151
  locales: {
133
152
  sourceLocale: ${JSON.stringify(resolvedSource)},
134
153
  pseudoLocale: ${JSON.stringify(pseudoLocale)},
@@ -144,7 +163,7 @@ const loader = async (project, title, language) => {
144
163
  };
145
164
 
146
165
  module.exports = MsgProject.create({
147
- project: { name: ${JSON.stringify(projectName)}, version: 1 },
166
+ ${projectSettings},
148
167
  locales: {
149
168
  sourceLocale: ${JSON.stringify(resolvedSource)},
150
169
  pseudoLocale: ${JSON.stringify(pseudoLocale)},
@@ -181,7 +181,7 @@ function generateMsgResourceContent(params) {
181
181
  const langStr = `'${escapeSingleQuoted(sourceLocale)}'`;
182
182
  const dirStr = `'${dir}'`;
183
183
  const resourceNote = `This is the ${escapeSingleQuoted(title)} resource.`;
184
- const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}`;
184
+ const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}.js`;
185
185
  const createAndAdd = `MsgResource.create({
186
186
  title: ${titleStr},
187
187
  attributes: {
@@ -4,7 +4,7 @@ import {
4
4
  importMsgProjectForResource,
5
5
  readPackageJsonForCreateResource,
6
6
  writeMsgResourceFile
7
- } from "../../chunk-JQKAEOL7.mjs";
7
+ } from "../../chunk-PO2Z7EWJ.mjs";
8
8
  import {
9
9
  findPackageJsonPath
10
10
  } from "../../chunk-F7XZRKP7.mjs";
@@ -5,11 +5,11 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-KZ47S4SH.mjs";
8
+ } from "../chunk-XMMVPJHX.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
10
  import "../chunk-XID5J2F7.mjs";
11
11
  import "../chunk-MGHC4AYZ.mjs";
12
- import "../chunk-JQKAEOL7.mjs";
12
+ import "../chunk-PO2Z7EWJ.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
15
15
  } from "../chunk-F7XZRKP7.mjs";
@@ -5,11 +5,11 @@ import {
5
5
  parseXliffFilename,
6
6
  processXliffFile,
7
7
  writeTranslationFiles
8
- } from "../chunk-77PP26JZ.mjs";
8
+ } from "../chunk-LPZ6YNLY.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
10
  import "../chunk-XID5J2F7.mjs";
11
11
  import "../chunk-MGHC4AYZ.mjs";
12
- import "../chunk-JQKAEOL7.mjs";
12
+ import "../chunk-PO2Z7EWJ.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
15
15
  } from "../chunk-F7XZRKP7.mjs";
@@ -20,15 +20,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/lib/create-project-helpers.ts
21
21
  var create_project_helpers_exports = {};
22
22
  __export(create_project_helpers_exports, {
23
+ CREATE_PROJECT_FORMATS: () => CREATE_PROJECT_FORMATS,
23
24
  calculateRelativePath: () => calculateRelativePath,
24
25
  importMsgProjectFile: () => importMsgProjectFile,
25
26
  loadPackageJsonForCreateProject: () => loadPackageJsonForCreateProject,
27
+ resolveCreateProjectFormat: () => resolveCreateProjectFormat,
26
28
  writeMsgProjectFile: () => writeMsgProjectFile
27
29
  });
28
30
  module.exports = __toCommonJS(create_project_helpers_exports);
29
31
  var import_fs2 = require("fs");
30
32
  var import_path2 = require("path");
31
33
  var import_url2 = require("url");
34
+ var import_msg = require("@worldware/msg");
32
35
 
33
36
  // src/lib/create-resource-helpers.ts
34
37
  var import_module = require("module");
@@ -122,6 +125,12 @@ async function dynamicImportFromUrl(url) {
122
125
  }
123
126
 
124
127
  // src/lib/create-project-helpers.ts
128
+ var CREATE_PROJECT_FORMATS = ["MF1", "MF2", "NONE"];
129
+ function resolveCreateProjectFormat(flagFormat, base) {
130
+ if (flagFormat) return flagFormat;
131
+ const inherited = base?.project?.format ?? base?.format;
132
+ return inherited ?? import_msg.MSG_DEFAULT_FORMAT;
133
+ }
125
134
  function calculateRelativePath(projectsDir, translationsDir) {
126
135
  const rel = (0, import_path2.relative)(projectsDir, translationsDir);
127
136
  return rel.startsWith(".") ? rel : `./${rel}`;
@@ -156,8 +165,10 @@ function loadPackageJsonForCreateProject(cwd) {
156
165
  }
157
166
  // Annotate the CommonJS export names for ESM import in node:
158
167
  0 && (module.exports = {
168
+ CREATE_PROJECT_FORMATS,
159
169
  calculateRelativePath,
160
170
  importMsgProjectFile,
161
171
  loadPackageJsonForCreateProject,
172
+ resolveCreateProjectFormat,
162
173
  writeMsgProjectFile
163
174
  });
@@ -1,11 +1,15 @@
1
1
  import { PackageJson } from './init-helpers.mjs';
2
+ import { MsgFormat } from '@worldware/msg';
2
3
 
3
4
  /** Minimal type for MsgProject-like data we read from an existing project file. */
4
5
  interface MsgProjectFileData {
5
6
  project?: {
6
7
  name?: string;
7
8
  version?: number;
9
+ format?: MsgFormat;
8
10
  };
11
+ /** Resolved format getter on MsgProject instances. */
12
+ format?: MsgFormat;
9
13
  locales?: {
10
14
  sourceLocale?: string;
11
15
  pseudoLocale?: string;
@@ -13,6 +17,15 @@ interface MsgProjectFileData {
13
17
  };
14
18
  loader?: unknown;
15
19
  }
20
+ /** Allowed `--format` / `-f` values for `create project`. */
21
+ declare const CREATE_PROJECT_FORMATS: readonly ["MF1", "MF2", "NONE"];
22
+ /**
23
+ * Resolves the format to write into a new MsgProject file.
24
+ * Explicit flag wins; otherwise inherit from an extended project; else library default.
25
+ * @param flagFormat - Value from `--format` / `-f`, if provided
26
+ * @param base - Imported base project when `--extend` is used
27
+ */
28
+ declare function resolveCreateProjectFormat(flagFormat: MsgFormat | undefined, base?: MsgProjectFileData): MsgFormat;
16
29
  /**
17
30
  * Calculates the relative path from the i18n projects directory to the l10n translations directory.
18
31
  * @param projectsDir - Absolute path to i18n/projects (e.g. root/i18n/projects)
@@ -47,4 +60,4 @@ declare function loadPackageJsonForCreateProject(cwd: string): PackageJson & {
47
60
  };
48
61
  };
49
62
 
50
- export { type MsgProjectFileData, calculateRelativePath, importMsgProjectFile, loadPackageJsonForCreateProject, writeMsgProjectFile };
63
+ export { CREATE_PROJECT_FORMATS, type MsgProjectFileData, calculateRelativePath, importMsgProjectFile, loadPackageJsonForCreateProject, resolveCreateProjectFormat, writeMsgProjectFile };
@@ -1,11 +1,15 @@
1
1
  import { PackageJson } from './init-helpers.js';
2
+ import { MsgFormat } from '@worldware/msg';
2
3
 
3
4
  /** Minimal type for MsgProject-like data we read from an existing project file. */
4
5
  interface MsgProjectFileData {
5
6
  project?: {
6
7
  name?: string;
7
8
  version?: number;
9
+ format?: MsgFormat;
8
10
  };
11
+ /** Resolved format getter on MsgProject instances. */
12
+ format?: MsgFormat;
9
13
  locales?: {
10
14
  sourceLocale?: string;
11
15
  pseudoLocale?: string;
@@ -13,6 +17,15 @@ interface MsgProjectFileData {
13
17
  };
14
18
  loader?: unknown;
15
19
  }
20
+ /** Allowed `--format` / `-f` values for `create project`. */
21
+ declare const CREATE_PROJECT_FORMATS: readonly ["MF1", "MF2", "NONE"];
22
+ /**
23
+ * Resolves the format to write into a new MsgProject file.
24
+ * Explicit flag wins; otherwise inherit from an extended project; else library default.
25
+ * @param flagFormat - Value from `--format` / `-f`, if provided
26
+ * @param base - Imported base project when `--extend` is used
27
+ */
28
+ declare function resolveCreateProjectFormat(flagFormat: MsgFormat | undefined, base?: MsgProjectFileData): MsgFormat;
16
29
  /**
17
30
  * Calculates the relative path from the i18n projects directory to the l10n translations directory.
18
31
  * @param projectsDir - Absolute path to i18n/projects (e.g. root/i18n/projects)
@@ -47,4 +60,4 @@ declare function loadPackageJsonForCreateProject(cwd: string): PackageJson & {
47
60
  };
48
61
  };
49
62
 
50
- export { type MsgProjectFileData, calculateRelativePath, importMsgProjectFile, loadPackageJsonForCreateProject, writeMsgProjectFile };
63
+ export { CREATE_PROJECT_FORMATS, type MsgProjectFileData, calculateRelativePath, importMsgProjectFile, loadPackageJsonForCreateProject, resolveCreateProjectFormat, writeMsgProjectFile };
@@ -1,14 +1,18 @@
1
1
  import {
2
+ CREATE_PROJECT_FORMATS,
2
3
  calculateRelativePath,
3
4
  importMsgProjectFile,
4
5
  loadPackageJsonForCreateProject,
6
+ resolveCreateProjectFormat,
5
7
  writeMsgProjectFile
6
- } from "../chunk-5VZRQBSH.mjs";
7
- import "../chunk-JQKAEOL7.mjs";
8
+ } from "../chunk-QOEKYM6W.mjs";
9
+ import "../chunk-PO2Z7EWJ.mjs";
8
10
  import "../chunk-F7XZRKP7.mjs";
9
11
  export {
12
+ CREATE_PROJECT_FORMATS,
10
13
  calculateRelativePath,
11
14
  importMsgProjectFile,
12
15
  loadPackageJsonForCreateProject,
16
+ resolveCreateProjectFormat,
13
17
  writeMsgProjectFile
14
18
  };
@@ -169,7 +169,7 @@ function generateMsgResourceContent(params) {
169
169
  const langStr = `'${escapeSingleQuoted(sourceLocale)}'`;
170
170
  const dirStr = `'${dir}'`;
171
171
  const resourceNote = `This is the ${escapeSingleQuoted(title)} resource.`;
172
- const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}`;
172
+ const projectImport = `#i18n/projects/${escapeSingleQuoted(projectName)}.js`;
173
173
  const createAndAdd = `MsgResource.create({
174
174
  title: ${titleStr},
175
175
  attributes: {
@@ -38,7 +38,7 @@ declare function importMsgProjectForResource(projectsDir: string, projectName: s
38
38
  * Emits ESM or CJS boilerplate that creates a MsgResource, adds sample
39
39
  * messages via chainable `.add()`, and exports `resource` plus an async
40
40
  * `getMessages` loader that calls `resource.getTranslation(getLang())`.
41
- * Project import uses the `#i18n/projects/<name>` alias from `msg init`.
41
+ * Project import uses the `#i18n/projects/<name>.js` alias from `msg init`.
42
42
  * @param params - Title, projectName, sourceLocale, dir, and isEsm
43
43
  * @returns The generated file content
44
44
  */
@@ -38,7 +38,7 @@ declare function importMsgProjectForResource(projectsDir: string, projectName: s
38
38
  * Emits ESM or CJS boilerplate that creates a MsgResource, adds sample
39
39
  * messages via chainable `.add()`, and exports `resource` plus an async
40
40
  * `getMessages` loader that calls `resource.getTranslation(getLang())`.
41
- * Project import uses the `#i18n/projects/<name>` alias from `msg init`.
41
+ * Project import uses the `#i18n/projects/<name>.js` alias from `msg init`.
42
42
  * @param params - Title, projectName, sourceLocale, dir, and isEsm
43
43
  * @returns The generated file content
44
44
  */
@@ -4,7 +4,7 @@ import {
4
4
  importMsgProjectForResource,
5
5
  readPackageJsonForCreateResource,
6
6
  writeMsgResourceFile
7
- } from "../chunk-JQKAEOL7.mjs";
7
+ } from "../chunk-PO2Z7EWJ.mjs";
8
8
  import "../chunk-F7XZRKP7.mjs";
9
9
  export {
10
10
  dynamicImportFromUrl,
@@ -5,11 +5,11 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-KZ47S4SH.mjs";
8
+ } from "../chunk-XMMVPJHX.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
10
  import "../chunk-XID5J2F7.mjs";
11
11
  import "../chunk-MGHC4AYZ.mjs";
12
- import "../chunk-JQKAEOL7.mjs";
12
+ import "../chunk-PO2Z7EWJ.mjs";
13
13
  import "../chunk-F7XZRKP7.mjs";
14
14
  export {
15
15
  filterResourceGroupsByProject,
@@ -8,11 +8,11 @@ import {
8
8
  parseXliffFilename,
9
9
  processXliffFile,
10
10
  writeTranslationFiles
11
- } from "../chunk-77PP26JZ.mjs";
11
+ } from "../chunk-LPZ6YNLY.mjs";
12
12
  import "../chunk-Q775ZGC5.mjs";
13
13
  import "../chunk-XID5J2F7.mjs";
14
14
  import "../chunk-MGHC4AYZ.mjs";
15
- import "../chunk-JQKAEOL7.mjs";
15
+ import "../chunk-PO2Z7EWJ.mjs";
16
16
  import "../chunk-F7XZRKP7.mjs";
17
17
  export {
18
18
  extractResourceFromXliffFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "CLI for msg library",
5
5
  "main": "dist/commands/init.cjs",
6
6
  "module": "dist/commands/init.mjs",