@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.
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeGenerator = void 0;
4
+ const node_events_1 = require("node:events");
5
+ class CodeGenerator extends node_events_1.EventEmitter {
6
+ }
7
+ exports.CodeGenerator = CodeGenerator;
@@ -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
- const typeName = dataType.name;
23
- if (typeName) {
24
- if (internalTypeNames.includes(typeName))
25
- return { kind: 'internal', typeName: dataType.name };
26
- let file = this._filesMap.get(dataType);
27
- if (file) {
28
- if (currentFile)
29
- currentFile.addImport(file.filename, [typeName]);
30
- return { kind: 'named', file, typeName: dataType.name };
31
- }
32
- if (dataType instanceof common_1.SimpleType)
33
- file = this.addFile(node_path_1.default.join(this._documentRoot, '/simple-types.ts'), true);
34
- else if (dataType instanceof common_1.EnumType) {
35
- file = this.addFile(node_path_1.default.join(this._typesRoot, 'enums', typeName + '.ts'), true);
36
- }
37
- else
38
- file = this.addFile(node_path_1.default.join(this._typesRoot, 'types', typeName + '.ts'), true);
39
- this._filesMap.set(dataType, file);
40
- if (file.exportTypes.includes(typeName)) {
41
- if (currentFile)
42
- currentFile.addImport(file.filename, [typeName]);
43
- return { kind: 'named', file, typeName: dataType.name };
44
- }
45
- file.exportTypes.push(typeName);
46
- const typesIndexTs = this.addFile(node_path_1.default.join(this._typesRoot, 'index.ts'), true);
47
- const indexTs = this.addFile('/index.ts', true);
48
- indexTs.addExport(typesIndexTs.filename, undefined, this._typesNamespace);
49
- const codeBlock = (file.code['type_' + typeName] = new code_block_js_1.CodeBlock());
50
- codeBlock.head = `/**\n * ${(0, string_utils_js_1.wrapJSDocString)(dataType.description || '')}\n *`;
51
- codeBlock.head += `
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
- codeBlock.typeDef = (await this._generateTypeCode(file, dataType, 'root')) + '\n\n';
56
- typesIndexTs.addExport(file.filename);
57
- if (currentFile)
58
- currentFile.addImport(file.filename, [typeName]);
59
- return { kind: 'named', file, typeName };
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
@@ -0,0 +1,3 @@
1
+ import { EventEmitter } from 'node:events';
2
+ export class CodeGenerator extends EventEmitter {
3
+ }
@@ -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
- const typeName = dataType.name;
13
- if (typeName) {
14
- if (internalTypeNames.includes(typeName))
15
- return { kind: 'internal', typeName: dataType.name };
16
- let file = this._filesMap.get(dataType);
17
- if (file) {
18
- if (currentFile)
19
- currentFile.addImport(file.filename, [typeName]);
20
- return { kind: 'named', file, typeName: dataType.name };
21
- }
22
- if (dataType instanceof SimpleType)
23
- file = this.addFile(path.join(this._documentRoot, '/simple-types.ts'), true);
24
- else if (dataType instanceof EnumType) {
25
- file = this.addFile(path.join(this._typesRoot, 'enums', typeName + '.ts'), true);
26
- }
27
- else
28
- file = this.addFile(path.join(this._typesRoot, 'types', typeName + '.ts'), true);
29
- this._filesMap.set(dataType, file);
30
- if (file.exportTypes.includes(typeName)) {
31
- if (currentFile)
32
- currentFile.addImport(file.filename, [typeName]);
33
- return { kind: 'named', file, typeName: dataType.name };
34
- }
35
- file.exportTypes.push(typeName);
36
- const typesIndexTs = this.addFile(path.join(this._typesRoot, 'index.ts'), true);
37
- const indexTs = this.addFile('/index.ts', true);
38
- indexTs.addExport(typesIndexTs.filename, undefined, this._typesNamespace);
39
- const codeBlock = (file.code['type_' + typeName] = new CodeBlock());
40
- codeBlock.head = `/**\n * ${wrapJSDocString(dataType.description || '')}\n *`;
41
- codeBlock.head += `
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
- codeBlock.typeDef = (await this._generateTypeCode(file, dataType, 'root')) + '\n\n';
46
- typesIndexTs.addExport(file.filename);
47
- if (currentFile)
48
- currentFile.addImport(file.filename, [typeName]);
49
- return { kind: 'named', file, typeName };
50
- }
51
- if (!currentFile)
52
- throw new TypeError(`You must provide currentFile to generate data type`);
53
- const code = await this._generateTypeCode(currentFile, dataType, intent);
54
- return { kind: 'embedded', code };
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",
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.3",
10
- "@opra/common": "^1.0.0-beta.3",
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",
@@ -0,0 +1,3 @@
1
+ import { EventEmitter } from 'node:events';
2
+ export declare abstract class CodeGenerator extends EventEmitter {
3
+ }