@codenotch/codenotch.cli 1.0.36 → 1.0.37
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/README.md +2 -2
- package/dist/commands/generate/app.d.ts +2 -0
- package/dist/commands/generate/app.js +45 -0
- package/dist/commands/generate/app.js.map +1 -0
- package/dist/commands/generate/appmanifest.d.ts +2 -0
- package/dist/commands/generate/appmanifest.js +34 -0
- package/dist/commands/generate/appmanifest.js.map +1 -0
- package/dist/commands/generate/dbcontext.d.ts +2 -0
- package/dist/commands/generate/dbcontext.js +32 -0
- package/dist/commands/generate/dbcontext.js.map +1 -0
- package/dist/commands/generate/i18n.d.ts +2 -0
- package/dist/commands/generate/i18n.js +29 -0
- package/dist/commands/generate/i18n.js.map +1 -0
- package/dist/commands/generate/index.d.ts +0 -1
- package/dist/commands/generate/index.js +14 -33
- package/dist/commands/generate/index.js.map +1 -1
- package/dist/commands/generate/manifest.d.ts +2 -0
- package/dist/commands/generate/manifest.js +29 -0
- package/dist/commands/generate/manifest.js.map +1 -0
- package/dist/commands/generate/openapi.d.ts +2 -0
- package/dist/commands/generate/openapi.js +32 -0
- package/dist/commands/generate/openapi.js.map +1 -0
- package/dist/commands/generate/pkg.d.ts +2 -0
- package/dist/commands/generate/pkg.js +34 -0
- package/dist/commands/generate/pkg.js.map +1 -0
- package/dist/commands/generate/shared.d.ts +17 -0
- package/dist/commands/generate/shared.js +70 -0
- package/dist/commands/generate/shared.js.map +1 -0
- package/dist/commands/project/new.js +108 -96
- package/dist/commands/project/new.js.map +1 -1
- package/dist/commands/react/build.js +11 -5
- package/dist/commands/react/build.js.map +1 -1
- package/dist/commands/react/clean.d.ts +2 -0
- package/dist/commands/react/clean.js +46 -0
- package/dist/commands/react/clean.js.map +1 -0
- package/dist/commands/react/dev.d.ts +2 -0
- package/dist/commands/react/dev.js +27 -0
- package/dist/commands/react/dev.js.map +1 -0
- package/dist/commands/react/index.js +5 -1
- package/dist/commands/react/index.js.map +1 -1
- package/dist/commands/react/serve.js +33 -4
- package/dist/commands/react/serve.js.map +1 -1
- package/dist/commands/react/shared.d.ts +21 -0
- package/dist/commands/react/shared.js +80 -0
- package/dist/commands/react/shared.js.map +1 -0
- package/dist/commands/validation/ValidationUtils.d.ts +1 -1
- package/dist/commands/validation/ValidationUtils.js +3 -0
- package/dist/commands/validation/ValidationUtils.js.map +1 -1
- package/dist/commands/validation/files/I18nValidator.d.ts +29 -0
- package/dist/commands/validation/files/I18nValidator.js +198 -0
- package/dist/commands/validation/files/I18nValidator.js.map +1 -0
- package/dist/commands/validation/files/ProjectManifestValidator.d.ts +5 -0
- package/dist/commands/validation/files/ProjectManifestValidator.js +31 -0
- package/dist/commands/validation/files/ProjectManifestValidator.js.map +1 -0
- package/dist/commands/validation/files/ScriptValidator.js +1 -1
- package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
- package/dist/commands/validation/validate.js +11 -6
- package/dist/commands/validation/validate.js.map +1 -1
- package/dist/utils/BuildUtils.d.ts +61 -7
- package/dist/utils/BuildUtils.js +289 -222
- package/dist/utils/BuildUtils.js.map +1 -1
- package/dist/utils/ConsoleUtils.d.ts +8 -0
- package/dist/utils/ConsoleUtils.js +25 -0
- package/dist/utils/ConsoleUtils.js.map +1 -1
- package/dist/utils/DbSchemaUtils.d.ts +49 -0
- package/dist/utils/DbSchemaUtils.js +246 -0
- package/dist/utils/DbSchemaUtils.js.map +1 -0
- package/dist/utils/FileUtils.d.ts +104 -15
- package/dist/utils/FileUtils.js +285 -100
- package/dist/utils/FileUtils.js.map +1 -1
- package/dist/utils/I18nTsUtils.d.ts +66 -0
- package/dist/utils/I18nTsUtils.js +221 -0
- package/dist/utils/I18nTsUtils.js.map +1 -0
- package/dist/utils/OpenApiUtils.d.ts +81 -0
- package/dist/utils/OpenApiUtils.js +123 -0
- package/dist/utils/OpenApiUtils.js.map +1 -0
- package/dist/utils/ProjectCompilationUtils.d.ts +0 -1
- package/dist/utils/ProjectCompilationUtils.js +4 -52
- package/dist/utils/ProjectCompilationUtils.js.map +1 -1
- package/dist/utils/ProjectGeneratorUtils.d.ts +35 -0
- package/dist/utils/ProjectGeneratorUtils.js +119 -0
- package/dist/utils/ProjectGeneratorUtils.js.map +1 -0
- package/dist/utils/ProjectTemplates.d.ts +102 -0
- package/dist/utils/ProjectTemplates.js +284 -0
- package/dist/utils/ProjectTemplates.js.map +1 -0
- package/dist/utils/ProjectUtils.d.ts +216 -3
- package/dist/utils/ProjectUtils.js +387 -22
- package/dist/utils/ProjectUtils.js.map +1 -1
- package/dist/utils/RuntimeUtils.js +14 -8
- package/dist/utils/RuntimeUtils.js.map +1 -1
- package/dist/utils/ScriptDeclarationUtils.d.ts +169 -0
- package/dist/utils/ScriptDeclarationUtils.js +398 -0
- package/dist/utils/ScriptDeclarationUtils.js.map +1 -0
- package/dist/utils/ServeUtils.js +10 -5
- package/dist/utils/ServeUtils.js.map +1 -1
- package/dist/utils/ShellUtils.d.ts +6 -0
- package/dist/utils/ShellUtils.js +13 -0
- package/dist/utils/ShellUtils.js.map +1 -1
- package/dist/utils/TemplateUtils.d.ts +62 -0
- package/dist/utils/TemplateUtils.js +218 -0
- package/dist/utils/TemplateUtils.js.map +1 -0
- package/dist/utils/TypeSchemaUtils.d.ts +42 -0
- package/dist/utils/TypeSchemaUtils.js +171 -0
- package/dist/utils/TypeSchemaUtils.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* Generate an importable TypeScript class from the entries of a *.i18n.csv file.
|
|
7
|
+
*
|
|
8
|
+
* The generated class exposes one static method per translation key, e.g. for:
|
|
9
|
+
* key,en,de
|
|
10
|
+
* ,,
|
|
11
|
+
* userWelcome,hello,hallo
|
|
12
|
+
* hiMr,hello mister {0},hallo herr {0}
|
|
13
|
+
* we get `hello.userWelcome()` and `hello.hiMr(arg1)`.
|
|
14
|
+
*
|
|
15
|
+
* The file is fully regenerated on each run, it must not be edited by hand.
|
|
16
|
+
*/
|
|
17
|
+
class I18nTsUtils {
|
|
18
|
+
static RESERVED_MEMBERS = ['values', 'lang', 'setLanguage', 'getValue'];
|
|
19
|
+
static PLACEHOLDER_REGEX = /\{(\d+)\}/g;
|
|
20
|
+
static INDENT = ' ';
|
|
21
|
+
/**
|
|
22
|
+
* Converts a *.i18n.csv file name (or path) into a valid class name, e.g. 'src/hello.i18n.csv' => 'hello'
|
|
23
|
+
*/
|
|
24
|
+
static getClassName(fileNameOrPath) {
|
|
25
|
+
const fileName = fileNameOrPath.replaceAll('\\', '/').split('/').pop() ?? '';
|
|
26
|
+
const name = fileName.replace(/\.i18n\.csv$/i, '').replace(/\.csv$/i, '');
|
|
27
|
+
return this.toIdentifier(name) || 'I18n';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Keeps only the real translation entries of a parsed csv: the rows without key are ignored
|
|
31
|
+
* (the csv may still contain a leading empty row, kept for readability).
|
|
32
|
+
*/
|
|
33
|
+
static getEntries(lines) {
|
|
34
|
+
const entries = [];
|
|
35
|
+
for (const line of lines) {
|
|
36
|
+
const key = (line.key ?? '').trim();
|
|
37
|
+
if (key === '') {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
entries.push({ ...line, key });
|
|
41
|
+
}
|
|
42
|
+
return entries;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generates the TypeScript class.
|
|
46
|
+
* @param className name of the generated class
|
|
47
|
+
* @param sourceFileName name of the *.i18n.csv the class is generated from (mentioned in the file header)
|
|
48
|
+
* @param entries translation entries (see getEntries)
|
|
49
|
+
*/
|
|
50
|
+
static generate(className, sourceFileName, entries) {
|
|
51
|
+
const warnings = [];
|
|
52
|
+
const languages = this.getLanguages(entries);
|
|
53
|
+
const valuesBlock = this.generateValuesBlock(entries, languages);
|
|
54
|
+
const methodsBlock = this.generateMethodsBlock(entries, languages, warnings);
|
|
55
|
+
return { content: this.generateTemplate(className, sourceFileName, languages[0] ?? 'en', valuesBlock, methodsBlock), warnings };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Languages in csv column order (every column except 'key', papaparse internals are ignored)
|
|
59
|
+
*/
|
|
60
|
+
static getLanguages(entries) {
|
|
61
|
+
const languages = [];
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
for (const column of Object.keys(entry)) {
|
|
64
|
+
if (column === 'key' || column.startsWith('__') || languages.includes(column)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
languages.push(column);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return languages;
|
|
71
|
+
}
|
|
72
|
+
static generateValuesBlock(entries, languages) {
|
|
73
|
+
const i = this.INDENT;
|
|
74
|
+
const lines = [];
|
|
75
|
+
lines.push(`${i}static values: { [key: string]: { [lang: string]: string } } = {`);
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const values = languages
|
|
78
|
+
.filter(lang => (entry[lang] ?? '').trim() !== '')
|
|
79
|
+
.map(lang => `${i}${i}${i}${JSON.stringify(lang)}: ${JSON.stringify(entry[lang])}`);
|
|
80
|
+
lines.push(`${i}${i}${JSON.stringify(entry.key)}: {`);
|
|
81
|
+
if (values.length > 0) {
|
|
82
|
+
lines.push(values.join(',\n'));
|
|
83
|
+
}
|
|
84
|
+
lines.push(`${i}${i}},`);
|
|
85
|
+
}
|
|
86
|
+
lines.push(`${i}};`);
|
|
87
|
+
return lines.join('\n');
|
|
88
|
+
}
|
|
89
|
+
static generateMethodsBlock(entries, languages, warnings) {
|
|
90
|
+
const i = this.INDENT;
|
|
91
|
+
const lines = [];
|
|
92
|
+
const usedNames = new Set();
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
let methodName = this.toIdentifier(entry.key);
|
|
95
|
+
if (methodName !== entry.key) {
|
|
96
|
+
warnings.push(`Key '${entry.key}' is not a valid identifier, method '${methodName}' generated instead.`);
|
|
97
|
+
}
|
|
98
|
+
if (this.RESERVED_MEMBERS.includes(methodName)) {
|
|
99
|
+
warnings.push(`Key '${entry.key}' conflicts with a reserved member, method '${methodName}_' generated instead.`);
|
|
100
|
+
methodName = `${methodName}_`;
|
|
101
|
+
}
|
|
102
|
+
if (usedNames.has(methodName)) {
|
|
103
|
+
warnings.push(`Key '${entry.key}' produces the duplicated method '${methodName}', skipped.`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
usedNames.add(methodName);
|
|
107
|
+
const argCount = this.getArgCount(languages.map(lang => entry[lang] ?? ''));
|
|
108
|
+
const argNames = Array.from({ length: argCount }, (_, index) => `arg${index + 1}`);
|
|
109
|
+
const signature = argNames.map(name => `${name}: string`).join(', ');
|
|
110
|
+
const callArgs = [JSON.stringify(entry.key), ...argNames].join(', ');
|
|
111
|
+
lines.push(`${i}/**`);
|
|
112
|
+
for (const lang of languages) {
|
|
113
|
+
const value = (entry[lang] ?? '').trim();
|
|
114
|
+
if (value !== '') {
|
|
115
|
+
lines.push(`${i} * ${lang.toUpperCase()}: ${this.toCommentText(value)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
lines.push(`${i} */`);
|
|
119
|
+
lines.push(`${i}static ${methodName}(${signature}) { return this.getValue(${callArgs}); }`);
|
|
120
|
+
}
|
|
121
|
+
return lines.join('\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Number of arguments needed by a translation: highest {n} placeholder + 1 over all languages
|
|
125
|
+
*/
|
|
126
|
+
static getArgCount(values) {
|
|
127
|
+
let maxIndex = -1;
|
|
128
|
+
for (const value of values) {
|
|
129
|
+
for (const match of value.matchAll(this.PLACEHOLDER_REGEX)) {
|
|
130
|
+
maxIndex = Math.max(maxIndex, parseInt(match[1], 10));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return maxIndex + 1;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Makes a translation value safe inside a JSDoc comment: single line, no comment terminator
|
|
137
|
+
*/
|
|
138
|
+
static toCommentText(value) {
|
|
139
|
+
return value.replace(/\r?\n/g, ' ').replaceAll('*/', '* /');
|
|
140
|
+
}
|
|
141
|
+
static toIdentifier(name) {
|
|
142
|
+
let identifier = name.trim().replace(/[^\w$]/g, '_');
|
|
143
|
+
if (/^\d/.test(identifier)) {
|
|
144
|
+
identifier = `_${identifier}`;
|
|
145
|
+
}
|
|
146
|
+
return identifier;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Header written at the top of the generated file
|
|
150
|
+
*/
|
|
151
|
+
static generateHeader(className, sourceFileName) {
|
|
152
|
+
const version = this.getCliVersion();
|
|
153
|
+
const generator = version ? `codenotch-cli v${version}` : 'codenotch-cli';
|
|
154
|
+
const line = '-'.repeat(75);
|
|
155
|
+
return [
|
|
156
|
+
`/* ${line}`,
|
|
157
|
+
` * ${className}.i18n.ts`,
|
|
158
|
+
` *`,
|
|
159
|
+
` * Generated by ${generator} from '${this.toCommentText(sourceFileName)}'.`,
|
|
160
|
+
` *`,
|
|
161
|
+
` * THIS FILE IS GENERATED, DO NOT EDIT IT MANUALLY: it is entirely overwritten`,
|
|
162
|
+
` * each time it is regenerated, edit the csv instead and run:`,
|
|
163
|
+
` *`,
|
|
164
|
+
` * cn generate i18n -f ${this.toCommentText(sourceFileName)}`,
|
|
165
|
+
` * ${line} */`
|
|
166
|
+
].join('\n');
|
|
167
|
+
}
|
|
168
|
+
static getCliVersion() {
|
|
169
|
+
try {
|
|
170
|
+
// works from both src/utils (tsx) and dist/utils (build)
|
|
171
|
+
const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../package.json'), 'utf8'));
|
|
172
|
+
return typeof packageJson.version === 'string' ? packageJson.version : undefined;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
static generateTemplate(className, sourceFileName, defaultLang, valuesBlock, methodsBlock) {
|
|
179
|
+
const i = this.INDENT;
|
|
180
|
+
return [
|
|
181
|
+
this.generateHeader(className, sourceFileName),
|
|
182
|
+
``,
|
|
183
|
+
`export default abstract class ${className} {`,
|
|
184
|
+
``,
|
|
185
|
+
valuesBlock,
|
|
186
|
+
``,
|
|
187
|
+
`${i}static lang: string = ${JSON.stringify(defaultLang)};`,
|
|
188
|
+
`${i}static setLanguage(lang: string) {`,
|
|
189
|
+
`${i}${i}this.lang = lang.toLowerCase();`,
|
|
190
|
+
`${i}}`,
|
|
191
|
+
``,
|
|
192
|
+
`${i}private static getValue(key: string, ...args: any[]) {`,
|
|
193
|
+
`${i}${i}try {`,
|
|
194
|
+
`${i}${i}${i}const values = this.values[key];`,
|
|
195
|
+
`${i}${i}${i}if (values === undefined) {`,
|
|
196
|
+
`${i}${i}${i}${i}return \`KEY '\${key}' NOT EXISTS\`;`,
|
|
197
|
+
`${i}${i}${i}}`,
|
|
198
|
+
``,
|
|
199
|
+
`${i}${i}${i}let langValue = values[this.lang] ?? values[Object.keys(values)[0]];`,
|
|
200
|
+
`${i}${i}${i}let argIndex = 0;`,
|
|
201
|
+
`${i}${i}${i}for (const arg of args) {`,
|
|
202
|
+
`${i}${i}${i}${i}langValue = langValue.replaceAll(\`{\${argIndex}}\`, \`\${(arg ?? '')}\`.trim());`,
|
|
203
|
+
`${i}${i}${i}${i}argIndex++;`,
|
|
204
|
+
`${i}${i}${i}}`,
|
|
205
|
+
``,
|
|
206
|
+
`${i}${i}${i}return langValue;`,
|
|
207
|
+
`${i}${i}}`,
|
|
208
|
+
`${i}${i}catch (e) {`,
|
|
209
|
+
`${i}${i}${i}console.error('I18N', e);`,
|
|
210
|
+
`${i}${i}${i}return 'ERROR';`,
|
|
211
|
+
`${i}${i}}`,
|
|
212
|
+
`${i}}`,
|
|
213
|
+
``,
|
|
214
|
+
methodsBlock,
|
|
215
|
+
`}`,
|
|
216
|
+
``
|
|
217
|
+
].join('\n');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.default = I18nTsUtils;
|
|
221
|
+
//# sourceMappingURL=I18nTsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18nTsUtils.js","sourceRoot":"","sources":["../../src/utils/I18nTsUtils.ts"],"names":[],"mappings":";;AAAA,2BAAkC;AAClC,+BAA4B;AAiB5B;;;;;;;;;;;GAWG;AACH,MAA8B,WAAW;IAE7B,MAAM,CAAU,gBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACjF,MAAM,CAAU,iBAAiB,GAAG,YAAY,CAAC;IACjD,MAAM,CAAU,MAAM,GAAG,MAAM,CAAC;IAExC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,cAAsB;QACtC,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;QAC7E,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,KAA2B;QACzC,MAAM,OAAO,GAAyB,EAAE,CAAC;QAEzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACpC,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;gBACb,SAAS;YACb,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,I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,GAAG,CAAC,GAAG;YACX,GAAG,CAAC,GAAG,CAAC,aAAa;YACrB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,2BAA2B;YACvC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG;YACX,GAAG,CAAC,GAAG;YACP,EAAE;YACF,YAAY;YACZ,GAAG;YACH,EAAE;SACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;;AAhOL,8BAiOC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { IDiscoveredProcess } from './ProjectUtils';
|
|
2
|
+
import { IJsonSchema } from './TypeSchemaUtils';
|
|
3
|
+
export interface IOpenApiOptions {
|
|
4
|
+
/** Title of the API, usually the project name */
|
|
5
|
+
title: string;
|
|
6
|
+
/** Version of the API, usually the project version */
|
|
7
|
+
version: string;
|
|
8
|
+
/** Description shown at the top of the document */
|
|
9
|
+
description?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IOpenApiGenerationResult {
|
|
12
|
+
document: IOpenApiDocument;
|
|
13
|
+
warnings: string[];
|
|
14
|
+
/** Number of endpoints written */
|
|
15
|
+
endpointCount: number;
|
|
16
|
+
}
|
|
17
|
+
export interface IOpenApiParameter {
|
|
18
|
+
name: string;
|
|
19
|
+
in: 'path' | 'query';
|
|
20
|
+
required: boolean;
|
|
21
|
+
schema: IJsonSchema;
|
|
22
|
+
description?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface IOpenApiOperation {
|
|
25
|
+
operationId: string;
|
|
26
|
+
summary?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
tags?: string[];
|
|
29
|
+
parameters?: IOpenApiParameter[];
|
|
30
|
+
requestBody?: {
|
|
31
|
+
required: boolean;
|
|
32
|
+
content: {
|
|
33
|
+
'application/json': {
|
|
34
|
+
schema: IJsonSchema;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
responses: Record<string, {
|
|
39
|
+
description: string;
|
|
40
|
+
content?: {
|
|
41
|
+
'application/json': {
|
|
42
|
+
schema: IJsonSchema;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
/** Value of 'auth.scope' of the process, a Codenotch specific extension */
|
|
47
|
+
'x-codenotch-scope'?: string;
|
|
48
|
+
/** Id of the process behind the endpoint */
|
|
49
|
+
'x-codenotch-process': string;
|
|
50
|
+
}
|
|
51
|
+
export interface IOpenApiDocument {
|
|
52
|
+
openapi: '3.0.3';
|
|
53
|
+
info: {
|
|
54
|
+
title: string;
|
|
55
|
+
version: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
};
|
|
58
|
+
paths: Record<string, Record<string, IOpenApiOperation>>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Builds the OpenAPI document of a project out of its processes triggered by `api.*(...)`.
|
|
62
|
+
*
|
|
63
|
+
* The input type of `run` is split between the path (its properties named like a route segment),
|
|
64
|
+
* the query string (GET and DELETE) or the request body (other methods). The declared return
|
|
65
|
+
* type becomes the 200 response. What the sources do not state is left open rather than invented:
|
|
66
|
+
* an input without annotation gives no parameter, a return type that is a reference stays named.
|
|
67
|
+
*/
|
|
68
|
+
export default abstract class OpenApiUtils {
|
|
69
|
+
static generate(processes: IDiscoveredProcess[], options: IOpenApiOptions): IOpenApiGenerationResult;
|
|
70
|
+
/** Express style ':bookId' becomes OpenAPI style '{bookId}' */
|
|
71
|
+
static toOpenApiPath(route: string): string;
|
|
72
|
+
/** Names of the '{param}' segments of a path, in order */
|
|
73
|
+
static getPathParameterNames(route: string): string[];
|
|
74
|
+
private static sortKey;
|
|
75
|
+
private static toOperation;
|
|
76
|
+
/**
|
|
77
|
+
* Dispatches the properties of the input between the path, the query string and the body.
|
|
78
|
+
* A path parameter is always documented, typed from the input when it says so.
|
|
79
|
+
*/
|
|
80
|
+
private static splitInput;
|
|
81
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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 FileUtils_1 = __importDefault(require("./FileUtils"));
|
|
7
|
+
/** Methods whose input travels in the query string rather than in a body */
|
|
8
|
+
const QUERY_METHODS = ['get', 'delete', 'head', 'options'];
|
|
9
|
+
/**
|
|
10
|
+
* Builds the OpenAPI document of a project out of its processes triggered by `api.*(...)`.
|
|
11
|
+
*
|
|
12
|
+
* The input type of `run` is split between the path (its properties named like a route segment),
|
|
13
|
+
* the query string (GET and DELETE) or the request body (other methods). The declared return
|
|
14
|
+
* type becomes the 200 response. What the sources do not state is left open rather than invented:
|
|
15
|
+
* an input without annotation gives no parameter, a return type that is a reference stays named.
|
|
16
|
+
*/
|
|
17
|
+
class OpenApiUtils {
|
|
18
|
+
static generate(processes, options) {
|
|
19
|
+
const warnings = [];
|
|
20
|
+
const paths = {};
|
|
21
|
+
let endpointCount = 0;
|
|
22
|
+
const endpoints = processes
|
|
23
|
+
.filter(process => process.trigger?.kind === 'api')
|
|
24
|
+
// Sorted so that regenerating an unchanged project produces an unchanged file
|
|
25
|
+
.sort((left, right) => this.sortKey(left).localeCompare(this.sortKey(right)));
|
|
26
|
+
for (const process of endpoints) {
|
|
27
|
+
const trigger = process.trigger;
|
|
28
|
+
const where = `${FileUtils_1.default.getNameFromPath(process.filePath)}:${process.line}`;
|
|
29
|
+
if (process.id === undefined) {
|
|
30
|
+
warnings.push(`The endpoint ${trigger.method} ${trigger.route} (${where}) has a computed id, it cannot be given an operationId and is left out.`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const route = this.toOpenApiPath(trigger.route);
|
|
34
|
+
const method = trigger.method.toLowerCase();
|
|
35
|
+
if (paths[route]?.[method] !== undefined) {
|
|
36
|
+
warnings.push(`${trigger.method} ${route} is declared twice, by '${paths[route][method].operationId}' and '${process.id}' (${where}); only the first one is kept.`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// A process that takes no input has nothing to document, one that takes an untyped input does
|
|
40
|
+
if (process.takesInput && process.input === undefined) {
|
|
41
|
+
warnings.push(`'${process.id}' (${where}) declares no type for its input, its parameters are not documented.`);
|
|
42
|
+
}
|
|
43
|
+
paths[route] = paths[route] ?? {};
|
|
44
|
+
paths[route][method] = this.toOperation(process, method, route);
|
|
45
|
+
endpointCount++;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
document: {
|
|
49
|
+
openapi: '3.0.3',
|
|
50
|
+
info: { title: options.title, version: options.version, ...(options.description ? { description: options.description } : {}) },
|
|
51
|
+
paths
|
|
52
|
+
},
|
|
53
|
+
warnings,
|
|
54
|
+
endpointCount
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Express style ':bookId' becomes OpenAPI style '{bookId}' */
|
|
58
|
+
static toOpenApiPath(route) {
|
|
59
|
+
return route.replace(/:([A-Za-z_$][\w$]*)/g, '{$1}');
|
|
60
|
+
}
|
|
61
|
+
/** Names of the '{param}' segments of a path, in order */
|
|
62
|
+
static getPathParameterNames(route) {
|
|
63
|
+
return [...route.matchAll(/\{([^}]+)\}/g)].map(match => match[1]);
|
|
64
|
+
}
|
|
65
|
+
static sortKey(process) {
|
|
66
|
+
const trigger = process.trigger;
|
|
67
|
+
return `${this.toOpenApiPath(trigger.route)} ${trigger.method}`;
|
|
68
|
+
}
|
|
69
|
+
static toOperation(process, method, route) {
|
|
70
|
+
const { parameters, body } = this.splitInput(process.input, route, method);
|
|
71
|
+
// Built in the order a reader expects: what it is, what it takes, what it gives back
|
|
72
|
+
return {
|
|
73
|
+
operationId: process.id,
|
|
74
|
+
...(process.description === undefined ? {} : { summary: process.description }),
|
|
75
|
+
tags: [FileUtils_1.default.getNameFromPath(process.filePath, true)],
|
|
76
|
+
...(parameters.length === 0 ? {} : { parameters }),
|
|
77
|
+
...(body === undefined ? {} : {
|
|
78
|
+
requestBody: { required: (body.required ?? []).length > 0, content: { 'application/json': { schema: body } } }
|
|
79
|
+
}),
|
|
80
|
+
responses: {
|
|
81
|
+
'200': {
|
|
82
|
+
description: 'Successful response',
|
|
83
|
+
...(process.output === undefined ? {} : { content: { 'application/json': { schema: process.output } } })
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
'x-codenotch-process': process.id,
|
|
87
|
+
...(process.scope === undefined ? {} : { 'x-codenotch-scope': process.scope })
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Dispatches the properties of the input between the path, the query string and the body.
|
|
92
|
+
* A path parameter is always documented, typed from the input when it says so.
|
|
93
|
+
*/
|
|
94
|
+
static splitInput(input, route, method) {
|
|
95
|
+
const pathNames = this.getPathParameterNames(route);
|
|
96
|
+
const properties = input?.properties ?? {};
|
|
97
|
+
const required = new Set(input?.required ?? []);
|
|
98
|
+
const parameters = pathNames.map(name => ({
|
|
99
|
+
name,
|
|
100
|
+
in: 'path',
|
|
101
|
+
required: true,
|
|
102
|
+
schema: properties[name] ?? { type: 'string' }
|
|
103
|
+
}));
|
|
104
|
+
const remaining = Object.entries(properties).filter(([name]) => !pathNames.includes(name));
|
|
105
|
+
if (remaining.length === 0) {
|
|
106
|
+
return { parameters };
|
|
107
|
+
}
|
|
108
|
+
if (QUERY_METHODS.includes(method)) {
|
|
109
|
+
for (const [name, schema] of remaining) {
|
|
110
|
+
parameters.push({ name, in: 'query', required: required.has(name), schema });
|
|
111
|
+
}
|
|
112
|
+
return { parameters };
|
|
113
|
+
}
|
|
114
|
+
const body = { type: 'object', properties: Object.fromEntries(remaining) };
|
|
115
|
+
const bodyRequired = remaining.map(([name]) => name).filter(name => required.has(name));
|
|
116
|
+
if (bodyRequired.length > 0) {
|
|
117
|
+
body.required = bodyRequired;
|
|
118
|
+
}
|
|
119
|
+
return { parameters, body };
|
|
120
|
+
}
|
|
121
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C,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3F,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,UAAU,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;gBACrC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,EAAE,UAAU,EAAE,CAAC;QAC1B,CAAC;QAED,MAAM,IAAI,GAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACxF,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACxF,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QACjC,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ;AAjID,+BAiIC"}
|
|
@@ -28,7 +28,6 @@ export default abstract class ProjectCompilationUtils {
|
|
|
28
28
|
*/
|
|
29
29
|
static compileTestProject(targetPath: string): Promise<CompilationResult>;
|
|
30
30
|
static generateDbSchema(context: CompilationContext): Promise<string>;
|
|
31
|
-
static getManifestFileType(file: string): "" | "table" | "document" | "script" | "jsxtsx" | "i18n";
|
|
32
31
|
/**
|
|
33
32
|
* Generate the full project manifest
|
|
34
33
|
* Uses the manifest cache if available, otherwise read the project files to generate the full manifest
|
|
@@ -24,7 +24,9 @@ class ProjectCompilationUtils {
|
|
|
24
24
|
// TODO: Generate ts files for i18n (one per *.i18n.csv)
|
|
25
25
|
const context = {
|
|
26
26
|
targetPath: targetPath,
|
|
27
|
-
files: FileUtils_1.default.
|
|
27
|
+
files: FileUtils_1.default.listFilesRecursively(targetPath, {
|
|
28
|
+
ignoredFolderNames: ['node_modules', '.codenotch', '.git', 'dist', 'build', 'out', '.github']
|
|
29
|
+
}),
|
|
28
30
|
errors: [],
|
|
29
31
|
warnings: []
|
|
30
32
|
};
|
|
@@ -35,7 +37,7 @@ class ProjectCompilationUtils {
|
|
|
35
37
|
// Overwrite manifest
|
|
36
38
|
FileUtils_1.default.writeFileSync(path_1.default.join(targetPath, MANIFEST_FILE_NAME), JSON.stringify(context.manifest, null, 4));
|
|
37
39
|
// Remove .npmrc if exists, we don't want to expose it
|
|
38
|
-
FileUtils_1.default.
|
|
40
|
+
FileUtils_1.default.deleteRecursively(path_1.default.join(targetPath, '.npmrc'));
|
|
39
41
|
if (context.errors.length > 0) {
|
|
40
42
|
console.log(chalk_1.default.red(`Compilation finished with ${context.errors.length} error(s)`));
|
|
41
43
|
}
|
|
@@ -72,16 +74,6 @@ class ProjectCompilationUtils {
|
|
|
72
74
|
// TODO: Generate DB schema (read all .ts/.js files that declare a table)
|
|
73
75
|
throw new Error('Not implemented.');
|
|
74
76
|
}
|
|
75
|
-
static getManifestFileType(file) {
|
|
76
|
-
file = file.toLowerCase();
|
|
77
|
-
let fileType = file.endsWith('.table') ? 'table' :
|
|
78
|
-
file.endsWith('.jschema') ? 'document' :
|
|
79
|
-
file.endsWith('.tsx') ? 'jsxtsx' :
|
|
80
|
-
file.endsWith('.jsx') ? 'jsxtsx' :
|
|
81
|
-
file.endsWith('.i18n.csv') ? 'i18n' :
|
|
82
|
-
file.endsWith('.js') ? 'script' : '';
|
|
83
|
-
return fileType;
|
|
84
|
-
}
|
|
85
77
|
/**
|
|
86
78
|
* Generate the full project manifest
|
|
87
79
|
* Uses the manifest cache if available, otherwise read the project files to generate the full manifest
|
|
@@ -121,44 +113,4 @@ class ProjectCompilationUtils {
|
|
|
121
113
|
}
|
|
122
114
|
}
|
|
123
115
|
exports.default = ProjectCompilationUtils;
|
|
124
|
-
class TypescriptUtils {
|
|
125
|
-
/**
|
|
126
|
-
* Read TS table definition file like:
|
|
127
|
-
* ```ts
|
|
128
|
-
import { defineEntity, type InferEntity, p } from '@codenotch/orm';
|
|
129
|
-
|
|
130
|
-
export const User = defineEntity({
|
|
131
|
-
name: 'User',
|
|
132
|
-
properties: {
|
|
133
|
-
id: p.integer().primary(),
|
|
134
|
-
fullName: p.string(),
|
|
135
|
-
email: p.string()
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
export type IUser = InferEntity<typeof User>;
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* And returns the table structure(s) (can have multiple table in one file)
|
|
143
|
-
*/
|
|
144
|
-
static async parseTablesFromScript(ts) {
|
|
145
|
-
// TODO
|
|
146
|
-
return [];
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Find all file (recursivly) in a given folder (workspacePath) that contains a table declaration ('defineEntity').
|
|
150
|
-
*/
|
|
151
|
-
static async discoverTableFiles(workspacePath) {
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Find all file (recursivly) in a given folder (workspacePath) that contains a table declaration ('defineDocument').
|
|
155
|
-
*/
|
|
156
|
-
static async discoverDocumentFiles(workspacePath) {
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Find all file (recursivly) in a given folder (workspacePath) that contains a table declaration ('process').
|
|
160
|
-
*/
|
|
161
|
-
static async discoverProcessFiles(workspacePath) {
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
116
|
//# sourceMappingURL=ProjectCompilationUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectCompilationUtils.js","sourceRoot":"","sources":["../../src/utils/ProjectCompilationUtils.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAExB,4DAAoC;AACpC,kEAA0C;AAE1C,kDAA0B;AAmB1B,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAA8B,uBAAuB;IAEjD;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,UAAkB;QAEjD,+EAA+E;QAC/E,8EAA8E;QAC9E,wDAAwD;QAExD,MAAM,OAAO,GAAuB;YAChC,UAAU,EAAE,UAAU;YACtB,KAAK,EAAE,mBAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"ProjectCompilationUtils.js","sourceRoot":"","sources":["../../src/utils/ProjectCompilationUtils.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAExB,4DAAoC;AACpC,kEAA0C;AAE1C,kDAA0B;AAmB1B,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAA8B,uBAAuB;IAEjD;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,UAAkB;QAEjD,+EAA+E;QAC/E,8EAA8E;QAC9E,wDAAwD;QAExD,MAAM,OAAO,GAAuB;YAChC,UAAU,EAAE,UAAU;YACtB,KAAK,EAAE,mBAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE;gBAC9C,kBAAkB,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;aAChG,CACA;YACD,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACf,CAAC;QAGF,qFAAqF;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AE,EAAE,CAAC;YACzC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/B,CAAC;QAED,qCAAqC;QACrC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;YAChF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,4BAA4B;aAC5C,CAAC,CAAC;QACP,CAAC;QACD,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,+BAA+B;aAC/C,CAAC,CAAC;QACP,CAAC;QAED,qDAAqD;QACrD,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,QAAQ,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QAGD,OAAO,QAAQ,CAAC;IACpB,CAAC;CAKJ;AAxID,0CAwIC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface IGenerationResult {
|
|
2
|
+
/** Absolute paths of the files written */
|
|
3
|
+
written: string[];
|
|
4
|
+
warnings: string[];
|
|
5
|
+
/** Why nothing was written, when the project simply has nothing to generate from */
|
|
6
|
+
skipped?: string;
|
|
7
|
+
/** Why the generation failed, when it did */
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The generators of the derived files of a project, shared by 'cn generate ...' (one at a time)
|
|
12
|
+
* and 'cn project new' (all of them, once the template is written).
|
|
13
|
+
*
|
|
14
|
+
* Every generator reports rather than prints: the command decides how to show the outcome.
|
|
15
|
+
*/
|
|
16
|
+
export default abstract class ProjectGeneratorUtils {
|
|
17
|
+
/** 'db-schema.xml' and 'db-schema.ts' from the 'defineEntity' declarations of the project */
|
|
18
|
+
static generateDbContext(projectPath: string): Promise<IGenerationResult & {
|
|
19
|
+
tableCount: number;
|
|
20
|
+
}>;
|
|
21
|
+
/** 'openapi.json' from the processes triggered by an api call */
|
|
22
|
+
static generateOpenApi(projectPath: string): Promise<IGenerationResult & {
|
|
23
|
+
endpointCount: number;
|
|
24
|
+
}>;
|
|
25
|
+
/** The '*.i18n.ts' class of one '*.i18n.csv', written next to it */
|
|
26
|
+
static generateI18n(csvPath: string): Promise<IGenerationResult & {
|
|
27
|
+
keyCount: number;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Every derived file of a project: the database schema when it declares tables, the class of
|
|
31
|
+
* each translation file, the openapi document when it exposes endpoints. Skipped generators
|
|
32
|
+
* are silent, since a project without tables is not an error.
|
|
33
|
+
*/
|
|
34
|
+
static generateAll(projectPath: string): Promise<IGenerationResult>;
|
|
35
|
+
}
|