@opra/cli 1.0.0-beta.3 → 1.0.0-beta.5
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/cjs/generator/code-generator.js +7 -0
- package/cjs/ts-generator/generators/generate-data-type.js +45 -39
- package/cjs/ts-generator/ts-generator.js +1 -0
- package/esm/generator/code-generator.js +3 -0
- package/esm/ts-generator/generators/generate-data-type.js +46 -40
- package/esm/ts-generator/ts-generator.js +1 -0
- package/package.json +3 -3
- package/types/generator/code-generator.d.ts +3 -0
|
@@ -19,49 +19,55 @@ async function generateDataType(dataType, intent, currentFile) {
|
|
|
19
19
|
const { generator } = await this.generateDocument(doc);
|
|
20
20
|
return await generator.generateDataType(dataType, intent, currentFile);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
currentFile
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
currentFile
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
22
|
+
try {
|
|
23
|
+
const typeName = dataType.name;
|
|
24
|
+
if (typeName) {
|
|
25
|
+
if (internalTypeNames.includes(typeName))
|
|
26
|
+
return { kind: 'internal', typeName: dataType.name };
|
|
27
|
+
let file = this._filesMap.get(dataType);
|
|
28
|
+
if (file) {
|
|
29
|
+
if (currentFile)
|
|
30
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
31
|
+
return { kind: 'named', file, typeName: dataType.name };
|
|
32
|
+
}
|
|
33
|
+
if (dataType instanceof common_1.SimpleType)
|
|
34
|
+
file = this.addFile(node_path_1.default.join(this._documentRoot, '/simple-types.ts'), true);
|
|
35
|
+
else if (dataType instanceof common_1.EnumType) {
|
|
36
|
+
file = this.addFile(node_path_1.default.join(this._typesRoot, 'enums', typeName + '.ts'), true);
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
file = this.addFile(node_path_1.default.join(this._typesRoot, 'types', typeName + '.ts'), true);
|
|
40
|
+
this._filesMap.set(dataType, file);
|
|
41
|
+
if (file.exportTypes.includes(typeName)) {
|
|
42
|
+
if (currentFile)
|
|
43
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
44
|
+
return { kind: 'named', file, typeName: dataType.name };
|
|
45
|
+
}
|
|
46
|
+
file.exportTypes.push(typeName);
|
|
47
|
+
const typesIndexTs = this.addFile(node_path_1.default.join(this._typesRoot, 'index.ts'), true);
|
|
48
|
+
const indexTs = this.addFile('/index.ts', true);
|
|
49
|
+
indexTs.addExport(typesIndexTs.filename, undefined, this._typesNamespace);
|
|
50
|
+
const codeBlock = (file.code['type_' + typeName] = new code_block_js_1.CodeBlock());
|
|
51
|
+
codeBlock.head = `/**\n * ${(0, string_utils_js_1.wrapJSDocString)(dataType.description || '')}\n *`;
|
|
52
|
+
codeBlock.head += `
|
|
52
53
|
* @url ${node_path_1.default.posix.join(doc.url || this.serviceUrl, '$schema', '#types/' + typeName)}
|
|
53
54
|
*/
|
|
54
55
|
export `;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
codeBlock.typeDef = (await this._generateTypeCode(file, dataType, 'root')) + '\n\n';
|
|
57
|
+
typesIndexTs.addExport(file.filename);
|
|
58
|
+
if (currentFile)
|
|
59
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
60
|
+
return { kind: 'named', file, typeName };
|
|
61
|
+
}
|
|
62
|
+
if (!currentFile)
|
|
63
|
+
throw new TypeError(`You must provide currentFile to generate data type`);
|
|
64
|
+
const code = await this._generateTypeCode(currentFile, dataType, intent);
|
|
65
|
+
return { kind: 'embedded', code };
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
e.message = `(${dataType.name}) ` + e.message;
|
|
69
|
+
throw e;
|
|
60
70
|
}
|
|
61
|
-
if (!currentFile)
|
|
62
|
-
throw new TypeError(`You must provide currentFile to generate data type`);
|
|
63
|
-
const code = await this._generateTypeCode(currentFile, dataType, intent);
|
|
64
|
-
return { kind: 'embedded', code };
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
67
73
|
*
|
|
@@ -49,6 +49,7 @@ class TsGenerator extends node_events_1.EventEmitter {
|
|
|
49
49
|
this.emit('log', ansi_colors_1.default.cyan('Removing old files..'));
|
|
50
50
|
this.cleanDirectory(this.outDir);
|
|
51
51
|
this._apiPath = '/api';
|
|
52
|
+
this._typesRoot = '/models';
|
|
52
53
|
await this.generateDocument();
|
|
53
54
|
const { importExt } = this.options;
|
|
54
55
|
// Write files
|
|
@@ -9,49 +9,55 @@ export async function generateDataType(dataType, intent, currentFile) {
|
|
|
9
9
|
const { generator } = await this.generateDocument(doc);
|
|
10
10
|
return await generator.generateDataType(dataType, intent, currentFile);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
currentFile
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
currentFile
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
12
|
+
try {
|
|
13
|
+
const typeName = dataType.name;
|
|
14
|
+
if (typeName) {
|
|
15
|
+
if (internalTypeNames.includes(typeName))
|
|
16
|
+
return { kind: 'internal', typeName: dataType.name };
|
|
17
|
+
let file = this._filesMap.get(dataType);
|
|
18
|
+
if (file) {
|
|
19
|
+
if (currentFile)
|
|
20
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
21
|
+
return { kind: 'named', file, typeName: dataType.name };
|
|
22
|
+
}
|
|
23
|
+
if (dataType instanceof SimpleType)
|
|
24
|
+
file = this.addFile(path.join(this._documentRoot, '/simple-types.ts'), true);
|
|
25
|
+
else if (dataType instanceof EnumType) {
|
|
26
|
+
file = this.addFile(path.join(this._typesRoot, 'enums', typeName + '.ts'), true);
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
file = this.addFile(path.join(this._typesRoot, 'types', typeName + '.ts'), true);
|
|
30
|
+
this._filesMap.set(dataType, file);
|
|
31
|
+
if (file.exportTypes.includes(typeName)) {
|
|
32
|
+
if (currentFile)
|
|
33
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
34
|
+
return { kind: 'named', file, typeName: dataType.name };
|
|
35
|
+
}
|
|
36
|
+
file.exportTypes.push(typeName);
|
|
37
|
+
const typesIndexTs = this.addFile(path.join(this._typesRoot, 'index.ts'), true);
|
|
38
|
+
const indexTs = this.addFile('/index.ts', true);
|
|
39
|
+
indexTs.addExport(typesIndexTs.filename, undefined, this._typesNamespace);
|
|
40
|
+
const codeBlock = (file.code['type_' + typeName] = new CodeBlock());
|
|
41
|
+
codeBlock.head = `/**\n * ${wrapJSDocString(dataType.description || '')}\n *`;
|
|
42
|
+
codeBlock.head += `
|
|
42
43
|
* @url ${path.posix.join(doc.url || this.serviceUrl, '$schema', '#types/' + typeName)}
|
|
43
44
|
*/
|
|
44
45
|
export `;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
codeBlock.typeDef = (await this._generateTypeCode(file, dataType, 'root')) + '\n\n';
|
|
47
|
+
typesIndexTs.addExport(file.filename);
|
|
48
|
+
if (currentFile)
|
|
49
|
+
currentFile.addImport(file.filename, [typeName]);
|
|
50
|
+
return { kind: 'named', file, typeName };
|
|
51
|
+
}
|
|
52
|
+
if (!currentFile)
|
|
53
|
+
throw new TypeError(`You must provide currentFile to generate data type`);
|
|
54
|
+
const code = await this._generateTypeCode(currentFile, dataType, intent);
|
|
55
|
+
return { kind: 'embedded', code };
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
e.message = `(${dataType.name}) ` + e.message;
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
57
63
|
*
|
|
@@ -45,6 +45,7 @@ export class TsGenerator extends EventEmitter {
|
|
|
45
45
|
this.emit('log', colors.cyan('Removing old files..'));
|
|
46
46
|
this.cleanDirectory(this.outDir);
|
|
47
47
|
this._apiPath = '/api';
|
|
48
|
+
this._typesRoot = '/models';
|
|
48
49
|
await this.generateDocument();
|
|
49
50
|
const { importExt } = this.options;
|
|
50
51
|
// Write files
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@browsery/type-is": "^1.6.18-r5",
|
|
9
|
-
"@opra/client": "^1.0.0-beta.
|
|
10
|
-
"@opra/common": "^1.0.0-beta.
|
|
9
|
+
"@opra/client": "^1.0.0-beta.5",
|
|
10
|
+
"@opra/common": "^1.0.0-beta.5",
|
|
11
11
|
"ansi-colors": "^4.1.3",
|
|
12
12
|
"commander": "^12.0.0",
|
|
13
13
|
"js-string-escape": "^1.0.1",
|