@superdesk/build-tools 1.0.18 → 1.1.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/package.json +1 -2
- package/src/extensions/extract-translations.js +1 -1
- package/src/extensions/get-extension-directories-sync.js +1 -1
- package/src/extensions/install-extensions.js +18 -0
- package/src/index.js +2 -12
- package/src/po-to-json/index.js +1 -2
- package/src/generate-instance-configuration-schema.js +0 -71
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdesk/build-tools",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"gettext-extractor": "3.5.3",
|
|
15
15
|
"gettext.js": "0.9.0",
|
|
16
16
|
"glob": "7.1.7",
|
|
17
|
-
"lodash": "4.17.19",
|
|
18
17
|
"rimraf": "3.0.2"
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -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
|
-
|
|
15
|
+
continue;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const pathsAbsolute = paths.map((p) => path.join(extensionRootPath, p));
|
|
@@ -110,7 +110,7 @@ function getExtensionDirectoriesSync(clientPath) {
|
|
|
110
110
|
.then((res) => res.default),
|
|
111
111
|
}
|
|
112
112
|
*/
|
|
113
|
-
var extensionRegistrationPattern = /id:\W*'(.*)',\W*load:\W*import\('(.+?)'/g;
|
|
113
|
+
var extensionRegistrationPattern = /id:\W*['"](.*)['"],\W*load:\W*import\(['"](.+?)['"]/g;
|
|
114
114
|
|
|
115
115
|
const matches = [];
|
|
116
116
|
|
|
@@ -83,6 +83,24 @@ module.exports = function installExtensions(clientDir) {
|
|
|
83
83
|
directories.forEach(({extensionRootPath, extensionSrcPath}) => {
|
|
84
84
|
// if src dir doesn't exist, assume that the extension is already built (e.g. when installed from npm)
|
|
85
85
|
if (fs.existsSync(extensionSrcPath)) {
|
|
86
|
+
const pkgPath = path.join(extensionRootPath, 'package.json');
|
|
87
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
88
|
+
|
|
89
|
+
// Extensions whose `main` points at TypeScript source are consumed
|
|
90
|
+
// directly by webpack's ts-loader. Skip compile and the legacy
|
|
91
|
+
// `correct*` fixups. Still install runtime `dependencies` so webpack
|
|
92
|
+
// can resolve them via the extension's nested node_modules walk.
|
|
93
|
+
// (When workspaces land, this per-extension install goes away.)
|
|
94
|
+
if (typeof pkg.main === 'string' && /\.(ts|tsx)$/.test(pkg.main)) {
|
|
95
|
+
if (pkg.dependencies && Object.keys(pkg.dependencies).length > 0) {
|
|
96
|
+
execSync(
|
|
97
|
+
'npm install --no-audit --omit=dev',
|
|
98
|
+
{stdio: 'inherit', cwd: extensionRootPath}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
86
104
|
correctApiDefinitionsPath(extensionRootPath, clientDir);
|
|
87
105
|
|
|
88
106
|
execSync(
|
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,6 +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);
|
|
42
|
+
const poDir = path.join(clientDirAbs, 'node_modules/superdesk-core/po');
|
|
43
|
+
const translationsDir = path.join(currentDir, mainClientDir, 'dist/languages');
|
|
51
44
|
|
|
52
45
|
// build will fail if extensions are not installed
|
|
53
46
|
installExtensions(clientDirAbs);
|
|
@@ -58,9 +51,6 @@ program.command('build-root-repo <main-client-dir>')
|
|
|
58
51
|
{stdio: 'inherit'}
|
|
59
52
|
);
|
|
60
53
|
|
|
61
|
-
const poDir = path.join(clientDirAbs, 'node_modules/superdesk-core/po');
|
|
62
|
-
const translationsDir = path.join(currentDir, mainClientDir, 'dist/languages');
|
|
63
|
-
|
|
64
54
|
// translationsDir is only created after the build and would get removed if created before build
|
|
65
55
|
poToJson(poDir, translationsDir);
|
|
66
56
|
mergeTranslationsFromExtensions(clientDirAbs);
|
package/src/po-to-json/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var fs = require('fs');
|
|
2
2
|
var path = require('path');
|
|
3
3
|
var execSync = require('child_process').execSync;
|
|
4
|
-
var _ = require('lodash');
|
|
5
4
|
const {isDirectory} = require('../utils');
|
|
6
5
|
|
|
7
6
|
function getModuleDir(moduleName) {
|
|
@@ -90,7 +89,7 @@ function compileTranslationsPoToJson(translationsPoDir, translationsJsonDir) {
|
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
if (
|
|
92
|
+
if (filename.endsWith('.po') !== true) {
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
|
|
@@ -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, ''');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function unescapeSingleQuoteAsHtml(str) {
|
|
11
|
-
return str.replace(/'/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
|
-
};
|