@izara_project/izara-core-generate-service-code 1.0.25 → 1.0.26
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/jsconfig.json +7 -3
- package/package.json +2 -2
- package/src/generateCode/generateTranslation/generateTranslation.js +57 -0
- package/src/generateCode/generateTranslation/translations/data.js +87 -0
- package/src/generateCode/generateTranslation/translations/template.ejs +5 -0
- package/src/generateCode.js +8 -3
- package/src/libs/Consts.js +6 -2
package/jsconfig.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"author": "Sven Mason <thebarbariansven@gmail.com>",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@izara_project/izara-core-library-core": "^1.0.31",
|
|
28
28
|
"@izara_project/izara-core-library-logger": "^1.0.8",
|
|
29
29
|
"@izara_project/izara-core-library-s3": "^1.0.5",
|
|
30
|
-
"@izara_project/izara-core-library-service-schemas": "^1.0.
|
|
30
|
+
"@izara_project/izara-core-library-service-schemas": "^1.0.127",
|
|
31
31
|
"@izara_project/izara-shared-core": "^1.0.9",
|
|
32
32
|
"ejs": "^5.0.1",
|
|
33
33
|
"js-beautify": "^1.15.4",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
import libs from '#libs/Utils.js';
|
|
22
|
+
|
|
23
|
+
const { checkValidTableYaml } = libs;
|
|
24
|
+
import createSourceTranslations from './translations/data.js';
|
|
25
|
+
|
|
26
|
+
async function translationComponent(
|
|
27
|
+
_izContext,
|
|
28
|
+
appPath,
|
|
29
|
+
allObjSchemas,
|
|
30
|
+
allFlowSchemas
|
|
31
|
+
) {
|
|
32
|
+
try {
|
|
33
|
+
const objSchemaPath = join(appPath, '/src/schemas');
|
|
34
|
+
|
|
35
|
+
const createSources = [];
|
|
36
|
+
const translationComponent = await createSourceTranslations(
|
|
37
|
+
_izContext,
|
|
38
|
+
allObjSchemas,
|
|
39
|
+
allFlowSchemas,
|
|
40
|
+
objSchemaPath
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
console.log("translationComponent", translationComponent)
|
|
44
|
+
createSources.push(translationComponent);
|
|
45
|
+
|
|
46
|
+
return createSources;
|
|
47
|
+
|
|
48
|
+
} catch (error) {
|
|
49
|
+
_izContext.logger.error(
|
|
50
|
+
'Error generating code with template resourceYaml: ',
|
|
51
|
+
error
|
|
52
|
+
);
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default translationComponent;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
22
|
+
|
|
23
|
+
import consts from '#libs/Consts.js';
|
|
24
|
+
import utils from '#libs/Utils.js';
|
|
25
|
+
|
|
26
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } =
|
|
27
|
+
utils;
|
|
28
|
+
const {
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
SAVE_FILE_NAME,
|
|
31
|
+
} = consts;
|
|
32
|
+
|
|
33
|
+
const templatePath = path.join(__dirname, 'template.ejs');
|
|
34
|
+
|
|
35
|
+
import { utils as coreUtils } from '@izara_project/izara-core-library-service-schemas'
|
|
36
|
+
/**
|
|
37
|
+
* receive objectSchema
|
|
38
|
+
* create data for hdrInv template
|
|
39
|
+
*
|
|
40
|
+
* @return {{ templatePath, templateData, setting } }
|
|
41
|
+
*/
|
|
42
|
+
function createSourceTranslations(_izContext, allObjectSchema, allFlowSchemas, srcPath) {
|
|
43
|
+
const createSourceArray = [];
|
|
44
|
+
// console.log("params objSchema", JSON.stringify(allObjectSchema, null, 2));
|
|
45
|
+
for (const objectSchema of allObjectSchema.records) {
|
|
46
|
+
for (const fieldName of Object.keys(objectSchema.fieldNames)) {
|
|
47
|
+
const objType = {
|
|
48
|
+
objectType: objectSchema.objectType,
|
|
49
|
+
serviceTag: getLocalConfig('iz_serviceTag')
|
|
50
|
+
}
|
|
51
|
+
const translationTextObjSchemas = {
|
|
52
|
+
nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
|
|
53
|
+
systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
|
|
54
|
+
}
|
|
55
|
+
createSourceArray.push(translationTextObjSchemas)
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
for (const flowSchema of allFlowSchemas.records) {
|
|
60
|
+
const flowType = {
|
|
61
|
+
flowTag: flowSchema.flowTag,
|
|
62
|
+
serviceTag: getLocalConfig('iz_serviceTag')
|
|
63
|
+
}
|
|
64
|
+
const translationTextFlowSchemas = {
|
|
65
|
+
nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
|
|
66
|
+
systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
|
|
67
|
+
}
|
|
68
|
+
createSourceArray.push(translationTextFlowSchemas)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// console.log("createSourceArray", createSourceArray)
|
|
72
|
+
return {
|
|
73
|
+
templatePath: templatePath,
|
|
74
|
+
templateData: { datas: createSourceArray },
|
|
75
|
+
setting: {
|
|
76
|
+
savePath: path.join(srcPath, SOURCE_PATH.translationSchema),
|
|
77
|
+
saveFileName: SAVE_FILE_NAME.translationSchema,
|
|
78
|
+
fileExtension: '.js',
|
|
79
|
+
isAppend: true,
|
|
80
|
+
generateHookFile: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
export default createSourceTranslations;
|
package/src/generateCode.js
CHANGED
|
@@ -37,6 +37,7 @@ import generateTemplateDataInitialSetup from './generateCode/generateInitialSetu
|
|
|
37
37
|
import generateTemplateDataOther from './generateCode/generateOther/generateCodeOther.js';
|
|
38
38
|
|
|
39
39
|
import generateTemplateDataRole from './generateCode/generateRole/generateCodeRole.js';
|
|
40
|
+
import generateTemplateTranslations from './generateCode/generateTranslation/generateTranslation.js';
|
|
40
41
|
|
|
41
42
|
const __filename = fileURLToPath(import.meta.url);
|
|
42
43
|
const __dirname = dirname(__filename);
|
|
@@ -92,7 +93,7 @@ async function generateCodeWithTemplate(
|
|
|
92
93
|
console.info('[INFO] [generateCode] STATUS=GENERATING| template data...');
|
|
93
94
|
_izContext.logger.info('[generateCode] generating template data...');
|
|
94
95
|
const genStartTime = Date.now();
|
|
95
|
-
const [flowSchemaResult, schemaResult, initialSetupResult, otherResult] =
|
|
96
|
+
const [flowSchemaResult, schemaResult, initialSetupResult, otherResult, translationResult] =
|
|
96
97
|
await Promise.all([
|
|
97
98
|
generateTemplateDataFromFlowSchema(
|
|
98
99
|
_izContext,
|
|
@@ -120,7 +121,8 @@ async function generateCodeWithTemplate(
|
|
|
120
121
|
allLocalFlowSchemas.records,
|
|
121
122
|
settings
|
|
122
123
|
),
|
|
123
|
-
generateTemplateDataOther(_izContext, appPath)
|
|
124
|
+
generateTemplateDataOther(_izContext, appPath),
|
|
125
|
+
generateTemplateTranslations(_izContext, appPath, allObjSchemas, allLocalFlowSchemas),
|
|
124
126
|
]);
|
|
125
127
|
|
|
126
128
|
const genDuration = Date.now() - genStartTime;
|
|
@@ -129,11 +131,14 @@ async function generateCodeWithTemplate(
|
|
|
129
131
|
`[INFO] [generateCode] STATUS=GENERATED | ${genStr.padEnd(40)} | elapsedMs=${genDuration}`
|
|
130
132
|
);
|
|
131
133
|
|
|
134
|
+
console.log(translationResult)
|
|
135
|
+
|
|
132
136
|
const allCreateSource = [
|
|
133
137
|
...flowSchemaResult,
|
|
134
138
|
...schemaResult,
|
|
135
139
|
...initialSetupResult,
|
|
136
|
-
...otherResult
|
|
140
|
+
...otherResult,
|
|
141
|
+
...translationResult
|
|
137
142
|
];
|
|
138
143
|
|
|
139
144
|
// ── 3. Generate role configs ─────────────────────────────────────────────
|
package/src/libs/Consts.js
CHANGED
|
@@ -91,7 +91,10 @@ const SOURCE_PATH = {
|
|
|
91
91
|
'src/generatedCode/ActionEndpoint/source/',
|
|
92
92
|
createRecordComplete: '/src/generatedCode/CreateRecordComplete/',
|
|
93
93
|
resourceLocationCreateRecordComplete:
|
|
94
|
-
'src/generatedCode/CreateRecordComplete/'
|
|
94
|
+
'src/generatedCode/CreateRecordComplete/',
|
|
95
|
+
|
|
96
|
+
// translations
|
|
97
|
+
translationSchema: 'translations/'
|
|
95
98
|
};
|
|
96
99
|
|
|
97
100
|
const SQS_RESOURCE = {
|
|
@@ -151,7 +154,8 @@ const SAVE_FILE_NAME = {
|
|
|
151
154
|
objectRelationship: 'ObjectRelationships',
|
|
152
155
|
refObjectRelationship: 'RefObjectRelationships',
|
|
153
156
|
objectSchema: 'ObjectFieldSchema',
|
|
154
|
-
roleNameConfig: 'RoleNameConfig'
|
|
157
|
+
roleNameConfig: 'RoleNameConfig',
|
|
158
|
+
translationSchema: 'TranslationsSchema'
|
|
155
159
|
};
|
|
156
160
|
|
|
157
161
|
const FUNCTION_NAME = {
|