@julianpoemp/node-service 0.1.5 → 1.0.0
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/CHANGELOG.md +87 -67
- package/README.md +140 -140
- package/package.json +4 -3
- package/src/lib/functions.js +1 -1
- package/src/lib/functions.js.map +1 -1
- package/src/lib/os-service-manager.d.ts +3 -2
- package/src/lib/os-service-manager.js.map +1 -1
- package/src/lib/windows-service-manager.d.ts +2 -2
- package/src/lib/windows-service-manager.js +59 -102
- package/src/lib/windows-service-manager.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,77 +2,97 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# [1.0.0](https://github.com/julianpoemp/node-service/compare/node-service-0.1.5...node-service-1.0.0) (2026-06-02)
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
###
|
|
8
|
+
### deps
|
|
9
9
|
|
|
10
|
-
* **
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [0.1.4](https://github.com/julianpoemp/node-service/compare/node-service-0.1.3...node-service-0.1.4) (2024-08-06)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## [0.1.3](https://github.com/julianpoemp/node-service/compare/node-service-0.1.2...node-service-0.1.3) (2024-08-06)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### Bug Fixes
|
|
22
|
-
|
|
23
|
-
* **node-service:** requesting admin privileges not working on headless macos/linux ([92328c9](https://github.com/julianpoemp/node-service/commit/92328c90abe8c1f5f0fe233471fe96f4b08b8ac5))
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## [0.1.2](https://github.com/julianpoemp/node-service/compare/node-service-0.1.1...node-service-0.1.2) (2024-08-01)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### Bug Fixes
|
|
31
|
-
|
|
32
|
-
* **node-service:** process exits when readline used ([30cbeff](https://github.com/julianpoemp/node-service/commit/30cbeffa0e2bb98b04bf94b4cd3693f83d519ef2))
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
## [0.1.1](https://github.com/julianpoemp/node-service/compare/node-service-0.1.0...node-service-0.1.1) (2024-07-30)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# [0.1.0](https://github.com/julianpoemp/node-service/compare/node-service-0.0.1...node-service-0.1.0) (2024-07-30)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
## 0.0.1 (2024-07-30)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Bug Fixes
|
|
48
|
-
|
|
49
|
-
* **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
|
|
50
|
-
* **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
### Features
|
|
54
|
-
|
|
55
|
-
* **node-service:** macos service manager can now install user or system services ([acf19a5](https://github.com/julianpoemp/node-service/commit/acf19a57037831e8a8fa5bea7d0fb9eef815b728))
|
|
56
|
-
* **node-service:** os service management on macos ([651def8](https://github.com/julianpoemp/node-service/commit/651def8dcc11732849ee346a15b7113cebebddad))
|
|
57
|
-
* **node-service:** service manager implementation for linux ([8f406c1](https://github.com/julianpoemp/node-service/commit/8f406c14858de3498445529a4638d7ef35a61cf4))
|
|
58
|
-
* **node-windows:** implementation for windows ([fbb35d1](https://github.com/julianpoemp/node-service/commit/fbb35d19d0b142a013fc1ee0150f4446dc7ef288))
|
|
59
|
-
* **node-windows:** re-implementation for windows using winsw ([99ece41](https://github.com/julianpoemp/node-service/commit/99ece4153b779f404396af2286706cd1d846945b))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# 0.1.0 (2024-07-30)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Bug Fixes
|
|
67
|
-
|
|
68
|
-
* **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
|
|
69
|
-
* **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
|
|
10
|
+
* **node-service:** change peer dependency ([98b3630](https://github.com/julianpoemp/node-service/commit/98b3630e9ae425877bb975ece131756f37032cff))
|
|
70
11
|
|
|
71
12
|
|
|
72
13
|
### Features
|
|
73
14
|
|
|
74
|
-
* **node-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
15
|
+
* **node-windows:** replace winsw with servy ([46e1e48](https://github.com/julianpoemp/node-service/commit/46e1e48400fe1c638c014b685695690978680dec))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* **node-service:** sudo-prompt was replaced by @vscode/sudo-prompt
|
|
21
|
+
* **node-windows:** Winsw was replaced by servy, so the options related to winsw.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [0.1.5](https://github.com/julianpoemp/node-service/compare/node-service-0.1.4...node-service-0.1.5) (2024-08-07)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **windows-service:** installation not working if path to winsw config does not exit ([6394471](https://github.com/julianpoemp/node-service/commit/63944718482a20c4bb6dc289f15b91e2df51465f))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [0.1.4](https://github.com/julianpoemp/node-service/compare/node-service-0.1.3...node-service-0.1.4) (2024-08-06)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## [0.1.3](https://github.com/julianpoemp/node-service/compare/node-service-0.1.2...node-service-0.1.3) (2024-08-06)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **node-service:** requesting admin privileges not working on headless macos/linux ([92328c9](https://github.com/julianpoemp/node-service/commit/92328c90abe8c1f5f0fe233471fe96f4b08b8ac5))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## [0.1.2](https://github.com/julianpoemp/node-service/compare/node-service-0.1.1...node-service-0.1.2) (2024-08-01)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Bug Fixes
|
|
51
|
+
|
|
52
|
+
* **node-service:** process exits when readline used ([30cbeff](https://github.com/julianpoemp/node-service/commit/30cbeffa0e2bb98b04bf94b4cd3693f83d519ef2))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## [0.1.1](https://github.com/julianpoemp/node-service/compare/node-service-0.1.0...node-service-0.1.1) (2024-07-30)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# [0.1.0](https://github.com/julianpoemp/node-service/compare/node-service-0.0.1...node-service-0.1.0) (2024-07-30)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## 0.0.1 (2024-07-30)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Bug Fixes
|
|
68
|
+
|
|
69
|
+
* **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
|
|
70
|
+
* **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Features
|
|
74
|
+
|
|
75
|
+
* **node-service:** macos service manager can now install user or system services ([acf19a5](https://github.com/julianpoemp/node-service/commit/acf19a57037831e8a8fa5bea7d0fb9eef815b728))
|
|
76
|
+
* **node-service:** os service management on macos ([651def8](https://github.com/julianpoemp/node-service/commit/651def8dcc11732849ee346a15b7113cebebddad))
|
|
77
|
+
* **node-service:** service manager implementation for linux ([8f406c1](https://github.com/julianpoemp/node-service/commit/8f406c14858de3498445529a4638d7ef35a61cf4))
|
|
78
|
+
* **node-windows:** implementation for windows ([fbb35d1](https://github.com/julianpoemp/node-service/commit/fbb35d19d0b142a013fc1ee0150f4446dc7ef288))
|
|
79
|
+
* **node-windows:** re-implementation for windows using winsw ([99ece41](https://github.com/julianpoemp/node-service/commit/99ece4153b779f404396af2286706cd1d846945b))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# 0.1.0 (2024-07-30)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Bug Fixes
|
|
87
|
+
|
|
88
|
+
* **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
|
|
89
|
+
* **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
|
|
94
|
+
* **node-service:** macos service manager can now install user or system services ([acf19a5](https://github.com/julianpoemp/node-service/commit/acf19a57037831e8a8fa5bea7d0fb9eef815b728))
|
|
95
|
+
* **node-service:** os service management on macos ([651def8](https://github.com/julianpoemp/node-service/commit/651def8dcc11732849ee346a15b7113cebebddad))
|
|
96
|
+
* **node-service:** service manager implementation for linux ([8f406c1](https://github.com/julianpoemp/node-service/commit/8f406c14858de3498445529a4638d7ef35a61cf4))
|
|
97
|
+
* **node-windows:** implementation for windows ([fbb35d1](https://github.com/julianpoemp/node-service/commit/fbb35d19d0b142a013fc1ee0150f4446dc7ef288))
|
|
98
|
+
* **node-windows:** re-implementation for windows using winsw ([99ece41](https://github.com/julianpoemp/node-service/commit/99ece4153b779f404396af2286706cd1d846945b))
|
package/README.md
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
<h1>node-service <a href="https://www.npmjs.com/package/@julianpoemp/node-service?activeTab=readme"><img alt="NPM Version" src="https://img.shields.io/npm/v/@julianpoemp/node-service"></a></h1>
|
|
2
|
-
|
|
3
|
-
This NodeJS library allows to easily install and control OS background services on Windows, MacOS and Linux using shell commands. Uses [sudo-prompt](https://github.com/jorangreef/sudo-prompt) to request on desktop and "sudo" only on headless servers.
|
|
4
|
-
|
|
5
|
-
## Goal
|
|
6
|
-
The goal of this repository is to simplify the creation and management of OS services using NodeJS.
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
|
|
10
|
-
- One configuration for all OS services: Windows, MacOS, Linux
|
|
11
|
-
- Supported functions: installation/uninstallation, start, stop, status
|
|
12
|
-
- Supported scopes: "system" (user asked for admin privileges) or "user"
|
|
13
|
-
- Option "headless" for headless servers (Linux, MacOS only)
|
|
14
|
-
- TS typings
|
|
15
|
-
- Async functions
|
|
16
|
-
|
|
17
|
-
## Disclaimer
|
|
18
|
-
|
|
19
|
-
This project is in an early development stage. There may be bugs or missing features. Currently this package doesn't parse existing service config files (e.g. on Linux).
|
|
20
|
-
|
|
21
|
-
## Requirements
|
|
22
|
-
|
|
23
|
-
- Windows: If you plan to use this library for windows, make sure that winsw is installed on the user's machine. You can add a winsw.exe binary to your application and define the path to that file in the options.
|
|
24
|
-
- MacOS: Make sure, that the plist package is installed: `npm install plist`
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
Make sure that sudo-prompt is installed:
|
|
29
|
-
|
|
30
|
-
```shell
|
|
31
|
-
npm install sudo-prompt
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
```shell
|
|
35
|
-
npm install @julianpoemp/node-service
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
On macOS targets "plist" is needed:
|
|
39
|
-
|
|
40
|
-
```shell
|
|
41
|
-
npm install plist
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Example
|
|
45
|
-
|
|
46
|
-
````javascript
|
|
47
|
-
import {initializeOSService} from 'node-service';
|
|
48
|
-
import {join, resolve} from 'path';
|
|
49
|
-
|
|
50
|
-
async function wait(seconds: number) {
|
|
51
|
-
return new Promise((resolve) => {
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
resolve();
|
|
54
|
-
}, 1000 * seconds)
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function main() {
|
|
59
|
-
const manager = await initializeOSService({
|
|
60
|
-
name: 'Hello World Service Example',
|
|
61
|
-
level: 'system',
|
|
62
|
-
slug: 'hello-world',
|
|
63
|
-
windows: {
|
|
64
|
-
pathToWinswConfig: resolve(join("data", "winsw.xml"))
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
console.log("UNINSTALL!");
|
|
69
|
-
await manager.uninstall();
|
|
70
|
-
|
|
71
|
-
if (manager.status === 'not_installed') {
|
|
72
|
-
console.log('Install...');
|
|
73
|
-
const args: string[] = [
|
|
74
|
-
"node"
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
await manager.install(resolve(join("demo", "src", "assets", "hello-world.js")), args, {
|
|
78
|
-
description: "This service just prints 'Hello world' every second.",
|
|
79
|
-
logging: {
|
|
80
|
-
enabled: true
|
|
81
|
-
},
|
|
82
|
-
linux: {
|
|
83
|
-
Unit: {
|
|
84
|
-
After: "network.target",
|
|
85
|
-
StartLimitIntervalSync: 0
|
|
86
|
-
},
|
|
87
|
-
Service: {
|
|
88
|
-
Type: "simple",
|
|
89
|
-
Restart: "always",
|
|
90
|
-
RestartSec: 5
|
|
91
|
-
},
|
|
92
|
-
Install: {
|
|
93
|
-
WantedBy: "multi-user.target"
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
console.log('installed!');
|
|
98
|
-
await manager.start();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
while (true) {
|
|
102
|
-
console.log(`STATUS: ${manager.status}`);
|
|
103
|
-
await manager.updateStatus();
|
|
104
|
-
await wait(1);
|
|
105
|
-
console.log(`STATUS: ${manager.status}`);
|
|
106
|
-
await manager.updateStatus();
|
|
107
|
-
await wait(1);
|
|
108
|
-
console.log(`STAsTUS: ${manager.status}`);
|
|
109
|
-
await manager.updateStatus();
|
|
110
|
-
await wait(1);
|
|
111
|
-
console.log(`STATUS: ${manager.status}`);
|
|
112
|
-
await manager.updateStatus();
|
|
113
|
-
await wait(1);
|
|
114
|
-
console.log(`STATUS: ${manager.status}`);
|
|
115
|
-
await manager.updateStatus();
|
|
116
|
-
await wait(1);
|
|
117
|
-
await manager.stop();
|
|
118
|
-
console.log(`STATUS: ${manager.status}`);
|
|
119
|
-
await manager.updateStatus();
|
|
120
|
-
await wait(1);
|
|
121
|
-
console.log(`STATUS: ${manager.status}`);
|
|
122
|
-
await manager.updateStatus();
|
|
123
|
-
await wait(1);
|
|
124
|
-
console.log(`STATUS: ${manager.status}`);
|
|
125
|
-
await manager.updateStatus();
|
|
126
|
-
await wait(1);
|
|
127
|
-
console.log(`STATUS: ${manager.status}`);
|
|
128
|
-
await manager.updateStatus();
|
|
129
|
-
await wait(1);
|
|
130
|
-
console.log(`STATUS: ${manager.status}`);
|
|
131
|
-
await manager.updateStatus();
|
|
132
|
-
await wait(1);
|
|
133
|
-
await manager.start();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
main().catch((e)=>{
|
|
138
|
-
console.log(e?.message ?? e);
|
|
139
|
-
})
|
|
140
|
-
````
|
|
1
|
+
<h1>node-service <a href="https://www.npmjs.com/package/@julianpoemp/node-service?activeTab=readme"><img alt="NPM Version" src="https://img.shields.io/npm/v/@julianpoemp/node-service"></a></h1>
|
|
2
|
+
|
|
3
|
+
This NodeJS library allows to easily install and control OS background services on Windows, MacOS and Linux using shell commands. Uses [sudo-prompt](https://github.com/jorangreef/sudo-prompt) to request on desktop and "sudo" only on headless servers.
|
|
4
|
+
|
|
5
|
+
## Goal
|
|
6
|
+
The goal of this repository is to simplify the creation and management of OS services using NodeJS.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- One configuration for all OS services: Windows, MacOS, Linux
|
|
11
|
+
- Supported functions: installation/uninstallation, start, stop, status
|
|
12
|
+
- Supported scopes: "system" (user asked for admin privileges) or "user"
|
|
13
|
+
- Option "headless" for headless servers (Linux, MacOS only)
|
|
14
|
+
- TS typings
|
|
15
|
+
- Async functions
|
|
16
|
+
|
|
17
|
+
## Disclaimer
|
|
18
|
+
|
|
19
|
+
This project is in an early development stage. There may be bugs or missing features. Currently this package doesn't parse existing service config files (e.g. on Linux).
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Windows: If you plan to use this library for windows, make sure that winsw is installed on the user's machine. You can add a winsw.exe binary to your application and define the path to that file in the options.
|
|
24
|
+
- MacOS: Make sure, that the plist package is installed: `npm install plist`
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Make sure that sudo-prompt is installed:
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
npm install sudo-prompt
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
npm install @julianpoemp/node-service
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
On macOS targets "plist" is needed:
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
npm install plist
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
````javascript
|
|
47
|
+
import {initializeOSService} from 'node-service';
|
|
48
|
+
import {join, resolve} from 'path';
|
|
49
|
+
|
|
50
|
+
async function wait(seconds: number) {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
resolve();
|
|
54
|
+
}, 1000 * seconds)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
const manager = await initializeOSService({
|
|
60
|
+
name: 'Hello World Service Example',
|
|
61
|
+
level: 'system',
|
|
62
|
+
slug: 'hello-world',
|
|
63
|
+
windows: {
|
|
64
|
+
pathToWinswConfig: resolve(join("data", "winsw.xml"))
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log("UNINSTALL!");
|
|
69
|
+
await manager.uninstall();
|
|
70
|
+
|
|
71
|
+
if (manager.status === 'not_installed') {
|
|
72
|
+
console.log('Install...');
|
|
73
|
+
const args: string[] = [
|
|
74
|
+
"node"
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
await manager.install(resolve(join("demo", "src", "assets", "hello-world.js")), args, {
|
|
78
|
+
description: "This service just prints 'Hello world' every second.",
|
|
79
|
+
logging: {
|
|
80
|
+
enabled: true
|
|
81
|
+
},
|
|
82
|
+
linux: {
|
|
83
|
+
Unit: {
|
|
84
|
+
After: "network.target",
|
|
85
|
+
StartLimitIntervalSync: 0
|
|
86
|
+
},
|
|
87
|
+
Service: {
|
|
88
|
+
Type: "simple",
|
|
89
|
+
Restart: "always",
|
|
90
|
+
RestartSec: 5
|
|
91
|
+
},
|
|
92
|
+
Install: {
|
|
93
|
+
WantedBy: "multi-user.target"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
console.log('installed!');
|
|
98
|
+
await manager.start();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
while (true) {
|
|
102
|
+
console.log(`STATUS: ${manager.status}`);
|
|
103
|
+
await manager.updateStatus();
|
|
104
|
+
await wait(1);
|
|
105
|
+
console.log(`STATUS: ${manager.status}`);
|
|
106
|
+
await manager.updateStatus();
|
|
107
|
+
await wait(1);
|
|
108
|
+
console.log(`STAsTUS: ${manager.status}`);
|
|
109
|
+
await manager.updateStatus();
|
|
110
|
+
await wait(1);
|
|
111
|
+
console.log(`STATUS: ${manager.status}`);
|
|
112
|
+
await manager.updateStatus();
|
|
113
|
+
await wait(1);
|
|
114
|
+
console.log(`STATUS: ${manager.status}`);
|
|
115
|
+
await manager.updateStatus();
|
|
116
|
+
await wait(1);
|
|
117
|
+
await manager.stop();
|
|
118
|
+
console.log(`STATUS: ${manager.status}`);
|
|
119
|
+
await manager.updateStatus();
|
|
120
|
+
await wait(1);
|
|
121
|
+
console.log(`STATUS: ${manager.status}`);
|
|
122
|
+
await manager.updateStatus();
|
|
123
|
+
await wait(1);
|
|
124
|
+
console.log(`STATUS: ${manager.status}`);
|
|
125
|
+
await manager.updateStatus();
|
|
126
|
+
await wait(1);
|
|
127
|
+
console.log(`STATUS: ${manager.status}`);
|
|
128
|
+
await manager.updateStatus();
|
|
129
|
+
await wait(1);
|
|
130
|
+
console.log(`STATUS: ${manager.status}`);
|
|
131
|
+
await manager.updateStatus();
|
|
132
|
+
await wait(1);
|
|
133
|
+
await manager.start();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
main().catch((e)=>{
|
|
138
|
+
console.log(e?.message ?? e);
|
|
139
|
+
})
|
|
140
|
+
````
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@julianpoemp/node-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"sudo-prompt": "^9.2
|
|
5
|
+
"@vscode/sudo-prompt": "^9.3.2"
|
|
6
6
|
},
|
|
7
|
-
"description": "This NodeJS library allows to easily install and control OS services on Windows, MacOS and
|
|
7
|
+
"description": "This NodeJS library allows to easily install and control OS services on Windows, MacOS and Linux using shell commands. Uses sudo-prompt if admin privileges are needed.",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Julian Poemp",
|
|
10
10
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"typescript",
|
|
20
20
|
"javascript"
|
|
21
21
|
],
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
22
23
|
"main": "./src/index.js",
|
|
23
24
|
"type": "commonjs"
|
|
24
25
|
}
|
package/src/lib/functions.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.removeEmptyProperties = removeEmptyProperties;
|
|
|
5
5
|
exports.exists = exists;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
|
-
const SudoPrompt = require("sudo-prompt");
|
|
8
|
+
const SudoPrompt = require("@vscode/sudo-prompt");
|
|
9
9
|
const fs = require("fs");
|
|
10
10
|
const os = require("node:os");
|
|
11
11
|
/**
|
package/src/lib/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;AAUA,sDA+CC;AAgHD,wBAOC;;AAhLD,iDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;AAUA,sDA+CC;AAgHD,wBAOC;;AAhLD,iDAAiD;AACjD,kDAAkD;AAClD,yBAAyB;AACzB,8BAA8B;AAE9B;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,GAAM,EACN,UAII;IACF,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;CACtB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CACzB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,KAAK,SAAS,CAAC;YAC7C,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC;YACnC,CAAC,CAAC,OAAO,CAAC,kBAAkB;gBAC1B,OAAO,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,CAAC,KAAK,CAAC,CAAC;;oBACrB,OAAO,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -14,6 +14,7 @@ export interface OSServiceInstallationOptions {
|
|
|
14
14
|
enabled: boolean;
|
|
15
15
|
outDir?: string;
|
|
16
16
|
};
|
|
17
|
+
debugging?: boolean;
|
|
17
18
|
macos?: MacOSServiceOptions;
|
|
18
19
|
linux?: LinuxOSServiceOptions;
|
|
19
20
|
}
|
|
@@ -43,8 +44,8 @@ export interface LinuxOSServiceOptions {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
export interface WindowsOSServiceOptions {
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
pathToServyCliExe?: string;
|
|
48
|
+
serviceName?: string;
|
|
48
49
|
}
|
|
49
50
|
export declare enum OSServiceStatus {
|
|
50
51
|
'not_installed' = "not_installed",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/os-service-manager.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"os-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/os-service-manager.ts"],"names":[],"mappings":";;;;AAsDA,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,kDAAiC,CAAA;IACjC,4CAA2B,CAAA;IAC3B,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B;AAED,MAAsB,gBAAgB;IAAtC;QAcY,YAAO,GAAG,eAAe,CAAC,aAAa,CAAC;IAmBpD,CAAC;IAhCC,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAMY,UAAU,CAAC,OAAyB;;YAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;KAAA;CAaF;AAjCD,4CAiCC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { OSServiceInstallationOptions, OSServiceManager, OSServiceOptions } from './os-service-manager';
|
|
2
2
|
export declare class WindowsServiceManager extends OSServiceManager {
|
|
3
3
|
initialize(options: OSServiceOptions): Promise<void>;
|
|
4
|
-
private get
|
|
4
|
+
private get servyCLIExecPath();
|
|
5
|
+
private get getServiceName();
|
|
5
6
|
checkRequirements(): Promise<void>;
|
|
6
7
|
install(command: string, commandArgs: string[], options: OSServiceInstallationOptions): Promise<void>;
|
|
7
8
|
uninstall(): Promise<void>;
|
|
@@ -9,5 +10,4 @@ export declare class WindowsServiceManager extends OSServiceManager {
|
|
|
9
10
|
stop(): Promise<void>;
|
|
10
11
|
isInstalled(): Promise<boolean>;
|
|
11
12
|
updateStatus(): Promise<void>;
|
|
12
|
-
private buildWinsXML;
|
|
13
13
|
}
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WindowsServiceManager = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const functions_1 = require("./functions");
|
|
6
|
-
const promises_1 = require("fs/promises");
|
|
7
6
|
const os_service_manager_1 = require("./os-service-manager");
|
|
8
|
-
const Path = require("node:path");
|
|
9
7
|
class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
10
8
|
initialize(options) {
|
|
11
9
|
const _super = Object.create(null, {
|
|
@@ -17,43 +15,55 @@ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
|
17
15
|
yield this.updateStatus();
|
|
18
16
|
});
|
|
19
17
|
}
|
|
20
|
-
get
|
|
18
|
+
get servyCLIExecPath() {
|
|
21
19
|
var _a, _b;
|
|
22
|
-
return (_b = (_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.
|
|
20
|
+
return (_b = (_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToServyCliExe) !== null && _b !== void 0 ? _b : 'servy-cli';
|
|
21
|
+
}
|
|
22
|
+
get getServiceName() {
|
|
23
|
+
return this.options.slug;
|
|
23
24
|
}
|
|
24
25
|
checkRequirements() {
|
|
25
26
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var _a;
|
|
27
27
|
let version = '';
|
|
28
28
|
try {
|
|
29
|
-
version = yield functions_1.ScriptRunner.run(`${this.
|
|
29
|
+
version = yield functions_1.ScriptRunner.run(`${this.servyCLIExecPath} version`);
|
|
30
|
+
version = /Servy.CLI ([0-9]\.[0-9]\.[0-9])/g.exec(version)[1];
|
|
30
31
|
}
|
|
31
32
|
catch (e) {
|
|
32
|
-
throw new Error(`Node-Service Error: Can't find
|
|
33
|
+
throw new Error(`Node-Service Error: Can't find servy-cli.exe binary. Make sure to have servy-cli v8 installed and referenced to %PATH$ environment variable. Or set the path to servy-cli.exe in options.windows.servyCLIExecPath. Download servy here: https://servy-win.github.io/`);
|
|
33
34
|
}
|
|
34
35
|
if (!version) {
|
|
35
|
-
throw new Error(`Node-Service Error: Can't read version information. Make sure that you have
|
|
36
|
-
}
|
|
37
|
-
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.windows.pathToWinswConfig)) {
|
|
38
|
-
throw new Error('Node-Service Error: You have to define a path to a (non)-existing winsw configuration file. Please check options.windows.pathToWinswConfig');
|
|
36
|
+
throw new Error(`Node-Service Error: Can't read version information. Make sure that you have servy-cli v8 installed.`);
|
|
39
37
|
}
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
install(command, commandArgs, options) {
|
|
43
41
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
42
|
+
const envVars = [];
|
|
43
|
+
if (options.env && Object.keys(options.env).length > 0) {
|
|
44
|
+
for (const key of Object.keys(options.env)) {
|
|
45
|
+
envVars.push(`${key}=${options.env[key].replace(/([=";])/g, '\\$1')}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const installArgs = [
|
|
49
|
+
`-n "${this.options.slug}"`,
|
|
50
|
+
`-d "${options.description}"`,
|
|
51
|
+
`-p "${command}"`,
|
|
52
|
+
`-q`
|
|
53
|
+
];
|
|
54
|
+
if (options.debugging) {
|
|
55
|
+
installArgs.push(`--debug`);
|
|
56
|
+
}
|
|
57
|
+
if (options.cwd) {
|
|
58
|
+
installArgs.push(`--startupDir="${options.cwd}"`);
|
|
47
59
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
yield (0, promises_1.writeFile)((_c = this.options.windows) === null || _c === void 0 ? void 0 : _c.pathToWinswConfig, this.buildWinsXML(command, commandArgs, options), {
|
|
51
|
-
encoding: 'utf-8'
|
|
52
|
-
});
|
|
60
|
+
if (envVars.length > 0) {
|
|
61
|
+
installArgs.push(`--envVars="${envVars.join(';')}"`);
|
|
53
62
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
if (commandArgs.length > 0) {
|
|
64
|
+
installArgs.push(`--params="${commandArgs.join(' ').replace(/\\"/g, '\\"')}"`);
|
|
65
|
+
}
|
|
66
|
+
const script = `${this.servyCLIExecPath} install ${installArgs.join(' ')}`;
|
|
57
67
|
yield functions_1.ScriptRunner.runAsAdmin(script, {
|
|
58
68
|
name: this.options.name,
|
|
59
69
|
headless: this.options.headless
|
|
@@ -63,11 +73,7 @@ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
|
63
73
|
}
|
|
64
74
|
uninstall() {
|
|
65
75
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
67
|
-
if (!((_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig)) {
|
|
68
|
-
throw new Error('Node-Service Error: Missing config path to winsw config.');
|
|
69
|
-
}
|
|
70
|
-
yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} stop "${(_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig}" && ${this.winswExePath} uninstall "${(_c = this.options.windows) === null || _c === void 0 ? void 0 : _c.pathToWinswConfig}"`, {
|
|
76
|
+
yield functions_1.ScriptRunner.runAsAdmin(`${this.servyCLIExecPath} stop -n ${this.getServiceName} -q && ${this.servyCLIExecPath} uninstall -n ${this.getServiceName} -q`, {
|
|
71
77
|
name: this.options.name,
|
|
72
78
|
headless: this.options.headless
|
|
73
79
|
});
|
|
@@ -76,11 +82,7 @@ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
|
76
82
|
}
|
|
77
83
|
start() {
|
|
78
84
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
80
|
-
if (!((_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig)) {
|
|
81
|
-
throw new Error('Node-Service Error: Missing config path to winsw config.');
|
|
82
|
-
}
|
|
83
|
-
yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} start ${(_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig}`, {
|
|
85
|
+
yield functions_1.ScriptRunner.runAsAdmin(`${this.servyCLIExecPath} start -n ${this.getServiceName} -q`, {
|
|
84
86
|
name: this.options.name,
|
|
85
87
|
headless: this.options.headless
|
|
86
88
|
});
|
|
@@ -89,11 +91,7 @@ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
|
89
91
|
}
|
|
90
92
|
stop() {
|
|
91
93
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
|
|
93
|
-
if (!((_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig)) {
|
|
94
|
-
throw new Error('Node-Service Error: Missing config path to winsw config.');
|
|
95
|
-
}
|
|
96
|
-
yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} stop ${(_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig}`, {
|
|
94
|
+
yield functions_1.ScriptRunner.runAsAdmin(`${this.servyCLIExecPath} stop -n ${this.getServiceName} -q`, {
|
|
97
95
|
name: this.options.name,
|
|
98
96
|
headless: this.options.headless
|
|
99
97
|
});
|
|
@@ -102,83 +100,42 @@ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
|
|
|
102
100
|
}
|
|
103
101
|
isInstalled() {
|
|
104
102
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
var _a;
|
|
106
103
|
yield this.updateStatus();
|
|
107
|
-
return
|
|
104
|
+
return this._status !== os_service_manager_1.OSServiceStatus.not_installed;
|
|
108
105
|
});
|
|
109
106
|
}
|
|
110
107
|
updateStatus() {
|
|
111
108
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
let output = "";
|
|
110
|
+
try {
|
|
111
|
+
output = yield functions_1.ScriptRunner.run(`${this.servyCLIExecPath} status -n ${this.getServiceName} -q`);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
output = e;
|
|
115
|
+
if (output.indexOf(" was not found on computer") > -1) {
|
|
115
116
|
this._status = os_service_manager_1.OSServiceStatus.not_installed;
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
const matches = /I?n?[aA]ctive \(([^)]+)\)/g.exec(output);
|
|
120
|
-
if (matches && matches.length > 0) {
|
|
121
|
-
switch (matches[1]) {
|
|
122
|
-
case 'running':
|
|
123
|
-
this._status = os_service_manager_1.OSServiceStatus.running;
|
|
124
|
-
break;
|
|
125
|
-
case 'stopped':
|
|
126
|
-
this._status = os_service_manager_1.OSServiceStatus.stopped;
|
|
127
|
-
break;
|
|
128
|
-
case 'waiting':
|
|
129
|
-
this._status = os_service_manager_1.OSServiceStatus.waiting;
|
|
130
|
-
break;
|
|
131
|
-
default:
|
|
132
|
-
this._status = os_service_manager_1.OSServiceStatus.unknown;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else if (output === 'NonExistent\n') {
|
|
136
|
-
this._status = os_service_manager_1.OSServiceStatus.not_installed;
|
|
137
|
-
}
|
|
119
|
+
process.exit(1);
|
|
138
120
|
}
|
|
139
|
-
|
|
140
|
-
|
|
121
|
+
const matches = /Service status for '[^']+': (\w+)/g.exec(output);
|
|
122
|
+
if (matches && matches.length > 0) {
|
|
123
|
+
switch (matches[1]) {
|
|
124
|
+
case 'Running':
|
|
125
|
+
this._status = os_service_manager_1.OSServiceStatus.running;
|
|
126
|
+
break;
|
|
127
|
+
case 'Stopped':
|
|
128
|
+
this._status = os_service_manager_1.OSServiceStatus.stopped;
|
|
129
|
+
break;
|
|
130
|
+
case 'Start Pending':
|
|
131
|
+
this._status = os_service_manager_1.OSServiceStatus.waiting;
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
this._status = os_service_manager_1.OSServiceStatus.unknown;
|
|
135
|
+
}
|
|
141
136
|
}
|
|
142
137
|
});
|
|
143
138
|
}
|
|
144
|
-
buildWinsXML(command, commandArgs, installationOptions) {
|
|
145
|
-
var _a, _b, _c;
|
|
146
|
-
let winswFileContent = `<service>
|
|
147
|
-
<id>${this.options.slug}</id>
|
|
148
|
-
<name>${this.options.name}</name>
|
|
149
|
-
<description>${installationOptions.description}</description>
|
|
150
|
-
<executable>${command}</executable>
|
|
151
|
-
<arguments>${commandArgs.join(' ')}</arguments>`;
|
|
152
|
-
if (installationOptions.cwd) {
|
|
153
|
-
winswFileContent += `
|
|
154
|
-
<workingdirectory>${installationOptions.cwd}</workingdirectory>`;
|
|
155
|
-
}
|
|
156
|
-
if (installationOptions.env && Object.keys(installationOptions.env).length > 0) {
|
|
157
|
-
for (const key of Object.keys(installationOptions.env)) {
|
|
158
|
-
winswFileContent += `
|
|
159
|
-
<env name="${key}" value="${installationOptions.env[key].replace(/"/g, '"')}" />`;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if ((_a = installationOptions.logging) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
163
|
-
if ((_b = installationOptions.logging) === null || _b === void 0 ? void 0 : _b.outDir) {
|
|
164
|
-
winswFileContent += `
|
|
165
|
-
<logpath>${(_c = installationOptions.logging) === null || _c === void 0 ? void 0 : _c.outDir}</logpath>`;
|
|
166
|
-
}
|
|
167
|
-
winswFileContent += `
|
|
168
|
-
<log mode="roll-by-size">
|
|
169
|
-
<sizeThreshold>10240</sizeThreshold>
|
|
170
|
-
<keepFiles>4</keepFiles>`;
|
|
171
|
-
winswFileContent += `
|
|
172
|
-
</log>`;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
winswFileContent += `
|
|
176
|
-
<log mode="none"></log>`;
|
|
177
|
-
}
|
|
178
|
-
winswFileContent += `
|
|
179
|
-
</service>`;
|
|
180
|
-
return winswFileContent;
|
|
181
|
-
}
|
|
182
139
|
}
|
|
183
140
|
exports.WindowsServiceManager = WindowsServiceManager;
|
|
184
141
|
//# sourceMappingURL=windows-service-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/windows-service-manager.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"windows-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/windows-service-manager.ts"],"names":[],"mappings":";;;;AAAA,2CAA2C;AAC3C,6DAK8B;AAE9B,MAAa,qBAAsB,SAAQ,qCAAgB;IAC1C,UAAU,CAAC,OAAyB;;;;;YACjD,MAAM,OAAM,UAAU,YAAC,OAAO,CAAC,CAAC;YAChC,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC/B,MAAM,IAAI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