@opra/cli 0.16.1 → 0.17.0

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.
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExporter = void 0;
4
- const tslib_1 = require("tslib");
5
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
- const node_process_1 = tslib_1.__importDefault(require("node:process"));
9
- const node_client_1 = require("@opra/node-client");
10
- const file_writer_js_1 = require("./file-writer.js");
11
- const process_resources_js_1 = require("./process-resources.js");
12
- const process_types_js_1 = require("./process-types.js");
13
- const ts_file_js_1 = require("./ts-file.js");
14
- class ApiExporter {
1
+ import chalk from 'chalk';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import process from 'node:process';
5
+ import { OpraHttpClient } from '@opra/node-client';
6
+ import { FileWriter } from './file-writer.js';
7
+ import { processResources } from './process-resources.js';
8
+ import { generateComplexTypeDefinition, generateEnumTypeDefinition, generateMappedTypeDefinition, generateSimpleTypeDefinition, generateTypeFile, generateUnionTypeDefinition, processTypes, resolveTypeNameOrDef } from './process-types.js';
9
+ import { TsFile } from './ts-file.js';
10
+ export class ApiExporter {
15
11
  constructor(config) {
16
12
  this.files = {};
17
- this.client = new node_client_1.OpraHttpClient(config.serviceUrl);
18
- this.cwd = config.cwd || node_process_1.default.cwd();
19
- this.outDir = node_path_1.default.resolve(this.cwd, config.outDir);
13
+ this.client = new OpraHttpClient(config.serviceUrl);
14
+ this.cwd = config.cwd || process.cwd();
15
+ this.outDir = path.resolve(this.cwd, config.outDir);
20
16
  this.logger = config.logger || {
21
17
  log: () => void 0,
22
18
  error: () => void 0,
@@ -26,13 +22,13 @@ class ApiExporter {
26
22
  };
27
23
  this.fileHeader = config.fileHeader || '';
28
24
  this.importExt = config.importExt || '';
29
- this.writer = config.writer || new file_writer_js_1.FileWriter();
25
+ this.writer = config.writer || new FileWriter();
30
26
  // this.nsMap = nsMap || new ResponsiveMap(); // implement references later
31
27
  }
32
28
  async execute() {
33
- this.logger.log(chalk_1.default.yellow('Fetching service metadata from'), chalk_1.default.whiteBright(this.client.serviceUrl));
29
+ this.logger.log(chalk.yellow('Fetching service metadata from'), chalk.whiteBright(this.client.serviceUrl));
34
30
  this.document = await this.client.getMetadata();
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');
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');
36
32
  this.name = (this.name || this.document.info.title || 'Service1').replace(/[^\w_$]*/g, '');
37
33
  this.name = this.name.charAt(0).toUpperCase() + this.name.substring(1);
38
34
  this.fileHeader += `/*
@@ -40,21 +36,21 @@ class ApiExporter {
40
36
  * Version ${this.document.info.version}
41
37
  * ${this.client.serviceUrl}
42
38
  */`;
43
- this.logger.log(chalk_1.default.yellow('Removing old files..'));
39
+ this.logger.log(chalk.yellow('Removing old files..'));
44
40
  this.cleanDirectory(this.outDir);
45
- this.logger.log(chalk_1.default.yellow(`Generating service interface ( ${chalk_1.default.whiteBright(this.name)} )`));
46
- node_fs_1.default.mkdirSync(this.outDir, { recursive: true });
41
+ this.logger.log(chalk.yellow(`Generating service interface ( ${chalk.whiteBright(this.name)} )`));
42
+ fs.mkdirSync(this.outDir, { recursive: true });
47
43
  await this.processTypes();
48
44
  await this.processResources();
49
45
  // Write files
50
46
  for (const file of Object.values(this.files)) {
51
- const targetDir = node_path_1.default.dirname(file.filename);
52
- node_fs_1.default.mkdirSync(targetDir, { recursive: true });
47
+ const targetDir = path.dirname(file.filename);
48
+ fs.mkdirSync(targetDir, { recursive: true });
53
49
  await this.writer.writeFile(file.filename, file.generate({ importExt: this.importExt }));
54
50
  }
55
51
  }
56
52
  getFile(filePath) {
57
- return this.files[node_path_1.default.resolve(node_path_1.default.join(this.outDir, filePath))];
53
+ return this.files[path.resolve(path.join(this.outDir, filePath))];
58
54
  }
59
55
  addFile(filePath, returnExists) {
60
56
  let file = this.getFile(filePath);
@@ -63,27 +59,27 @@ class ApiExporter {
63
59
  return file;
64
60
  throw new Error(`File "${filePath}" already exists`);
65
61
  }
66
- file = new ts_file_js_1.TsFile(node_path_1.default.resolve(node_path_1.default.join(this.outDir, filePath)));
62
+ file = new TsFile(path.resolve(path.join(this.outDir, filePath)));
67
63
  file.header = this.fileHeader;
68
64
  this.files[file.filename] = file;
69
65
  return file;
70
66
  }
71
67
  cleanDirectory(dirname) {
72
- if (!node_fs_1.default.existsSync(dirname))
68
+ if (!fs.existsSync(dirname))
73
69
  return;
74
- const files = node_fs_1.default.readdirSync(dirname);
70
+ const files = fs.readdirSync(dirname);
75
71
  for (const f of files) {
76
- const absolutePath = node_path_1.default.join(dirname, f);
77
- if (node_fs_1.default.statSync(absolutePath).isDirectory()) {
72
+ const absolutePath = path.join(dirname, f);
73
+ if (fs.statSync(absolutePath).isDirectory()) {
78
74
  this.cleanDirectory(absolutePath);
79
- if (!node_fs_1.default.readdirSync(absolutePath).length)
80
- node_fs_1.default.rmdirSync(absolutePath);
75
+ if (!fs.readdirSync(absolutePath).length)
76
+ fs.rmdirSync(absolutePath);
81
77
  continue;
82
78
  }
83
- if (node_path_1.default.extname(f) === '.ts') {
84
- const contents = node_fs_1.default.readFileSync(absolutePath, 'utf-8');
79
+ if (path.extname(f) === '.ts') {
80
+ const contents = fs.readFileSync(absolutePath, 'utf-8');
85
81
  if (contents.includes('#!oprimp_auto_generated!#')) {
86
- node_fs_1.default.unlinkSync(absolutePath);
82
+ fs.unlinkSync(absolutePath);
87
83
  }
88
84
  }
89
85
  }
@@ -93,15 +89,14 @@ class ApiExporter {
93
89
  await exporter.execute();
94
90
  }
95
91
  }
96
- exports.ApiExporter = ApiExporter;
97
92
  (() => {
98
- ApiExporter.prototype.processResources = process_resources_js_1.processResources;
99
- ApiExporter.prototype.processTypes = process_types_js_1.processTypes;
100
- ApiExporter.prototype.generateTypeFile = process_types_js_1.generateTypeFile;
101
- ApiExporter.prototype.generateComplexTypeDefinition = process_types_js_1.generateComplexTypeDefinition;
102
- ApiExporter.prototype.generateSimpleTypeDefinition = process_types_js_1.generateSimpleTypeDefinition;
103
- ApiExporter.prototype.resolveTypeNameOrDef = process_types_js_1.resolveTypeNameOrDef;
104
- ApiExporter.prototype.generateEnumTypeDefinition = process_types_js_1.generateEnumTypeDefinition;
105
- ApiExporter.prototype.generateUnionTypeDefinition = process_types_js_1.generateUnionTypeDefinition;
106
- ApiExporter.prototype.generateMappedTypeDefinition = process_types_js_1.generateMappedTypeDefinition;
93
+ ApiExporter.prototype.processResources = processResources;
94
+ ApiExporter.prototype.processTypes = processTypes;
95
+ ApiExporter.prototype.generateTypeFile = generateTypeFile;
96
+ ApiExporter.prototype.generateComplexTypeDefinition = generateComplexTypeDefinition;
97
+ ApiExporter.prototype.generateSimpleTypeDefinition = generateSimpleTypeDefinition;
98
+ ApiExporter.prototype.resolveTypeNameOrDef = resolveTypeNameOrDef;
99
+ ApiExporter.prototype.generateEnumTypeDefinition = generateEnumTypeDefinition;
100
+ ApiExporter.prototype.generateUnionTypeDefinition = generateUnionTypeDefinition;
101
+ ApiExporter.prototype.generateMappedTypeDefinition = generateMappedTypeDefinition;
107
102
  })();
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileWriter = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
6
- class FileWriter {
1
+ import fs from 'fs';
2
+ export class FileWriter {
7
3
  writeFile(filename, contents) {
8
- fs_1.default.writeFileSync(filename, contents, 'utf-8');
4
+ fs.writeFileSync(filename, contents, 'utf-8');
9
5
  }
10
6
  }
11
- exports.FileWriter = FileWriter;
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./api-exporter.js"), exports);
1
+ export * from './api-exporter.js';
@@ -1,28 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processResources = void 0;
4
- const tslib_1 = require("tslib");
5
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
- const common_1 = require("@opra/common");
8
- const string_utils_js_1 = require("../utils/string-utils.js");
1
+ import chalk from 'chalk';
2
+ import path from 'node:path';
3
+ import { Collection, joinPath, Singleton } from '@opra/common';
4
+ import { wrapJSDocString } from '../utils/string-utils.js';
9
5
  /**
10
6
  *
11
7
  * @param targetDir
12
8
  */
13
- async function processResources(targetDir = '') {
14
- this.logger.log(chalk_1.default.yellow('Processing resources'));
9
+ export async function processResources(targetDir = '') {
10
+ this.logger.log(chalk.yellow('Processing resources'));
15
11
  const { document } = this;
16
- const serviceTs = this.addFile(node_path_1.default.join(targetDir, this.name + '.ts'));
12
+ const serviceTs = this.addFile(path.join(targetDir, this.name + '.ts'));
17
13
  serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
18
14
  const indexTs = this.addFile('/index.ts', true);
19
15
  indexTs.addExportFile(serviceTs.filename);
20
16
  serviceTs.content = `\nexport class ${this.name} extends HttpServiceBase {\n`;
21
17
  for (const resource of document.resources.values()) {
22
- serviceTs.content += `\n/**\n * ${(0, string_utils_js_1.wrapJSDocString)(resource.description || resource.name)}
23
- * @url ${(0, common_1.joinPath)(this.client.serviceUrl, '$metadata#resources/' + resource.name)}
18
+ serviceTs.content += `\n/**\n * ${wrapJSDocString(resource.description || resource.name)}
19
+ * @url ${joinPath(this.client.serviceUrl, '$metadata#resources/' + resource.name)}
24
20
  */`;
25
- if (resource instanceof common_1.Collection) {
21
+ if (resource instanceof Collection) {
26
22
  const typeName = resource.type.name || '';
27
23
  serviceTs.addImportPackage('@opra/client', ['HttpCollectionNode']);
28
24
  serviceTs.addImportFile('types/' + typeName, [typeName]);
@@ -33,7 +29,7 @@ async function processResources(targetDir = '') {
33
29
  return this.$client.collection('${resource.name}');
34
30
  }\n`;
35
31
  }
36
- else if (resource instanceof common_1.Singleton) {
32
+ else if (resource instanceof Singleton) {
37
33
  const typeName = resource.type.name || '';
38
34
  serviceTs.addImportPackage('@opra/client', ['HttpSingletonNode']);
39
35
  serviceTs.addImportFile('types/' + typeName, [typeName]);
@@ -47,4 +43,3 @@ async function processResources(targetDir = '') {
47
43
  }
48
44
  serviceTs.content += '}';
49
45
  }
50
- exports.processResources = processResources;
@@ -1,63 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateMappedTypeDefinition = exports.generateUnionTypeDefinition = exports.generateEnumTypeDefinition = exports.generateSimpleTypeDefinition = exports.generateComplexTypeDefinition = exports.resolveTypeNameOrDef = exports.generateTypeFile = exports.processTypes = void 0;
4
- const tslib_1 = require("tslib");
5
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
- const common_1 = require("@opra/common");
8
- const string_utils_js_1 = require("../utils/string-utils.js");
1
+ import chalk from 'chalk';
2
+ import path from 'node:path';
3
+ import { ComplexType, EnumType, joinPath, MappedType, SimpleType, UnionType } from '@opra/common';
4
+ import { wrapJSDocString } from '../utils/string-utils.js';
9
5
  const internalTypeNames = ['boolean', 'bigint', 'number', 'null', 'string'];
10
6
  /**
11
7
  *
12
8
  * @param targetDir
13
9
  */
14
- async function processTypes(targetDir = '') {
15
- this.logger.log(chalk_1.default.yellow('Processing types'));
10
+ export async function processTypes(targetDir = '') {
11
+ this.logger.log(chalk.yellow('Processing types'));
16
12
  const { document } = this;
17
- const typesTs = this.addFile(node_path_1.default.join(targetDir, 'types.ts'));
13
+ const typesTs = this.addFile(path.join(targetDir, 'types.ts'));
18
14
  for (const dataType of document.types.values()) {
19
15
  const expFile = await this.generateTypeFile(dataType, targetDir);
20
16
  typesTs.addExportFile(expFile.filename);
21
17
  }
22
18
  }
23
- exports.processTypes = processTypes;
24
19
  /**
25
20
  *
26
21
  * @param dataType
27
22
  * @param targetDir
28
23
  */
29
- async function generateTypeFile(dataType, targetDir = '') {
24
+ export async function generateTypeFile(dataType, targetDir = '') {
30
25
  const typeName = dataType.name;
31
26
  if (!typeName)
32
27
  throw new TypeError(`DataType has no name`);
33
28
  let filePath;
34
- if (dataType instanceof common_1.SimpleType)
29
+ if (dataType instanceof SimpleType)
35
30
  filePath = '/simple-types.ts';
36
- else if (dataType instanceof common_1.ComplexType)
31
+ else if (dataType instanceof ComplexType)
37
32
  filePath = `/types/${typeName}.ts`;
38
- else if (dataType instanceof common_1.EnumType) {
33
+ else if (dataType instanceof EnumType) {
39
34
  filePath = `/enums/${typeName}.ts`;
40
35
  }
41
36
  else
42
37
  throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
43
- const file = this.addFile(node_path_1.default.join(targetDir, filePath), true);
38
+ const file = this.addFile(path.join(targetDir, filePath), true);
44
39
  if (file.exportTypes.includes(typeName))
45
40
  return file;
46
41
  file.exportTypes.push(typeName);
47
42
  const indexTs = this.addFile('/index.ts', true);
48
43
  indexTs.addExportFile(file.filename);
49
- file.content += `\n/**\n * ${(0, string_utils_js_1.wrapJSDocString)(dataType.description || typeName)}
44
+ file.content += `\n/**\n * ${wrapJSDocString(dataType.description || typeName)}
50
45
  * @type ${typeName}
51
46
  * @kind ${dataType.kind}
52
- * @url ${(0, common_1.joinPath)(this.client.serviceUrl, '$metadata#types/' + typeName)}
47
+ * @url ${joinPath(this.client.serviceUrl, '$metadata#types/' + typeName)}
53
48
  */\n`;
54
- if (dataType instanceof common_1.SimpleType) {
49
+ if (dataType instanceof SimpleType) {
55
50
  file.content += `export type ${typeName} = ` + await this.generateSimpleTypeDefinition(file, dataType);
56
51
  }
57
- else if (dataType instanceof common_1.EnumType) {
52
+ else if (dataType instanceof EnumType) {
58
53
  file.content += `export enum ${typeName} ` + await this.generateEnumTypeDefinition(file, dataType);
59
54
  }
60
- else if (dataType instanceof common_1.ComplexType) {
55
+ else if (dataType instanceof ComplexType) {
61
56
  file.content += `export class ${typeName} {
62
57
  constructor(init?: Partial<I${typeName}>) {
63
58
  if (init)
@@ -73,14 +68,13 @@ interface I${typeName} ${await this.generateComplexTypeDefinition(file, dataType
73
68
  }
74
69
  return file;
75
70
  }
76
- exports.generateTypeFile = generateTypeFile;
77
71
  /**
78
72
  *
79
73
  * @param file
80
74
  * @param dataType
81
75
  * @param forInterface
82
76
  */
83
- async function resolveTypeNameOrDef(file, dataType, forInterface) {
77
+ export async function resolveTypeNameOrDef(file, dataType, forInterface) {
84
78
  if (dataType.name) {
85
79
  if (internalTypeNames.includes(dataType.name))
86
80
  return dataType.name;
@@ -88,26 +82,25 @@ async function resolveTypeNameOrDef(file, dataType, forInterface) {
88
82
  file.addImportFile(f.filename, [dataType.name]);
89
83
  return dataType.name;
90
84
  }
91
- if (dataType instanceof common_1.ComplexType)
85
+ if (dataType instanceof ComplexType)
92
86
  return this.generateComplexTypeDefinition(file, dataType, forInterface);
93
- if (dataType instanceof common_1.SimpleType)
87
+ if (dataType instanceof SimpleType)
94
88
  return this.generateSimpleTypeDefinition(file, dataType);
95
- if (dataType instanceof common_1.EnumType)
89
+ if (dataType instanceof EnumType)
96
90
  return this.generateEnumTypeDefinition(file, dataType);
97
- if (dataType instanceof common_1.UnionType)
91
+ if (dataType instanceof UnionType)
98
92
  return this.generateUnionTypeDefinition(file, dataType, forInterface);
99
- if (dataType instanceof common_1.MappedType)
93
+ if (dataType instanceof MappedType)
100
94
  return this.generateMappedTypeDefinition(file, dataType, forInterface);
101
95
  return 'xxx';
102
96
  }
103
- exports.resolveTypeNameOrDef = resolveTypeNameOrDef;
104
97
  /**
105
98
  *
106
99
  * @param file
107
100
  * @param dataType
108
101
  * @param forInterface
109
102
  */
110
- async function generateComplexTypeDefinition(file, dataType, forInterface) {
103
+ export async function generateComplexTypeDefinition(file, dataType, forInterface) {
111
104
  let out = '';
112
105
  if (dataType.base) {
113
106
  const base = await this.resolveTypeNameOrDef(file, dataType.base, forInterface);
@@ -142,13 +135,12 @@ async function generateComplexTypeDefinition(file, dataType, forInterface) {
142
135
  out += '[key: string]: any;\n';
143
136
  return out + '\b}';
144
137
  }
145
- exports.generateComplexTypeDefinition = generateComplexTypeDefinition;
146
138
  /**
147
139
  *
148
140
  * @param file
149
141
  * @param dataType
150
142
  */
151
- async function generateSimpleTypeDefinition(file, dataType) {
143
+ export async function generateSimpleTypeDefinition(file, dataType) {
152
144
  if (dataType.ctor === Boolean)
153
145
  return 'boolean';
154
146
  if (dataType.ctor === String)
@@ -163,13 +155,12 @@ async function generateSimpleTypeDefinition(file, dataType) {
163
155
  return 'object';
164
156
  return 'any';
165
157
  }
166
- exports.generateSimpleTypeDefinition = generateSimpleTypeDefinition;
167
158
  /**
168
159
  *
169
160
  * @param file
170
161
  * @param dataType
171
162
  */
172
- async function generateEnumTypeDefinition(file, dataType) {
163
+ export async function generateEnumTypeDefinition(file, dataType) {
173
164
  let out = '{\n\t';
174
165
  for (const [k, v] of Object.entries(dataType.values)) {
175
166
  // Print JSDoc
@@ -185,26 +176,24 @@ async function generateEnumTypeDefinition(file, dataType) {
185
176
  }
186
177
  return out + '\b}';
187
178
  }
188
- exports.generateEnumTypeDefinition = generateEnumTypeDefinition;
189
179
  /**
190
180
  *
191
181
  * @param file
192
182
  * @param dataType
193
183
  * @param forInterface
194
184
  */
195
- async function generateUnionTypeDefinition(file, dataType, forInterface) {
185
+ export async function generateUnionTypeDefinition(file, dataType, forInterface) {
196
186
  // let out = '';
197
187
  return (await Promise.all(dataType.types
198
188
  .map(t => this.resolveTypeNameOrDef(file, t, forInterface)))).join(forInterface ? ', ' : ' & ');
199
189
  }
200
- exports.generateUnionTypeDefinition = generateUnionTypeDefinition;
201
190
  /**
202
191
  *
203
192
  * @param file
204
193
  * @param dataType
205
194
  * @param forInterface
206
195
  */
207
- async function generateMappedTypeDefinition(file, dataType, forInterface) {
196
+ export async function generateMappedTypeDefinition(file, dataType, forInterface) {
208
197
  return (dataType.pick ? 'Pick<' : 'Omit<') +
209
198
  (await this.resolveTypeNameOrDef(file, dataType.type, forInterface)) +
210
199
  ', ' +
@@ -212,4 +201,3 @@ async function generateMappedTypeDefinition(file, dataType, forInterface) {
212
201
  .map(x => `'${x}'`).join(' | ') +
213
202
  '>';
214
203
  }
215
- exports.generateMappedTypeDefinition = generateMappedTypeDefinition;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setExt = exports.relativePath = exports.TsFile = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const putil_flattentext_1 = tslib_1.__importDefault(require("putil-flattentext"));
7
- class TsFile {
1
+ import path from 'path';
2
+ import flattenText from 'putil-flattentext';
3
+ export class TsFile {
8
4
  constructor(filename) {
9
5
  this.filename = filename;
10
6
  this.importFiles = {};
@@ -20,7 +16,7 @@ class TsFile {
20
16
  });
21
17
  };
22
18
  this.addImportFile = (filename, types) => {
23
- filename = path_1.default.resolve(this.dirname, filename);
19
+ filename = path.resolve(this.dirname, filename);
24
20
  this.importFiles[filename] = this.importFiles[filename] || [];
25
21
  types?.forEach(x => {
26
22
  if (!this.importFiles[filename].includes(x))
@@ -28,7 +24,7 @@ class TsFile {
28
24
  });
29
25
  };
30
26
  this.addExportFile = (filename, types) => {
31
- filename = path_1.default.resolve(this.dirname, filename);
27
+ filename = path.resolve(this.dirname, filename);
32
28
  if (filename.endsWith('.ts') || filename.endsWith('.js'))
33
29
  filename = setExt(filename, '');
34
30
  this.exportFiles[filename] = this.exportFiles[filename] || [];
@@ -37,18 +33,18 @@ class TsFile {
37
33
  this.exportFiles[filename].push(x);
38
34
  });
39
35
  };
40
- this.dirname = path_1.default.dirname(filename);
36
+ this.dirname = path.dirname(filename);
41
37
  }
42
38
  generate(options) {
43
- const dirname = path_1.default.dirname(this.filename);
39
+ const dirname = path.dirname(this.filename);
44
40
  let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
45
- (this.header ? (0, putil_flattentext_1.default)(this.header) + '\n\n' : '\n');
41
+ (this.header ? flattenText(this.header) + '\n\n' : '\n');
46
42
  const importStr = Object.keys(this.importFiles)
47
43
  .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
48
44
  .map(filename => {
49
45
  const types = this.importFiles[filename];
50
46
  let relFile = filename;
51
- if (path_1.default.isAbsolute(filename)) {
47
+ if (path.isAbsolute(filename)) {
52
48
  relFile = relativePath(dirname, filename);
53
49
  if (options?.importExt)
54
50
  relFile = setExt(relFile, options.importExt);
@@ -57,14 +53,14 @@ class TsFile {
57
53
  })
58
54
  .join('\n');
59
55
  if (importStr)
60
- output += (0, putil_flattentext_1.default)(importStr) + '\n';
61
- output += (0, putil_flattentext_1.default)(this.content);
56
+ output += flattenText(importStr) + '\n';
57
+ output += flattenText(this.content);
62
58
  const exportStr = Object.keys(this.exportFiles)
63
59
  .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
64
60
  .map(filename => {
65
61
  const types = this.exportFiles[filename];
66
62
  let relFile = filename;
67
- if (path_1.default.isAbsolute(filename)) {
63
+ if (path.isAbsolute(filename)) {
68
64
  relFile = relativePath(dirname, filename);
69
65
  if (options?.importExt)
70
66
  relFile = setExt(relFile, options.importExt);
@@ -73,18 +69,15 @@ class TsFile {
73
69
  })
74
70
  .join('\n');
75
71
  if (exportStr)
76
- output += (0, putil_flattentext_1.default)(exportStr) + '\n';
72
+ output += flattenText(exportStr) + '\n';
77
73
  return output;
78
74
  }
79
75
  }
80
- exports.TsFile = TsFile;
81
- function relativePath(from, to) {
82
- const s = path_1.default.relative(from, to);
76
+ export function relativePath(from, to) {
77
+ const s = path.relative(from, to);
83
78
  return s.startsWith('.') ? s : ('./' + s);
84
79
  }
85
- exports.relativePath = relativePath;
86
- function setExt(filename, ext) {
87
- const e = path_1.default.extname(filename);
80
+ export function setExt(filename, ext) {
81
+ const e = path.extname(filename);
88
82
  return filename.substring(0, filename.length - e.length) + (ext ? '.' + ext : '');
89
83
  }
90
- exports.setExt = setExt;
package/esm/index.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./api-exporter/index.js"), exports);
1
+ export * from './api-exporter/index.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/esm/oprimp-cli.js CHANGED
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
- const commander_1 = require("commander");
6
- const console = tslib_1.__importStar(require("console"));
7
- const fs = tslib_1.__importStar(require("fs"));
8
- const path_1 = tslib_1.__importDefault(require("path"));
9
- const process = tslib_1.__importStar(require("process"));
10
- const api_exporter_js_1 = require("./api-exporter/api-exporter.js");
11
- const get_caller_file_util_js_1 = require("./utils/get-caller-file.util.js");
12
- const dirname = path_1.default.dirname((0, get_caller_file_util_js_1.getCallerFile)());
13
- const pkgJson = JSON.parse(fs.readFileSync(path_1.default.resolve(dirname, '../package.json'), 'utf-8'));
14
- commander_1.program
1
+ import chalk from 'chalk';
2
+ import { program } from 'commander';
3
+ import * as console from 'console';
4
+ import * as fs from 'fs';
5
+ import path from 'path';
6
+ import * as process from 'process';
7
+ import { ApiExporter } from './api-exporter/api-exporter.js';
8
+ import { getCallerFile } from './utils/get-caller-file.util.js';
9
+ const dirname = path.dirname(getCallerFile());
10
+ const pkgJson = JSON.parse(fs.readFileSync(path.resolve(dirname, '../package.json'), 'utf-8'));
11
+ program
15
12
  .version(pkgJson.version)
16
13
  .argument('<serviceUrl>', 'OPRA service url')
17
14
  .argument('<outDir>', 'Output directory')
@@ -20,8 +17,8 @@ commander_1.program
20
17
  .option('--no-color', 'Disables colors in logs messages')
21
18
  .action(async (serviceUrl, outDir, options) => {
22
19
  if (!options.color)
23
- chalk_1.default.level = 0;
24
- await api_exporter_js_1.ApiExporter.execute({
20
+ chalk.level = 0;
21
+ await ApiExporter.execute({
25
22
  serviceUrl,
26
23
  logger: console,
27
24
  outDir,
@@ -30,6 +27,6 @@ commander_1.program
30
27
  fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
31
28
  '/* eslint-disable import/extensions,simple-import-sort/imports */\n'
32
29
  });
33
- console.log(chalk_1.default.greenBright('Completed'));
30
+ console.log(chalk.greenBright('Completed'));
34
31
  });
35
- commander_1.program.parse(process.argv);
32
+ program.parse(process.argv);
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCallerFile = void 0;
4
1
  const PATH_PATTERN = /^(?:file:\/\/)?(.+)$/;
5
- function getCallerFile(position = 1) {
2
+ export function getCallerFile(position = 1) {
6
3
  if (position >= Error.stackTraceLimit) {
7
4
  throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' +
8
5
  position + '` and Error.stackTraceLimit was: `' + Error.stackTraceLimit + '`');
@@ -21,4 +18,3 @@ function getCallerFile(position = 1) {
21
18
  }
22
19
  return '';
23
20
  }
24
- exports.getCallerFile = getCallerFile;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapTypeArray = exports.wrapStringArray = exports.wrapQuotedString = exports.wrapJSDocString = void 0;
4
- const tslib_1 = require("tslib");
5
- const js_string_escape_1 = tslib_1.__importDefault(require("js-string-escape"));
6
- function wrapJSDocString(s, indent, currentColumn) {
1
+ import jsStringEscape from 'js-string-escape';
2
+ export function wrapJSDocString(s, indent, currentColumn) {
7
3
  const arr = (s || '')
8
4
  .split(/[ \n\r]/)
9
5
  .map((x, i, a) => i < a.length - 1 ? x + ' ' : x);
@@ -14,9 +10,8 @@ function wrapJSDocString(s, indent, currentColumn) {
14
10
  lineEnd: ''
15
11
  });
16
12
  }
17
- exports.wrapJSDocString = wrapJSDocString;
18
- function wrapQuotedString(s, indent, currentColumn) {
19
- const arr = (0, js_string_escape_1.default)(s || '')
13
+ export function wrapQuotedString(s, indent, currentColumn) {
14
+ const arr = jsStringEscape(s || '')
20
15
  .split(' ')
21
16
  .map((x, i, a) => i < a.length - 1 ? x + ' ' : x);
22
17
  return '\'' + _printLines(arr, {
@@ -26,19 +21,16 @@ function wrapQuotedString(s, indent, currentColumn) {
26
21
  lineEnd: '\' +',
27
22
  }) + '\'';
28
23
  }
29
- exports.wrapQuotedString = wrapQuotedString;
30
- function wrapStringArray(arr, indent, currentColumn) {
24
+ export function wrapStringArray(arr, indent, currentColumn) {
31
25
  const ar1 = arr
32
26
  .map((x, i, a) => ('\'' + x + '\'') + (i < a.length - 1 ? ', ' : ''));
33
27
  return '[' + _printLines(ar1, { indent, currentColumn }) + ']';
34
28
  }
35
- exports.wrapStringArray = wrapStringArray;
36
- function wrapTypeArray(arr, indent, currentColumn) {
29
+ export function wrapTypeArray(arr, indent, currentColumn) {
37
30
  const ar1 = arr
38
31
  .map((x, i, a) => x + (i < a.length - 1 ? ' | ' : ''));
39
32
  return _printLines(ar1, { indent, currentColumn });
40
33
  }
41
- exports.wrapTypeArray = wrapTypeArray;
42
34
  function _printLines(arr, opts = {}) {
43
35
  let s = '';
44
36
  let line = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/cli",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
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/node-client": "^0.16.1",
31
+ "@opra/node-client": "^0.17.0",
32
32
  "chalk": "^5.2.0",
33
33
  "commander": "^10.0.1",
34
34
  "js-string-escape": "^1.0.1",