@tonk/cli 0.2.5 → 0.2.6
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/dist/commands/worker/commands.d.ts +42 -0
- package/dist/commands/worker/commands.d.ts.map +1 -0
- package/dist/commands/worker/commands.js +580 -0
- package/dist/commands/worker/commands.js.map +1 -0
- package/dist/commands/worker/index.d.ts +7 -0
- package/dist/commands/worker/index.d.ts.map +1 -0
- package/dist/commands/worker/index.js +28 -0
- package/dist/commands/worker/index.js.map +1 -0
- package/dist/commands/worker/utils/config.d.ts +26 -0
- package/dist/commands/worker/utils/config.d.ts.map +1 -0
- package/dist/commands/worker/utils/config.js +197 -0
- package/dist/commands/worker/utils/config.js.map +1 -0
- package/dist/commands/worker/utils/display.d.ts +6 -0
- package/dist/commands/worker/utils/display.d.ts.map +1 -0
- package/dist/commands/worker/utils/display.js +32 -0
- package/dist/commands/worker/utils/display.js.map +1 -0
- package/dist/commands/worker/utils/finder.d.ts +12 -0
- package/dist/commands/worker/utils/finder.d.ts.map +1 -0
- package/dist/commands/worker/utils/finder.js +60 -0
- package/dist/commands/worker/utils/finder.js.map +1 -0
- package/dist/lib/workerManager.d.ts +60 -0
- package/dist/lib/workerManager.d.ts.map +1 -0
- package/dist/lib/workerManager.js +426 -0
- package/dist/lib/workerManager.js.map +1 -0
- package/dist/tonk.js +2 -0
- package/dist/tonk.js.map +1 -1
- package/dist/types/worker.d.ts +102 -0
- package/dist/types/worker.d.ts.map +1 -0
- package/dist/types/worker.js +7 -0
- package/dist/types/worker.js.map +1 -0
- package/dist/types/workerConfig.d.ts +164 -0
- package/dist/types/workerConfig.d.ts.map +1 -0
- package/dist/types/workerConfig.js +80 -0
- package/dist/types/workerConfig.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAclC;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAqB7C;AAGD,eAAO,MAAM,aAAa,SAAwB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { registerInspectCommand, registerListCommand, registerRemoveCommand, registerPingCommand, registerStartCommand, registerStopCommand, registerLogsCommand, registerRegisterCommand, registerInstallCommand, registerInitCommand, } from './commands.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create and configure the worker command
|
|
5
|
+
*/
|
|
6
|
+
export function createWorkerCommand() {
|
|
7
|
+
const workerCommand = new Command('worker')
|
|
8
|
+
.description('Manage Tonk workers')
|
|
9
|
+
.action(async () => {
|
|
10
|
+
// Display help when no subcommand is provided
|
|
11
|
+
workerCommand.help();
|
|
12
|
+
});
|
|
13
|
+
// Register all subcommands
|
|
14
|
+
registerInspectCommand(workerCommand);
|
|
15
|
+
registerListCommand(workerCommand);
|
|
16
|
+
registerRemoveCommand(workerCommand);
|
|
17
|
+
registerPingCommand(workerCommand);
|
|
18
|
+
registerStartCommand(workerCommand);
|
|
19
|
+
registerStopCommand(workerCommand);
|
|
20
|
+
registerLogsCommand(workerCommand);
|
|
21
|
+
registerRegisterCommand(workerCommand);
|
|
22
|
+
registerInstallCommand(workerCommand);
|
|
23
|
+
registerInitCommand(workerCommand);
|
|
24
|
+
return workerCommand;
|
|
25
|
+
}
|
|
26
|
+
// Export the worker command
|
|
27
|
+
export const workerCommand = createWorkerCommand();
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;SACxC,WAAW,CAAC,qBAAqB,CAAC;SAClC,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,8CAA8C;QAC9C,aAAa,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEL,2BAA2B;IAC3B,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACtC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACnC,qBAAqB,CAAC,aAAa,CAAC,CAAC;IACrC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACnC,oBAAoB,CAAC,aAAa,CAAC,CAAC;IACpC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACnC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACnC,uBAAuB,CAAC,aAAa,CAAC,CAAC;IACvC,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACtC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAEnC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TonkWorkerManager } from '../../../lib/workerManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read and parse the package.json file
|
|
4
|
+
*/
|
|
5
|
+
export declare function readPackageJson(packageJsonPath: string): Promise<any | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Read and parse the worker.config.js file
|
|
8
|
+
*/
|
|
9
|
+
export declare function readWorkerConfigJs(configPath: string): Promise<any | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Generate package.json content for a worker
|
|
12
|
+
*/
|
|
13
|
+
export declare function generatePackageJsonContent(options: any): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate worker.config.js content
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateWorkerConfigJsContent(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to update worker configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateWorkerConfig(workerManager: TonkWorkerManager, id: string, configPath: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Helper function to prompt for missing options (for init command)
|
|
24
|
+
*/
|
|
25
|
+
export declare function promptForMissingOptions(options: any): Promise<any>;
|
|
26
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/commands/worker/utils/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAEhE;;GAEG;AACH,wBAAsB,eAAe,CACnC,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAYrB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAarB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CA8B/D;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,CA2DtD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,iBAAiB,EAChC,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAwCf;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,GAAG,gBAkCzD"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
/**
|
|
5
|
+
* Read and parse the package.json file
|
|
6
|
+
*/
|
|
7
|
+
export async function readPackageJson(packageJsonPath) {
|
|
8
|
+
try {
|
|
9
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const fileContent = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
13
|
+
return JSON.parse(fileContent);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error('Error reading package.json:', error);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read and parse the worker.config.js file
|
|
22
|
+
*/
|
|
23
|
+
export async function readWorkerConfigJs(configPath) {
|
|
24
|
+
try {
|
|
25
|
+
if (!fs.existsSync(configPath)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// For JavaScript files, we can use dynamic import
|
|
29
|
+
const configModule = await import(`file://${configPath}`);
|
|
30
|
+
return configModule.default || configModule;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error('Error reading worker.config.js:', error);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generate package.json content for a worker
|
|
39
|
+
*/
|
|
40
|
+
export function generatePackageJsonContent(options) {
|
|
41
|
+
const name = options.name || 'tonk-worker';
|
|
42
|
+
const description = options.description || 'A Tonk worker';
|
|
43
|
+
return JSON.stringify({
|
|
44
|
+
name,
|
|
45
|
+
version: '1.0.0',
|
|
46
|
+
description,
|
|
47
|
+
main: 'dist/index.js',
|
|
48
|
+
bin: {
|
|
49
|
+
[name]: 'dist/cli.js',
|
|
50
|
+
},
|
|
51
|
+
scripts: {
|
|
52
|
+
start: 'node dist/index.js',
|
|
53
|
+
build: 'tsc',
|
|
54
|
+
dev: 'ts-node src/index.ts',
|
|
55
|
+
},
|
|
56
|
+
dependencies: {
|
|
57
|
+
'@tonk/worker': '^0.1.0',
|
|
58
|
+
},
|
|
59
|
+
devDependencies: {
|
|
60
|
+
typescript: '^5.0.0',
|
|
61
|
+
'ts-node': '^10.9.1',
|
|
62
|
+
'@types/node': '^18.0.0',
|
|
63
|
+
},
|
|
64
|
+
}, null, 2);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generate worker.config.js content
|
|
68
|
+
*/
|
|
69
|
+
export function generateWorkerConfigJsContent() {
|
|
70
|
+
return `/**
|
|
71
|
+
* Tonk Worker Configuration
|
|
72
|
+
*/
|
|
73
|
+
module.exports = {
|
|
74
|
+
// Runtime configuration
|
|
75
|
+
runtime: {
|
|
76
|
+
port: {{port}},
|
|
77
|
+
healthCheck: {
|
|
78
|
+
endpoint: '/health',
|
|
79
|
+
method: 'GET',
|
|
80
|
+
interval: 30000,
|
|
81
|
+
timeout: 5000,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// Process management
|
|
86
|
+
process: {
|
|
87
|
+
script: './dist/cli.js',
|
|
88
|
+
cwd: './',
|
|
89
|
+
instances: 1,
|
|
90
|
+
autorestart: true,
|
|
91
|
+
watch: false,
|
|
92
|
+
max_memory_restart: '500M',
|
|
93
|
+
env: {
|
|
94
|
+
NODE_ENV: 'production',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// CLI configuration
|
|
99
|
+
cli: {
|
|
100
|
+
script: './dist/cli.js',
|
|
101
|
+
command: 'start',
|
|
102
|
+
args: ['--port', '{{port}}'],
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Data schema
|
|
106
|
+
// This section defines the schemas for data stored in keepsync
|
|
107
|
+
// Can be used to validate data before storing it
|
|
108
|
+
schemas: {
|
|
109
|
+
// Define schemas for different document types
|
|
110
|
+
documents: {
|
|
111
|
+
// Main document schema
|
|
112
|
+
default: {},
|
|
113
|
+
|
|
114
|
+
// Additional document types can be defined here
|
|
115
|
+
// For example:
|
|
116
|
+
//
|
|
117
|
+
// specialDocument: {
|
|
118
|
+
// type: "object",
|
|
119
|
+
// properties: { ... }
|
|
120
|
+
// }
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// Additional configuration
|
|
125
|
+
config: {},
|
|
126
|
+
};
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Helper function to update worker configuration
|
|
131
|
+
*/
|
|
132
|
+
export async function updateWorkerConfig(workerManager, id, configPath) {
|
|
133
|
+
try {
|
|
134
|
+
// Check if config file exists
|
|
135
|
+
if (!fs.existsSync(configPath)) {
|
|
136
|
+
console.error(chalk.red(`Configuration file not found: ${configPath}`));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Read config file
|
|
140
|
+
const configContent = fs.readFileSync(configPath, 'utf-8');
|
|
141
|
+
let config;
|
|
142
|
+
try {
|
|
143
|
+
config = JSON.parse(configContent);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(chalk.red('Invalid JSON in configuration file:'), error);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Get worker
|
|
150
|
+
const worker = await workerManager.get(id);
|
|
151
|
+
if (!worker) {
|
|
152
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Update worker config
|
|
156
|
+
await workerManager.update(id, {
|
|
157
|
+
config: { ...worker.config, ...config },
|
|
158
|
+
});
|
|
159
|
+
console.log(chalk.green(`Worker '${worker.name}' configuration updated successfully!`));
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error(chalk.red('Failed to update worker configuration:'), error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Helper function to prompt for missing options (for init command)
|
|
167
|
+
*/
|
|
168
|
+
export async function promptForMissingOptions(options) {
|
|
169
|
+
const questions = [];
|
|
170
|
+
if (!options.name) {
|
|
171
|
+
questions.push({
|
|
172
|
+
type: 'input',
|
|
173
|
+
name: 'name',
|
|
174
|
+
message: 'Enter worker name:',
|
|
175
|
+
validate: (input) => input.trim() !== '' ? true : 'Name is required',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (!options.description) {
|
|
179
|
+
questions.push({
|
|
180
|
+
type: 'input',
|
|
181
|
+
name: 'description',
|
|
182
|
+
message: 'Enter worker description:',
|
|
183
|
+
default: 'A Tonk worker',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (!options.port) {
|
|
187
|
+
questions.push({
|
|
188
|
+
type: 'input',
|
|
189
|
+
name: 'port',
|
|
190
|
+
message: 'Enter port number for the worker:',
|
|
191
|
+
default: '5555',
|
|
192
|
+
validate: (input) => /^\d+$/.test(input) ? true : 'Port must be a number',
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return inquirer.prompt(questions);
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/commands/worker/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,eAAuB;IAEvB,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;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/worker/utils/display.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAEhD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA4CzD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
/**
|
|
3
|
+
* Display detailed information about a worker
|
|
4
|
+
*/
|
|
5
|
+
export function displayWorkerDetails(worker) {
|
|
6
|
+
console.log(chalk.bold(`Worker Details: ${worker.name}`));
|
|
7
|
+
console.log(chalk.cyan('ID:'), worker.id);
|
|
8
|
+
console.log(chalk.cyan('Name:'), worker.name);
|
|
9
|
+
console.log(chalk.cyan('Description:'), worker.description || '(No description)');
|
|
10
|
+
console.log(chalk.cyan('Endpoint:'), worker.endpoint);
|
|
11
|
+
console.log(chalk.cyan('Protocol:'), worker.protocol);
|
|
12
|
+
console.log(chalk.cyan('Status:'), worker.status.active ? chalk.green('Active') : chalk.yellow('Inactive'));
|
|
13
|
+
if (worker.status.lastSeen) {
|
|
14
|
+
console.log(chalk.cyan('Last Seen:'), new Date(worker.status.lastSeen).toLocaleString());
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
console.log(chalk.cyan('Last Seen:'), 'Never');
|
|
18
|
+
}
|
|
19
|
+
console.log(chalk.cyan('Created:'), new Date(worker.createdAt).toLocaleString());
|
|
20
|
+
console.log(chalk.cyan('Updated:'), new Date(worker.updatedAt).toLocaleString());
|
|
21
|
+
if (Object.keys(worker.env).length > 0) {
|
|
22
|
+
console.log(chalk.cyan('\nEnvironment Variables:'));
|
|
23
|
+
Object.entries(worker.env).forEach(([key, value]) => {
|
|
24
|
+
console.log(` ${key}=${value}`);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (Object.keys(worker.config).length > 0) {
|
|
28
|
+
console.log(chalk.cyan('\nConfiguration:'));
|
|
29
|
+
console.log(JSON.stringify(worker.config, null, 2));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../../../src/commands/worker/utils/display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,EAC1B,MAAM,CAAC,WAAW,IAAI,kBAAkB,CACzC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CACxE,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,IAAI,CAAC,YAAY,C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|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the worker root directory by looking for package.json and worker.config.js
|
|
3
|
+
* Searches in the given directory and parent directories
|
|
4
|
+
*/
|
|
5
|
+
export declare function findWorkerRoot(startDir: string): Promise<string | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Find an available port starting from the given port number
|
|
8
|
+
* @param startPort The port to start checking from
|
|
9
|
+
* @returns A promise that resolves to an available port
|
|
10
|
+
*/
|
|
11
|
+
export declare function findAvailablePort(startPort: number): Promise<number>;
|
|
12
|
+
//# sourceMappingURL=finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../../../../src/commands/worker/utils/finder.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA+B7E;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB1E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
/**
|
|
5
|
+
* Find the worker root directory by looking for package.json and worker.config.js
|
|
6
|
+
* Searches in the given directory and parent directories
|
|
7
|
+
*/
|
|
8
|
+
export async function findWorkerRoot(startDir) {
|
|
9
|
+
try {
|
|
10
|
+
let currentDir = path.resolve(startDir);
|
|
11
|
+
const rootDir = path.parse(currentDir).root;
|
|
12
|
+
// Search up to the root directory
|
|
13
|
+
while (currentDir !== rootDir) {
|
|
14
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
15
|
+
const workerConfigPath = path.join(currentDir, 'worker.config.js');
|
|
16
|
+
// Check if both files exist
|
|
17
|
+
if (fs.existsSync(packageJsonPath) && fs.existsSync(workerConfigPath)) {
|
|
18
|
+
return currentDir;
|
|
19
|
+
}
|
|
20
|
+
// Move up one directory
|
|
21
|
+
const parentDir = path.dirname(currentDir);
|
|
22
|
+
// If we've reached the root, stop searching
|
|
23
|
+
if (parentDir === currentDir) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
currentDir = parentDir;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Error finding worker root:', error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Find an available port starting from the given port number
|
|
37
|
+
* @param startPort The port to start checking from
|
|
38
|
+
* @returns A promise that resolves to an available port
|
|
39
|
+
*/
|
|
40
|
+
export async function findAvailablePort(startPort) {
|
|
41
|
+
let port = startPort;
|
|
42
|
+
const isPortAvailable = (port) => {
|
|
43
|
+
return new Promise(resolve => {
|
|
44
|
+
const server = net.createServer();
|
|
45
|
+
server.once('error', () => {
|
|
46
|
+
resolve(false);
|
|
47
|
+
});
|
|
48
|
+
server.once('listening', () => {
|
|
49
|
+
server.close();
|
|
50
|
+
resolve(true);
|
|
51
|
+
});
|
|
52
|
+
server.listen(port);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
while (!(await isPortAvailable(port))) {
|
|
56
|
+
port++;
|
|
57
|
+
}
|
|
58
|
+
return port;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=finder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finder.js","sourceRoot":"","sources":["../../../../src/commands/worker/utils/finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,IAAI,CAAC;QACH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AC,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;gBAC5B,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CAAC,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACtC,IAAI,EAAE,CAAC;IACT,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Worker, WorkerManager, WorkerRegistrationOptions } from '../types/worker.js';
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of the WorkerManager interface
|
|
4
|
+
*/
|
|
5
|
+
export declare class TonkWorkerManager implements WorkerManager {
|
|
6
|
+
private workersPath;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Register a new worker
|
|
10
|
+
*/
|
|
11
|
+
register(options: WorkerRegistrationOptions): Promise<Worker>;
|
|
12
|
+
/**
|
|
13
|
+
* Register a worker from a YAML configuration file
|
|
14
|
+
*/
|
|
15
|
+
registerFromYamlConfig(yamlConfig: any): Promise<Worker>;
|
|
16
|
+
/**
|
|
17
|
+
* Get a worker by ID
|
|
18
|
+
*/
|
|
19
|
+
get(id: string): Promise<Worker | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Find a worker by name or ID
|
|
22
|
+
* If the identifier matches an ID exactly, returns that worker
|
|
23
|
+
* Otherwise, searches for a worker with a matching name
|
|
24
|
+
*/
|
|
25
|
+
findByNameOrId(identifier: string): Promise<Worker | null>;
|
|
26
|
+
/**
|
|
27
|
+
* List all registered workers
|
|
28
|
+
*/
|
|
29
|
+
list(): Promise<Worker[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Update a worker
|
|
32
|
+
*/
|
|
33
|
+
update(id: string, updates: Partial<Worker>): Promise<Worker>;
|
|
34
|
+
/**
|
|
35
|
+
* Remove a worker
|
|
36
|
+
*/
|
|
37
|
+
remove(id: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Start a worker
|
|
40
|
+
* @param id Worker ID to start
|
|
41
|
+
*/
|
|
42
|
+
start(id: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Stop a worker
|
|
45
|
+
*/
|
|
46
|
+
stop(id: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Check worker health
|
|
49
|
+
*/
|
|
50
|
+
checkHealth(id: string): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Generate a worker ID
|
|
53
|
+
*/
|
|
54
|
+
private generateWorkerId;
|
|
55
|
+
/**
|
|
56
|
+
* Perform HTTP health check
|
|
57
|
+
*/
|
|
58
|
+
private httpHealthCheck;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=workerManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerManager.d.ts","sourceRoot":"","sources":["../../src/lib/workerManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,MAAM,EACN,aAAa,EACb,yBAAyB,EAC1B,MAAM,oBAAoB,CAAC;AAM5B;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,WAAW,CAAS;;IAc5B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IA8CnE;;OAEG;IACG,sBAAsB,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAiC9D;;OAEG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW7C;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAA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