@edifice.io/edifice-nestjs-core 1.0.0-develop-pedago.20251210153355 → 1.0.0-develop-pedago.20251218101723
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/README.md +35 -0
- package/dist/bin/generate-rest-clients.d.ts +2 -0
- package/dist/bin/generate-rest-clients.js +581 -0
- package/dist/bin/generate-rest-clients.js.map +1 -0
- package/dist/bin/generate-swagger-pdf.d.ts +1 -0
- package/dist/bin/generate-swagger-pdf.js +172 -0
- package/dist/bin/generate-swagger-pdf.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -6
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const wait_on_1 = __importDefault(require("wait-on"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
12
|
+
async function isServerRunning() {
|
|
13
|
+
try {
|
|
14
|
+
const response = await axios_1.default.get(`http://${host}:${port}/openapi-json`, {
|
|
15
|
+
timeout: 3000,
|
|
16
|
+
validateStatus: () => true,
|
|
17
|
+
});
|
|
18
|
+
return response.status >= 200 && response.status < 300;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error('Connection error:', error.message);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function generateSwaggerPdf() {
|
|
26
|
+
const apiUrl = `http://${host}:${port}`;
|
|
27
|
+
const swaggerJsonUrl = `${apiUrl}/openapi-json`;
|
|
28
|
+
const outputDir = path_1.default.resolve(process.cwd(), 'documentation');
|
|
29
|
+
const outputPath = path_1.default.join(outputDir, 'api-docs.pdf');
|
|
30
|
+
const tempJsonPath = path_1.default.join(outputDir, 'swagger-spec.json');
|
|
31
|
+
const htmlPath = path_1.default.join(outputDir, 'api-docs.html');
|
|
32
|
+
try {
|
|
33
|
+
console.log(`Fetching OpenAPI specification from ${swaggerJsonUrl}...`);
|
|
34
|
+
await fs_extra_1.default.ensureDir(outputDir);
|
|
35
|
+
const response = await axios_1.default.get(swaggerJsonUrl, { timeout: 5000 });
|
|
36
|
+
console.log('OpenAPI specification successfully retrieved.');
|
|
37
|
+
await fs_extra_1.default.writeJson(tempJsonPath, response.data, { spaces: 2 });
|
|
38
|
+
console.log(`Specification saved to ${tempJsonPath}`);
|
|
39
|
+
console.log('Generating documentation...');
|
|
40
|
+
let success = false;
|
|
41
|
+
if (!success) {
|
|
42
|
+
try {
|
|
43
|
+
console.log('Generating HTML with @redocly/cli...');
|
|
44
|
+
(0, child_process_1.execSync)(`npx @redocly/cli build-docs ${tempJsonPath} --output=${htmlPath}`, { stdio: 'inherit' });
|
|
45
|
+
success = true;
|
|
46
|
+
console.log('HTML documentation generated successfully with @redocly/cli.');
|
|
47
|
+
if (success && fs_extra_1.default.existsSync(htmlPath)) {
|
|
48
|
+
try {
|
|
49
|
+
console.log('Converting HTML to PDF with electron-pdf...');
|
|
50
|
+
(0, child_process_1.execSync)(`npx electron-pdf "${htmlPath}" "${outputPath}" --landscape=false --marginsType=1`, {
|
|
51
|
+
stdio: 'inherit',
|
|
52
|
+
});
|
|
53
|
+
console.log('PDF documentation generated successfully with electron-pdf.');
|
|
54
|
+
return outputPath;
|
|
55
|
+
}
|
|
56
|
+
catch (_) {
|
|
57
|
+
console.log('electron-pdf conversion failed, trying next method...');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (_) {
|
|
62
|
+
console.log('@redocly/cli failed, trying next method...');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!success) {
|
|
66
|
+
try {
|
|
67
|
+
console.log('Generating PDF with swagger-to-pdf...');
|
|
68
|
+
(0, child_process_1.execSync)(`npx swagger-to-pdf ${tempJsonPath} ${outputPath}`, {
|
|
69
|
+
stdio: 'inherit',
|
|
70
|
+
});
|
|
71
|
+
success = true;
|
|
72
|
+
console.log('PDF documentation generated successfully with swagger-to-pdf.');
|
|
73
|
+
return outputPath;
|
|
74
|
+
}
|
|
75
|
+
catch (_) {
|
|
76
|
+
console.log('swagger-to-pdf failed, trying next method...');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!success) {
|
|
80
|
+
throw new Error('All documentation generation methods failed.');
|
|
81
|
+
}
|
|
82
|
+
return outputPath;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Error generating documentation:', error.message);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function run() {
|
|
90
|
+
console.log('Checking if server is already running...');
|
|
91
|
+
const serverAlreadyRunning = await isServerRunning();
|
|
92
|
+
let serverProcess = null;
|
|
93
|
+
try {
|
|
94
|
+
if (!serverAlreadyRunning) {
|
|
95
|
+
console.log('Starting server...');
|
|
96
|
+
serverProcess = (0, child_process_1.spawn)('pnpm', ['start'], {
|
|
97
|
+
shell: true,
|
|
98
|
+
stdio: 'pipe',
|
|
99
|
+
detached: true,
|
|
100
|
+
env: { ...process.env, PORT: port, HOST: host },
|
|
101
|
+
});
|
|
102
|
+
serverProcess.stdout.on('data', (data) => {
|
|
103
|
+
console.log(`[Server]: ${data.toString().trim()}`);
|
|
104
|
+
});
|
|
105
|
+
serverProcess.stderr.on('data', (data) => {
|
|
106
|
+
console.error(`[Server Error]: ${data.toString().trim()}`);
|
|
107
|
+
});
|
|
108
|
+
console.log('Waiting for server to be ready...');
|
|
109
|
+
await (0, wait_on_1.default)({
|
|
110
|
+
resources: [`http-get://${host}:${port}/openapi-json`],
|
|
111
|
+
delay: 1000,
|
|
112
|
+
interval: 1000,
|
|
113
|
+
timeout: 60000,
|
|
114
|
+
verbose: true,
|
|
115
|
+
});
|
|
116
|
+
console.log('Server is ready!');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log('Server is already running.');
|
|
120
|
+
}
|
|
121
|
+
console.log('Generating API documentation...');
|
|
122
|
+
const docPath = await generateSwaggerPdf();
|
|
123
|
+
if (fs_extra_1.default.existsSync(docPath)) {
|
|
124
|
+
console.log(`Documentation generated: ${docPath}`);
|
|
125
|
+
if (docPath.endsWith('.pdf')) {
|
|
126
|
+
console.log('PDF documentation was successfully generated.');
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.log('HTML documentation was generated. Use browser print function to create PDF if needed.');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error('Error in run process:', error.message);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
if (serverProcess && !serverAlreadyRunning) {
|
|
139
|
+
console.log('Shutting down server...');
|
|
140
|
+
try {
|
|
141
|
+
if (process.platform === 'win32') {
|
|
142
|
+
(0, child_process_1.execSync)(`taskkill /pid ${serverProcess.pid} /T /F`);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
process.kill(-serverProcess.pid, 'SIGINT');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error('Error shutting down server:', error.message);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const argv = (0, yargs_1.default)(process.argv.slice(2))
|
|
155
|
+
.option('host', {
|
|
156
|
+
alias: 'h',
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Host of the API server',
|
|
159
|
+
default: '127.0.0.1',
|
|
160
|
+
})
|
|
161
|
+
.option('port', {
|
|
162
|
+
alias: 'p',
|
|
163
|
+
type: 'number',
|
|
164
|
+
description: 'Port of the API server',
|
|
165
|
+
default: 3002,
|
|
166
|
+
})
|
|
167
|
+
.help()
|
|
168
|
+
.parse();
|
|
169
|
+
const host = argv.host;
|
|
170
|
+
const port = argv.port;
|
|
171
|
+
run();
|
|
172
|
+
//# sourceMappingURL=generate-swagger-pdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-swagger-pdf.js","sourceRoot":"","sources":["../../src/bin/generate-swagger-pdf.ts"],"names":[],"mappings":";;;;;AAAA,iDAAgD;AAChD,kDAA0B;AAC1B,sDAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AACxB,kDAA0B;AAG1B,KAAK,UAAU,eAAe;IAC5B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,IAAI,eAAe,EAAE;YACtE,OAAO,EAAE,IAAI;YACb,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;SAC3B,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAGD,KAAK,UAAU,kBAAkB;IAC/B,MAAM,MAAM,GAAG,UAAU,IAAI,IAAI,IAAI,EAAE,CAAC;IACxC,MAAM,cAAc,GAAG,GAAG,MAAM,eAAe,CAAC;IAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAC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