@superdesk/build-tools 1.0.17 → 1.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdesk/build-tools",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -12,7 +12,7 @@ function extractTranslations(clientDir) {
12
12
  const paths = _.get(package, 'superdeskExtension.translations-extract-paths');
13
13
 
14
14
  if (paths == null || !Array.isArray(paths)) {
15
- return null;
15
+ continue;
16
16
  }
17
17
 
18
18
  const pathsAbsolute = paths.map((p) => path.join(extensionRootPath, p));
package/src/index.js CHANGED
@@ -9,7 +9,6 @@ const installExtensions = require('./extensions/install-extensions');
9
9
  const {mergeTranslationsFromExtensions} = require('./extensions/translations');
10
10
  const {extractTranslations} = require('./extensions/extract-translations');
11
11
  const {namespaceCSS, watchCSS} = require('./extensions/css');
12
- const {generateInstanceConfigurationSchema} = require('./generate-instance-configuration-schema');
13
12
 
14
13
  const {Command} = require('commander');
15
14
  const program = new Command();
@@ -27,14 +26,6 @@ program.configureHelp({
27
26
  },
28
27
  });
29
28
 
30
- program.command('generate-instance-configuration-schema <main-client-dir>')
31
- .description('reads typescript interfaces and generates JSON schema that will be used to generate the UI')
32
- .action((mainClientDir) => {
33
- const clientDirAbs = path.join(currentDir, mainClientDir);
34
-
35
- generateInstanceConfigurationSchema(clientDirAbs);
36
- });
37
-
38
29
  program.command('po-to-json <source-dir-po> <output-dir-json>')
39
30
  .description('convert .po files in the directory to .json format that is used by Superdesk')
40
31
  .action((sourcePo, outputJson) => {
@@ -48,8 +39,8 @@ program.command('build-root-repo <main-client-dir>')
48
39
  .description('executes all actions required to prepare the main repo for usage')
49
40
  .action((mainClientDir) => {
50
41
  const clientDirAbs = path.join(currentDir, mainClientDir);
51
-
52
- generateInstanceConfigurationSchema(clientDirAbs);
42
+ const poDir = path.join(clientDirAbs, 'node_modules/superdesk-core/po');
43
+ const translationsDir = path.join(currentDir, mainClientDir, 'dist/languages');
53
44
 
54
45
  // build will fail if extensions are not installed
55
46
  installExtensions(clientDirAbs);
@@ -60,9 +51,6 @@ program.command('build-root-repo <main-client-dir>')
60
51
  {stdio: 'inherit'}
61
52
  );
62
53
 
63
- const poDir = path.join(clientDirAbs, 'node_modules/superdesk-core/po');
64
- const translationsDir = path.join(currentDir, mainClientDir, 'dist/languages');
65
-
66
54
  // translationsDir is only created after the build and would get removed if created before build
67
55
  poToJson(poDir, translationsDir);
68
56
  mergeTranslationsFromExtensions(clientDirAbs);
@@ -1,71 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- var execSync = require('child_process').execSync;
4
- var _ = require('lodash');
5
-
6
- function escapeSingleQuoteAsHtml(str) {
7
- return str.replace(/'/g, '&apos;');
8
- }
9
-
10
- function unescapeSingleQuoteAsHtml(str) {
11
- return str.replace(/&apos;/g, '\\\'');
12
- }
13
-
14
- function addTranslations(branch) {
15
- if (branch.properties == null) {
16
- return branch;
17
- }
18
-
19
- branch.translations = Object.keys(branch.properties).reduce((acc, property) => {
20
- // gettext call will be unwrapped from the string later with regex
21
- acc[property] = `gettext('${_.lowerCase(escapeSingleQuoteAsHtml(property))}')`;
22
-
23
- return acc;
24
- }, {});
25
-
26
- for (const property of Object.keys(branch.properties)) {
27
- // handle nested properties
28
- branch.properties[property] = addTranslations(branch.properties[property]);
29
-
30
- // handle nested properties inside arrays
31
- if (branch.properties[property].items != null && branch.properties[property].items.properties != null) {
32
- branch.properties[property].items = addTranslations(branch.properties[property].items);
33
- }
34
-
35
- // translate description
36
- if (typeof branch.properties[property].description === 'string') {
37
- branch.properties[property].description =
38
- `gettext('${escapeSingleQuoteAsHtml(branch.properties[property].description)}')`;
39
- }
40
- }
41
-
42
- return branch;
43
- }
44
-
45
- function generateInstanceConfigurationSchema(clientDirAbs) {
46
- const file = path.join(clientDirAbs, 'node_modules/superdesk-core/scripts/core/superdesk-api.d.ts');
47
- const configFile = path.join(
48
- clientDirAbs,
49
- 'node_modules/superdesk-core/scripts/instance-settings.generated.ts'
50
- );
51
- const generatedSchema = JSON.parse(
52
- execSync(`npx typescript-json-schema "${file}" IInstanceSettings --strictNullChecks --required`).toString()
53
- );
54
- const schemaWithTranslations = unescapeSingleQuoteAsHtml(
55
- JSON.stringify(addTranslations(generatedSchema), null, 4)
56
- .replace(/"(gettext.+?)"/g, '$1')
57
- );
58
-
59
- const contents =
60
- `/* eslint-disable quotes, comma-dangle */
61
- /* tslint:disable: trailing-comma max-line-length */
62
-
63
- export const getInstanceConfigSchema = (gettext) => (${schemaWithTranslations});
64
- `;
65
-
66
- fs.writeFileSync(configFile, contents, 'utf-8');
67
- }
68
-
69
- module.exports = {
70
- generateInstanceConfigurationSchema,
71
- };