@opra/cli 1.0.0-alpha.32 → 1.0.0-alpha.34
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 +3 -3
- package/cjs/ts-generator/generators/clean-directory.js +3 -3
- package/cjs/ts-generator/generators/generate-document.js +7 -5
- package/cjs/ts-generator/ts-generator.js +2 -2
- package/esm/oprimp-cli.js +3 -3
- package/esm/package.json +3 -0
- package/esm/ts-generator/generators/clean-directory.js +3 -3
- package/esm/ts-generator/generators/generate-document.js +7 -5
- package/esm/ts-generator/ts-generator.js +2 -2
- package/package.json +26 -33
- package/bin/bin/oprimp.mjs +0 -3
package/cjs/oprimp-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const common_1 = require("@opra/common");
|
|
5
|
-
const
|
|
5
|
+
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const console = tslib_1.__importStar(require("console"));
|
|
8
8
|
const fs = tslib_1.__importStar(require("fs"));
|
|
@@ -20,7 +20,7 @@ commander_1.program
|
|
|
20
20
|
.option('--no-color', 'Disables colors in logs messages')
|
|
21
21
|
.action(async (serviceUrl, outDir, options) => {
|
|
22
22
|
if (!options.color)
|
|
23
|
-
|
|
23
|
+
ansi_colors_1.default.enabled = false;
|
|
24
24
|
const generator = new ts_generator_js_1.TsGenerator({
|
|
25
25
|
serviceUrl,
|
|
26
26
|
logger: console,
|
|
@@ -31,7 +31,7 @@ commander_1.program
|
|
|
31
31
|
});
|
|
32
32
|
await generator
|
|
33
33
|
.generate()
|
|
34
|
-
.then(() => console.log(
|
|
34
|
+
.then(() => console.log(ansi_colors_1.default.greenBright('Completed')))
|
|
35
35
|
.catch(e => console.error(e.message));
|
|
36
36
|
});
|
|
37
37
|
if (process.argv.length < 3)
|
|
@@ -4,7 +4,7 @@ exports.cleanDirectory = cleanDirectory;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
-
const
|
|
7
|
+
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
8
8
|
function cleanDirectory(dirname) {
|
|
9
9
|
const rootDir = dirname;
|
|
10
10
|
const _cleanDirectory = (targetDir) => {
|
|
@@ -16,7 +16,7 @@ function cleanDirectory(dirname) {
|
|
|
16
16
|
if (node_fs_1.default.statSync(absolutePath).isDirectory()) {
|
|
17
17
|
_cleanDirectory(absolutePath);
|
|
18
18
|
if (!node_fs_1.default.readdirSync(absolutePath).length) {
|
|
19
|
-
this.emit('verbose',
|
|
19
|
+
this.emit('verbose', ansi_colors_1.default.cyan(`Removing directory ${node_path_1.default.relative(absolutePath, rootDir)}`));
|
|
20
20
|
node_fs_1.default.rmdirSync(absolutePath);
|
|
21
21
|
}
|
|
22
22
|
continue;
|
|
@@ -24,7 +24,7 @@ function cleanDirectory(dirname) {
|
|
|
24
24
|
if (node_path_1.default.extname(f) === '.ts') {
|
|
25
25
|
const contents = node_fs_1.default.readFileSync(absolutePath, 'utf-8');
|
|
26
26
|
if (contents.includes('#!oprimp_auto_generated!#')) {
|
|
27
|
-
this.emit('verbose',
|
|
27
|
+
this.emit('verbose', ansi_colors_1.default.cyan(`Removing file ${node_path_1.default.relative(absolutePath, rootDir)}`));
|
|
28
28
|
node_fs_1.default.unlinkSync(absolutePath);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -4,7 +4,7 @@ exports.generateDocument = generateDocument;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const client_1 = require("@opra/client");
|
|
6
6
|
const common_1 = require("@opra/common");
|
|
7
|
-
const
|
|
7
|
+
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
8
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
9
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
10
10
|
async function generateDocument(document, options) {
|
|
@@ -14,7 +14,7 @@ async function generateDocument(document, options) {
|
|
|
14
14
|
if (out)
|
|
15
15
|
return out;
|
|
16
16
|
}
|
|
17
|
-
this.emit('log',
|
|
17
|
+
this.emit('log', ansi_colors_1.default.cyan('Fetching document schema from ') + ansi_colors_1.default.blueBright(this.serviceUrl));
|
|
18
18
|
const client = new client_1.OpraHttpClient(this.serviceUrl);
|
|
19
19
|
document = await client.fetchDocument({ documentId: document });
|
|
20
20
|
}
|
|
@@ -27,10 +27,12 @@ async function generateDocument(document, options) {
|
|
|
27
27
|
generator: this,
|
|
28
28
|
};
|
|
29
29
|
this._documentsMap.set(document.id, out);
|
|
30
|
-
this.emit('log',
|
|
30
|
+
this.emit('log', ansi_colors_1.default.white('[' + document.id + '] ') +
|
|
31
|
+
ansi_colors_1.default.cyan('Processing document ') +
|
|
32
|
+
ansi_colors_1.default.magenta(document.info.title || ''));
|
|
31
33
|
if (document.references.size) {
|
|
32
34
|
let refIdGenerator = options?.refIdGenerator || 1;
|
|
33
|
-
this.emit('log',
|
|
35
|
+
this.emit('log', ansi_colors_1.default.white('[' + document.id + '] ') + ansi_colors_1.default.cyan(`Processing references`));
|
|
34
36
|
for (const ref of document.references.values()) {
|
|
35
37
|
const generator = this.extend();
|
|
36
38
|
generator._document = ref;
|
|
@@ -48,7 +50,7 @@ async function generateDocument(document, options) {
|
|
|
48
50
|
* ${this.serviceUrl}
|
|
49
51
|
*/`;
|
|
50
52
|
if (document.types.size) {
|
|
51
|
-
this.emit('log',
|
|
53
|
+
this.emit('log', ansi_colors_1.default.white('[' + document.id + ']'), ansi_colors_1.default.cyan(`Processing data types`));
|
|
52
54
|
for (const t of document.types.values()) {
|
|
53
55
|
await this.generateDataType(t, 'root');
|
|
54
56
|
}
|
|
@@ -6,7 +6,7 @@ const node_events_1 = require("node:events");
|
|
|
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 ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
10
10
|
const file_writer_js_1 = require("../file-writer.js");
|
|
11
11
|
const clean_directory_js_1 = require("./generators/clean-directory.js");
|
|
12
12
|
const generate_data_type_js_1 = require("./generators/generate-data-type.js");
|
|
@@ -46,7 +46,7 @@ class TsGenerator extends node_events_1.EventEmitter {
|
|
|
46
46
|
this.emit('start');
|
|
47
47
|
try {
|
|
48
48
|
this._started = true;
|
|
49
|
-
this.emit('log',
|
|
49
|
+
this.emit('log', ansi_colors_1.default.cyan('Removing old files..'));
|
|
50
50
|
this.cleanDirectory(this.outDir);
|
|
51
51
|
this._apiPath = '/api';
|
|
52
52
|
await this.generateDocument();
|
package/esm/oprimp-cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getStackFileName } from '@opra/common';
|
|
2
|
-
import
|
|
2
|
+
import colors from 'ansi-colors';
|
|
3
3
|
import { program } from 'commander';
|
|
4
4
|
import * as console from 'console';
|
|
5
5
|
import * as fs from 'fs';
|
|
@@ -17,7 +17,7 @@ program
|
|
|
17
17
|
.option('--no-color', 'Disables colors in logs messages')
|
|
18
18
|
.action(async (serviceUrl, outDir, options) => {
|
|
19
19
|
if (!options.color)
|
|
20
|
-
|
|
20
|
+
colors.enabled = false;
|
|
21
21
|
const generator = new TsGenerator({
|
|
22
22
|
serviceUrl,
|
|
23
23
|
logger: console,
|
|
@@ -28,7 +28,7 @@ program
|
|
|
28
28
|
});
|
|
29
29
|
await generator
|
|
30
30
|
.generate()
|
|
31
|
-
.then(() => console.log(
|
|
31
|
+
.then(() => console.log(colors.greenBright('Completed')))
|
|
32
32
|
.catch(e => console.error(e.message));
|
|
33
33
|
});
|
|
34
34
|
if (process.argv.length < 3)
|
package/esm/package.json
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
3
|
+
import colors from 'ansi-colors';
|
|
4
4
|
export function cleanDirectory(dirname) {
|
|
5
5
|
const rootDir = dirname;
|
|
6
6
|
const _cleanDirectory = (targetDir) => {
|
|
@@ -12,7 +12,7 @@ export function cleanDirectory(dirname) {
|
|
|
12
12
|
if (fs.statSync(absolutePath).isDirectory()) {
|
|
13
13
|
_cleanDirectory(absolutePath);
|
|
14
14
|
if (!fs.readdirSync(absolutePath).length) {
|
|
15
|
-
this.emit('verbose',
|
|
15
|
+
this.emit('verbose', colors.cyan(`Removing directory ${path.relative(absolutePath, rootDir)}`));
|
|
16
16
|
fs.rmdirSync(absolutePath);
|
|
17
17
|
}
|
|
18
18
|
continue;
|
|
@@ -20,7 +20,7 @@ export function cleanDirectory(dirname) {
|
|
|
20
20
|
if (path.extname(f) === '.ts') {
|
|
21
21
|
const contents = fs.readFileSync(absolutePath, 'utf-8');
|
|
22
22
|
if (contents.includes('#!oprimp_auto_generated!#')) {
|
|
23
|
-
this.emit('verbose',
|
|
23
|
+
this.emit('verbose', colors.cyan(`Removing file ${path.relative(absolutePath, rootDir)}`));
|
|
24
24
|
fs.unlinkSync(absolutePath);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpraHttpClient } from '@opra/client';
|
|
2
2
|
import { BUILTIN, HttpApi } from '@opra/common';
|
|
3
|
-
import
|
|
3
|
+
import colors from 'ansi-colors';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { pascalCase } from 'putil-varhelpers';
|
|
6
6
|
export async function generateDocument(document, options) {
|
|
@@ -10,7 +10,7 @@ export async function generateDocument(document, options) {
|
|
|
10
10
|
if (out)
|
|
11
11
|
return out;
|
|
12
12
|
}
|
|
13
|
-
this.emit('log',
|
|
13
|
+
this.emit('log', colors.cyan('Fetching document schema from ') + colors.blueBright(this.serviceUrl));
|
|
14
14
|
const client = new OpraHttpClient(this.serviceUrl);
|
|
15
15
|
document = await client.fetchDocument({ documentId: document });
|
|
16
16
|
}
|
|
@@ -23,10 +23,12 @@ export async function generateDocument(document, options) {
|
|
|
23
23
|
generator: this,
|
|
24
24
|
};
|
|
25
25
|
this._documentsMap.set(document.id, out);
|
|
26
|
-
this.emit('log',
|
|
26
|
+
this.emit('log', colors.white('[' + document.id + '] ') +
|
|
27
|
+
colors.cyan('Processing document ') +
|
|
28
|
+
colors.magenta(document.info.title || ''));
|
|
27
29
|
if (document.references.size) {
|
|
28
30
|
let refIdGenerator = options?.refIdGenerator || 1;
|
|
29
|
-
this.emit('log',
|
|
31
|
+
this.emit('log', colors.white('[' + document.id + '] ') + colors.cyan(`Processing references`));
|
|
30
32
|
for (const ref of document.references.values()) {
|
|
31
33
|
const generator = this.extend();
|
|
32
34
|
generator._document = ref;
|
|
@@ -44,7 +46,7 @@ export async function generateDocument(document, options) {
|
|
|
44
46
|
* ${this.serviceUrl}
|
|
45
47
|
*/`;
|
|
46
48
|
if (document.types.size) {
|
|
47
|
-
this.emit('log',
|
|
49
|
+
this.emit('log', colors.white('[' + document.id + ']'), colors.cyan(`Processing data types`));
|
|
48
50
|
for (const t of document.types.values()) {
|
|
49
51
|
await this.generateDataType(t, 'root');
|
|
50
52
|
}
|
|
@@ -2,7 +2,7 @@ import { EventEmitter } from 'node:events';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
|
-
import
|
|
5
|
+
import colors from 'ansi-colors';
|
|
6
6
|
import { FileWriter } from '../file-writer.js';
|
|
7
7
|
import { cleanDirectory } from './generators/clean-directory.js';
|
|
8
8
|
import { _generateComplexTypeCode, _generateEnumTypeCode, _generateMappedTypeCode, _generateMixinTypeCode, _generateSimpleTypeCode, _generateTypeCode, generateDataType, } from './generators/generate-data-type.js';
|
|
@@ -42,7 +42,7 @@ export class TsGenerator extends EventEmitter {
|
|
|
42
42
|
this.emit('start');
|
|
43
43
|
try {
|
|
44
44
|
this._started = true;
|
|
45
|
-
this.emit('log',
|
|
45
|
+
this.emit('log', colors.cyan('Removing old files..'));
|
|
46
46
|
this.cleanDirectory(this.outDir);
|
|
47
47
|
this._apiPath = '/api';
|
|
48
48
|
await this.generateDocument();
|
package/package.json
CHANGED
|
@@ -1,40 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.34",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/panates/opra.git",
|
|
10
|
-
"directory": "packages/client"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"compile": "tsc",
|
|
14
|
-
"prebuild": "npm run check && npm run lint && npm run clean",
|
|
15
|
-
"build": "npm run build:cjs && npm run build:esm",
|
|
16
|
-
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
17
|
-
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
|
-
"postbuild": "npm run copy:files && npm run copy:bin",
|
|
19
|
-
"copy:files": "cp README.md package.json ../../LICENSE ../../build/cli && cp ../../package.cjs.json ../../build/cli/cjs/package.json",
|
|
20
|
-
"copy:bin": "cp -R bin ../../build/cli/bin",
|
|
21
|
-
"lint": "eslint . --max-warnings=0",
|
|
22
|
-
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
23
|
-
"format": "prettier . --write --log-level=warn",
|
|
24
|
-
"check": "madge --circular src/**",
|
|
25
|
-
"test": "jest --passWithNoTests",
|
|
26
|
-
"cover": "jest --passWithNoTests --collect-coverage",
|
|
27
|
-
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
28
|
-
"clean:src": "ts-cleanup -s src --all",
|
|
29
|
-
"clean:test": "ts-cleanup -s test --all",
|
|
30
|
-
"clean:dist": "rimraf ../../build/client",
|
|
31
|
-
"clean:cover": "rimraf ../../coverage/client"
|
|
32
|
-
},
|
|
33
7
|
"dependencies": {
|
|
34
|
-
"@browsery/type-is": "^1.6.18-
|
|
35
|
-
"@opra/client": "^1.0.0-alpha.
|
|
36
|
-
"@opra/common": "^1.0.0-alpha.
|
|
37
|
-
"
|
|
8
|
+
"@browsery/type-is": "^1.6.18-r5",
|
|
9
|
+
"@opra/client": "^1.0.0-alpha.34",
|
|
10
|
+
"@opra/common": "^1.0.0-alpha.34",
|
|
11
|
+
"ansi-colors": "^4.1.3",
|
|
38
12
|
"commander": "^12.0.0",
|
|
39
13
|
"js-string-escape": "^1.0.1",
|
|
40
14
|
"putil-flattentext": "^2.1.1",
|
|
@@ -42,12 +16,31 @@
|
|
|
42
16
|
"tslib": "^2.6.3"
|
|
43
17
|
},
|
|
44
18
|
"type": "module",
|
|
45
|
-
"
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./types/index.d.ts",
|
|
23
|
+
"default": "./esm/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./types/index.d.ts",
|
|
27
|
+
"default": "./cjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"default": "./esm/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
46
33
|
"main": "./cjs/index.js",
|
|
34
|
+
"module": "./esm/index.js",
|
|
47
35
|
"types": "./types/index.d.ts",
|
|
48
36
|
"bin": {
|
|
49
37
|
"oprimp": "bin/oprimp.mjs"
|
|
50
38
|
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/panates/opra.git",
|
|
42
|
+
"directory": "packages/client"
|
|
43
|
+
},
|
|
51
44
|
"engines": {
|
|
52
45
|
"node": ">=18.0",
|
|
53
46
|
"npm": ">=7.0.0"
|
|
@@ -66,4 +59,4 @@
|
|
|
66
59
|
"tool",
|
|
67
60
|
"oprimp"
|
|
68
61
|
]
|
|
69
|
-
}
|
|
62
|
+
}
|
package/bin/bin/oprimp.mjs
DELETED