@jsverse/transloco-optimize 7.0.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/CHANGELOG.md +61 -0
- package/README.md +3 -0
- package/package.json +42 -0
- package/src/index.js +25 -0
- package/src/lib/transloco-optimize.js +52 -0
- package/src/test-setup.js +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
# [7.0.0](https://github.com/jsverse/transloco/compare/transloco-optimize-6.0.0...transloco-optimize-7.0.0) (2024-03-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### chore
|
|
9
|
+
|
|
10
|
+
* **optimize:** ๐ค update package scope ([65645ee](https://github.com/jsverse/transloco/commit/65645ee0a79413c74be64ede5bf33174f06465f7))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* **optimize:** ๐งจ The package is now published under the jsverse scope
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# [6.0.0](https://github.com/jsverse/transloco/compare/transloco-optimize-5.0.3...transloco-optimize-6.0.0) (2024-03-23)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## [5.0.3](https://github.com/jsverse/transloco/compare/transloco-optimize-5.0.2...transloco-optimize-5.0.3) (2023-08-13)
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- **optimize:** ๐ fixed file resolution on windows ([#687](https://github.com/jsverse/transloco/issues/687)) ([5260127](https://github.com/jsverse/transloco/commit/52601277edfe5ef3502a822fc6129e28723bc16c))
|
|
28
|
+
|
|
29
|
+
## [5.0.2](https://github.com/jsverse/transloco/compare/transloco-optimize-5.0.1...transloco-optimize-5.0.2) (2023-08-04)
|
|
30
|
+
|
|
31
|
+
## [5.0.1](https://github.com/jsverse/transloco/compare/transloco-optimize-5.0.0...transloco-optimize-5.0.1) (2023-08-01)
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
- **optimize:** ๐ remove redundant peerDependencies ([7a3def8](https://github.com/jsverse/transloco/commit/7a3def8de36f9238c10bfce739fd9f3e83513e72)), closes [#677](https://github.com/jsverse/transloco/issues/677)
|
|
36
|
+
|
|
37
|
+
# [5.0.0](https://github.com/jsverse/transloco/compare/transloco-optimize-4.0.0...transloco-optimize-5.0.0) (2023-07-30)
|
|
38
|
+
|
|
39
|
+
# [4.0.0](https://github.com/jsverse/transloco/compare/transloco-optimize-3.0.2...transloco-optimize-4.0.0) (2023-06-17)
|
|
40
|
+
|
|
41
|
+
### chore
|
|
42
|
+
|
|
43
|
+
- ๐ค upgrade to angular v16 ([#661](https://github.com/jsverse/transloco/issues/661)) ([08db7e7](https://github.com/jsverse/transloco/commit/08db7e7d1f64846fa0b07123dee8ff5bff20b4f0))
|
|
44
|
+
- **optimize:** ๐ค min node version is 16 ([ee1bc0b](https://github.com/jsverse/transloco/commit/ee1bc0b88555c808482a9f6b60061f15ea4ddaf7))
|
|
45
|
+
|
|
46
|
+
### BREAKING CHANGES
|
|
47
|
+
|
|
48
|
+
- **optimize:** ๐งจ min node version is 16
|
|
49
|
+
- ๐งจ Angular 16
|
|
50
|
+
|
|
51
|
+
## [3.0.2](https://github.com/jsverse/transloco/compare/transloco-optimize-3.0.1...transloco-optimize-3.0.2) (2021-10-25)
|
|
52
|
+
|
|
53
|
+
### Bug Fixes
|
|
54
|
+
|
|
55
|
+
- **optimize:** ๐ wrong path resolution ([974b169](https://github.com/jsverse/transloco/commit/974b1698083913b99992e4994b77d4c2b6a5489e))
|
|
56
|
+
|
|
57
|
+
## [3.0.1](https://github.com/jsverse/transloco/compare/transloco-optimize-3.0.0...transloco-optimize-3.0.1) (2021-10-25)
|
|
58
|
+
|
|
59
|
+
### Bug Fixes
|
|
60
|
+
|
|
61
|
+
- **optimize:** ๐ bad import crash ([34ee25b](https://github.com/jsverse/transloco/commit/34ee25b0ffc811e5d0234190ec4f1a56ff873d63))
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsverse/transloco-optimize",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Transloco optimization process for production environments",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=16"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"transloco-optimize": "src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/jsverse/transloco/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://jsverse.github.io/transloco/docs/tools/optimize/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/jsverse/transloco"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"angular",
|
|
25
|
+
"angular 2",
|
|
26
|
+
"i18n",
|
|
27
|
+
"translate",
|
|
28
|
+
"angular translate",
|
|
29
|
+
"angular i18n",
|
|
30
|
+
"transloco",
|
|
31
|
+
"comments",
|
|
32
|
+
"build",
|
|
33
|
+
"optimize"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"flat": "^5.0.2",
|
|
38
|
+
"command-line-args": "^5.2.0",
|
|
39
|
+
"glob": "^10.0.0"
|
|
40
|
+
},
|
|
41
|
+
"type": "commonjs"
|
|
42
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const command_line_args_1 = tslib_1.__importDefault(require("command-line-args"));
|
|
6
|
+
const transloco_optimize_1 = require("./lib/transloco-optimize");
|
|
7
|
+
const optionDefinitions = [
|
|
8
|
+
{ name: 'commentsKey', alias: 'k', type: String, defaultValue: 'comment' },
|
|
9
|
+
{ name: 'dist', alias: 'd', type: String, defaultOption: true },
|
|
10
|
+
];
|
|
11
|
+
const { dist, commentsKey } = (0, command_line_args_1.default)(optionDefinitions);
|
|
12
|
+
(0, transloco_optimize_1.getTranslationFiles)(dist)
|
|
13
|
+
.then((filesPaths) => {
|
|
14
|
+
if (filesPaths.length === 0) {
|
|
15
|
+
return Promise.reject(`Transloco Optimize: No Translation path found under: ${(0, transloco_optimize_1.getTranslationsFolder)(dist)}`);
|
|
16
|
+
}
|
|
17
|
+
console.log(`Transloco Optimize: found ${filesPaths.length} translation files, optimizing...`);
|
|
18
|
+
return (0, transloco_optimize_1.optimizeFiles)(filesPaths, commentsKey);
|
|
19
|
+
})
|
|
20
|
+
.then(() => {
|
|
21
|
+
console.log('Transloco Optimize: Done! ๐ ');
|
|
22
|
+
})
|
|
23
|
+
.catch((err) => {
|
|
24
|
+
console.warn(err);
|
|
25
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.optimizeFiles = exports.getTranslationFiles = exports.getTranslationsFolder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const glob_1 = require("glob");
|
|
8
|
+
const flat_1 = require("flat");
|
|
9
|
+
const isWindows = process.platform === "win32";
|
|
10
|
+
function removeComments(translation, commentsKey = 'comment') {
|
|
11
|
+
return Object.keys(translation).reduce((acc, key) => {
|
|
12
|
+
const lastKey = key.split('.').pop();
|
|
13
|
+
if (lastKey !== commentsKey) {
|
|
14
|
+
acc[key] = translation[key];
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
function getTranslationsFolder(dist) {
|
|
20
|
+
return node_path_1.default.resolve(process.cwd(), dist);
|
|
21
|
+
}
|
|
22
|
+
exports.getTranslationsFolder = getTranslationsFolder;
|
|
23
|
+
function getTranslationFiles(dist) {
|
|
24
|
+
const filesMatcher = node_path_1.default.resolve(getTranslationsFolder(dist), '**/*.json');
|
|
25
|
+
return (0, glob_1.glob)(filesMatcher, { windowsPathsNoEscape: isWindows });
|
|
26
|
+
}
|
|
27
|
+
exports.getTranslationFiles = getTranslationFiles;
|
|
28
|
+
function optimizeFiles(translationPaths, commentsKey) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
let error;
|
|
31
|
+
for (const path of translationPaths) {
|
|
32
|
+
try {
|
|
33
|
+
const translation = node_fs_1.default.readFileSync(path, { encoding: 'utf8' });
|
|
34
|
+
const asObject = JSON.parse(translation);
|
|
35
|
+
const flatObject = (0, flat_1.flatten)(asObject, { safe: true });
|
|
36
|
+
const optimized = JSON.stringify(removeComments(flatObject, commentsKey));
|
|
37
|
+
node_fs_1.default.writeFileSync(path, optimized, { encoding: 'utf8' });
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
error = err;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (error) {
|
|
45
|
+
reject(error);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
resolve();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.optimizeFiles = optimizeFiles;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
require("zone.js");
|
|
5
|
+
require("zone.js/testing");
|
|
6
|
+
const testing_1 = require("@angular/core/testing");
|
|
7
|
+
const testing_2 = require("@angular/platform-browser-dynamic/testing");
|
|
8
|
+
// First, initialize the Angular testing environment.
|
|
9
|
+
(0, testing_1.getTestBed)().initTestEnvironment(testing_2.BrowserDynamicTestingModule, (0, testing_2.platformBrowserDynamicTesting)(), {
|
|
10
|
+
teardown: { destroyAfterEach: false },
|
|
11
|
+
});
|