@opra/cli 0.18.0 → 0.18.2

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.
@@ -26,14 +26,15 @@ class ApiExporter {
26
26
  };
27
27
  this.fileHeader = config.fileHeader || '';
28
28
  this.writer = config.writer || new file_writer_js_1.FileWriter();
29
+ this.serviceClassName = config.name;
29
30
  // this.nsMap = nsMap || new ResponsiveMap(); // implement references later
30
31
  }
31
32
  async execute() {
32
33
  this.logger.log(chalk_1.default.yellow('Fetching service metadata from'), chalk_1.default.whiteBright(this.client.serviceUrl));
33
34
  this.document = await this.client.getMetadata();
34
35
  this.logger.log(chalk_1.default.yellow('Retrieved service info:\n'), chalk_1.default.white('Title:'), chalk_1.default.magenta(this.document.info.title), '\n', chalk_1.default.white('Version:'), chalk_1.default.magenta(this.document.info.version), '\n', chalk_1.default.white('Resources:'), chalk_1.default.magenta(this.document.resources.size), 'resources found\n', chalk_1.default.white('Types:'), chalk_1.default.magenta(this.document.types.size), 'types found\n');
35
- this.name = (this.name || this.document.info.title || 'Service1').replace(/[^\w_$]*/g, '');
36
- this.name = this.name.charAt(0).toUpperCase() + this.name.substring(1);
36
+ this.serviceClassName = (this.serviceClassName || this.document.info.title || 'Service1').replace(/[^\w_$]*/g, '');
37
+ this.serviceClassName = this.serviceClassName.charAt(0).toUpperCase() + this.serviceClassName.substring(1);
37
38
  this.fileHeader += `/*
38
39
  * ${this.document.info.title}
39
40
  * Version ${this.document.info.version}
@@ -41,7 +42,7 @@ class ApiExporter {
41
42
  */`;
42
43
  this.logger.log(chalk_1.default.yellow('Removing old files..'));
43
44
  this.cleanDirectory(this.outDir);
44
- this.logger.log(chalk_1.default.yellow(`Generating service interface ( ${chalk_1.default.whiteBright(this.name)} )`));
45
+ this.logger.log(chalk_1.default.yellow(`Generating service interface ( ${chalk_1.default.whiteBright(this.serviceClassName)} )`));
45
46
  node_fs_1.default.mkdirSync(this.outDir, { recursive: true });
46
47
  await this.processTypes();
47
48
  await this.processResources();
@@ -13,11 +13,11 @@ const string_utils_js_1 = require("../utils/string-utils.js");
13
13
  async function processResources(targetDir = '') {
14
14
  this.logger.log(chalk_1.default.yellow('Processing resources'));
15
15
  const { document } = this;
16
- const serviceTs = this.addFile(node_path_1.default.join(targetDir, this.name + '.ts'));
16
+ const serviceTs = this.addFile(node_path_1.default.join(targetDir, this.serviceClassName + '.ts'));
17
17
  serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
18
18
  const indexTs = this.addFile('/index.d.ts', true);
19
19
  indexTs.addExportFile(serviceTs.filename);
20
- serviceTs.content = `\nexport class ${this.name} extends HttpServiceBase {\n`;
20
+ serviceTs.content = `\nexport class ${this.serviceClassName} extends HttpServiceBase {\n`;
21
21
  for (const resource of document.resources.values()) {
22
22
  serviceTs.content += `\n/**\n * ${(0, string_utils_js_1.wrapJSDocString)(resource.description || resource.name)}
23
23
  * @url ${(0, common_1.joinPath)(this.client.serviceUrl, '$metadata#resources/' + resource.name)}
@@ -25,7 +25,7 @@ async function processResources(targetDir = '') {
25
25
  if (resource instanceof common_1.Collection) {
26
26
  const typeName = resource.type.name || '';
27
27
  serviceTs.addImportPackage('@opra/client', ['HttpCollectionNode']);
28
- serviceTs.addImportFile('types/' + typeName, [typeName]);
28
+ serviceTs.addImportFile(`types/${typeName}-type`, [typeName]);
29
29
  const operations = Object.keys(resource.operations)
30
30
  .map(x => `'${x}'`).join(' | ');
31
31
  serviceTs.content += `
@@ -36,7 +36,7 @@ async function processResources(targetDir = '') {
36
36
  else if (resource instanceof common_1.Singleton) {
37
37
  const typeName = resource.type.name || '';
38
38
  serviceTs.addImportPackage('@opra/client', ['HttpSingletonNode']);
39
- serviceTs.addImportFile('types/' + typeName, [typeName]);
39
+ serviceTs.addImportFile(`types/${typeName}-type`, [typeName]);
40
40
  const operations = Object.keys(resource.operations)
41
41
  .map(x => `'${x}'`).join(' | ');
42
42
  serviceTs.content += `
@@ -34,9 +34,9 @@ async function generateTypeFile(dataType, targetDir = '') {
34
34
  if (dataType instanceof common_1.SimpleType)
35
35
  filePath = '/simple-types.d.ts';
36
36
  else if (dataType instanceof common_1.ComplexType)
37
- filePath = `/types/${typeName}.type.d.ts`;
37
+ filePath = `/types/${typeName}-type.d.ts`;
38
38
  else if (dataType instanceof common_1.EnumType) {
39
- filePath = `/enums/${typeName}.enum.d.ts`;
39
+ filePath = `/enums/${typeName}-enum.d.ts`;
40
40
  }
41
41
  else
42
42
  throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
@@ -22,14 +22,15 @@ export class ApiExporter {
22
22
  };
23
23
  this.fileHeader = config.fileHeader || '';
24
24
  this.writer = config.writer || new FileWriter();
25
+ this.serviceClassName = config.name;
25
26
  // this.nsMap = nsMap || new ResponsiveMap(); // implement references later
26
27
  }
27
28
  async execute() {
28
29
  this.logger.log(chalk.yellow('Fetching service metadata from'), chalk.whiteBright(this.client.serviceUrl));
29
30
  this.document = await this.client.getMetadata();
30
31
  this.logger.log(chalk.yellow('Retrieved service info:\n'), chalk.white('Title:'), chalk.magenta(this.document.info.title), '\n', chalk.white('Version:'), chalk.magenta(this.document.info.version), '\n', chalk.white('Resources:'), chalk.magenta(this.document.resources.size), 'resources found\n', chalk.white('Types:'), chalk.magenta(this.document.types.size), 'types found\n');
31
- this.name = (this.name || this.document.info.title || 'Service1').replace(/[^\w_$]*/g, '');
32
- this.name = this.name.charAt(0).toUpperCase() + this.name.substring(1);
32
+ this.serviceClassName = (this.serviceClassName || this.document.info.title || 'Service1').replace(/[^\w_$]*/g, '');
33
+ this.serviceClassName = this.serviceClassName.charAt(0).toUpperCase() + this.serviceClassName.substring(1);
33
34
  this.fileHeader += `/*
34
35
  * ${this.document.info.title}
35
36
  * Version ${this.document.info.version}
@@ -37,7 +38,7 @@ export class ApiExporter {
37
38
  */`;
38
39
  this.logger.log(chalk.yellow('Removing old files..'));
39
40
  this.cleanDirectory(this.outDir);
40
- this.logger.log(chalk.yellow(`Generating service interface ( ${chalk.whiteBright(this.name)} )`));
41
+ this.logger.log(chalk.yellow(`Generating service interface ( ${chalk.whiteBright(this.serviceClassName)} )`));
41
42
  fs.mkdirSync(this.outDir, { recursive: true });
42
43
  await this.processTypes();
43
44
  await this.processResources();
@@ -9,11 +9,11 @@ import { wrapJSDocString } from '../utils/string-utils.js';
9
9
  export async function processResources(targetDir = '') {
10
10
  this.logger.log(chalk.yellow('Processing resources'));
11
11
  const { document } = this;
12
- const serviceTs = this.addFile(path.join(targetDir, this.name + '.ts'));
12
+ const serviceTs = this.addFile(path.join(targetDir, this.serviceClassName + '.ts'));
13
13
  serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
14
14
  const indexTs = this.addFile('/index.d.ts', true);
15
15
  indexTs.addExportFile(serviceTs.filename);
16
- serviceTs.content = `\nexport class ${this.name} extends HttpServiceBase {\n`;
16
+ serviceTs.content = `\nexport class ${this.serviceClassName} extends HttpServiceBase {\n`;
17
17
  for (const resource of document.resources.values()) {
18
18
  serviceTs.content += `\n/**\n * ${wrapJSDocString(resource.description || resource.name)}
19
19
  * @url ${joinPath(this.client.serviceUrl, '$metadata#resources/' + resource.name)}
@@ -21,7 +21,7 @@ export async function processResources(targetDir = '') {
21
21
  if (resource instanceof Collection) {
22
22
  const typeName = resource.type.name || '';
23
23
  serviceTs.addImportPackage('@opra/client', ['HttpCollectionNode']);
24
- serviceTs.addImportFile('types/' + typeName, [typeName]);
24
+ serviceTs.addImportFile(`types/${typeName}-type`, [typeName]);
25
25
  const operations = Object.keys(resource.operations)
26
26
  .map(x => `'${x}'`).join(' | ');
27
27
  serviceTs.content += `
@@ -32,7 +32,7 @@ export async function processResources(targetDir = '') {
32
32
  else if (resource instanceof Singleton) {
33
33
  const typeName = resource.type.name || '';
34
34
  serviceTs.addImportPackage('@opra/client', ['HttpSingletonNode']);
35
- serviceTs.addImportFile('types/' + typeName, [typeName]);
35
+ serviceTs.addImportFile(`types/${typeName}-type`, [typeName]);
36
36
  const operations = Object.keys(resource.operations)
37
37
  .map(x => `'${x}'`).join(' | ');
38
38
  serviceTs.content += `
@@ -29,9 +29,9 @@ export async function generateTypeFile(dataType, targetDir = '') {
29
29
  if (dataType instanceof SimpleType)
30
30
  filePath = '/simple-types.d.ts';
31
31
  else if (dataType instanceof ComplexType)
32
- filePath = `/types/${typeName}.type.d.ts`;
32
+ filePath = `/types/${typeName}-type.d.ts`;
33
33
  else if (dataType instanceof EnumType) {
34
- filePath = `/enums/${typeName}.enum.d.ts`;
34
+ filePath = `/enums/${typeName}-enum.d.ts`;
35
35
  }
36
36
  else
37
37
  throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/cli",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Opra CLI tools",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "clean:cover": "rimraf ../../coverage/client"
29
29
  },
30
30
  "dependencies": {
31
- "@opra/client": "^0.18.0",
31
+ "@opra/client": "^0.18.2",
32
32
  "chalk": "^5.2.0",
33
33
  "commander": "^10.0.1",
34
34
  "js-string-escape": "^1.0.1",
@@ -22,7 +22,7 @@ export declare class ApiExporter {
22
22
  protected logger: ILogger;
23
23
  protected outDir: string;
24
24
  protected cwd: string;
25
- protected name: string;
25
+ protected serviceClassName?: string;
26
26
  protected fileHeader: string;
27
27
  protected writer: IFileWriter;
28
28
  protected files: Record<string, TsFile>;