@openedx/frontend-base 1.0.0-alpha.20 → 1.0.0-alpha.22

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.
Files changed (52) hide show
  1. package/dist/runtime/i18n/index.d.ts +1 -1
  2. package/dist/runtime/i18n/index.js +1 -1
  3. package/dist/runtime/i18n/index.js.map +1 -1
  4. package/dist/runtime/i18n/lib.d.ts +0 -6
  5. package/dist/runtime/i18n/lib.js +0 -13
  6. package/dist/runtime/i18n/lib.js.map +1 -1
  7. package/dist/shell/dev/devHome/app.js +0 -2
  8. package/dist/shell/dev/devHome/app.js.map +1 -1
  9. package/dist/shell/site.js +1 -3
  10. package/dist/shell/site.js.map +1 -1
  11. package/dist/tools/cli/commands/translations.d.ts +2 -0
  12. package/dist/tools/cli/commands/translations.js +20 -0
  13. package/dist/tools/cli/openedx.js +6 -0
  14. package/dist/tools/cli/utils/printUsage.js +8 -0
  15. package/dist/tools/cli/utils/translations/index.d.ts +2 -0
  16. package/dist/tools/cli/utils/translations/index.js +7 -0
  17. package/dist/tools/cli/utils/translations/messagesObject.d.ts +26 -0
  18. package/dist/tools/cli/utils/translations/messagesObject.js +66 -0
  19. package/dist/tools/cli/utils/translations/prepare.d.ts +5 -0
  20. package/dist/tools/cli/utils/translations/prepare.js +98 -0
  21. package/dist/tools/cli/utils/translations/pull.d.ts +6 -0
  22. package/dist/tools/cli/utils/translations/pull.js +102 -0
  23. package/dist/tools/types.d.ts +2 -0
  24. package/dist/tools/types.js +2 -0
  25. package/dist/tools/webpack/common-config/index.d.ts +1 -0
  26. package/dist/tools/webpack/common-config/index.js +3 -1
  27. package/dist/tools/webpack/common-config/site/getI18nMessagesFallbackPlugin/emptyI18n.d.ts +2 -0
  28. package/dist/tools/webpack/common-config/site/getI18nMessagesFallbackPlugin/emptyI18n.js +3 -0
  29. package/dist/tools/webpack/common-config/site/getI18nMessagesFallbackPlugin/index.d.ts +2 -0
  30. package/dist/tools/webpack/common-config/site/getI18nMessagesFallbackPlugin/index.js +26 -0
  31. package/dist/tools/webpack/utils/getResolvedSiteI18nPath.d.ts +1 -0
  32. package/dist/tools/webpack/utils/getResolvedSiteI18nPath.js +25 -0
  33. package/dist/tools/webpack/webpack.config.build.js +4 -0
  34. package/dist/tools/webpack/webpack.config.dev.js +4 -0
  35. package/dist/tools/webpack/webpack.config.dev.shell.js +3 -0
  36. package/dist/types.d.ts +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/package.json +14 -8
  39. package/dist/shell/dev/devHome/i18n/index.d.ts +0 -27
  40. package/dist/shell/dev/devHome/i18n/index.js +0 -28
  41. package/dist/shell/dev/devHome/i18n/index.js.map +0 -1
  42. package/dist/shell/i18n/index.d.ts +0 -25
  43. package/dist/shell/i18n/index.js +0 -26
  44. package/dist/shell/i18n/index.js.map +0 -1
  45. package/dist/tools/cli/intl-imports.d.ts +0 -7
  46. package/dist/tools/cli/intl-imports.js +0 -233
  47. package/dist/tools/cli/intl-imports.test.d.ts +0 -1
  48. package/dist/tools/cli/intl-imports.test.js +0 -146
  49. package/dist/tools/cli/transifex-utils.d.ts +0 -2
  50. package/dist/tools/cli/transifex-utils.js +0 -68
  51. package/dist/tools/webpack/plugins/html-webpack-new-relic-plugin/test/HtmlWebpackNewRelicPlugin.test.d.ts +0 -1
  52. package/dist/tools/webpack/plugins/html-webpack-new-relic-plugin/test/HtmlWebpackNewRelicPlugin.test.js +0 -66
@@ -1,146 +0,0 @@
1
- "use strict";
2
- // Tests for the intl-imports.js command line.
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const path_1 = __importDefault(require("path"));
8
- const intl_imports_1 = require("./intl-imports");
9
- const sampleAppDirectory = path_1.default.join(__dirname, '../../test-site');
10
- // History for `process.stdout.write` mock calls.
11
- const logHistory = {
12
- log: [],
13
- latest: '',
14
- };
15
- // History for `fs.writeFileSync` mock calls.
16
- const writeFileHistory = {
17
- log: [],
18
- latest: null,
19
- };
20
- // Mock for process.stdout.write
21
- const log = (text) => {
22
- logHistory.latest = text;
23
- logHistory.log.push(text);
24
- };
25
- // Mock for fs.writeFileSync
26
- const writeFileSync = (filename, content) => {
27
- const entry = { filename, content };
28
- writeFileHistory.latest = entry;
29
- writeFileHistory.log.push(entry);
30
- };
31
- // Main with mocked output
32
- const main = (...directories) => (0, intl_imports_1.main)({
33
- directories,
34
- log,
35
- writeFileSync,
36
- pwd: sampleAppDirectory,
37
- });
38
- // Clean up mock histories
39
- afterEach(() => {
40
- logHistory.log = [];
41
- logHistory.latest = null;
42
- writeFileHistory.log = [];
43
- writeFileHistory.latest = null;
44
- });
45
- describe('help document', () => {
46
- it('should print help for --help', () => {
47
- main('--help');
48
- expect(logHistory.latest).toMatch('Script to generate the src/i18n/index.js');
49
- });
50
- it('should print help for -h', () => {
51
- main('-h');
52
- expect(logHistory.latest).toMatch('Script to generate the src/i18n/index.js');
53
- });
54
- });
55
- describe('error validation', () => {
56
- it('expects a list of directories', () => {
57
- main();
58
- expect(logHistory.log.join('\n')).toMatch('Script to generate the src/i18n/index.js'); // Print help error
59
- expect(logHistory.latest).toMatch('Error: A list of directories is required'); // Print error message
60
- });
61
- it('expects a directory with a relative path of "src/i18n"', () => {
62
- (0, intl_imports_1.main)({
63
- directories: ['frontend-app-example'],
64
- log,
65
- writeFileSync,
66
- pwd: path_1.default.join(__dirname), // __dirname === `scripts` which has no sub-dir `src/i18n`
67
- });
68
- expect(logHistory.log.join('\n')).toMatch('Script to generate the src/i18n/index.js'); // Print help on error
69
- expect(logHistory.latest).toMatch('Error: src/i18n directory was not found.'); // Print error message
70
- });
71
- });
72
- describe('generated files', () => {
73
- it('writes a correct src/i18n/index.js file', () => {
74
- main('frontend-component-singlelang', 'frontend-component-nolangs', 'frontend-component-emptylangs', 'frontend-app-sample');
75
- const mainFileActualContent = writeFileHistory.log.find((file) => {
76
- return file.filename.endsWith('src/i18n/index.js');
77
- })?.content;
78
- const mainFileExpectedContent = `// This file is generated by the openedx/frontend-base's "intl-import.js" script.
79
- //
80
- // Refer to the i18n documents in https://docs.openedx.org/en/latest/developers/references/i18n.html to update
81
- // the file and use the Micro-frontend i18n pattern in new repositories.
82
- //
83
-
84
- import messagesFromFrontendComponentSinglelang from './messages/frontend-component-singlelang';
85
- // Skipped import due to missing 'frontend-component-nolangs/index.js' likely due to empty translations..
86
- // Skipped import due to missing 'frontend-component-emptylangs/index.js' likely due to empty translations..
87
- import messagesFromFrontendAppSample from './messages/frontend-app-sample';
88
-
89
- export default [
90
- messagesFromFrontendComponentSinglelang,
91
- messagesFromFrontendAppSample,
92
- ];
93
- `;
94
- expect(mainFileActualContent).toEqual(mainFileExpectedContent);
95
- });
96
- it('writes a correct frontend-component-singlelang/index.js file', () => {
97
- main('frontend-component-singlelang', 'frontend-component-nolangs', 'frontend-component-emptylangs', 'frontend-app-sample');
98
- const mainFileActualContent = writeFileHistory.log.find(file => file.filename.endsWith('frontend-component-singlelang/index.js'))?.content;
99
- const singleLangExpectedContent = `// This file is generated by the openedx/frontend-base's "intl-import.js" script.
100
- //
101
- // Refer to the i18n documents in https://docs.openedx.org/en/latest/developers/references/i18n.html to update
102
- // the file and use the Micro-frontend i18n pattern in new repositories.
103
- //
104
-
105
- import messagesOfArLanguage from './ar.json';
106
-
107
- export default {
108
- 'ar': messagesOfArLanguage,
109
- };
110
- `;
111
- expect(mainFileActualContent).toEqual(singleLangExpectedContent);
112
- });
113
- it('writes a correct frontend-app-sample/index.js file', () => {
114
- main('frontend-component-singlelang', 'frontend-component-nolangs', 'frontend-component-emptylangs', 'frontend-app-sample');
115
- const mainFileActualContent = writeFileHistory.log.find(file => file.filename.endsWith('frontend-app-sample/index.js'))?.content;
116
- const singleLangExpectedContent = `// This file is generated by the openedx/frontend-base's "intl-import.js" script.
117
- //
118
- // Refer to the i18n documents in https://docs.openedx.org/en/latest/developers/references/i18n.html to update
119
- // the file and use the Micro-frontend i18n pattern in new repositories.
120
- //
121
-
122
- import messagesOfArLanguage from './ar.json';
123
- // Note: Skipped empty 'eo.json' messages file.
124
- import messagesOfEs419Language from './es_419.json';
125
-
126
- export default {
127
- 'ar': messagesOfArLanguage,
128
- 'es-419': messagesOfEs419Language,
129
- };
130
- `;
131
- expect(mainFileActualContent).toEqual(singleLangExpectedContent);
132
- });
133
- });
134
- describe('list of generated index.js files', () => {
135
- it('writes only non-empty languages in addition to the main file', () => {
136
- main('frontend-component-singlelang', 'frontend-component-nolangs', 'frontend-component-emptylangs', 'frontend-app-sample');
137
- const writtenFiles = writeFileHistory.log
138
- .map(file => file.filename)
139
- .map(file => path_1.default.relative(sampleAppDirectory, file));
140
- expect(writtenFiles).toEqual([
141
- 'src/i18n/messages/frontend-component-singlelang/index.js',
142
- 'src/i18n/messages/frontend-app-sample/index.js',
143
- 'src/i18n/index.js',
144
- ]);
145
- });
146
- });
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const fs_1 = __importDefault(require("fs"));
8
- const glob_1 = __importDefault(require("glob"));
9
- const path_1 = __importDefault(require("path"));
10
- /*
11
- * See the Makefile for how the required hash file is downloaded from Transifex.
12
- */
13
- /*
14
- * Expected input: a directory, possibly containing subdirectories, with .json files. Each .json
15
- * file is an array of translation triplets (id, description, defaultMessage).
16
- *
17
- *
18
- */
19
- function gatherJson(dir) {
20
- const ret = [];
21
- const files = glob_1.default.sync(`${dir}/**/*.json`);
22
- files.forEach((filename) => {
23
- const messages = JSON.parse(fs_1.default.readFileSync(filename, { encoding: 'utf8' }));
24
- ret.push(...messages);
25
- });
26
- return ret;
27
- }
28
- // the hash file returns ids whose periods are "escaped" (sort of), like this:
29
- // "key": "profile\\.sociallinks\\.social\\.links"
30
- // so our regular messageIds won't match them out of the box
31
- function escapeDots(messageId) {
32
- return messageId.replace(/\./g, '\\.');
33
- }
34
- const jsonDir = process.argv[2];
35
- const messageObjects = gatherJson(jsonDir);
36
- if (messageObjects.length === 0) {
37
- process.exitCode = 1;
38
- throw new Error('Found no messages');
39
- }
40
- if (process.argv[3] === '--comments') { // prepare to handle the translator notes
41
- const loggingPrefix = path_1.default.basename(`${__filename}`); // the name of this JS file
42
- const bashScriptsPath = (process.argv[4] && process.argv[4] === '--v3-scripts-path'
43
- ? './node_modules/@edx/reactifex/bash_scripts'
44
- : './node_modules/reactifex/bash_scripts');
45
- const hashFile = `${bashScriptsPath}/hashmap.json`;
46
- process.stdout.write(`${loggingPrefix}: reading hash file ${hashFile}\n`);
47
- const messageInfo = JSON.parse(fs_1.default.readFileSync(hashFile, { encoding: 'utf8' }));
48
- const outputFile = `${bashScriptsPath}/hashed_data.txt`;
49
- process.stdout.write(`${loggingPrefix}: writing to output file ${outputFile}\n`);
50
- fs_1.default.writeFileSync(outputFile, '');
51
- messageObjects.forEach((message) => {
52
- const transifexFormatId = escapeDots(message.id);
53
- const info = messageInfo.find((mi) => mi.key === transifexFormatId);
54
- if (info) {
55
- fs_1.default.appendFileSync(outputFile, `${info.string_hash}|${message.description}\n`);
56
- }
57
- else {
58
- process.stdout.write(`${loggingPrefix}: string ${message.id} does not yet exist on transifex!\n`);
59
- }
60
- });
61
- }
62
- else {
63
- const output = {};
64
- messageObjects.forEach((message) => {
65
- output[message.id] = message.defaultMessage;
66
- });
67
- fs_1.default.writeFileSync(process.argv[3], JSON.stringify(output, null, 2));
68
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
8
- const path_1 = __importDefault(require("path"));
9
- const webpack_1 = __importDefault(require("webpack"));
10
- const HtmlWebpackNewRelicPlugin_1 = __importDefault(require("../HtmlWebpackNewRelicPlugin"));
11
- const OUTPUT_DIR = path_1.default.join(__dirname, './dist');
12
- describe('HtmlWebpackNewRelicPlugin', () => {
13
- const testPluginOptions = {
14
- accountID: '121212',
15
- agentID: '343434',
16
- trustKey: '565656',
17
- licenseKey: '123456',
18
- applicationID: '654321',
19
- };
20
- afterEach(() => {
21
- if (fs_1.default.existsSync(OUTPUT_DIR)) {
22
- fs_1.default.rmSync(OUTPUT_DIR, { recursive: true, force: true });
23
- }
24
- });
25
- it('should append new relic script to body', done => {
26
- (0, webpack_1.default)({
27
- entry: path_1.default.resolve(__dirname, 'fixtures', 'entry.js'),
28
- output: {
29
- path: path_1.default.resolve(__dirname, './dist'),
30
- },
31
- plugins: [
32
- new html_webpack_plugin_1.default(),
33
- new HtmlWebpackNewRelicPlugin_1.default(testPluginOptions),
34
- ],
35
- }, (err) => {
36
- const htmlFile = path_1.default.resolve(OUTPUT_DIR, 'index.html');
37
- expect(err).toBeNull();
38
- expect(fs_1.default.existsSync(htmlFile)).toBe(true);
39
- const file = fs_1.default.readFileSync(path_1.default.resolve(OUTPUT_DIR, htmlFile), { encoding: 'utf-8' }, (error, data) => data.toString());
40
- Object.entries(testPluginOptions).forEach(([optionName, optionValue]) => {
41
- expect(file.indexOf(`${optionName}:"${optionValue}"`)).toBeGreaterThan(-1);
42
- });
43
- done();
44
- });
45
- });
46
- describe('when its missing configuration variables', () => {
47
- function testMissingOption(missingOptionName) {
48
- it(`should throw error if ${missingOptionName} is missing`, done => {
49
- const compiler = (0, webpack_1.default)({
50
- entry: path_1.default.resolve(__dirname, 'fixtures', 'entry.js'),
51
- output: {
52
- path: path_1.default.resolve(__dirname, '../dist'),
53
- },
54
- plugins: [new html_webpack_plugin_1.default()],
55
- });
56
- const optionsMissingOne = { ...testPluginOptions };
57
- delete optionsMissingOne[missingOptionName];
58
- expect(() => compiler.options.plugins.push(new HtmlWebpackNewRelicPlugin_1.default(optionsMissingOne))).toThrow(`${missingOptionName} argument is required`);
59
- done();
60
- });
61
- }
62
- Object.keys(testPluginOptions).forEach((key) => {
63
- testMissingOption(key);
64
- });
65
- });
66
- });