@opra/cli 0.17.0 → 0.17.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.
- package/cjs/api-exporter/api-exporter.js +3 -4
- package/cjs/api-exporter/process-resources.js +1 -1
- package/cjs/api-exporter/process-types.js +7 -18
- package/cjs/api-exporter/ts-file.js +14 -19
- package/cjs/oprimp-cli.js +4 -3
- package/esm/api-exporter/api-exporter.js +2 -3
- package/esm/api-exporter/process-resources.js +1 -1
- package/esm/api-exporter/process-types.js +7 -18
- package/esm/api-exporter/ts-file.js +13 -17
- package/esm/oprimp-cli.js +4 -3
- package/package.json +2 -2
- package/types/api-exporter/api-exporter.d.ts +1 -3
- package/types/api-exporter/ts-file.d.ts +1 -4
|
@@ -6,7 +6,7 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
|
6
6
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
7
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
8
|
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
9
|
-
const
|
|
9
|
+
const client_1 = require("@opra/client");
|
|
10
10
|
const file_writer_js_1 = require("./file-writer.js");
|
|
11
11
|
const process_resources_js_1 = require("./process-resources.js");
|
|
12
12
|
const process_types_js_1 = require("./process-types.js");
|
|
@@ -14,7 +14,7 @@ const ts_file_js_1 = require("./ts-file.js");
|
|
|
14
14
|
class ApiExporter {
|
|
15
15
|
constructor(config) {
|
|
16
16
|
this.files = {};
|
|
17
|
-
this.client = new
|
|
17
|
+
this.client = new client_1.OpraHttpClient(config.serviceUrl);
|
|
18
18
|
this.cwd = config.cwd || node_process_1.default.cwd();
|
|
19
19
|
this.outDir = node_path_1.default.resolve(this.cwd, config.outDir);
|
|
20
20
|
this.logger = config.logger || {
|
|
@@ -25,7 +25,6 @@ class ApiExporter {
|
|
|
25
25
|
verbose: () => void 0,
|
|
26
26
|
};
|
|
27
27
|
this.fileHeader = config.fileHeader || '';
|
|
28
|
-
this.importExt = config.importExt || '';
|
|
29
28
|
this.writer = config.writer || new file_writer_js_1.FileWriter();
|
|
30
29
|
// this.nsMap = nsMap || new ResponsiveMap(); // implement references later
|
|
31
30
|
}
|
|
@@ -50,7 +49,7 @@ class ApiExporter {
|
|
|
50
49
|
for (const file of Object.values(this.files)) {
|
|
51
50
|
const targetDir = node_path_1.default.dirname(file.filename);
|
|
52
51
|
node_fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
53
|
-
await this.writer.writeFile(file.filename, file.generate(
|
|
52
|
+
await this.writer.writeFile(file.filename, file.generate());
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
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.name + '.ts'));
|
|
17
17
|
serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
|
|
18
|
-
const indexTs = this.addFile('/index.ts', true);
|
|
18
|
+
const indexTs = this.addFile('/index.d.ts', true);
|
|
19
19
|
indexTs.addExportFile(serviceTs.filename);
|
|
20
20
|
serviceTs.content = `\nexport class ${this.name} 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.ts'));
|
|
17
|
+
const typesTs = this.addFile(node_path_1.default.join(targetDir, 'types.d.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.ts';
|
|
35
|
+
filePath = '/simple-types.d.ts';
|
|
36
36
|
else if (dataType instanceof common_1.ComplexType)
|
|
37
|
-
filePath = `/types/${typeName}.ts`;
|
|
37
|
+
filePath = `/types/${typeName}.type.d.ts`;
|
|
38
38
|
else if (dataType instanceof common_1.EnumType) {
|
|
39
|
-
filePath = `/enums/${typeName}.ts`;
|
|
39
|
+
filePath = `/enums/${typeName}.enum.d.ts`;
|
|
40
40
|
}
|
|
41
41
|
else
|
|
42
42
|
throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
|
|
@@ -44,10 +44,10 @@ 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.ts', true);
|
|
47
|
+
const indexTs = this.addFile('/index.d.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}
|
|
51
51
|
* @kind ${dataType.kind}
|
|
52
52
|
* @url ${(0, common_1.joinPath)(this.client.serviceUrl, '$metadata#types/' + typeName)}
|
|
53
53
|
*/\n`;
|
|
@@ -58,18 +58,7 @@ async function generateTypeFile(dataType, targetDir = '') {
|
|
|
58
58
|
file.content += `export enum ${typeName} ` + await this.generateEnumTypeDefinition(file, dataType);
|
|
59
59
|
}
|
|
60
60
|
else if (dataType instanceof common_1.ComplexType) {
|
|
61
|
-
file.content += `export
|
|
62
|
-
constructor(init?: Partial<I${typeName}>) {
|
|
63
|
-
if (init)
|
|
64
|
-
Object.assign(this, init);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface ${typeName} extends I${typeName} {
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface I${typeName} ${await this.generateComplexTypeDefinition(file, dataType, true)}
|
|
72
|
-
`;
|
|
61
|
+
file.content += `export interface ${typeName} ${await this.generateComplexTypeDefinition(file, dataType, true)}`;
|
|
73
62
|
}
|
|
74
63
|
return file;
|
|
75
64
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.relativePath = exports.TsFile = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
6
|
const putil_flattentext_1 = tslib_1.__importDefault(require("putil-flattentext"));
|
|
@@ -21,6 +21,10 @@ class TsFile {
|
|
|
21
21
|
};
|
|
22
22
|
this.addImportFile = (filename, types) => {
|
|
23
23
|
filename = path_1.default.resolve(this.dirname, filename);
|
|
24
|
+
if (filename.endsWith('.d.ts'))
|
|
25
|
+
filename = filename.substring(0, filename.length - 5);
|
|
26
|
+
if (filename.endsWith('.ts'))
|
|
27
|
+
filename = filename.substring(0, filename.length - 3);
|
|
24
28
|
this.importFiles[filename] = this.importFiles[filename] || [];
|
|
25
29
|
types?.forEach(x => {
|
|
26
30
|
if (!this.importFiles[filename].includes(x))
|
|
@@ -29,8 +33,10 @@ class TsFile {
|
|
|
29
33
|
};
|
|
30
34
|
this.addExportFile = (filename, types) => {
|
|
31
35
|
filename = path_1.default.resolve(this.dirname, filename);
|
|
32
|
-
if (filename.endsWith('.ts')
|
|
33
|
-
filename =
|
|
36
|
+
if (filename.endsWith('.d.ts'))
|
|
37
|
+
filename = filename.substring(0, filename.length - 5);
|
|
38
|
+
if (filename.endsWith('.ts'))
|
|
39
|
+
filename = filename.substring(0, filename.length - 3);
|
|
34
40
|
this.exportFiles[filename] = this.exportFiles[filename] || [];
|
|
35
41
|
types?.forEach(x => {
|
|
36
42
|
if (!this.exportFiles[filename].includes(x))
|
|
@@ -39,7 +45,7 @@ class TsFile {
|
|
|
39
45
|
};
|
|
40
46
|
this.dirname = path_1.default.dirname(filename);
|
|
41
47
|
}
|
|
42
|
-
generate(
|
|
48
|
+
generate() {
|
|
43
49
|
const dirname = path_1.default.dirname(this.filename);
|
|
44
50
|
let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
|
|
45
51
|
(this.header ? (0, putil_flattentext_1.default)(this.header) + '\n\n' : '\n');
|
|
@@ -48,12 +54,9 @@ class TsFile {
|
|
|
48
54
|
.map(filename => {
|
|
49
55
|
const types = this.importFiles[filename];
|
|
50
56
|
let relFile = filename;
|
|
51
|
-
if (path_1.default.isAbsolute(filename))
|
|
57
|
+
if (path_1.default.isAbsolute(filename))
|
|
52
58
|
relFile = relativePath(dirname, filename);
|
|
53
|
-
|
|
54
|
-
relFile = setExt(relFile, options.importExt);
|
|
55
|
-
}
|
|
56
|
-
return `import ${types.length ? '{' + types.join(', ') + '} from ' : ''}'${relFile}';`;
|
|
59
|
+
return `import ${types.length ? '{ ' + types.join(', ') + ' } from ' : ''}'${relFile}';`;
|
|
57
60
|
})
|
|
58
61
|
.join('\n');
|
|
59
62
|
if (importStr)
|
|
@@ -64,12 +67,9 @@ class TsFile {
|
|
|
64
67
|
.map(filename => {
|
|
65
68
|
const types = this.exportFiles[filename];
|
|
66
69
|
let relFile = filename;
|
|
67
|
-
if (path_1.default.isAbsolute(filename))
|
|
70
|
+
if (path_1.default.isAbsolute(filename))
|
|
68
71
|
relFile = relativePath(dirname, filename);
|
|
69
|
-
|
|
70
|
-
relFile = setExt(relFile, options.importExt);
|
|
71
|
-
}
|
|
72
|
-
return `export ${types.length ? '{' + types.join(', ') + '}' : '*'} from '${relFile}';`;
|
|
72
|
+
return `export ${types.length ? '{ ' + types.join(', ') + ' }' : '*'} from '${relFile}';`;
|
|
73
73
|
})
|
|
74
74
|
.join('\n');
|
|
75
75
|
if (exportStr)
|
|
@@ -83,8 +83,3 @@ function relativePath(from, to) {
|
|
|
83
83
|
return s.startsWith('.') ? s : ('./' + s);
|
|
84
84
|
}
|
|
85
85
|
exports.relativePath = relativePath;
|
|
86
|
-
function setExt(filename, ext) {
|
|
87
|
-
const e = path_1.default.extname(filename);
|
|
88
|
-
return filename.substring(0, filename.length - e.length) + (ext ? '.' + ext : '');
|
|
89
|
-
}
|
|
90
|
-
exports.setExt = setExt;
|
package/cjs/oprimp-cli.js
CHANGED
|
@@ -16,7 +16,6 @@ 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')
|
|
20
19
|
.option('--no-color', 'Disables colors in logs messages')
|
|
21
20
|
.action(async (serviceUrl, outDir, options) => {
|
|
22
21
|
if (!options.color)
|
|
@@ -26,10 +25,12 @@ commander_1.program
|
|
|
26
25
|
logger: console,
|
|
27
26
|
outDir,
|
|
28
27
|
name: options.name,
|
|
29
|
-
importExt: (options.ext ? 'js' : ''),
|
|
30
28
|
fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
|
|
31
29
|
'/* eslint-disable import/extensions,simple-import-sort/imports */\n'
|
|
32
30
|
});
|
|
33
31
|
console.log(chalk_1.default.greenBright('Completed'));
|
|
34
32
|
});
|
|
35
|
-
|
|
33
|
+
if (process.argv.length < 3)
|
|
34
|
+
commander_1.program.help();
|
|
35
|
+
else
|
|
36
|
+
commander_1.program.parse(process.argv);
|
|
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
|
-
import { OpraHttpClient } from '@opra/
|
|
5
|
+
import { OpraHttpClient } from '@opra/client';
|
|
6
6
|
import { FileWriter } from './file-writer.js';
|
|
7
7
|
import { processResources } from './process-resources.js';
|
|
8
8
|
import { generateComplexTypeDefinition, generateEnumTypeDefinition, generateMappedTypeDefinition, generateSimpleTypeDefinition, generateTypeFile, generateUnionTypeDefinition, processTypes, resolveTypeNameOrDef } from './process-types.js';
|
|
@@ -21,7 +21,6 @@ export class ApiExporter {
|
|
|
21
21
|
verbose: () => void 0,
|
|
22
22
|
};
|
|
23
23
|
this.fileHeader = config.fileHeader || '';
|
|
24
|
-
this.importExt = config.importExt || '';
|
|
25
24
|
this.writer = config.writer || new FileWriter();
|
|
26
25
|
// this.nsMap = nsMap || new ResponsiveMap(); // implement references later
|
|
27
26
|
}
|
|
@@ -46,7 +45,7 @@ export class ApiExporter {
|
|
|
46
45
|
for (const file of Object.values(this.files)) {
|
|
47
46
|
const targetDir = path.dirname(file.filename);
|
|
48
47
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
49
|
-
await this.writer.writeFile(file.filename, file.generate(
|
|
48
|
+
await this.writer.writeFile(file.filename, file.generate());
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
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.name + '.ts'));
|
|
13
13
|
serviceTs.addImportPackage('@opra/client', ['HttpServiceBase']);
|
|
14
|
-
const indexTs = this.addFile('/index.ts', true);
|
|
14
|
+
const indexTs = this.addFile('/index.d.ts', true);
|
|
15
15
|
indexTs.addExportFile(serviceTs.filename);
|
|
16
16
|
serviceTs.content = `\nexport class ${this.name} 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.ts'));
|
|
13
|
+
const typesTs = this.addFile(path.join(targetDir, 'types.d.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.ts';
|
|
30
|
+
filePath = '/simple-types.d.ts';
|
|
31
31
|
else if (dataType instanceof ComplexType)
|
|
32
|
-
filePath = `/types/${typeName}.ts`;
|
|
32
|
+
filePath = `/types/${typeName}.type.d.ts`;
|
|
33
33
|
else if (dataType instanceof EnumType) {
|
|
34
|
-
filePath = `/enums/${typeName}.ts`;
|
|
34
|
+
filePath = `/enums/${typeName}.enum.d.ts`;
|
|
35
35
|
}
|
|
36
36
|
else
|
|
37
37
|
throw new TypeError(`Unimplemented DataType (${dataType.kind})`);
|
|
@@ -39,10 +39,10 @@ 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.ts', true);
|
|
42
|
+
const indexTs = this.addFile('/index.d.ts', true);
|
|
43
43
|
indexTs.addExportFile(file.filename);
|
|
44
44
|
file.content += `\n/**\n * ${wrapJSDocString(dataType.description || typeName)}
|
|
45
|
-
* @
|
|
45
|
+
* @interface ${typeName}
|
|
46
46
|
* @kind ${dataType.kind}
|
|
47
47
|
* @url ${joinPath(this.client.serviceUrl, '$metadata#types/' + typeName)}
|
|
48
48
|
*/\n`;
|
|
@@ -53,18 +53,7 @@ export async function generateTypeFile(dataType, targetDir = '') {
|
|
|
53
53
|
file.content += `export enum ${typeName} ` + await this.generateEnumTypeDefinition(file, dataType);
|
|
54
54
|
}
|
|
55
55
|
else if (dataType instanceof ComplexType) {
|
|
56
|
-
file.content += `export
|
|
57
|
-
constructor(init?: Partial<I${typeName}>) {
|
|
58
|
-
if (init)
|
|
59
|
-
Object.assign(this, init);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface ${typeName} extends I${typeName} {
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface I${typeName} ${await this.generateComplexTypeDefinition(file, dataType, true)}
|
|
67
|
-
`;
|
|
56
|
+
file.content += `export interface ${typeName} ${await this.generateComplexTypeDefinition(file, dataType, true)}`;
|
|
68
57
|
}
|
|
69
58
|
return file;
|
|
70
59
|
}
|
|
@@ -17,6 +17,10 @@ export class TsFile {
|
|
|
17
17
|
};
|
|
18
18
|
this.addImportFile = (filename, types) => {
|
|
19
19
|
filename = path.resolve(this.dirname, filename);
|
|
20
|
+
if (filename.endsWith('.d.ts'))
|
|
21
|
+
filename = filename.substring(0, filename.length - 5);
|
|
22
|
+
if (filename.endsWith('.ts'))
|
|
23
|
+
filename = filename.substring(0, filename.length - 3);
|
|
20
24
|
this.importFiles[filename] = this.importFiles[filename] || [];
|
|
21
25
|
types?.forEach(x => {
|
|
22
26
|
if (!this.importFiles[filename].includes(x))
|
|
@@ -25,8 +29,10 @@ export class TsFile {
|
|
|
25
29
|
};
|
|
26
30
|
this.addExportFile = (filename, types) => {
|
|
27
31
|
filename = path.resolve(this.dirname, filename);
|
|
28
|
-
if (filename.endsWith('.ts')
|
|
29
|
-
filename =
|
|
32
|
+
if (filename.endsWith('.d.ts'))
|
|
33
|
+
filename = filename.substring(0, filename.length - 5);
|
|
34
|
+
if (filename.endsWith('.ts'))
|
|
35
|
+
filename = filename.substring(0, filename.length - 3);
|
|
30
36
|
this.exportFiles[filename] = this.exportFiles[filename] || [];
|
|
31
37
|
types?.forEach(x => {
|
|
32
38
|
if (!this.exportFiles[filename].includes(x))
|
|
@@ -35,7 +41,7 @@ export class TsFile {
|
|
|
35
41
|
};
|
|
36
42
|
this.dirname = path.dirname(filename);
|
|
37
43
|
}
|
|
38
|
-
generate(
|
|
44
|
+
generate() {
|
|
39
45
|
const dirname = path.dirname(this.filename);
|
|
40
46
|
let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
|
|
41
47
|
(this.header ? flattenText(this.header) + '\n\n' : '\n');
|
|
@@ -44,12 +50,9 @@ export class TsFile {
|
|
|
44
50
|
.map(filename => {
|
|
45
51
|
const types = this.importFiles[filename];
|
|
46
52
|
let relFile = filename;
|
|
47
|
-
if (path.isAbsolute(filename))
|
|
53
|
+
if (path.isAbsolute(filename))
|
|
48
54
|
relFile = relativePath(dirname, filename);
|
|
49
|
-
|
|
50
|
-
relFile = setExt(relFile, options.importExt);
|
|
51
|
-
}
|
|
52
|
-
return `import ${types.length ? '{' + types.join(', ') + '} from ' : ''}'${relFile}';`;
|
|
55
|
+
return `import ${types.length ? '{ ' + types.join(', ') + ' } from ' : ''}'${relFile}';`;
|
|
53
56
|
})
|
|
54
57
|
.join('\n');
|
|
55
58
|
if (importStr)
|
|
@@ -60,12 +63,9 @@ export class TsFile {
|
|
|
60
63
|
.map(filename => {
|
|
61
64
|
const types = this.exportFiles[filename];
|
|
62
65
|
let relFile = filename;
|
|
63
|
-
if (path.isAbsolute(filename))
|
|
66
|
+
if (path.isAbsolute(filename))
|
|
64
67
|
relFile = relativePath(dirname, filename);
|
|
65
|
-
|
|
66
|
-
relFile = setExt(relFile, options.importExt);
|
|
67
|
-
}
|
|
68
|
-
return `export ${types.length ? '{' + types.join(', ') + '}' : '*'} from '${relFile}';`;
|
|
68
|
+
return `export ${types.length ? '{ ' + types.join(', ') + ' }' : '*'} from '${relFile}';`;
|
|
69
69
|
})
|
|
70
70
|
.join('\n');
|
|
71
71
|
if (exportStr)
|
|
@@ -77,7 +77,3 @@ export function relativePath(from, to) {
|
|
|
77
77
|
const s = path.relative(from, to);
|
|
78
78
|
return s.startsWith('.') ? s : ('./' + s);
|
|
79
79
|
}
|
|
80
|
-
export function setExt(filename, ext) {
|
|
81
|
-
const e = path.extname(filename);
|
|
82
|
-
return filename.substring(0, filename.length - e.length) + (ext ? '.' + ext : '');
|
|
83
|
-
}
|
package/esm/oprimp-cli.js
CHANGED
|
@@ -13,7 +13,6 @@ 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')
|
|
17
16
|
.option('--no-color', 'Disables colors in logs messages')
|
|
18
17
|
.action(async (serviceUrl, outDir, options) => {
|
|
19
18
|
if (!options.color)
|
|
@@ -23,10 +22,12 @@ program
|
|
|
23
22
|
logger: console,
|
|
24
23
|
outDir,
|
|
25
24
|
name: options.name,
|
|
26
|
-
importExt: (options.ext ? 'js' : ''),
|
|
27
25
|
fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
|
|
28
26
|
'/* eslint-disable import/extensions,simple-import-sort/imports */\n'
|
|
29
27
|
});
|
|
30
28
|
console.log(chalk.greenBright('Completed'));
|
|
31
29
|
});
|
|
32
|
-
|
|
30
|
+
if (process.argv.length < 3)
|
|
31
|
+
program.help();
|
|
32
|
+
else
|
|
33
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.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/
|
|
31
|
+
"@opra/client": "^0.17.2",
|
|
32
32
|
"chalk": "^5.2.0",
|
|
33
33
|
"commander": "^10.0.1",
|
|
34
34
|
"js-string-escape": "^1.0.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { OpraHttpClient } from '@opra/client';
|
|
1
2
|
import { ApiDocument } from '@opra/common';
|
|
2
|
-
import { OpraHttpClient } from '@opra/node-client';
|
|
3
3
|
import { IFileWriter } from '../interfaces/file-writer.interface.js';
|
|
4
4
|
import { ILogger } from '../interfaces/logger.interface.js';
|
|
5
5
|
import { processResources } from './process-resources.js';
|
|
@@ -14,7 +14,6 @@ export declare namespace ApiExporter {
|
|
|
14
14
|
logger?: ILogger;
|
|
15
15
|
writer?: IFileWriter;
|
|
16
16
|
fileHeader?: string;
|
|
17
|
-
importExt?: string;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
export declare class ApiExporter {
|
|
@@ -26,7 +25,6 @@ export declare class ApiExporter {
|
|
|
26
25
|
protected name: string;
|
|
27
26
|
protected fileHeader: string;
|
|
28
27
|
protected writer: IFileWriter;
|
|
29
|
-
protected importExt: string;
|
|
30
28
|
protected files: Record<string, TsFile>;
|
|
31
29
|
protected processResources: typeof processResources;
|
|
32
30
|
protected processTypes: typeof processTypes;
|
|
@@ -10,9 +10,6 @@ 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(
|
|
14
|
-
importExt?: string;
|
|
15
|
-
}): string;
|
|
13
|
+
generate(): string;
|
|
16
14
|
}
|
|
17
15
|
export declare function relativePath(from: string, to: string): string;
|
|
18
|
-
export declare function setExt(filename: string, ext: string): string;
|