@opra/cli 0.18.4 → 0.18.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.
@@ -27,6 +27,7 @@ class ApiExporter {
27
27
  this.fileHeader = config.fileHeader || '';
28
28
  this.writer = config.writer || new file_writer_js_1.FileWriter();
29
29
  this.serviceClassName = config.name;
30
+ this.importExt = config.importExt;
30
31
  // this.nsMap = nsMap || new ResponsiveMap(); // implement references later
31
32
  }
32
33
  async execute() {
@@ -46,11 +47,12 @@ class ApiExporter {
46
47
  node_fs_1.default.mkdirSync(this.outDir, { recursive: true });
47
48
  await this.processTypes();
48
49
  await this.processResources();
50
+ const { importExt } = this;
49
51
  // Write files
50
52
  for (const file of Object.values(this.files)) {
51
53
  const targetDir = node_path_1.default.dirname(file.filename);
52
54
  node_fs_1.default.mkdirSync(targetDir, { recursive: true });
53
- await this.writer.writeFile(file.filename, file.generate());
55
+ await this.writer.writeFile(file.filename, file.generate({ importExt }));
54
56
  }
55
57
  }
56
58
  getFile(filePath) {
@@ -15,7 +15,7 @@ async function processResources(targetDir = '') {
15
15
  const { document } = this;
16
16
  const serviceTs = this.addFile(node_path_1.default.join(targetDir, this.serviceClassName + '.ts'));
17
17
  serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
18
- const indexTs = this.addFile('/index.d.ts', true);
18
+ const indexTs = this.addFile('/index.ts', true);
19
19
  indexTs.addExportFile(serviceTs.filename);
20
20
  serviceTs.content = `\nexport class ${this.serviceClassName} extends HttpServiceBase {\n`;
21
21
  for (const resource of document.resources.values()) {
@@ -14,7 +14,7 @@ const internalTypeNames = ['boolean', 'bigint', 'number', 'null', 'string'];
14
14
  async function processTypes(targetDir = '') {
15
15
  this.logger.log(chalk_1.default.yellow('Processing types'));
16
16
  const { document } = this;
17
- const typesTs = this.addFile(node_path_1.default.join(targetDir, 'types.d.ts'));
17
+ const typesTs = this.addFile(node_path_1.default.join(targetDir, 'types.ts'));
18
18
  for (const dataType of document.types.values()) {
19
19
  const expFile = await this.generateTypeFile(dataType, targetDir);
20
20
  typesTs.addExportFile(expFile.filename);
@@ -32,11 +32,11 @@ async function generateTypeFile(dataType, targetDir = '') {
32
32
  throw new TypeError(`DataType has no name`);
33
33
  let filePath;
34
34
  if (dataType instanceof common_1.SimpleType)
35
- filePath = '/simple-types.d.ts';
35
+ filePath = '/simple-types.ts';
36
36
  else if (dataType instanceof common_1.ComplexType)
37
- filePath = `/types/${typeName}-type.d.ts`;
37
+ filePath = `/types/${typeName}-type.ts`;
38
38
  else if (dataType instanceof common_1.EnumType) {
39
- filePath = `/enums/${typeName}-enum.d.ts`;
39
+ filePath = `/enums/${typeName}-enum.ts`;
40
40
  }
41
41
  else
42
42
  throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
@@ -44,7 +44,7 @@ async function generateTypeFile(dataType, targetDir = '') {
44
44
  if (file.exportTypes.includes(typeName))
45
45
  return file;
46
46
  file.exportTypes.push(typeName);
47
- const indexTs = this.addFile('/index.d.ts', true);
47
+ const indexTs = this.addFile('/index.ts', true);
48
48
  indexTs.addExportFile(file.filename);
49
49
  file.content += `\n/**\n * ${(0, string_utils_js_1.wrapJSDocString)(dataType.description || typeName)}
50
50
  * @interface ${typeName}
@@ -45,7 +45,7 @@ class TsFile {
45
45
  };
46
46
  this.dirname = path_1.default.dirname(filename);
47
47
  }
48
- generate() {
48
+ generate(options) {
49
49
  const dirname = path_1.default.dirname(this.filename);
50
50
  let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
51
51
  (this.header ? (0, putil_flattentext_1.default)(this.header) + '\n\n' : '\n');
@@ -54,8 +54,11 @@ class TsFile {
54
54
  .map(filename => {
55
55
  const types = this.importFiles[filename];
56
56
  let relFile = filename;
57
- if (path_1.default.isAbsolute(filename))
57
+ if (path_1.default.isAbsolute(filename)) {
58
58
  relFile = relativePath(dirname, filename);
59
+ if (options?.importExt)
60
+ relFile += '.js';
61
+ }
59
62
  return `import ${types.length ? '{ ' + types.join(', ') + ' } from ' : ''}'${relFile}';`;
60
63
  })
61
64
  .join('\n');
@@ -67,8 +70,11 @@ class TsFile {
67
70
  .map(filename => {
68
71
  const types = this.exportFiles[filename];
69
72
  let relFile = filename;
70
- if (path_1.default.isAbsolute(filename))
73
+ if (path_1.default.isAbsolute(filename)) {
71
74
  relFile = relativePath(dirname, filename);
75
+ if (options?.importExt)
76
+ relFile += '.js';
77
+ }
72
78
  return `export ${types.length ? '{ ' + types.join(', ') + ' }' : '*'} from '${relFile}';`;
73
79
  })
74
80
  .join('\n');
package/cjs/oprimp-cli.js CHANGED
@@ -16,6 +16,7 @@ commander_1.program
16
16
  .argument('<serviceUrl>', 'OPRA service url')
17
17
  .argument('<outDir>', 'Output directory')
18
18
  .option('--name <name>', 'Name of the service')
19
+ .option('--ext', 'Adds js extension to imports')
19
20
  .option('--no-color', 'Disables colors in logs messages')
20
21
  .action(async (serviceUrl, outDir, options) => {
21
22
  if (!options.color)
@@ -25,6 +26,7 @@ commander_1.program
25
26
  logger: console,
26
27
  outDir,
27
28
  name: options.name,
29
+ importExt: options.ext,
28
30
  fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
29
31
  '/* eslint-disable import/extensions,simple-import-sort/imports */\n'
30
32
  });
@@ -23,6 +23,7 @@ export class ApiExporter {
23
23
  this.fileHeader = config.fileHeader || '';
24
24
  this.writer = config.writer || new FileWriter();
25
25
  this.serviceClassName = config.name;
26
+ this.importExt = config.importExt;
26
27
  // this.nsMap = nsMap || new ResponsiveMap(); // implement references later
27
28
  }
28
29
  async execute() {
@@ -42,11 +43,12 @@ export class ApiExporter {
42
43
  fs.mkdirSync(this.outDir, { recursive: true });
43
44
  await this.processTypes();
44
45
  await this.processResources();
46
+ const { importExt } = this;
45
47
  // Write files
46
48
  for (const file of Object.values(this.files)) {
47
49
  const targetDir = path.dirname(file.filename);
48
50
  fs.mkdirSync(targetDir, { recursive: true });
49
- await this.writer.writeFile(file.filename, file.generate());
51
+ await this.writer.writeFile(file.filename, file.generate({ importExt }));
50
52
  }
51
53
  }
52
54
  getFile(filePath) {
@@ -11,7 +11,7 @@ export async function processResources(targetDir = '') {
11
11
  const { document } = this;
12
12
  const serviceTs = this.addFile(path.join(targetDir, this.serviceClassName + '.ts'));
13
13
  serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
14
- const indexTs = this.addFile('/index.d.ts', true);
14
+ const indexTs = this.addFile('/index.ts', true);
15
15
  indexTs.addExportFile(serviceTs.filename);
16
16
  serviceTs.content = `\nexport class ${this.serviceClassName} extends HttpServiceBase {\n`;
17
17
  for (const resource of document.resources.values()) {
@@ -10,7 +10,7 @@ const internalTypeNames = ['boolean', 'bigint', 'number', 'null', 'string'];
10
10
  export async function processTypes(targetDir = '') {
11
11
  this.logger.log(chalk.yellow('Processing types'));
12
12
  const { document } = this;
13
- const typesTs = this.addFile(path.join(targetDir, 'types.d.ts'));
13
+ const typesTs = this.addFile(path.join(targetDir, 'types.ts'));
14
14
  for (const dataType of document.types.values()) {
15
15
  const expFile = await this.generateTypeFile(dataType, targetDir);
16
16
  typesTs.addExportFile(expFile.filename);
@@ -27,11 +27,11 @@ export async function generateTypeFile(dataType, targetDir = '') {
27
27
  throw new TypeError(`DataType has no name`);
28
28
  let filePath;
29
29
  if (dataType instanceof SimpleType)
30
- filePath = '/simple-types.d.ts';
30
+ filePath = '/simple-types.ts';
31
31
  else if (dataType instanceof ComplexType)
32
- filePath = `/types/${typeName}-type.d.ts`;
32
+ filePath = `/types/${typeName}-type.ts`;
33
33
  else if (dataType instanceof EnumType) {
34
- filePath = `/enums/${typeName}-enum.d.ts`;
34
+ filePath = `/enums/${typeName}-enum.ts`;
35
35
  }
36
36
  else
37
37
  throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
@@ -39,7 +39,7 @@ export async function generateTypeFile(dataType, targetDir = '') {
39
39
  if (file.exportTypes.includes(typeName))
40
40
  return file;
41
41
  file.exportTypes.push(typeName);
42
- const indexTs = this.addFile('/index.d.ts', true);
42
+ const indexTs = this.addFile('/index.ts', true);
43
43
  indexTs.addExportFile(file.filename);
44
44
  file.content += `\n/**\n * ${wrapJSDocString(dataType.description || typeName)}
45
45
  * @interface ${typeName}
@@ -41,7 +41,7 @@ export class TsFile {
41
41
  };
42
42
  this.dirname = path.dirname(filename);
43
43
  }
44
- generate() {
44
+ generate(options) {
45
45
  const dirname = path.dirname(this.filename);
46
46
  let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
47
47
  (this.header ? flattenText(this.header) + '\n\n' : '\n');
@@ -50,8 +50,11 @@ export class TsFile {
50
50
  .map(filename => {
51
51
  const types = this.importFiles[filename];
52
52
  let relFile = filename;
53
- if (path.isAbsolute(filename))
53
+ if (path.isAbsolute(filename)) {
54
54
  relFile = relativePath(dirname, filename);
55
+ if (options?.importExt)
56
+ relFile += '.js';
57
+ }
55
58
  return `import ${types.length ? '{ ' + types.join(', ') + ' } from ' : ''}'${relFile}';`;
56
59
  })
57
60
  .join('\n');
@@ -63,8 +66,11 @@ export class TsFile {
63
66
  .map(filename => {
64
67
  const types = this.exportFiles[filename];
65
68
  let relFile = filename;
66
- if (path.isAbsolute(filename))
69
+ if (path.isAbsolute(filename)) {
67
70
  relFile = relativePath(dirname, filename);
71
+ if (options?.importExt)
72
+ relFile += '.js';
73
+ }
68
74
  return `export ${types.length ? '{ ' + types.join(', ') + ' }' : '*'} from '${relFile}';`;
69
75
  })
70
76
  .join('\n');
package/esm/oprimp-cli.js CHANGED
@@ -13,6 +13,7 @@ program
13
13
  .argument('<serviceUrl>', 'OPRA service url')
14
14
  .argument('<outDir>', 'Output directory')
15
15
  .option('--name <name>', 'Name of the service')
16
+ .option('--ext', 'Adds js extension to imports')
16
17
  .option('--no-color', 'Disables colors in logs messages')
17
18
  .action(async (serviceUrl, outDir, options) => {
18
19
  if (!options.color)
@@ -22,6 +23,7 @@ program
22
23
  logger: console,
23
24
  outDir,
24
25
  name: options.name,
26
+ importExt: options.ext,
25
27
  fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
26
28
  '/* eslint-disable import/extensions,simple-import-sort/imports */\n'
27
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/cli",
3
- "version": "0.18.4",
3
+ "version": "0.18.5",
4
4
  "description": "Opra CLI tools",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -64,4 +64,4 @@
64
64
  "tool",
65
65
  "oprimp"
66
66
  ]
67
- }
67
+ }
@@ -14,6 +14,7 @@ export declare namespace ApiExporter {
14
14
  logger?: ILogger;
15
15
  writer?: IFileWriter;
16
16
  fileHeader?: string;
17
+ importExt?: boolean;
17
18
  }
18
19
  }
19
20
  export declare class ApiExporter {
@@ -26,6 +27,7 @@ export declare class ApiExporter {
26
27
  protected fileHeader: string;
27
28
  protected writer: IFileWriter;
28
29
  protected files: Record<string, TsFile>;
30
+ protected importExt?: boolean;
29
31
  protected processResources: typeof processResources;
30
32
  protected processTypes: typeof processTypes;
31
33
  protected generateTypeFile: typeof generateTypeFile;
@@ -10,6 +10,8 @@ export declare class TsFile {
10
10
  addImportPackage: (name: string, types?: string[]) => void;
11
11
  addImportFile: (filename: string, types?: string[]) => void;
12
12
  addExportFile: (filename: string, types?: string[]) => void;
13
- generate(): string;
13
+ generate(options?: {
14
+ importExt?: boolean;
15
+ }): string;
14
16
  }
15
17
  export declare function relativePath(from: string, to: string): string;