@lang-tag/cli 0.14.0 → 0.15.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.
@@ -0,0 +1,95 @@
1
+ import { mkdir, writeFile, readFile, rm } from "fs/promises";
2
+ import { dirname, resolve } from "path";
3
+ import path, { resolve as resolve$1 } from "pathe";
4
+ import process__default from "node:process";
5
+ class TranslationsCollector {
6
+ config;
7
+ logger;
8
+ }
9
+ async function $LT_EnsureDirectoryExists(filePath) {
10
+ await mkdir(filePath, { recursive: true });
11
+ }
12
+ async function $LT_RemoveDirectory(dirPath) {
13
+ try {
14
+ await rm(dirPath, { recursive: true, force: true });
15
+ } catch (error) {
16
+ }
17
+ }
18
+ async function $LT_RemoveFile(filePath) {
19
+ try {
20
+ await rm(filePath, { force: true });
21
+ } catch (error) {
22
+ }
23
+ }
24
+ async function $LT_WriteJSON(filePath, data) {
25
+ await writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
26
+ }
27
+ async function $LT_ReadJSON(filePath) {
28
+ const content = await readFile(filePath, "utf-8");
29
+ return JSON.parse(content);
30
+ }
31
+ async function $LT_WriteFileWithDirs(filePath, content) {
32
+ const dir = dirname(filePath);
33
+ try {
34
+ await mkdir(dir, { recursive: true });
35
+ } catch (error) {
36
+ }
37
+ await writeFile(filePath, content, "utf-8");
38
+ }
39
+ async function $LT_ReadFileContent(relativeFilePath) {
40
+ const cwd = process.cwd();
41
+ const absolutePath = resolve(cwd, relativeFilePath);
42
+ return await readFile(absolutePath, "utf-8");
43
+ }
44
+ class NamespaceCollector extends TranslationsCollector {
45
+ clean;
46
+ languageDirectory;
47
+ aggregateCollection(namespace) {
48
+ return namespace;
49
+ }
50
+ transformTag(tag) {
51
+ return tag;
52
+ }
53
+ async preWrite(clean) {
54
+ this.clean = clean;
55
+ this.languageDirectory = path.join(this.config.localesDirectory, this.config.baseLanguageCode);
56
+ if (clean) {
57
+ this.logger.info("Cleaning output directory...");
58
+ await $LT_RemoveDirectory(this.languageDirectory);
59
+ }
60
+ await $LT_EnsureDirectoryExists(this.languageDirectory);
61
+ }
62
+ async resolveCollectionFilePath(collectionName) {
63
+ return resolve$1(
64
+ process__default.cwd(),
65
+ this.languageDirectory,
66
+ collectionName + ".json"
67
+ );
68
+ }
69
+ async onMissingCollection(collectionName) {
70
+ if (!this.clean) {
71
+ this.logger.warn(`Original namespace file "{namespace}.json" not found. A new one will be created.`, { namespace: collectionName });
72
+ }
73
+ }
74
+ async postWrite(changedCollections) {
75
+ if (!changedCollections?.length) {
76
+ this.logger.info("No changes were made based on the current configuration and files");
77
+ return;
78
+ }
79
+ const n = changedCollections.map((n2) => `"${n2}.json"`).join(", ");
80
+ this.logger.success("Updated namespaces {outputDir} ({namespaces})", {
81
+ outputDir: this.config.localesDirectory,
82
+ namespaces: n
83
+ });
84
+ }
85
+ }
86
+ export {
87
+ $LT_ReadFileContent as $,
88
+ NamespaceCollector as N,
89
+ TranslationsCollector as T,
90
+ $LT_ReadJSON as a,
91
+ $LT_WriteJSON as b,
92
+ $LT_EnsureDirectoryExists as c,
93
+ $LT_WriteFileWithDirs as d,
94
+ $LT_RemoveFile as e
95
+ };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ const promises = require("fs/promises");
3
+ const path = require("path");
4
+ const path$1 = require("pathe");
5
+ const process$1 = require("node:process");
6
+ class TranslationsCollector {
7
+ config;
8
+ logger;
9
+ }
10
+ async function $LT_EnsureDirectoryExists(filePath) {
11
+ await promises.mkdir(filePath, { recursive: true });
12
+ }
13
+ async function $LT_RemoveDirectory(dirPath) {
14
+ try {
15
+ await promises.rm(dirPath, { recursive: true, force: true });
16
+ } catch (error) {
17
+ }
18
+ }
19
+ async function $LT_RemoveFile(filePath) {
20
+ try {
21
+ await promises.rm(filePath, { force: true });
22
+ } catch (error) {
23
+ }
24
+ }
25
+ async function $LT_WriteJSON(filePath, data) {
26
+ await promises.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
27
+ }
28
+ async function $LT_ReadJSON(filePath) {
29
+ const content = await promises.readFile(filePath, "utf-8");
30
+ return JSON.parse(content);
31
+ }
32
+ async function $LT_WriteFileWithDirs(filePath, content) {
33
+ const dir = path.dirname(filePath);
34
+ try {
35
+ await promises.mkdir(dir, { recursive: true });
36
+ } catch (error) {
37
+ }
38
+ await promises.writeFile(filePath, content, "utf-8");
39
+ }
40
+ async function $LT_ReadFileContent(relativeFilePath) {
41
+ const cwd = process.cwd();
42
+ const absolutePath = path.resolve(cwd, relativeFilePath);
43
+ return await promises.readFile(absolutePath, "utf-8");
44
+ }
45
+ class NamespaceCollector extends TranslationsCollector {
46
+ clean;
47
+ languageDirectory;
48
+ aggregateCollection(namespace) {
49
+ return namespace;
50
+ }
51
+ transformTag(tag) {
52
+ return tag;
53
+ }
54
+ async preWrite(clean) {
55
+ this.clean = clean;
56
+ this.languageDirectory = path$1.join(this.config.localesDirectory, this.config.baseLanguageCode);
57
+ if (clean) {
58
+ this.logger.info("Cleaning output directory...");
59
+ await $LT_RemoveDirectory(this.languageDirectory);
60
+ }
61
+ await $LT_EnsureDirectoryExists(this.languageDirectory);
62
+ }
63
+ async resolveCollectionFilePath(collectionName) {
64
+ return path$1.resolve(
65
+ process$1.cwd(),
66
+ this.languageDirectory,
67
+ collectionName + ".json"
68
+ );
69
+ }
70
+ async onMissingCollection(collectionName) {
71
+ if (!this.clean) {
72
+ this.logger.warn(`Original namespace file "{namespace}.json" not found. A new one will be created.`, { namespace: collectionName });
73
+ }
74
+ }
75
+ async postWrite(changedCollections) {
76
+ if (!changedCollections?.length) {
77
+ this.logger.info("No changes were made based on the current configuration and files");
78
+ return;
79
+ }
80
+ const n = changedCollections.map((n2) => `"${n2}.json"`).join(", ");
81
+ this.logger.success("Updated namespaces {outputDir} ({namespaces})", {
82
+ outputDir: this.config.localesDirectory,
83
+ namespaces: n
84
+ });
85
+ }
86
+ }
87
+ exports.$LT_EnsureDirectoryExists = $LT_EnsureDirectoryExists;
88
+ exports.$LT_ReadFileContent = $LT_ReadFileContent;
89
+ exports.$LT_ReadJSON = $LT_ReadJSON;
90
+ exports.$LT_RemoveFile = $LT_RemoveFile;
91
+ exports.$LT_WriteFileWithDirs = $LT_WriteFileWithDirs;
92
+ exports.$LT_WriteJSON = $LT_WriteJSON;
93
+ exports.NamespaceCollector = NamespaceCollector;
94
+ exports.TranslationsCollector = TranslationsCollector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lang-tag/cli",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"