i18ntk 2.4.0 → 2.5.1
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/CODE_OF_CONDUCT.md +133 -0
- package/CONTRIBUTING.md +41 -0
- package/FUNDING.md +5 -0
- package/README.md +62 -15
- package/SECURITY.md +52 -0
- package/main/manage/commands/FixerCommand.js +97 -97
- package/main/manage/managers/DebugMenu.js +10 -9
- package/package.json +59 -184
- package/runtime/index.js +14 -8
- package/utils/admin-auth.js +655 -576
- package/utils/config-manager.js +72 -72
- package/utils/env-manager.js +117 -26
- package/utils/i18n-helper.js +50 -49
- package/utils/json-output.js +13 -12
- package/utils/logger.js +7 -6
- package/utils/prompt-helper.js +44 -41
- package/utils/secure-errors.js +156 -154
- package/utils/security.js +235 -233
- package/utils/setup-enforcer.js +110 -109
- package/utils/terminal-icons.js +164 -163
- package/settings/i18ntk-config.json +0 -283
- package/utils/admin-pin.js +0 -520
- package/utils/arg-parser.js +0 -40
- package/utils/cli-args.js +0 -210
- package/utils/mini-commander.js +0 -179
- package/utils/missing-key-validator.js +0 -858
- package/utils/path-utils.js +0 -33
- package/utils/performance-optimizer.js +0 -246
- package/utils/prompt-new.js +0 -55
- package/utils/promptPin.js +0 -76
- package/utils/safe-json.js +0 -40
- package/utils/secure-backup.js +0 -340
- package/utils/security-check-improved.js +0 -393
- package/utils/security-config.js +0 -239
- package/utils/setup-validator.js +0 -717
- package/utils/ultra-performance-optimizer.js +0 -352
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances
|
|
31
|
+
of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
GitHub Security Advisories for sensitive reports, or GitHub issues for non-sensitive community concerns.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
126
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
127
|
+
|
|
128
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
129
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
130
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
131
|
+
|
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Contributing to i18ntk
|
|
2
|
+
|
|
3
|
+
Thanks for helping improve i18ntk.
|
|
4
|
+
|
|
5
|
+
## Project Priorities
|
|
6
|
+
|
|
7
|
+
- Keep the npm package zero-dependency.
|
|
8
|
+
- Keep the published package minimal and free of tests, local setup state, reports, backups, logs, credentials, and generated artifacts.
|
|
9
|
+
- Preserve backward compatibility unless a breaking change is intentional and documented.
|
|
10
|
+
- Prefer small, well-tested fixes over broad refactors.
|
|
11
|
+
|
|
12
|
+
## Development Setup
|
|
13
|
+
|
|
14
|
+
Clone the repository, install with npm, and run the project validation checks before opening a pull request.
|
|
15
|
+
|
|
16
|
+
## Release Validation
|
|
17
|
+
|
|
18
|
+
Maintainer release commands are documented in the repository development guide. The package published to npm uses a stripped public manifest.
|
|
19
|
+
|
|
20
|
+
## Security
|
|
21
|
+
|
|
22
|
+
Follow the security guidance in `SECURITY.md` and `docs/development/AGENTS.md`.
|
|
23
|
+
|
|
24
|
+
Report vulnerabilities through GitHub Security Advisories. Do not open public issues for sensitive security reports.
|
|
25
|
+
|
|
26
|
+
## Translations
|
|
27
|
+
|
|
28
|
+
When editing `ui-locales/`, preserve JSON structure, placeholders, command names, file paths, and config keys.
|
|
29
|
+
|
|
30
|
+
Run:
|
|
31
|
+
|
|
32
|
+
Run the locale lint check before submitting translation changes.
|
|
33
|
+
|
|
34
|
+
## Pull Requests
|
|
35
|
+
|
|
36
|
+
Include:
|
|
37
|
+
|
|
38
|
+
- the problem being fixed
|
|
39
|
+
- the user-visible behavior change
|
|
40
|
+
- validation commands that were run
|
|
41
|
+
- any remaining risk or unverified behavior
|
package/FUNDING.md
ADDED
package/README.md
CHANGED
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
# i18ntk v2.
|
|
1
|
+
# i18ntk v2.5.1
|
|
2
2
|
|
|
3
3
|
Zero-dependency internationalization toolkit for setup, scanning, analysis, validation, usage tracking, and translation completion.
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/i18ntk)
|
|
8
8
|
[](https://www.npmjs.com/package/i18ntk)
|
|
9
9
|
[](https://nodejs.org)
|
|
10
10
|
[](https://www.npmjs.com/package/i18ntk)
|
|
11
11
|
[](LICENSE)
|
|
12
|
-
[](https://socket.dev/npm/package/i18ntk/overview/2.5.1)
|
|
13
13
|
|
|
14
14
|
## Upgrade Notice
|
|
15
15
|
|
|
16
|
-
Versions earlier than `2.
|
|
17
|
-
They are considered unsupported for production use. Upgrade to `2.
|
|
16
|
+
Versions earlier than `2.5.1` may contain known stability and security issues.
|
|
17
|
+
They are considered unsupported for production use. Upgrade to `2.5.1` or newer.
|
|
18
|
+
|
|
19
|
+
## v2.5.1 Security Update
|
|
20
|
+
|
|
21
|
+
`v2.5.1` is a security and packaging-process update for the `2.5.x` release line.
|
|
22
|
+
|
|
23
|
+
### Change Summary
|
|
24
|
+
|
|
25
|
+
- Hardened `utils/admin-auth.js` so `verifyPin()` fails closed when admin config is missing, disabled, or malformed.
|
|
26
|
+
- Hardened auth-required checks so enabled PIN protection does not silently bypass authentication when admin config is unusable.
|
|
27
|
+
- Normalized admin session expiry handling by storing both `expires` and `expiresAt` and cleaning up either format consistently.
|
|
28
|
+
- Marked the root `package.json` as development-only and added a separate public manifest flow.
|
|
29
|
+
- Added package scripts to stage, pack, and publish the public npm package from `package.public.json`.
|
|
30
|
+
- Added a root publish guard via `prepack` and `prepublishOnly` to block accidental publishing of the development manifest.
|
|
31
|
+
- Updated ignore rules to exclude release staging artifacts and public package metadata from the repo/package payload.
|
|
32
|
+
- Replaced the expanded `SECURITY.md` policy with a shorter reporting-oriented policy and added community docs links.
|
|
33
|
+
- Updated docs and release reset automation to use `npm run package:public` instead of `npm pack --dry-run`.
|
|
34
|
+
|
|
35
|
+
### Files Changed
|
|
36
|
+
|
|
37
|
+
- `utils/admin-auth.js`: fixed fail-open PIN verification and session expiry consistency.
|
|
38
|
+
- `tests/security.test.js`: added admin-auth fail-closed and session cleanup coverage.
|
|
39
|
+
- `package.json`: set development-only metadata, adjusted included files, and added public packaging/publish scripts.
|
|
40
|
+
- `package.public.json`: introduced the stripped public npm manifest.
|
|
41
|
+
- `scripts/build-public-package.js`: added the public package staging, pack, and publish workflow.
|
|
42
|
+
- `scripts/prevent-root-publish.js`: added a guard against publishing the root development manifest.
|
|
43
|
+
- `scripts/reset-release-state.js`: switched release validation to the public package build flow.
|
|
44
|
+
- `README.md`, `docs/README.md`, `docs/development/AGENTS.md`, `docs/migration-guide-v2.5.1.md`, `docs/migration-guide-v2.5.0.md`: documented the security fix, packaging, and community file layout.
|
|
45
|
+
- `SECURITY.md`, `CODE_OF_CONDUCT.md`, `CONTRIBUTING.md`, `FUNDING.md`: updated or added community and security-facing docs.
|
|
46
|
+
- `.gitignore`, `.npmignore`: excluded release staging output and public-package metadata.
|
|
47
|
+
|
|
48
|
+
### Audit Trail
|
|
49
|
+
|
|
50
|
+
- Risk addressed: AI-based analysis flagged `verifyPin()` as fail-open when admin config was missing or disabled.
|
|
51
|
+
- Behavior change: direct `verifyPin()` calls now return `false` unless a usable enabled PIN config exists.
|
|
52
|
+
- Behavior change: when settings require PIN auth but admin config is broken, protected auth checks now require authentication and verification fails closed.
|
|
53
|
+
- Risk: the root manifest is intentionally non-publishable, so publishing flows must use the public-package scripts.
|
|
54
|
+
- Behavior change: `npm pack` and `npm publish` at the repo root are blocked by guard scripts.
|
|
55
|
+
- Behavior change: the public npm payload is staged from `package.public.json` rather than the development manifest.
|
|
56
|
+
- Validation note: release-state reset now exercises `npm run package:public` as part of its checks.
|
|
57
|
+
- Validation note: this documentation update describes the working tree changes used for the packaging split.
|
|
18
58
|
|
|
19
59
|
## What i18ntk Does
|
|
20
60
|
|
|
@@ -154,7 +194,7 @@ Example `.i18ntk-config`:
|
|
|
154
194
|
|
|
155
195
|
```json
|
|
156
196
|
{
|
|
157
|
-
"version": "2.
|
|
197
|
+
"version": "2.5.1",
|
|
158
198
|
"sourceDir": "./locales",
|
|
159
199
|
"i18nDir": "./locales",
|
|
160
200
|
"outputDir": "./i18ntk-reports",
|
|
@@ -170,15 +210,22 @@ See [docs/api/CONFIGURATION.md](docs/api/CONFIGURATION.md) for the full configur
|
|
|
170
210
|
|
|
171
211
|
## Docs
|
|
172
212
|
|
|
173
|
-
- [Documentation Index](docs/README.md)
|
|
174
|
-
- [Getting Started](docs/getting-started.md)
|
|
175
|
-
- [API Reference](docs/api/API_REFERENCE.md)
|
|
176
|
-
- [Configuration Guide](docs/api/CONFIGURATION.md)
|
|
177
|
-
- [Runtime API Guide](docs/runtime.md)
|
|
178
|
-
- [Scanner Guide](docs/scanner-guide.md)
|
|
179
|
-
- [Environment Variables](docs/environment-variables.md)
|
|
180
|
-
- [Migration Guide v2.
|
|
181
|
-
- [
|
|
213
|
+
- [Documentation Index](https://github.com/vladnoskv/i18ntk/blob/main/docs/README.md)
|
|
214
|
+
- [Getting Started](https://github.com/vladnoskv/i18ntk/blob/main/docs/getting-started.md)
|
|
215
|
+
- [API Reference](https://github.com/vladnoskv/i18ntk/blob/main/docs/api/API_REFERENCE.md)
|
|
216
|
+
- [Configuration Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/api/CONFIGURATION.md)
|
|
217
|
+
- [Runtime API Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/runtime.md)
|
|
218
|
+
- [Scanner Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/scanner-guide.md)
|
|
219
|
+
- [Environment Variables](https://github.com/vladnoskv/i18ntk/blob/main/docs/environment-variables.md)
|
|
220
|
+
- [Migration Guide v2.5.1](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v2.5.1.md)
|
|
221
|
+
- [Migration Guide v2.5.0](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v2.5.0.md)
|
|
222
|
+
|
|
223
|
+
## Community
|
|
224
|
+
|
|
225
|
+
- [Contributing](CONTRIBUTING.md)
|
|
226
|
+
- [Code of Conduct](CODE_OF_CONDUCT.md)
|
|
227
|
+
- [Security Policy](SECURITY.md)
|
|
228
|
+
- [Funding](FUNDING.md)
|
|
182
229
|
|
|
183
230
|
## Code of Conduct
|
|
184
231
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
The supported production line is `2.5.x`.
|
|
6
|
+
|
|
7
|
+
Versions earlier than `2.5.0` are not recommended for production use because later releases include package, filesystem, environment, and admin-auth hardening.
|
|
8
|
+
|
|
9
|
+
## Security Model
|
|
10
|
+
|
|
11
|
+
i18ntk is a local developer CLI and runtime helper. It is expected to read and write project files, but it must do so with conservative path validation and without external runtime dependencies.
|
|
12
|
+
|
|
13
|
+
Security priorities:
|
|
14
|
+
|
|
15
|
+
- zero runtime dependencies
|
|
16
|
+
- no install-time lifecycle commands in the public package manifest
|
|
17
|
+
- no shipped local setup state, admin PINs, backups, reports, logs, credentials, or generated artifacts
|
|
18
|
+
- centralized environment-variable access through `utils/env-manager.js`
|
|
19
|
+
- path containment checks based on resolved paths and `path.relative()`
|
|
20
|
+
- timing-safe comparison for authentication hashes or tokens
|
|
21
|
+
- silent-by-default logging for production-like contexts
|
|
22
|
+
|
|
23
|
+
## Published Package Controls
|
|
24
|
+
|
|
25
|
+
The npm package uses a stripped public manifest. It must not contain install-time lifecycle commands, dependency fields, local setup state, or development tooling.
|
|
26
|
+
|
|
27
|
+
## Reporting Vulnerabilities
|
|
28
|
+
|
|
29
|
+
Do not report security vulnerabilities in public GitHub issues.
|
|
30
|
+
|
|
31
|
+
Use GitHub Security Advisories for private vulnerability reports. Include:
|
|
32
|
+
|
|
33
|
+
- affected version
|
|
34
|
+
- clear reproduction steps
|
|
35
|
+
- expected and actual behavior
|
|
36
|
+
- impact assessment
|
|
37
|
+
- proof of concept, if safe to share privately
|
|
38
|
+
|
|
39
|
+
## Disclosure Process
|
|
40
|
+
|
|
41
|
+
Security reports are reviewed privately first. Confirmed issues should receive:
|
|
42
|
+
|
|
43
|
+
- a fix or mitigation
|
|
44
|
+
- a release note or migration note when user action is required
|
|
45
|
+
- an npm release when the fix affects published users
|
|
46
|
+
|
|
47
|
+
## User Guidance
|
|
48
|
+
|
|
49
|
+
- Keep i18ntk updated to `2.5.0` or newer.
|
|
50
|
+
- Do not commit `.i18ntk-config`, admin PIN files, backup directories, generated reports, logs, npm credentials, or secret material.
|
|
51
|
+
- Run i18ntk only in project directories you trust.
|
|
52
|
+
- Review generated translation changes before committing them.
|
|
@@ -27,21 +27,21 @@ class FixerCommand {
|
|
|
27
27
|
// Initialize fixer properties
|
|
28
28
|
this.sourceDir = null;
|
|
29
29
|
this.outputDir = null;
|
|
30
|
-
this.backupDir = null;
|
|
31
|
-
this.dryRun = false;
|
|
32
|
-
this.force = false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
isExcludedLanguageDirectory(name) {
|
|
36
|
-
if (!name || typeof name !== 'string') return true;
|
|
37
|
-
const lowered = name.toLowerCase();
|
|
38
|
-
return lowered.startsWith('backup-') ||
|
|
39
|
-
lowered === 'backup' ||
|
|
40
|
-
lowered === 'backups' ||
|
|
41
|
-
lowered === 'i18ntk-backups' ||
|
|
42
|
-
lowered === 'reports' ||
|
|
43
|
-
lowered === 'i18ntk-reports';
|
|
44
|
-
}
|
|
30
|
+
this.backupDir = null;
|
|
31
|
+
this.dryRun = false;
|
|
32
|
+
this.force = false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
isExcludedLanguageDirectory(name) {
|
|
36
|
+
if (!name || typeof name !== 'string') return true;
|
|
37
|
+
const lowered = name.toLowerCase();
|
|
38
|
+
return lowered.startsWith('backup-') ||
|
|
39
|
+
lowered === 'backup' ||
|
|
40
|
+
lowered === 'backups' ||
|
|
41
|
+
lowered === 'i18ntk-backups' ||
|
|
42
|
+
lowered === 'reports' ||
|
|
43
|
+
lowered === 'i18ntk-reports';
|
|
44
|
+
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Set runtime dependencies for interactive operations
|
|
@@ -79,7 +79,7 @@ class FixerCommand {
|
|
|
79
79
|
|
|
80
80
|
this.sourceDir = this.config.sourceDir;
|
|
81
81
|
this.outputDir = this.config.outputDir;
|
|
82
|
-
this.backupDir = path.resolve(this.config.backup?.location || './i18ntk-backups', 'fixer');
|
|
82
|
+
this.backupDir = path.resolve(this.config.backup?.location || './i18ntk-backups', 'fixer');
|
|
83
83
|
|
|
84
84
|
// Validate source directory exists
|
|
85
85
|
const { validateSourceDir } = require('../../../utils/config-helper');
|
|
@@ -138,15 +138,15 @@ class FixerCommand {
|
|
|
138
138
|
const languages = [];
|
|
139
139
|
|
|
140
140
|
// Check for directory-based structure
|
|
141
|
-
const directories = items
|
|
142
|
-
.filter(item => item.isDirectory())
|
|
143
|
-
.map(item => item.name)
|
|
144
|
-
.filter(name =>
|
|
145
|
-
name !== 'node_modules' &&
|
|
146
|
-
!name.startsWith('.') &&
|
|
147
|
-
name !== this.config.sourceLanguage &&
|
|
148
|
-
!this.isExcludedLanguageDirectory(name)
|
|
149
|
-
);
|
|
141
|
+
const directories = items
|
|
142
|
+
.filter(item => item.isDirectory())
|
|
143
|
+
.map(item => item.name)
|
|
144
|
+
.filter(name =>
|
|
145
|
+
name !== 'node_modules' &&
|
|
146
|
+
!name.startsWith('.') &&
|
|
147
|
+
name !== this.config.sourceLanguage &&
|
|
148
|
+
!this.isExcludedLanguageDirectory(name)
|
|
149
|
+
);
|
|
150
150
|
|
|
151
151
|
// Check for monolith files (language.json files)
|
|
152
152
|
const files = items
|
|
@@ -158,13 +158,13 @@ class FixerCommand {
|
|
|
158
158
|
|
|
159
159
|
// Add monolith files as languages (without .json extension)
|
|
160
160
|
const monolithLanguages = files
|
|
161
|
-
.map(file => file.replace('.json', ''))
|
|
162
|
-
.filter(lang =>
|
|
163
|
-
!languages.includes(lang) &&
|
|
164
|
-
lang !== this.config.sourceLanguage &&
|
|
165
|
-
!this.isExcludedLanguageDirectory(lang)
|
|
166
|
-
);
|
|
167
|
-
languages.push(...monolithLanguages);
|
|
161
|
+
.map(file => file.replace('.json', ''))
|
|
162
|
+
.filter(lang =>
|
|
163
|
+
!languages.includes(lang) &&
|
|
164
|
+
lang !== this.config.sourceLanguage &&
|
|
165
|
+
!this.isExcludedLanguageDirectory(lang)
|
|
166
|
+
);
|
|
167
|
+
languages.push(...monolithLanguages);
|
|
168
168
|
|
|
169
169
|
return [...new Set(languages)].sort();
|
|
170
170
|
} catch (error) {
|
|
@@ -299,21 +299,21 @@ class FixerCommand {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// Create backup of translation files
|
|
302
|
-
async createBackup() {
|
|
303
|
-
if (this.dryRun) return;
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
const backupEnabled = this.config?.backup?.enabled === true;
|
|
307
|
-
if (!backupEnabled) {
|
|
308
|
-
this.backupDir = null;
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
313
|
-
const backupRoot = path.resolve(this.config?.backup?.location || './i18ntk-backups');
|
|
314
|
-
this.backupDir = path.join(backupRoot, 'fixer', `backup-${timestamp}`);
|
|
315
|
-
|
|
316
|
-
console.log(t('fixer.creatingBackup', { dir: this.backupDir }));
|
|
302
|
+
async createBackup() {
|
|
303
|
+
if (this.dryRun) return;
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const backupEnabled = this.config?.backup?.enabled === true;
|
|
307
|
+
if (!backupEnabled) {
|
|
308
|
+
this.backupDir = null;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
313
|
+
const backupRoot = path.resolve(this.config?.backup?.location || './i18ntk-backups');
|
|
314
|
+
this.backupDir = path.join(backupRoot, 'fixer', `backup-${timestamp}`);
|
|
315
|
+
|
|
316
|
+
console.log(t('fixer.creatingBackup', { dir: this.backupDir }));
|
|
317
317
|
|
|
318
318
|
// Ensure backup directory exists
|
|
319
319
|
const dirCreated = SecurityUtils.safeMkdirSync(this.backupDir, process.cwd(), { recursive: true });
|
|
@@ -326,8 +326,8 @@ class FixerCommand {
|
|
|
326
326
|
const languages = this.getAvailableLanguages();
|
|
327
327
|
languages.push(this.config.sourceLanguage); // Include source language
|
|
328
328
|
|
|
329
|
-
for (const language of languages) {
|
|
330
|
-
const languageFiles = this.getLanguageFiles(language);
|
|
329
|
+
for (const language of languages) {
|
|
330
|
+
const languageFiles = this.getLanguageFiles(language);
|
|
331
331
|
|
|
332
332
|
for (const fileName of languageFiles) {
|
|
333
333
|
const sourcePath = path.join(this.sourceDir, language, fileName);
|
|
@@ -343,42 +343,42 @@ class FixerCommand {
|
|
|
343
343
|
SecurityUtils.safeWriteFileSync(backupPath, content, process.cwd(), 'utf8');
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
this.cleanupOldBackups();
|
|
349
|
-
|
|
350
|
-
console.log(t('fixer.backupCreated'));
|
|
351
|
-
} catch (error) {
|
|
352
|
-
console.warn(`Failed to create backup: ${error.message}`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
cleanupOldBackups() {
|
|
357
|
-
try {
|
|
358
|
-
const fixerBackupRoot = path.resolve(this.config?.backup?.location || './i18ntk-backups', 'fixer');
|
|
359
|
-
if (!SecurityUtils.safeExistsSync(fixerBackupRoot, process.cwd())) return;
|
|
360
|
-
|
|
361
|
-
const configuredKeep = parseInt(this.config?.backup?.maxBackups, 10);
|
|
362
|
-
const keepCount = Number.isInteger(configuredKeep) ? Math.min(Math.max(configuredKeep, 1), 3) : 1;
|
|
363
|
-
|
|
364
|
-
const backupDirs = SecurityUtils.safeReaddirSync(fixerBackupRoot, process.cwd(), { withFileTypes: true })
|
|
365
|
-
.filter(entry => entry.isDirectory() && entry.name.startsWith('backup-'))
|
|
366
|
-
.map(entry => {
|
|
367
|
-
const dirPath = path.join(fixerBackupRoot, entry.name);
|
|
368
|
-
const stat = SecurityUtils.safeStatSync(dirPath, process.cwd());
|
|
369
|
-
return { name: entry.name, path: dirPath, mtimeMs: stat ? stat.mtimeMs : 0 };
|
|
370
|
-
})
|
|
371
|
-
.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
372
|
-
|
|
373
|
-
if (backupDirs.length <= keepCount) return;
|
|
374
|
-
|
|
375
|
-
for (const staleDir of backupDirs.slice(keepCount)) {
|
|
376
|
-
fs.rmSync(staleDir.path, { recursive: true, force: true });
|
|
377
|
-
}
|
|
378
|
-
} catch (error) {
|
|
379
|
-
console.warn(`Failed to clean old backups: ${error.message}`);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this.cleanupOldBackups();
|
|
349
|
+
|
|
350
|
+
console.log(t('fixer.backupCreated'));
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.warn(`Failed to create backup: ${error.message}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
cleanupOldBackups() {
|
|
357
|
+
try {
|
|
358
|
+
const fixerBackupRoot = path.resolve(this.config?.backup?.location || './i18ntk-backups', 'fixer');
|
|
359
|
+
if (!SecurityUtils.safeExistsSync(fixerBackupRoot, process.cwd())) return;
|
|
360
|
+
|
|
361
|
+
const configuredKeep = parseInt(this.config?.backup?.maxBackups, 10);
|
|
362
|
+
const keepCount = Number.isInteger(configuredKeep) ? Math.min(Math.max(configuredKeep, 1), 3) : 1;
|
|
363
|
+
|
|
364
|
+
const backupDirs = SecurityUtils.safeReaddirSync(fixerBackupRoot, process.cwd(), { withFileTypes: true })
|
|
365
|
+
.filter(entry => entry.isDirectory() && entry.name.startsWith('backup-'))
|
|
366
|
+
.map(entry => {
|
|
367
|
+
const dirPath = path.join(fixerBackupRoot, entry.name);
|
|
368
|
+
const stat = SecurityUtils.safeStatSync(dirPath, process.cwd());
|
|
369
|
+
return { name: entry.name, path: dirPath, mtimeMs: stat ? stat.mtimeMs : 0 };
|
|
370
|
+
})
|
|
371
|
+
.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
372
|
+
|
|
373
|
+
if (backupDirs.length <= keepCount) return;
|
|
374
|
+
|
|
375
|
+
for (const staleDir of backupDirs.slice(keepCount)) {
|
|
376
|
+
fs.rmSync(staleDir.path, { recursive: true, force: true });
|
|
377
|
+
}
|
|
378
|
+
} catch (error) {
|
|
379
|
+
console.warn(`Failed to clean old backups: ${error.message}`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
382
|
|
|
383
383
|
// Analyze translation issues for fixing
|
|
384
384
|
analyzeIssues(language, fileName) {
|
|
@@ -420,7 +420,7 @@ class FixerCommand {
|
|
|
420
420
|
type: 'missing_key',
|
|
421
421
|
key,
|
|
422
422
|
sourceValue,
|
|
423
|
-
fix: () => this.setValueByPath(
|
|
423
|
+
fix: (obj) => this.setValueByPath(obj, key, sourceValue)
|
|
424
424
|
});
|
|
425
425
|
} else if (targetValue === '') {
|
|
426
426
|
// Empty value
|
|
@@ -428,7 +428,7 @@ class FixerCommand {
|
|
|
428
428
|
type: 'empty_value',
|
|
429
429
|
key,
|
|
430
430
|
sourceValue,
|
|
431
|
-
fix: () => this.setValueByPath(
|
|
431
|
+
fix: (obj) => this.setValueByPath(obj, key, sourceValue)
|
|
432
432
|
});
|
|
433
433
|
} else {
|
|
434
434
|
const markers = this.config.notTranslatedMarkers || [this.config.notTranslatedMarker];
|
|
@@ -438,7 +438,7 @@ class FixerCommand {
|
|
|
438
438
|
type: 'untranslated_marker',
|
|
439
439
|
key,
|
|
440
440
|
sourceValue,
|
|
441
|
-
fix: () => this.setValueByPath(
|
|
441
|
+
fix: (obj) => this.setValueByPath(obj, key, sourceValue)
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
}
|
|
@@ -486,7 +486,7 @@ class FixerCommand {
|
|
|
486
486
|
|
|
487
487
|
for (const issue of issues) {
|
|
488
488
|
if (typeof issue.fix === 'function') {
|
|
489
|
-
issue.fix();
|
|
489
|
+
issue.fix(targetObj);
|
|
490
490
|
fixes.files[fileName].fixed++;
|
|
491
491
|
fixes.fixedIssues++;
|
|
492
492
|
}
|
|
@@ -494,7 +494,7 @@ class FixerCommand {
|
|
|
494
494
|
|
|
495
495
|
// Write back the fixed content
|
|
496
496
|
const fixedContent = JSON.stringify(targetObj, null, 2);
|
|
497
|
-
SecurityUtils.safeWriteFileSync(targetFilePath, fixedContent,
|
|
497
|
+
SecurityUtils.safeWriteFileSync(targetFilePath, fixedContent, this.sourceDir, 'utf8');
|
|
498
498
|
|
|
499
499
|
} catch (error) {
|
|
500
500
|
console.warn(`Error fixing ${language}/${fileName}: ${error.message}`);
|
|
@@ -527,9 +527,9 @@ class FixerCommand {
|
|
|
527
527
|
}
|
|
528
528
|
|
|
529
529
|
// Create backup unless disabled
|
|
530
|
-
if (!args.noBackup && !this.dryRun && this.config?.backup?.enabled === true) {
|
|
531
|
-
await this.createBackup();
|
|
532
|
-
}
|
|
530
|
+
if (!args.noBackup && !this.dryRun && this.config?.backup?.enabled === true) {
|
|
531
|
+
await this.createBackup();
|
|
532
|
+
}
|
|
533
533
|
|
|
534
534
|
const languages = this.getAvailableLanguages();
|
|
535
535
|
|
|
@@ -591,9 +591,9 @@ class FixerCommand {
|
|
|
591
591
|
console.log(t('fixer.totalIssues', { count: totalIssues }));
|
|
592
592
|
console.log(t('fixer.totalFixed', { count: totalFixed }));
|
|
593
593
|
|
|
594
|
-
if (this.backupDir && !args.noBackup && this.config?.backup?.enabled === true) {
|
|
595
|
-
console.log(t('fixer.backupLocation', { dir: this.backupDir }));
|
|
596
|
-
}
|
|
594
|
+
if (this.backupDir && !args.noBackup && this.config?.backup?.enabled === true) {
|
|
595
|
+
console.log(t('fixer.backupLocation', { dir: this.backupDir }));
|
|
596
|
+
}
|
|
597
597
|
|
|
598
598
|
console.log(t('fixer.completed'));
|
|
599
599
|
|
|
@@ -677,4 +677,4 @@ class FixerCommand {
|
|
|
677
677
|
}
|
|
678
678
|
}
|
|
679
679
|
|
|
680
|
-
module.exports = FixerCommand;
|
|
680
|
+
module.exports = FixerCommand;
|