@gravity-ui/app-builder 0.28.1-beta.0 → 0.28.1-beta.10
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 +2 -0
- package/dist/commands/build/build-service/server.js +33 -16
- package/dist/commands/dev/index.js +7 -85
- package/dist/commands/dev/server.js +47 -26
- package/dist/common/config.js +1 -0
- package/dist/common/models/index.d.ts +8 -1
- package/dist/common/swc/compile.d.ts +8 -0
- package/dist/common/swc/compile.js +49 -0
- package/dist/common/swc/index.d.ts +2 -0
- package/dist/common/swc/index.js +7 -0
- package/dist/common/swc/utils.d.ts +4 -0
- package/dist/common/swc/utils.js +33 -0
- package/dist/common/swc/watch.d.ts +8 -0
- package/dist/common/swc/watch.js +46 -0
- package/package.json +3 -4
- package/dist/commands/dev/ui/LogCollector.d.ts +0 -13
- package/dist/commands/dev/ui/LogCollector.js +0 -89
- package/dist/commands/dev/ui/TerminalTabs.d.ts +0 -25
- package/dist/commands/dev/ui/TerminalTabs.js +0 -183
- package/dist/commands/dev/ui/demo.d.ts +0 -2
- package/dist/commands/dev/ui/demo.js +0 -61
package/README.md
CHANGED
|
@@ -143,6 +143,8 @@ All server settings are used only in dev mode:
|
|
|
143
143
|
- `watchThrottle` (`number`) — use to add an extra throttle, or delay restarting.
|
|
144
144
|
- `inspect/inspectBrk` (`number | true`) — listen for a debugging client on specified port.
|
|
145
145
|
If specified `true`, try to listen on `9229`.
|
|
146
|
+
- `compiler` (`'typescript' | 'swc'`) — choose TypeScript compiler for server code compilation.
|
|
147
|
+
Default is `'typescript'`. Set to `'swc'` for faster compilation with SWC.
|
|
146
148
|
|
|
147
149
|
### Client
|
|
148
150
|
|
|
@@ -8,25 +8,42 @@ const signal_exit_1 = require("signal-exit");
|
|
|
8
8
|
const controllable_script_1 = require("../../../common/child-process/controllable-script");
|
|
9
9
|
const paths_1 = __importDefault(require("../../../common/paths"));
|
|
10
10
|
const utils_1 = require("../../../common/utils");
|
|
11
|
+
function createSWCBuildScript(config) {
|
|
12
|
+
return `
|
|
13
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
14
|
+
const {compile} = require(${JSON.stringify(require.resolve('../../../common/swc/compile'))});
|
|
15
|
+
|
|
16
|
+
const logger = new Logger('server', ${config.verbose});
|
|
17
|
+
compile({
|
|
18
|
+
logger,
|
|
19
|
+
outputPath: ${JSON.stringify(paths_1.default.appDist)},
|
|
20
|
+
projectPath: ${JSON.stringify(paths_1.default.appServer)},
|
|
21
|
+
});`;
|
|
22
|
+
}
|
|
23
|
+
function createTypescriptBuildScript(config) {
|
|
24
|
+
return `
|
|
25
|
+
let ts;
|
|
26
|
+
try {
|
|
27
|
+
ts = require('typescript');
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
33
|
+
}
|
|
34
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
35
|
+
const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
|
|
36
|
+
|
|
37
|
+
const logger = new Logger('server', ${config.verbose});
|
|
38
|
+
compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});`;
|
|
39
|
+
}
|
|
11
40
|
function buildServer(config) {
|
|
12
41
|
(0, utils_1.createRunFolder)();
|
|
42
|
+
// Используем TypeScript для компиляции (по умолчанию)
|
|
13
43
|
return new Promise((resolve, reject) => {
|
|
14
|
-
const build = new controllable_script_1.ControllableScript(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ts = require('typescript');
|
|
18
|
-
} catch (e) {
|
|
19
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
20
|
-
throw e;
|
|
21
|
-
}
|
|
22
|
-
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
23
|
-
}
|
|
24
|
-
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
25
|
-
const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
|
|
26
|
-
|
|
27
|
-
const logger = new Logger('server', ${config.verbose});
|
|
28
|
-
compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});
|
|
29
|
-
`, null);
|
|
44
|
+
const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
|
|
45
|
+
? createSWCBuildScript(config)
|
|
46
|
+
: createTypescriptBuildScript(config), null);
|
|
30
47
|
build.start().then(() => {
|
|
31
48
|
build.onExit((code) => {
|
|
32
49
|
if (code) {
|
|
@@ -34,70 +34,8 @@ const rimraf_1 = require("rimraf");
|
|
|
34
34
|
const utils_1 = require("../../common/utils");
|
|
35
35
|
const logger_1 = __importDefault(require("../../common/logger"));
|
|
36
36
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
37
|
-
// Импортируем систему табов для логирования
|
|
38
|
-
const TerminalTabs_1 = require("./ui/TerminalTabs");
|
|
39
|
-
// Глобальная система табов
|
|
40
|
-
let terminalTabs;
|
|
41
|
-
// Функция для добавления лога в систему табов
|
|
42
|
-
function addLogToTabs(type, message, level = 'message') {
|
|
43
|
-
if (terminalTabs && process.stdout.isTTY) {
|
|
44
|
-
terminalTabs.addLog({
|
|
45
|
-
type,
|
|
46
|
-
message,
|
|
47
|
-
timestamp: Date.now(),
|
|
48
|
-
level,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// Обёртка для logger с интеграцией в табы
|
|
53
|
-
function createLoggerWrapper(type) {
|
|
54
|
-
return {
|
|
55
|
-
message: (...args) => {
|
|
56
|
-
const message = args.join(' ');
|
|
57
|
-
addLogToTabs(type, message, 'message');
|
|
58
|
-
if (!process.stdout.isTTY) {
|
|
59
|
-
logger_1.default.message(`[${type}]`, message);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
success: (...args) => {
|
|
63
|
-
const message = args.join(' ');
|
|
64
|
-
addLogToTabs(type, message, 'success');
|
|
65
|
-
if (!process.stdout.isTTY) {
|
|
66
|
-
logger_1.default.success(`[${type}]`, message);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
warning: (...args) => {
|
|
70
|
-
const message = args.join(' ');
|
|
71
|
-
addLogToTabs(type, message, 'warning');
|
|
72
|
-
if (!process.stdout.isTTY) {
|
|
73
|
-
logger_1.default.warning(`[${type}]`, message);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
error: (...args) => {
|
|
77
|
-
const message = args.join(' ');
|
|
78
|
-
addLogToTabs(type, message, 'error');
|
|
79
|
-
if (!process.stdout.isTTY) {
|
|
80
|
-
logger_1.default.error(`[${type}]`, message);
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
verbose: (...args) => {
|
|
84
|
-
const message = args.join(' ');
|
|
85
|
-
addLogToTabs(type, message, 'verbose');
|
|
86
|
-
if (!process.stdout.isTTY) {
|
|
87
|
-
logger_1.default.verbose(`[${type}]`, message);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
37
|
async function default_1(config) {
|
|
93
38
|
process.env.NODE_ENV = 'development';
|
|
94
|
-
// Инициализируем систему табов только в TTY
|
|
95
|
-
if (process.stdout.isTTY) {
|
|
96
|
-
terminalTabs = new TerminalTabs_1.TerminalTabs();
|
|
97
|
-
terminalTabs.initialize();
|
|
98
|
-
// Добавляем начальный лог
|
|
99
|
-
addLogToTabs('all', 'Запуск режима разработки...', 'message');
|
|
100
|
-
}
|
|
101
39
|
const shouldCompileClient = (0, utils_1.shouldCompileTarget)(config.target, 'client');
|
|
102
40
|
const shouldCompileServer = (0, utils_1.shouldCompileTarget)(config.target, 'server');
|
|
103
41
|
if (shouldCompileClient && shouldCompileServer) {
|
|
@@ -110,8 +48,7 @@ async function default_1(config) {
|
|
|
110
48
|
const { inspect, inspectBrk } = config.server;
|
|
111
49
|
const startNodemon = () => {
|
|
112
50
|
if (needToStartNodemon && serverCompiled && clientCompiled) {
|
|
113
|
-
|
|
114
|
-
serverLogger.message('Starting application at', serverPath);
|
|
51
|
+
logger_1.default.message('Starting application at', serverPath);
|
|
115
52
|
const nodeArgs = ['--enable-source-maps'];
|
|
116
53
|
if (inspect || inspectBrk) {
|
|
117
54
|
nodeArgs.push(`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`);
|
|
@@ -140,8 +77,6 @@ async function default_1(config) {
|
|
|
140
77
|
serverCompilation.onMessage((msg) => {
|
|
141
78
|
if (typeof msg === 'object' && 'type' in msg && msg.type === 'Emitted') {
|
|
142
79
|
serverCompiled = true;
|
|
143
|
-
const serverLogger = createLoggerWrapper('server');
|
|
144
|
-
serverLogger.success('Server compilation completed');
|
|
145
80
|
startNodemon();
|
|
146
81
|
}
|
|
147
82
|
});
|
|
@@ -150,38 +85,25 @@ async function default_1(config) {
|
|
|
150
85
|
if (shouldCompileClient) {
|
|
151
86
|
const { watchClientCompilation } = await import('./client.js');
|
|
152
87
|
clientCompilation = await watchClientCompilation(config, () => {
|
|
153
|
-
|
|
154
|
-
clientLogger.success('Manifest was compiled successfully');
|
|
88
|
+
logger_1.default.success('Manifest was compiled successfully');
|
|
155
89
|
clientCompiled = true;
|
|
156
90
|
startNodemon();
|
|
157
91
|
});
|
|
158
92
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
terminalTabs.destroy();
|
|
162
|
-
}
|
|
93
|
+
process.on('SIGINT', async () => {
|
|
94
|
+
logger_1.default.success('\nCleaning up...');
|
|
163
95
|
await serverCompilation?.stop('SIGINT');
|
|
164
96
|
await clientCompilation?.stop();
|
|
165
|
-
};
|
|
166
|
-
process.on('SIGINT', async () => {
|
|
167
|
-
if (!process.stdout.isTTY) {
|
|
168
|
-
logger_1.default.success('\nCleaning up...');
|
|
169
|
-
}
|
|
170
|
-
await cleanup();
|
|
171
97
|
process.exit(1);
|
|
172
98
|
});
|
|
173
99
|
process.on('SIGTERM', async () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
await cleanup();
|
|
100
|
+
logger_1.default.success('\nCleaning up...');
|
|
101
|
+
await serverCompilation?.stop('SIGTERM');
|
|
102
|
+
await clientCompilation?.stop();
|
|
178
103
|
process.exit(1);
|
|
179
104
|
});
|
|
180
105
|
(0, signal_exit_1.onExit)((_code, signal) => {
|
|
181
106
|
serverCompilation?.stop(signal);
|
|
182
107
|
clientCompilation?.stop();
|
|
183
|
-
if (terminalTabs) {
|
|
184
|
-
terminalTabs.destroy();
|
|
185
|
-
}
|
|
186
108
|
});
|
|
187
109
|
}
|
|
@@ -32,36 +32,57 @@ const rimraf_1 = require("rimraf");
|
|
|
32
32
|
const controllable_script_1 = require("../../common/child-process/controllable-script");
|
|
33
33
|
const utils_1 = require("../../common/utils");
|
|
34
34
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
35
|
+
function createTypescriptBuildScript(config) {
|
|
36
|
+
return `
|
|
37
|
+
let ts;
|
|
38
|
+
try {
|
|
39
|
+
ts = require('typescript');
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
45
|
+
}
|
|
46
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
47
|
+
const {watch} = require(${JSON.stringify(require.resolve('../../common/typescript/watch'))});
|
|
48
|
+
|
|
49
|
+
const logger = new Logger('server', ${config.verbose});
|
|
50
|
+
watch(
|
|
51
|
+
ts,
|
|
52
|
+
${JSON.stringify(paths_1.default.appServer)},
|
|
53
|
+
{
|
|
54
|
+
logger,
|
|
55
|
+
onAfterFilesEmitted: () => {
|
|
56
|
+
process.send({type: 'Emitted'});
|
|
57
|
+
},
|
|
58
|
+
enableSourceMap: true
|
|
59
|
+
}
|
|
60
|
+
);`;
|
|
61
|
+
}
|
|
62
|
+
function createSWCBuildScript(config) {
|
|
63
|
+
return `
|
|
64
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
65
|
+
const {watch} = require(${JSON.stringify(require.resolve('../../common/swc/watch'))});
|
|
66
|
+
|
|
67
|
+
const logger = new Logger('server', ${config.verbose});
|
|
68
|
+
watch(
|
|
69
|
+
${JSON.stringify(paths_1.default.appServer)},
|
|
70
|
+
{
|
|
71
|
+
outputPath: ${JSON.stringify(paths_1.default.appDist)},
|
|
72
|
+
logger,
|
|
73
|
+
onAfterFilesEmitted: () => {
|
|
74
|
+
process.send({type: 'Emitted'});
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
);`;
|
|
78
|
+
}
|
|
35
79
|
async function watchServerCompilation(config) {
|
|
36
80
|
const serverPath = path.resolve(paths_1.default.appDist, 'server');
|
|
37
81
|
rimraf_1.rimraf.sync(serverPath);
|
|
38
82
|
(0, utils_1.createRunFolder)();
|
|
39
|
-
const build = new controllable_script_1.ControllableScript(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ts = require('typescript');
|
|
43
|
-
} catch (e) {
|
|
44
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
48
|
-
}
|
|
49
|
-
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
50
|
-
const {watch} = require(${JSON.stringify(require.resolve('../../common/typescript/watch'))});
|
|
51
|
-
|
|
52
|
-
const logger = new Logger('server', ${config.verbose});
|
|
53
|
-
watch(
|
|
54
|
-
ts,
|
|
55
|
-
${JSON.stringify(paths_1.default.appServer)},
|
|
56
|
-
{
|
|
57
|
-
logger,
|
|
58
|
-
onAfterFilesEmitted: () => {
|
|
59
|
-
process.send({type: 'Emitted'});
|
|
60
|
-
},
|
|
61
|
-
enableSourceMap: true
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
`, null);
|
|
83
|
+
const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
|
|
84
|
+
? createSWCBuildScript(config)
|
|
85
|
+
: createTypescriptBuildScript(config), null);
|
|
65
86
|
await build.start();
|
|
66
87
|
return build;
|
|
67
88
|
}
|
package/dist/common/config.js
CHANGED
|
@@ -18,6 +18,7 @@ import type { TerserOptions } from 'terser-webpack-plugin';
|
|
|
18
18
|
import type { ReactRefreshPluginOptions } from '@pmmmwh/react-refresh-webpack-plugin/types/lib/types';
|
|
19
19
|
type Bundler = 'webpack' | 'rspack';
|
|
20
20
|
type JavaScriptLoader = 'babel' | 'swc';
|
|
21
|
+
type ServerCompiler = 'typescript' | 'swc';
|
|
21
22
|
export type SwcConfig = Swc.Config & Pick<Swc.Options, 'isModule'>;
|
|
22
23
|
export interface Entities<T> {
|
|
23
24
|
data: Record<string, T>;
|
|
@@ -266,6 +267,11 @@ export interface ServerConfig {
|
|
|
266
267
|
watchThrottle?: number;
|
|
267
268
|
inspect?: number | true;
|
|
268
269
|
inspectBrk?: number | true;
|
|
270
|
+
/**
|
|
271
|
+
* Compiler for server code compilation
|
|
272
|
+
* @default 'typescript'
|
|
273
|
+
*/
|
|
274
|
+
compiler?: ServerCompiler;
|
|
269
275
|
}
|
|
270
276
|
export interface ServiceConfig {
|
|
271
277
|
target?: 'client' | 'server';
|
|
@@ -306,11 +312,12 @@ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'pu
|
|
|
306
312
|
}) => SwcConfig | Promise<SwcConfig>;
|
|
307
313
|
reactRefresh: NonNullable<ClientConfig['reactRefresh']>;
|
|
308
314
|
};
|
|
309
|
-
export type NormalizedServerConfig = Omit<ServerConfig, 'port' | 'inspect' | 'inspectBrk'> & {
|
|
315
|
+
export type NormalizedServerConfig = Omit<ServerConfig, 'port' | 'inspect' | 'inspectBrk' | 'compiler'> & {
|
|
310
316
|
port?: number;
|
|
311
317
|
verbose?: boolean;
|
|
312
318
|
inspect?: number;
|
|
313
319
|
inspectBrk?: number;
|
|
320
|
+
compiler: ServerCompiler;
|
|
314
321
|
};
|
|
315
322
|
export type NormalizedServiceConfig = Omit<ServiceConfig, 'client' | 'server'> & {
|
|
316
323
|
client: NormalizedClientConfig;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compile = compile;
|
|
4
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
5
|
+
// @ts-ignore @swc/cli is not typed
|
|
6
|
+
const cli_1 = require("@swc/cli");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
async function compile({ projectPath, outputPath, logger }) {
|
|
9
|
+
const start = process.hrtime.bigint();
|
|
10
|
+
logger.message('Start compilation');
|
|
11
|
+
const { swcOptions, directoriesToCompile } = (0, utils_1.getSwcOptionsFromTsconfig)(projectPath);
|
|
12
|
+
const cliOptions = {
|
|
13
|
+
filenames: directoriesToCompile,
|
|
14
|
+
outDir: outputPath,
|
|
15
|
+
watch: false,
|
|
16
|
+
extensions: ['.js', '.ts', '.mjs', '.cjs'],
|
|
17
|
+
stripLeadingPaths: true,
|
|
18
|
+
sync: false,
|
|
19
|
+
};
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const callbacks = {
|
|
22
|
+
onSuccess: (_result) => {
|
|
23
|
+
logger.success(`Compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
|
|
24
|
+
resolve();
|
|
25
|
+
},
|
|
26
|
+
onFail: (result) => {
|
|
27
|
+
logger.error(`Compilation failed in ${result.duration}ms`);
|
|
28
|
+
if (result.reasons) {
|
|
29
|
+
for (const [filename, error] of result.reasons) {
|
|
30
|
+
logger.error(`${filename}: ${error}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
logger.error(`Error compile, elapsed time ${(0, pretty_time_1.elapsedTime)(start)}`);
|
|
34
|
+
reject(new Error('Compilation failed'));
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
(0, cli_1.swcDir)({
|
|
39
|
+
cliOptions,
|
|
40
|
+
swcOptions,
|
|
41
|
+
callbacks,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
logger.error(`Failed to start compilation: ${error}`);
|
|
46
|
+
reject(error);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watch = exports.compile = void 0;
|
|
4
|
+
var compile_1 = require("./compile");
|
|
5
|
+
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
|
6
|
+
var watch_1 = require("./watch");
|
|
7
|
+
Object.defineProperty(exports, "watch", { enumerable: true, get: function () { return watch_1.watch; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
exports.getSwcOptionsFromTsconfig = getSwcOptionsFromTsconfig;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const tsconfig_to_swcconfig_1 = require("tsconfig-to-swcconfig");
|
|
9
|
+
function resolvePaths(paths, baseUrl) {
|
|
10
|
+
const entries = [];
|
|
11
|
+
for (const targets of Object.values(paths)) {
|
|
12
|
+
for (const target of targets) {
|
|
13
|
+
const resolvedPath = path_1.default.resolve(baseUrl, target.replace(/\*$/, ''));
|
|
14
|
+
entries.push(resolvedPath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return entries;
|
|
18
|
+
}
|
|
19
|
+
function getSwcOptionsFromTsconfig(projectPath, filename = 'tsconfig.json') {
|
|
20
|
+
const swcOptions = (0, tsconfig_to_swcconfig_1.convert)(filename, projectPath);
|
|
21
|
+
swcOptions.jsc = {
|
|
22
|
+
...swcOptions.jsc,
|
|
23
|
+
// SWC requires absolute path as baseUrl
|
|
24
|
+
baseUrl: projectPath,
|
|
25
|
+
};
|
|
26
|
+
// SWC don't compile referenced files like tsc, so we need collect all directories to compile.
|
|
27
|
+
const paths = swcOptions.jsc.paths || {};
|
|
28
|
+
const directoriesToCompile = [projectPath, ...resolvePaths(paths, projectPath)];
|
|
29
|
+
return {
|
|
30
|
+
swcOptions,
|
|
31
|
+
directoriesToCompile,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Logger } from '../logger';
|
|
2
|
+
interface SwcWatchOptions {
|
|
3
|
+
outputPath: string;
|
|
4
|
+
logger: Logger;
|
|
5
|
+
onAfterFilesEmitted?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function watch(projectPath: string, { outputPath, logger, onAfterFilesEmitted }: SwcWatchOptions): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watch = watch;
|
|
4
|
+
// @ts-ignore @swc/cli is not typed
|
|
5
|
+
const cli_1 = require("@swc/cli");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
async function watch(projectPath, { outputPath, logger, onAfterFilesEmitted }) {
|
|
8
|
+
logger.message('Start compilation in watch mode');
|
|
9
|
+
const { swcOptions, directoriesToCompile } = (0, utils_1.getSwcOptionsFromTsconfig)(projectPath);
|
|
10
|
+
const cliOptions = {
|
|
11
|
+
filenames: directoriesToCompile,
|
|
12
|
+
outDir: outputPath,
|
|
13
|
+
watch: true,
|
|
14
|
+
extensions: ['.js', '.ts', '.mjs', '.cjs'],
|
|
15
|
+
stripLeadingPaths: true,
|
|
16
|
+
sync: false,
|
|
17
|
+
logWatchCompilation: true,
|
|
18
|
+
};
|
|
19
|
+
const callbacks = {
|
|
20
|
+
onSuccess: (result) => {
|
|
21
|
+
if (result.filename) {
|
|
22
|
+
logger.message(`Successfully compiled ${result.filename} in ${result.duration}ms`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
logger.message(`Successfully compiled ${result.compiled || 0} files in ${result.duration}ms`);
|
|
26
|
+
}
|
|
27
|
+
onAfterFilesEmitted?.();
|
|
28
|
+
},
|
|
29
|
+
onFail: (result) => {
|
|
30
|
+
logger.error(`Compilation failed in ${result.duration}ms`);
|
|
31
|
+
if (result.reasons) {
|
|
32
|
+
for (const [filename, error] of result.reasons) {
|
|
33
|
+
logger.error(`${filename}: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
onWatchReady: () => {
|
|
38
|
+
logger.message('Watching for file changes');
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
(0, cli_1.swcDir)({
|
|
42
|
+
cliOptions,
|
|
43
|
+
swcOptions,
|
|
44
|
+
callbacks,
|
|
45
|
+
});
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.28.1-beta.
|
|
3
|
+
"version": "0.28.1-beta.10",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"@svgr/core": "^8.1.0",
|
|
83
83
|
"@svgr/plugin-jsx": "^8.1.0",
|
|
84
84
|
"@svgr/webpack": "^8.1.0",
|
|
85
|
+
"@swc/cli": "0.7.7",
|
|
85
86
|
"@swc/core": "1.11.24",
|
|
86
87
|
"@swc/plugin-transform-imports": "7.0.3",
|
|
87
|
-
"@types/react": "^19.1.6",
|
|
88
88
|
"babel-loader": "^9.2.1",
|
|
89
89
|
"babel-plugin-import": "^1.13.8",
|
|
90
90
|
"babel-plugin-inline-react-svg": "^2.0.2",
|
|
@@ -108,8 +108,6 @@
|
|
|
108
108
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
109
109
|
"fs-extra": "^11.2.0",
|
|
110
110
|
"get-port": "^7.1.0",
|
|
111
|
-
"ink": "^5.2.1",
|
|
112
|
-
"keypress": "^0.2.1",
|
|
113
111
|
"mime-types": "^2.1.35",
|
|
114
112
|
"mini-css-extract-plugin": "^2.9.1",
|
|
115
113
|
"moment-timezone-data-webpack-plugin": "^1.5.1",
|
|
@@ -138,6 +136,7 @@
|
|
|
138
136
|
"terser-webpack-plugin": "5.3.10",
|
|
139
137
|
"ts-checker-rspack-plugin": "^1.1.1",
|
|
140
138
|
"ts-node": "10.9.2",
|
|
139
|
+
"tsconfig-to-swcconfig": "^2.8.1",
|
|
141
140
|
"tslib": "^2.6.2",
|
|
142
141
|
"typescript": "~5.6.0",
|
|
143
142
|
"webpack": "^5.95.0",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { BaseLogger } from '../../../common/logger';
|
|
3
|
-
import type { LogEntry } from './TerminalTabs';
|
|
4
|
-
export declare class LogCollector extends EventEmitter {
|
|
5
|
-
private logs;
|
|
6
|
-
private maxLogs;
|
|
7
|
-
constructor(maxLogs?: number);
|
|
8
|
-
addLog(entry: LogEntry): void;
|
|
9
|
-
getLogs(): LogEntry[];
|
|
10
|
-
clear(): void;
|
|
11
|
-
createLogger(type: 'server' | 'client', namespace?: string, verbose?: boolean): BaseLogger;
|
|
12
|
-
}
|
|
13
|
-
export declare const globalLogCollector: LogCollector;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.globalLogCollector = exports.LogCollector = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
const logger_1 = require("../../../common/logger");
|
|
6
|
-
class LogCollector extends events_1.EventEmitter {
|
|
7
|
-
logs = [];
|
|
8
|
-
maxLogs = 1000;
|
|
9
|
-
constructor(maxLogs = 1000) {
|
|
10
|
-
super();
|
|
11
|
-
this.maxLogs = maxLogs;
|
|
12
|
-
}
|
|
13
|
-
addLog(entry) {
|
|
14
|
-
this.logs.push(entry);
|
|
15
|
-
if (this.logs.length > this.maxLogs) {
|
|
16
|
-
this.logs = this.logs.slice(-this.maxLogs);
|
|
17
|
-
}
|
|
18
|
-
this.emit('log', entry);
|
|
19
|
-
}
|
|
20
|
-
getLogs() {
|
|
21
|
-
return [...this.logs];
|
|
22
|
-
}
|
|
23
|
-
clear() {
|
|
24
|
-
this.logs = [];
|
|
25
|
-
this.emit('clear');
|
|
26
|
-
}
|
|
27
|
-
createLogger(type, namespace, verbose = false) {
|
|
28
|
-
const logger = new logger_1.Logger(namespace, verbose);
|
|
29
|
-
// Перехватываем методы логирования
|
|
30
|
-
const originalMessage = logger.message.bind(logger);
|
|
31
|
-
const originalSuccess = logger.success.bind(logger);
|
|
32
|
-
const originalWarning = logger.warning.bind(logger);
|
|
33
|
-
const originalError = logger.error.bind(logger);
|
|
34
|
-
const originalVerbose = logger.verbose.bind(logger);
|
|
35
|
-
logger.message = (...args) => {
|
|
36
|
-
const message = args.join(' ');
|
|
37
|
-
this.addLog({
|
|
38
|
-
type,
|
|
39
|
-
message,
|
|
40
|
-
timestamp: Date.now(),
|
|
41
|
-
level: 'message',
|
|
42
|
-
});
|
|
43
|
-
return originalMessage(...args);
|
|
44
|
-
};
|
|
45
|
-
logger.success = (...args) => {
|
|
46
|
-
const message = args.join(' ');
|
|
47
|
-
this.addLog({
|
|
48
|
-
type,
|
|
49
|
-
message,
|
|
50
|
-
timestamp: Date.now(),
|
|
51
|
-
level: 'success',
|
|
52
|
-
});
|
|
53
|
-
return originalSuccess(...args);
|
|
54
|
-
};
|
|
55
|
-
logger.warning = (...args) => {
|
|
56
|
-
const message = args.join(' ');
|
|
57
|
-
this.addLog({
|
|
58
|
-
type,
|
|
59
|
-
message,
|
|
60
|
-
timestamp: Date.now(),
|
|
61
|
-
level: 'warning',
|
|
62
|
-
});
|
|
63
|
-
return originalWarning(...args);
|
|
64
|
-
};
|
|
65
|
-
logger.error = (...args) => {
|
|
66
|
-
const message = args.join(' ');
|
|
67
|
-
this.addLog({
|
|
68
|
-
type,
|
|
69
|
-
message,
|
|
70
|
-
timestamp: Date.now(),
|
|
71
|
-
level: 'error',
|
|
72
|
-
});
|
|
73
|
-
return originalError(...args);
|
|
74
|
-
};
|
|
75
|
-
logger.verbose = (...args) => {
|
|
76
|
-
const message = args.join(' ');
|
|
77
|
-
this.addLog({
|
|
78
|
-
type,
|
|
79
|
-
message,
|
|
80
|
-
timestamp: Date.now(),
|
|
81
|
-
level: 'verbose',
|
|
82
|
-
});
|
|
83
|
-
return originalVerbose(...args);
|
|
84
|
-
};
|
|
85
|
-
return logger;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.LogCollector = LogCollector;
|
|
89
|
-
exports.globalLogCollector = new LogCollector();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
export interface LogEntry {
|
|
3
|
-
type: 'server' | 'client' | 'all';
|
|
4
|
-
message: string;
|
|
5
|
-
timestamp: number;
|
|
6
|
-
level: 'message' | 'success' | 'warning' | 'error' | 'verbose';
|
|
7
|
-
}
|
|
8
|
-
export declare class TerminalTabs extends EventEmitter {
|
|
9
|
-
private logs;
|
|
10
|
-
private activeTab;
|
|
11
|
-
private maxLogs;
|
|
12
|
-
private rl;
|
|
13
|
-
private isInitialized;
|
|
14
|
-
constructor(maxLogs?: number);
|
|
15
|
-
initialize(): void;
|
|
16
|
-
addLog(entry: LogEntry): void;
|
|
17
|
-
destroy(): void;
|
|
18
|
-
private setupKeyHandlers;
|
|
19
|
-
private clearLogs;
|
|
20
|
-
private render;
|
|
21
|
-
private renderTabs;
|
|
22
|
-
private renderLogs;
|
|
23
|
-
private formatLogMessage;
|
|
24
|
-
private renderHelp;
|
|
25
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TerminalTabs = void 0;
|
|
27
|
-
const readline = __importStar(require("readline"));
|
|
28
|
-
const events_1 = require("events");
|
|
29
|
-
// ANSI escape codes для цветов
|
|
30
|
-
const ansi = {
|
|
31
|
-
reset: '\x1b[0m',
|
|
32
|
-
bold: '\x1b[1m',
|
|
33
|
-
dim: '\x1b[2m',
|
|
34
|
-
cyan: '\x1b[36m',
|
|
35
|
-
blue: '\x1b[34m',
|
|
36
|
-
green: '\x1b[32m',
|
|
37
|
-
yellow: '\x1b[33m',
|
|
38
|
-
red: '\x1b[31m',
|
|
39
|
-
white: '\x1b[37m',
|
|
40
|
-
bgBlue: '\x1b[44m',
|
|
41
|
-
};
|
|
42
|
-
const tabs = [
|
|
43
|
-
{ key: 'all', title: 'Все логи', filter: () => true },
|
|
44
|
-
{ key: 'server', title: 'Сервер', filter: (log) => log.type === 'server' },
|
|
45
|
-
{ key: 'client', title: 'Клиент', filter: (log) => log.type === 'client' },
|
|
46
|
-
];
|
|
47
|
-
class TerminalTabs extends events_1.EventEmitter {
|
|
48
|
-
logs = [];
|
|
49
|
-
activeTab = 0;
|
|
50
|
-
maxLogs = 1000;
|
|
51
|
-
rl;
|
|
52
|
-
isInitialized = false;
|
|
53
|
-
constructor(maxLogs = 1000) {
|
|
54
|
-
super();
|
|
55
|
-
this.maxLogs = maxLogs;
|
|
56
|
-
this.rl = readline.createInterface({
|
|
57
|
-
input: process.stdin,
|
|
58
|
-
output: process.stdout,
|
|
59
|
-
});
|
|
60
|
-
this.setupKeyHandlers();
|
|
61
|
-
}
|
|
62
|
-
initialize() {
|
|
63
|
-
if (this.isInitialized)
|
|
64
|
-
return;
|
|
65
|
-
this.isInitialized = true;
|
|
66
|
-
console.clear();
|
|
67
|
-
this.render();
|
|
68
|
-
}
|
|
69
|
-
addLog(entry) {
|
|
70
|
-
this.logs.push(entry);
|
|
71
|
-
if (this.logs.length > this.maxLogs) {
|
|
72
|
-
this.logs = this.logs.slice(-this.maxLogs);
|
|
73
|
-
}
|
|
74
|
-
// Обновляем только если таб инициализирован
|
|
75
|
-
if (this.isInitialized) {
|
|
76
|
-
this.render();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
destroy() {
|
|
80
|
-
if (process.stdin.isTTY) {
|
|
81
|
-
process.stdin.setRawMode(false);
|
|
82
|
-
}
|
|
83
|
-
this.rl.close();
|
|
84
|
-
}
|
|
85
|
-
setupKeyHandlers() {
|
|
86
|
-
if (process.stdin.isTTY) {
|
|
87
|
-
process.stdin.setRawMode(true);
|
|
88
|
-
process.stdin.setEncoding('utf8');
|
|
89
|
-
process.stdin.on('data', (key) => {
|
|
90
|
-
// Ctrl+C
|
|
91
|
-
if (key === '\u0003') {
|
|
92
|
-
process.exit();
|
|
93
|
-
}
|
|
94
|
-
switch (key) {
|
|
95
|
-
case '\u001b[D': // Стрелка влево
|
|
96
|
-
case 'h':
|
|
97
|
-
this.activeTab = this.activeTab > 0 ? this.activeTab - 1 : tabs.length - 1;
|
|
98
|
-
this.render();
|
|
99
|
-
break;
|
|
100
|
-
case '\u001b[C': // Стрелка вправо
|
|
101
|
-
case 'l':
|
|
102
|
-
this.activeTab = this.activeTab < tabs.length - 1 ? this.activeTab + 1 : 0;
|
|
103
|
-
this.render();
|
|
104
|
-
break;
|
|
105
|
-
case 'c':
|
|
106
|
-
this.clearLogs();
|
|
107
|
-
break;
|
|
108
|
-
case 'q':
|
|
109
|
-
process.exit();
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
clearLogs() {
|
|
116
|
-
this.logs = [];
|
|
117
|
-
this.render();
|
|
118
|
-
}
|
|
119
|
-
render() {
|
|
120
|
-
if (!process.stdout.isTTY)
|
|
121
|
-
return;
|
|
122
|
-
// Очищаем экран
|
|
123
|
-
console.clear();
|
|
124
|
-
// Рендерим табы
|
|
125
|
-
this.renderTabs();
|
|
126
|
-
// Рендерим логи для активного таба
|
|
127
|
-
this.renderLogs();
|
|
128
|
-
// Рендерим справку
|
|
129
|
-
this.renderHelp();
|
|
130
|
-
}
|
|
131
|
-
renderTabs() {
|
|
132
|
-
let tabsLine = '';
|
|
133
|
-
tabs.forEach((tab, index) => {
|
|
134
|
-
const isActive = index === this.activeTab;
|
|
135
|
-
const title = ` ${tab.title} `;
|
|
136
|
-
if (isActive) {
|
|
137
|
-
tabsLine += `${ansi.cyan}${ansi.bold}${ansi.bgBlue}${title}${ansi.reset}`;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
tabsLine += `${ansi.white}${title}${ansi.reset}`;
|
|
141
|
-
}
|
|
142
|
-
tabsLine += ' ';
|
|
143
|
-
});
|
|
144
|
-
console.log(tabsLine);
|
|
145
|
-
console.log(`${ansi.dim}${'─'.repeat(process.stdout.columns || 80)}${ansi.reset}`);
|
|
146
|
-
}
|
|
147
|
-
renderLogs() {
|
|
148
|
-
const currentTab = tabs[this.activeTab];
|
|
149
|
-
if (!currentTab)
|
|
150
|
-
return;
|
|
151
|
-
const filteredLogs = this.logs.filter(currentTab.filter);
|
|
152
|
-
const displayLogs = filteredLogs.slice(-40); // Показываем последние 40 логов
|
|
153
|
-
displayLogs.forEach((log) => {
|
|
154
|
-
console.log(this.formatLogMessage(log));
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
formatLogMessage(log) {
|
|
158
|
-
const timestamp = new Date(log.timestamp).toLocaleTimeString();
|
|
159
|
-
const prefix = `${ansi.dim}[${timestamp}] ${ansi.reset}`;
|
|
160
|
-
let colorCode = ansi.white;
|
|
161
|
-
switch (log.level) {
|
|
162
|
-
case 'success':
|
|
163
|
-
colorCode = ansi.green;
|
|
164
|
-
break;
|
|
165
|
-
case 'warning':
|
|
166
|
-
colorCode = ansi.yellow;
|
|
167
|
-
break;
|
|
168
|
-
case 'error':
|
|
169
|
-
colorCode = ansi.red;
|
|
170
|
-
break;
|
|
171
|
-
case 'verbose':
|
|
172
|
-
colorCode = ansi.dim;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
return `${prefix}${colorCode}${log.message}${ansi.reset}`;
|
|
176
|
-
}
|
|
177
|
-
renderHelp() {
|
|
178
|
-
const filteredCount = this.logs.filter(tabs[this.activeTab]?.filter || (() => true)).length;
|
|
179
|
-
const help = `${ansi.dim}\nУправление: ← → (или h/l) - переключение табов | c - очистить | q - выход | Показано: ${filteredCount} логов${ansi.reset}`;
|
|
180
|
-
console.log(help);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.TerminalTabs = TerminalTabs;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const TerminalTabs_1 = require("./TerminalTabs");
|
|
5
|
-
const tabs = new TerminalTabs_1.TerminalTabs();
|
|
6
|
-
// Инициализируем интерфейс табов
|
|
7
|
-
tabs.initialize();
|
|
8
|
-
// Симулируем логи от сервера и клиента
|
|
9
|
-
let logCounter = 0;
|
|
10
|
-
const addServerLog = () => {
|
|
11
|
-
tabs.addLog({
|
|
12
|
-
type: 'server',
|
|
13
|
-
message: `Server log message ${++logCounter}`,
|
|
14
|
-
timestamp: Date.now(),
|
|
15
|
-
level: Math.random() > 0.7 ? 'success' : 'message',
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
const addClientLog = () => {
|
|
19
|
-
tabs.addLog({
|
|
20
|
-
type: 'client',
|
|
21
|
-
message: `Client build progress ${++logCounter}`,
|
|
22
|
-
timestamp: Date.now(),
|
|
23
|
-
level: Math.random() > 0.8 ? 'warning' : 'message',
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const addErrorLog = () => {
|
|
27
|
-
const type = Math.random() > 0.5 ? 'server' : 'client';
|
|
28
|
-
tabs.addLog({
|
|
29
|
-
type,
|
|
30
|
-
message: `Error in ${type}: Something went wrong ${++logCounter}`,
|
|
31
|
-
timestamp: Date.now(),
|
|
32
|
-
level: 'error',
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
// Добавляем начальные логи
|
|
36
|
-
tabs.addLog({
|
|
37
|
-
type: 'all',
|
|
38
|
-
message: 'Демонстрация системы табов запущена',
|
|
39
|
-
timestamp: Date.now(),
|
|
40
|
-
level: 'success',
|
|
41
|
-
});
|
|
42
|
-
// Симулируем активность
|
|
43
|
-
setInterval(() => {
|
|
44
|
-
const rand = Math.random();
|
|
45
|
-
if (rand > 0.7) {
|
|
46
|
-
addServerLog();
|
|
47
|
-
}
|
|
48
|
-
else if (rand > 0.4) {
|
|
49
|
-
addClientLog();
|
|
50
|
-
}
|
|
51
|
-
else if (rand > 0.9) {
|
|
52
|
-
addErrorLog();
|
|
53
|
-
}
|
|
54
|
-
}, 500);
|
|
55
|
-
// Обработка выхода
|
|
56
|
-
process.on('SIGINT', () => {
|
|
57
|
-
tabs.destroy();
|
|
58
|
-
console.log('\nДемонстрация завершена');
|
|
59
|
-
process.exit(0);
|
|
60
|
-
});
|
|
61
|
-
console.log('Нажмите Ctrl+C для выхода, стрелки влево/вправо для переключения табов, c для очистки');
|