@opra/cli 1.0.0-alpha.7 → 1.0.0-alpha.9
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/oprimp-cli.js +1 -1
- package/cjs/ts-generator/processors/clean-directory.js +1 -1
- package/cjs/ts-generator/processors/process-data-types.js +21 -11
- package/cjs/ts-generator/processors/process-document.js +2 -2
- package/cjs/ts-generator/ts-generator.js +1 -1
- package/cjs/ts-generator/utils/locate-named-type.js +2 -1
- package/esm/oprimp-cli.js +1 -1
- package/esm/ts-generator/processors/clean-directory.js +1 -1
- package/esm/ts-generator/processors/process-data-types.js +21 -11
- package/esm/ts-generator/processors/process-document.js +2 -2
- package/esm/ts-generator/ts-generator.js +1 -1
- package/esm/ts-generator/utils/locate-named-type.js +2 -1
- package/package.json +5 -4
package/cjs/oprimp-cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const common_1 = require("@opra/common");
|
|
4
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
6
|
const commander_1 = require("commander");
|
|
6
7
|
const console = tslib_1.__importStar(require("console"));
|
|
7
8
|
const fs = tslib_1.__importStar(require("fs"));
|
|
8
9
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
10
|
const process = tslib_1.__importStar(require("process"));
|
|
10
|
-
const common_1 = require("@opra/common");
|
|
11
11
|
const ts_generator_js_1 = require("./ts-generator/ts-generator.js");
|
|
12
12
|
const dirname = path_1.default.dirname((0, common_1.getStackFileName)());
|
|
13
13
|
const pkgJson = JSON.parse(fs.readFileSync(path_1.default.resolve(dirname, '../package.json'), 'utf-8'));
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cleanDirectory = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
8
|
function cleanDirectory(dirname) {
|
|
9
9
|
const rootDir = dirname;
|
|
10
10
|
const _cleanDirectory = (targetDir) => {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveTypeNameOrDef = exports.generateMappedTypeDefinition = exports.generateMixinTypeDefinition = exports.generateSimpleTypeDefinition = exports.generateComplexTypeDefinition = exports.generateEnumTypeDefinition = exports.processDataType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
5
|
const common_1 = require("@opra/common");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const code_block_js_1 = require("../../code-block.js");
|
|
8
8
|
const string_utils_js_1 = require("../utils/string-utils.js");
|
|
9
9
|
const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string', 'object'];
|
|
@@ -47,14 +47,18 @@ async function processDataType(dataType) {
|
|
|
47
47
|
export `;
|
|
48
48
|
if (dataType instanceof common_1.EnumType)
|
|
49
49
|
codeBlock.typeDef = await this.generateEnumTypeDefinition(dataType, 'scope');
|
|
50
|
-
else if (dataType instanceof common_1.ComplexType)
|
|
50
|
+
else if (dataType instanceof common_1.ComplexType) {
|
|
51
51
|
codeBlock.typeDef = await this.generateComplexTypeDefinition(dataType, file, 'scope');
|
|
52
|
-
|
|
52
|
+
}
|
|
53
|
+
else if (dataType instanceof common_1.SimpleType) {
|
|
53
54
|
codeBlock.typeDef = await this.generateSimpleTypeDefinition(dataType, 'scope');
|
|
54
|
-
|
|
55
|
+
}
|
|
56
|
+
else if (dataType instanceof common_1.MappedType) {
|
|
55
57
|
codeBlock.typeDef = await this.generateMappedTypeDefinition(dataType, file, 'scope');
|
|
56
|
-
|
|
58
|
+
}
|
|
59
|
+
else if (dataType instanceof common_1.MixinType) {
|
|
57
60
|
codeBlock.typeDef = await this.generateMixinTypeDefinition(dataType, file, 'scope');
|
|
61
|
+
}
|
|
58
62
|
else
|
|
59
63
|
throw new TypeError(`${dataType.kind} data type (${typeName}) can not be directly exported`);
|
|
60
64
|
typesIndexTs.addExport(file.filename);
|
|
@@ -65,12 +69,13 @@ exports.processDataType = processDataType;
|
|
|
65
69
|
*
|
|
66
70
|
*/
|
|
67
71
|
async function generateEnumTypeDefinition(dataType, intent) {
|
|
68
|
-
if (intent === 'field')
|
|
72
|
+
if (intent === 'field') {
|
|
69
73
|
return ('(' +
|
|
70
74
|
Object.keys(dataType.attributes)
|
|
71
75
|
.map(t => `'${t}'`)
|
|
72
76
|
.join(' | ') +
|
|
73
77
|
')');
|
|
78
|
+
}
|
|
74
79
|
if (intent !== 'scope')
|
|
75
80
|
throw new TypeError(`Can't generate EnumType for "${intent}" intent`);
|
|
76
81
|
if (!dataType.name)
|
|
@@ -94,8 +99,9 @@ exports.generateEnumTypeDefinition = generateEnumTypeDefinition;
|
|
|
94
99
|
*
|
|
95
100
|
*/
|
|
96
101
|
async function generateComplexTypeDefinition(dataType, file, intent) {
|
|
97
|
-
if (intent === 'scope' && !dataType.name)
|
|
102
|
+
if (intent === 'scope' && !dataType.name) {
|
|
98
103
|
throw new TypeError(`Name required to generate ComplexType for "${intent}" intent`);
|
|
104
|
+
}
|
|
99
105
|
let out = intent === 'scope' ? `interface ${dataType.name} ` : '';
|
|
100
106
|
const ownFields = [...dataType.fields.values()].filter(f => f.origin === dataType);
|
|
101
107
|
if (dataType.base) {
|
|
@@ -130,8 +136,9 @@ async function generateComplexTypeDefinition(dataType, file, intent) {
|
|
|
130
136
|
out += ` * @readonly\n`;
|
|
131
137
|
if (field.writeonly)
|
|
132
138
|
out += ` * @writeonly\n`;
|
|
133
|
-
if (field.deprecated)
|
|
139
|
+
if (field.deprecated) {
|
|
134
140
|
out += ` * @deprecated ` + (typeof field.deprecated === 'string' ? field.deprecated : '') + '\n';
|
|
141
|
+
}
|
|
135
142
|
out += ' */\n';
|
|
136
143
|
// Print field name
|
|
137
144
|
if (field.readonly)
|
|
@@ -154,8 +161,9 @@ exports.generateComplexTypeDefinition = generateComplexTypeDefinition;
|
|
|
154
161
|
*
|
|
155
162
|
*/
|
|
156
163
|
async function generateSimpleTypeDefinition(dataType, intent) {
|
|
157
|
-
if (intent === 'scope' && !dataType.name)
|
|
164
|
+
if (intent === 'scope' && !dataType.name) {
|
|
158
165
|
throw new TypeError(`Name required to generate SimpleType for "${intent}" intent`);
|
|
166
|
+
}
|
|
159
167
|
let out = intent === 'scope' ? `type ${dataType.name} = ` : '';
|
|
160
168
|
out += dataType.nameMappings.js || 'any';
|
|
161
169
|
return intent === 'scope' ? out + ';' : out;
|
|
@@ -203,7 +211,7 @@ async function generateMappedTypeDefinition(dataType, file, intent) {
|
|
|
203
211
|
else if (omit)
|
|
204
212
|
out += 'Omit<';
|
|
205
213
|
out += typeDef;
|
|
206
|
-
if (omit || pick)
|
|
214
|
+
if (omit || pick) {
|
|
207
215
|
out +=
|
|
208
216
|
', ' +
|
|
209
217
|
(omit || pick)
|
|
@@ -211,14 +219,16 @@ async function generateMappedTypeDefinition(dataType, file, intent) {
|
|
|
211
219
|
.map(x => `'${x}'`)
|
|
212
220
|
.join(' | ') +
|
|
213
221
|
'>';
|
|
222
|
+
}
|
|
214
223
|
if (partial) {
|
|
215
|
-
if (Array.isArray(partial))
|
|
224
|
+
if (Array.isArray(partial)) {
|
|
216
225
|
out +=
|
|
217
226
|
', ' +
|
|
218
227
|
partial
|
|
219
228
|
.filter(x => !!x)
|
|
220
229
|
.map(x => `'${x}'`)
|
|
221
230
|
.join(' | ');
|
|
231
|
+
}
|
|
222
232
|
out += '>';
|
|
223
233
|
}
|
|
224
234
|
return out;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processDocument = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const client_1 = require("@opra/client");
|
|
6
|
+
const common_1 = require("@opra/common");
|
|
5
7
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
9
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
-
const client_1 = require("@opra/client");
|
|
9
|
-
const common_1 = require("@opra/common");
|
|
10
10
|
async function processDocument(document, options) {
|
|
11
11
|
if (!document || typeof document === 'string') {
|
|
12
12
|
if (document) {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TsGenerator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
5
|
const node_events_1 = require("node:events");
|
|
7
6
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
8
7
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
9
8
|
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
9
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
10
|
const file_writer_js_1 = require("../file-writer.js");
|
|
11
11
|
const clean_directory_js_1 = require("./processors/clean-directory.js");
|
|
12
12
|
const process_data_types_js_1 = require("./processors/process-data-types.js");
|
|
@@ -10,7 +10,8 @@ function locateNamedType(type) {
|
|
|
10
10
|
if (type instanceof common_1.SimpleType ||
|
|
11
11
|
type instanceof common_1.ComplexType ||
|
|
12
12
|
type instanceof common_1.EnumType ||
|
|
13
|
-
type instanceof common_1.MappedType)
|
|
13
|
+
type instanceof common_1.MappedType) {
|
|
14
14
|
return locateNamedType(type.base);
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
17
|
exports.locateNamedType = locateNamedType;
|
package/esm/oprimp-cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { getStackFileName } from '@opra/common';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
3
|
import { program } from 'commander';
|
|
3
4
|
import * as console from 'console';
|
|
4
5
|
import * as fs from 'fs';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import * as process from 'process';
|
|
7
|
-
import { getStackFileName } from '@opra/common';
|
|
8
8
|
import { TsGenerator } from './ts-generator/ts-generator.js';
|
|
9
9
|
const dirname = path.dirname(getStackFileName());
|
|
10
10
|
const pkgJson = JSON.parse(fs.readFileSync(path.resolve(dirname, '../package.json'), 'utf-8'));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { ComplexType, EnumType, MappedType, MixinType, SimpleType } from '@opra/common';
|
|
2
|
+
import path from 'path';
|
|
3
3
|
import { CodeBlock } from '../../code-block.js';
|
|
4
4
|
import { wrapJSDocString } from '../utils/string-utils.js';
|
|
5
5
|
const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string', 'object'];
|
|
@@ -43,14 +43,18 @@ export async function processDataType(dataType) {
|
|
|
43
43
|
export `;
|
|
44
44
|
if (dataType instanceof EnumType)
|
|
45
45
|
codeBlock.typeDef = await this.generateEnumTypeDefinition(dataType, 'scope');
|
|
46
|
-
else if (dataType instanceof ComplexType)
|
|
46
|
+
else if (dataType instanceof ComplexType) {
|
|
47
47
|
codeBlock.typeDef = await this.generateComplexTypeDefinition(dataType, file, 'scope');
|
|
48
|
-
|
|
48
|
+
}
|
|
49
|
+
else if (dataType instanceof SimpleType) {
|
|
49
50
|
codeBlock.typeDef = await this.generateSimpleTypeDefinition(dataType, 'scope');
|
|
50
|
-
|
|
51
|
+
}
|
|
52
|
+
else if (dataType instanceof MappedType) {
|
|
51
53
|
codeBlock.typeDef = await this.generateMappedTypeDefinition(dataType, file, 'scope');
|
|
52
|
-
|
|
54
|
+
}
|
|
55
|
+
else if (dataType instanceof MixinType) {
|
|
53
56
|
codeBlock.typeDef = await this.generateMixinTypeDefinition(dataType, file, 'scope');
|
|
57
|
+
}
|
|
54
58
|
else
|
|
55
59
|
throw new TypeError(`${dataType.kind} data type (${typeName}) can not be directly exported`);
|
|
56
60
|
typesIndexTs.addExport(file.filename);
|
|
@@ -60,12 +64,13 @@ export `;
|
|
|
60
64
|
*
|
|
61
65
|
*/
|
|
62
66
|
export async function generateEnumTypeDefinition(dataType, intent) {
|
|
63
|
-
if (intent === 'field')
|
|
67
|
+
if (intent === 'field') {
|
|
64
68
|
return ('(' +
|
|
65
69
|
Object.keys(dataType.attributes)
|
|
66
70
|
.map(t => `'${t}'`)
|
|
67
71
|
.join(' | ') +
|
|
68
72
|
')');
|
|
73
|
+
}
|
|
69
74
|
if (intent !== 'scope')
|
|
70
75
|
throw new TypeError(`Can't generate EnumType for "${intent}" intent`);
|
|
71
76
|
if (!dataType.name)
|
|
@@ -88,8 +93,9 @@ export async function generateEnumTypeDefinition(dataType, intent) {
|
|
|
88
93
|
*
|
|
89
94
|
*/
|
|
90
95
|
export async function generateComplexTypeDefinition(dataType, file, intent) {
|
|
91
|
-
if (intent === 'scope' && !dataType.name)
|
|
96
|
+
if (intent === 'scope' && !dataType.name) {
|
|
92
97
|
throw new TypeError(`Name required to generate ComplexType for "${intent}" intent`);
|
|
98
|
+
}
|
|
93
99
|
let out = intent === 'scope' ? `interface ${dataType.name} ` : '';
|
|
94
100
|
const ownFields = [...dataType.fields.values()].filter(f => f.origin === dataType);
|
|
95
101
|
if (dataType.base) {
|
|
@@ -124,8 +130,9 @@ export async function generateComplexTypeDefinition(dataType, file, intent) {
|
|
|
124
130
|
out += ` * @readonly\n`;
|
|
125
131
|
if (field.writeonly)
|
|
126
132
|
out += ` * @writeonly\n`;
|
|
127
|
-
if (field.deprecated)
|
|
133
|
+
if (field.deprecated) {
|
|
128
134
|
out += ` * @deprecated ` + (typeof field.deprecated === 'string' ? field.deprecated : '') + '\n';
|
|
135
|
+
}
|
|
129
136
|
out += ' */\n';
|
|
130
137
|
// Print field name
|
|
131
138
|
if (field.readonly)
|
|
@@ -147,8 +154,9 @@ export async function generateComplexTypeDefinition(dataType, file, intent) {
|
|
|
147
154
|
*
|
|
148
155
|
*/
|
|
149
156
|
export async function generateSimpleTypeDefinition(dataType, intent) {
|
|
150
|
-
if (intent === 'scope' && !dataType.name)
|
|
157
|
+
if (intent === 'scope' && !dataType.name) {
|
|
151
158
|
throw new TypeError(`Name required to generate SimpleType for "${intent}" intent`);
|
|
159
|
+
}
|
|
152
160
|
let out = intent === 'scope' ? `type ${dataType.name} = ` : '';
|
|
153
161
|
out += dataType.nameMappings.js || 'any';
|
|
154
162
|
return intent === 'scope' ? out + ';' : out;
|
|
@@ -194,7 +202,7 @@ export async function generateMappedTypeDefinition(dataType, file, intent) {
|
|
|
194
202
|
else if (omit)
|
|
195
203
|
out += 'Omit<';
|
|
196
204
|
out += typeDef;
|
|
197
|
-
if (omit || pick)
|
|
205
|
+
if (omit || pick) {
|
|
198
206
|
out +=
|
|
199
207
|
', ' +
|
|
200
208
|
(omit || pick)
|
|
@@ -202,14 +210,16 @@ export async function generateMappedTypeDefinition(dataType, file, intent) {
|
|
|
202
210
|
.map(x => `'${x}'`)
|
|
203
211
|
.join(' | ') +
|
|
204
212
|
'>';
|
|
213
|
+
}
|
|
205
214
|
if (partial) {
|
|
206
|
-
if (Array.isArray(partial))
|
|
215
|
+
if (Array.isArray(partial)) {
|
|
207
216
|
out +=
|
|
208
217
|
', ' +
|
|
209
218
|
partial
|
|
210
219
|
.filter(x => !!x)
|
|
211
220
|
.map(x => `'${x}'`)
|
|
212
221
|
.join(' | ');
|
|
222
|
+
}
|
|
213
223
|
out += '>';
|
|
214
224
|
}
|
|
215
225
|
return out;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { OpraHttpClient } from '@opra/client';
|
|
2
|
+
import { HttpApi } from '@opra/common';
|
|
1
3
|
import chalk from 'chalk';
|
|
2
4
|
import path from 'path';
|
|
3
5
|
import { pascalCase } from 'putil-varhelpers';
|
|
4
|
-
import { OpraHttpClient } from '@opra/client';
|
|
5
|
-
import { HttpApi } from '@opra/common';
|
|
6
6
|
export async function processDocument(document, options) {
|
|
7
7
|
if (!document || typeof document === 'string') {
|
|
8
8
|
if (document) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { EventEmitter } from 'node:events';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
import process from 'node:process';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
6
|
import { FileWriter } from '../file-writer.js';
|
|
7
7
|
import { cleanDirectory } from './processors/clean-directory.js';
|
|
8
8
|
import { generateComplexTypeDefinition, generateEnumTypeDefinition, generateMappedTypeDefinition, generateMixinTypeDefinition, generateSimpleTypeDefinition, processDataType, resolveTypeNameOrDef, } from './processors/process-data-types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"copy:files": "cp README.md package.json ../../LICENSE ../../build/cli && cp ../../package.cjs.json ../../build/cli/cjs/package.json",
|
|
20
20
|
"copy:bin": "cp -R bin ../../build/cli/bin",
|
|
21
21
|
"lint": "eslint . --max-warnings=0",
|
|
22
|
-
"
|
|
22
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
23
23
|
"format": "prettier . --write --log-level=warn",
|
|
24
|
+
"check": "madge --circular src/**",
|
|
24
25
|
"test": "jest --passWithNoTests",
|
|
25
26
|
"cover": "jest --passWithNoTests --collect-coverage",
|
|
26
27
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
@@ -30,8 +31,8 @@
|
|
|
30
31
|
"clean:cover": "rimraf ../../coverage/client"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@opra/client": "^1.0.0-alpha.
|
|
34
|
-
"@opra/common": "^1.0.0-alpha.
|
|
34
|
+
"@opra/client": "^1.0.0-alpha.9",
|
|
35
|
+
"@opra/common": "^1.0.0-alpha.9",
|
|
35
36
|
"chalk": "^5.3.0",
|
|
36
37
|
"commander": "^12.0.0",
|
|
37
38
|
"js-string-escape": "^1.0.1",
|