@lppx/taskmgr 0.0.0 → 0.1.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.
@@ -1,3 +1,3 @@
1
-
2
-
1
+
2
+
3
3
  shutdown -h
@@ -1,68 +1,68 @@
1
- 
2
- # 这个脚本的任务 是实现倒计时30S关机
3
- # 要求倒计时的时间是易于更改的
4
- # 要求每一秒的倒计时 是通过弹出的窗口 同步通知给用户的
5
- # 要求完全的异常处理 用户执行CTRL+C 只有直接退出程序 而不能弹出错误窗口
6
-
7
- # 配置倒计时秒数(易于修改)
8
- $countdownSeconds = 10
9
-
10
- # 加载必要的程序集
11
- Add-Type -AssemblyName System.Windows.Forms
12
- Add-Type -AssemblyName System.Drawing
13
-
14
- # 全局变量用于窗体
15
- $script:form = $null
16
- $script:cancelled = $false
17
-
18
- try {
19
- # 创建通知窗体
20
- $form = New-Object System.Windows.Forms.Form
21
- $form.FormBorderStyle = 'None'
22
- $form.BackColor = 'Black'
23
- $form.ForeColor = 'White'
24
- $form.TopMost = $true
25
- $form.StartPosition = 'Manual'
26
- $form.Size = New-Object System.Drawing.Size(300, 100)
27
- $form.Location = New-Object System.Drawing.Point(([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width - 300), 50)
28
-
29
- $label = New-Object System.Windows.Forms.Label
30
- $label.AutoSize = $false
31
- $label.Dock = 'Fill'
32
- $label.TextAlign = 'MiddleCenter'
33
- $label.Font = New-Object System.Drawing.Font("Microsoft YaHei", 12, [System.Drawing.FontStyle]::Bold)
34
- $form.Controls.Add($label)
35
-
36
- $form.Show()
37
-
38
- for ($i = $countdownSeconds; $i -gt 0; $i--) {
39
- if ($script:cancelled) { break }
40
- $label.Text = "系统将在 $i 秒后休眠"
41
- [System.Windows.Forms.Application]::DoEvents()
42
-
43
- # 分段 Sleep 以便更快响应 Ctrl+C
44
- for ($j = 0; $j -lt 10; $j++) {
45
- Start-Sleep -Milliseconds 100
46
- [System.Windows.Forms.Application]::DoEvents()
47
- }
48
- }
49
-
50
- $form.Close()
51
- $form.Dispose()
52
- # rundll32.exe powrprof.dll,SetSuspendState 0,1,0
53
- # 这种 休眠方式 无法唤醒
54
- shutdown -h
55
- }
56
- catch [System.Management.Automation.PipelineStoppedException] {
57
- # Ctrl+C 被按下,静默退出
58
- $script:cancelled = $true
59
- }
60
- catch {
61
- # 捕获其他异常,静默退出
62
- $script:cancelled = $true
63
- }
64
- finally {
65
- if ($form) {
66
- $form.Dispose()
67
- }
68
- }
1
+ 
2
+ # 这个脚本的任务 是实现倒计时30S关机
3
+ # 要求倒计时的时间是易于更改的
4
+ # 要求每一秒的倒计时 是通过弹出的窗口 同步通知给用户的
5
+ # 要求完全的异常处理 用户执行CTRL+C 只有直接退出程序 而不能弹出错误窗口
6
+
7
+ # 配置倒计时秒数(易于修改)
8
+ $countdownSeconds = 10
9
+
10
+ # 加载必要的程序集
11
+ Add-Type -AssemblyName System.Windows.Forms
12
+ Add-Type -AssemblyName System.Drawing
13
+
14
+ # 全局变量用于窗体
15
+ $script:form = $null
16
+ $script:cancelled = $false
17
+
18
+ try {
19
+ # 创建通知窗体
20
+ $form = New-Object System.Windows.Forms.Form
21
+ $form.FormBorderStyle = 'None'
22
+ $form.BackColor = 'Black'
23
+ $form.ForeColor = 'White'
24
+ $form.TopMost = $true
25
+ $form.StartPosition = 'Manual'
26
+ $form.Size = New-Object System.Drawing.Size(300, 100)
27
+ $form.Location = New-Object System.Drawing.Point(([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width - 300), 50)
28
+
29
+ $label = New-Object System.Windows.Forms.Label
30
+ $label.AutoSize = $false
31
+ $label.Dock = 'Fill'
32
+ $label.TextAlign = 'MiddleCenter'
33
+ $label.Font = New-Object System.Drawing.Font("Microsoft YaHei", 12, [System.Drawing.FontStyle]::Bold)
34
+ $form.Controls.Add($label)
35
+
36
+ $form.Show()
37
+
38
+ for ($i = $countdownSeconds; $i -gt 0; $i--) {
39
+ if ($script:cancelled) { break }
40
+ $label.Text = "系统将在 $i 秒后休眠"
41
+ [System.Windows.Forms.Application]::DoEvents()
42
+
43
+ # 分段 Sleep 以便更快响应 Ctrl+C
44
+ for ($j = 0; $j -lt 10; $j++) {
45
+ Start-Sleep -Milliseconds 100
46
+ [System.Windows.Forms.Application]::DoEvents()
47
+ }
48
+ }
49
+
50
+ $form.Close()
51
+ $form.Dispose()
52
+ # rundll32.exe powrprof.dll,SetSuspendState 0,1,0
53
+ # 这种 休眠方式 无法唤醒
54
+ shutdown -h
55
+ }
56
+ catch [System.Management.Automation.PipelineStoppedException] {
57
+ # Ctrl+C 被按下,静默退出
58
+ $script:cancelled = $true
59
+ }
60
+ catch {
61
+ # 捕获其他异常,静默退出
62
+ $script:cancelled = $true
63
+ }
64
+ finally {
65
+ if ($form) {
66
+ $form.Dispose()
67
+ }
68
+ }
@@ -1,66 +1,66 @@
1
- 
2
- # 这个脚本的任务 是实现倒计时30S关机
3
- # 要求倒计时的时间是易于更改的
4
- # 要求每一秒的倒计时 是通过弹出的窗口 同步通知给用户的
5
- # 要求完全的异常处理 用户执行CTRL+C 只有直接退出程序 而不能弹出错误窗口
6
-
7
- # 配置倒计时秒数(易于修改)
8
- $countdownSeconds = 30
9
-
10
- # 加载必要的程序集
11
- Add-Type -AssemblyName System.Windows.Forms
12
- Add-Type -AssemblyName System.Drawing
13
-
14
- # 全局变量用于窗体
15
- $script:form = $null
16
- $script:cancelled = $false
17
-
18
- try {
19
- # 创建通知窗体
20
- $form = New-Object System.Windows.Forms.Form
21
- $form.FormBorderStyle = 'None'
22
- $form.BackColor = 'Black'
23
- $form.ForeColor = 'White'
24
- $form.TopMost = $true
25
- $form.StartPosition = 'Manual'
26
- $form.Size = New-Object System.Drawing.Size(300, 100)
27
- $form.Location = New-Object System.Drawing.Point(([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width - 300), 50)
28
-
29
- $label = New-Object System.Windows.Forms.Label
30
- $label.AutoSize = $false
31
- $label.Dock = 'Fill'
32
- $label.TextAlign = 'MiddleCenter'
33
- $label.Font = New-Object System.Drawing.Font("Microsoft YaHei", 12, [System.Drawing.FontStyle]::Bold)
34
- $form.Controls.Add($label)
35
-
36
- $form.Show()
37
-
38
- for ($i = $countdownSeconds; $i -gt 0; $i--) {
39
- if ($script:cancelled) { break }
40
- $label.Text = "系统将在 $i 秒后关机"
41
- [System.Windows.Forms.Application]::DoEvents()
42
-
43
- # 分段 Sleep 以便更快响应 Ctrl+C
44
- for ($j = 0; $j -lt 10; $j++) {
45
- Start-Sleep -Milliseconds 100
46
- [System.Windows.Forms.Application]::DoEvents()
47
- }
48
- }
49
-
50
- $form.Close()
51
- $form.Dispose()
52
- Stop-Computer -Force
53
- }
54
- catch [System.Management.Automation.PipelineStoppedException] {
55
- # Ctrl+C 被按下,静默退出
56
- $script:cancelled = $true
57
- }
58
- catch {
59
- # 捕获其他异常,静默退出
60
- $script:cancelled = $true
61
- }
62
- finally {
63
- if ($form) {
64
- $form.Dispose()
65
- }
66
- }
1
+ 
2
+ # 这个脚本的任务 是实现倒计时30S关机
3
+ # 要求倒计时的时间是易于更改的
4
+ # 要求每一秒的倒计时 是通过弹出的窗口 同步通知给用户的
5
+ # 要求完全的异常处理 用户执行CTRL+C 只有直接退出程序 而不能弹出错误窗口
6
+
7
+ # 配置倒计时秒数(易于修改)
8
+ $countdownSeconds = 30
9
+
10
+ # 加载必要的程序集
11
+ Add-Type -AssemblyName System.Windows.Forms
12
+ Add-Type -AssemblyName System.Drawing
13
+
14
+ # 全局变量用于窗体
15
+ $script:form = $null
16
+ $script:cancelled = $false
17
+
18
+ try {
19
+ # 创建通知窗体
20
+ $form = New-Object System.Windows.Forms.Form
21
+ $form.FormBorderStyle = 'None'
22
+ $form.BackColor = 'Black'
23
+ $form.ForeColor = 'White'
24
+ $form.TopMost = $true
25
+ $form.StartPosition = 'Manual'
26
+ $form.Size = New-Object System.Drawing.Size(300, 100)
27
+ $form.Location = New-Object System.Drawing.Point(([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width - 300), 50)
28
+
29
+ $label = New-Object System.Windows.Forms.Label
30
+ $label.AutoSize = $false
31
+ $label.Dock = 'Fill'
32
+ $label.TextAlign = 'MiddleCenter'
33
+ $label.Font = New-Object System.Drawing.Font("Microsoft YaHei", 12, [System.Drawing.FontStyle]::Bold)
34
+ $form.Controls.Add($label)
35
+
36
+ $form.Show()
37
+
38
+ for ($i = $countdownSeconds; $i -gt 0; $i--) {
39
+ if ($script:cancelled) { break }
40
+ $label.Text = "系统将在 $i 秒后关机"
41
+ [System.Windows.Forms.Application]::DoEvents()
42
+
43
+ # 分段 Sleep 以便更快响应 Ctrl+C
44
+ for ($j = 0; $j -lt 10; $j++) {
45
+ Start-Sleep -Milliseconds 100
46
+ [System.Windows.Forms.Application]::DoEvents()
47
+ }
48
+ }
49
+
50
+ $form.Close()
51
+ $form.Dispose()
52
+ Stop-Computer -Force
53
+ }
54
+ catch [System.Management.Automation.PipelineStoppedException] {
55
+ # Ctrl+C 被按下,静默退出
56
+ $script:cancelled = $true
57
+ }
58
+ catch {
59
+ # 捕获其他异常,静默退出
60
+ $script:cancelled = $true
61
+ }
62
+ finally {
63
+ if ($form) {
64
+ $form.Dispose()
65
+ }
66
+ }
package/bin/run.js CHANGED
File without changes
@@ -6,8 +6,9 @@ export default class Add extends Command {
6
6
  static description: string;
7
7
  static examples: string[];
8
8
  static flags: {
9
+ path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  arguments: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
- path: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'ps-script': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  hidden: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
14
  'start-when-available': import("@oclif/core/interfaces").BooleanFlag<boolean>;
@@ -11,27 +11,36 @@ export default class Add extends Command {
11
11
  String.raw `<%= config.bin %> <%= command.id %> reportTask --path "C:\report.exe" --arguments '-f json -o "output.txt"' --trigger weekly`,
12
12
  String.raw `<%= config.bin %> <%= command.id %> psTask --path "powershell.exe" --arguments '-ExecutionPolicy Bypass -File "C:\scripts\cleanup.ps1"' --trigger daily`,
13
13
  String.raw `<%= config.bin %> <%= command.id %> psInlineTask --path "powershell.exe" --arguments '-Command "Get-ChildItem C:\temp | Remove-Item -Recurse -Force"' --trigger weekly`,
14
+ String.raw `<%= config.bin %> <%= command.id %> scriptTask --ps-script "C:\scripts\cleanup.ps1" --trigger daily`,
14
15
  ];
15
16
  static flags = {
17
+ path: Flags.string({
18
+ description: '可执行文件路径'
19
+ }),
16
20
  arguments: Flags.string({
17
- description: '执行参数'
21
+ dependsOn: ['path'],
22
+ description: '执行参数',
18
23
  }),
19
- path: Flags.string({
20
- description: '可执行文件路径',
21
- required: true
24
+ 'ps-script': Flags.string({
25
+ char: 'p',
26
+ description: 'PowerShell 脚本路径,自动使用 powershell.exe 执行',
27
+ exclusive: ['path', 'arguments'],
22
28
  }),
23
29
  description: Flags.string({
24
30
  description: '任务描述'
25
31
  }),
26
32
  hidden: Flags.boolean({
33
+ allowNo: true,
27
34
  default: true,
28
35
  description: '是否隐藏任务'
29
36
  }),
30
37
  'start-when-available': Flags.boolean({
38
+ allowNo: true,
31
39
  default: false,
32
40
  description: '错过启动时间后是否自动启动'
33
41
  }),
34
42
  'stop-on-battery': Flags.boolean({
43
+ allowNo: true,
35
44
  default: false,
36
45
  description: '使用电池供电时是否停止任务'
37
46
  }),
@@ -45,18 +54,28 @@ export default class Add extends Command {
45
54
  options: ['boot', 'daily', 'logon', 'monthly', 'once', 'weekly'],
46
55
  }),
47
56
  wake: Flags.boolean({
57
+ allowNo: true,
48
58
  default: true,
49
59
  description: '是否唤醒计算机运行任务'
50
60
  }),
51
61
  };
52
62
  async run() {
53
63
  const { args, flags } = await this.parse(Add);
64
+ if (!flags.path && !flags['ps-script']) {
65
+ this.error('必须指定 --path 或 --ps-script');
66
+ }
67
+ let executablePath = flags.path;
68
+ let execArguments = flags.arguments;
69
+ if (flags['ps-script']) {
70
+ executablePath = 'powershell.exe';
71
+ execArguments = `-ExecutionPolicy Bypass -File "${flags['ps-script']}"`;
72
+ }
54
73
  const result = await createScheduledTask({
55
- arguments: flags.arguments,
74
+ arguments: execArguments,
56
75
  description: flags.description,
57
76
  disallowStartIfOnBatteries: false,
58
77
  enabled: true,
59
- executablePath: flags.path,
78
+ executablePath: executablePath,
60
79
  hidden: flags.hidden,
61
80
  startTime: flags.time,
62
81
  startWhenAvailable: flags['start-when-available'],
@@ -5,6 +5,7 @@ export default class List extends Command {
5
5
  static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --multi'];
6
6
  static flags = {
7
7
  multi: Flags.boolean({
8
+ allowNo: true,
8
9
  default: false,
9
10
  description: '使用多行格式显示任务详情',
10
11
  }),
@@ -2,6 +2,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  const hook = async function (options) {
4
4
  const scriptsDir = join(options.config.configDir, 'scripts');
5
+ // 若脚本目录不存在,则创建目录并从模板目录复制初始脚本文件
5
6
  if (!existsSync(scriptsDir)) {
6
7
  mkdirSync(scriptsDir, { recursive: true });
7
8
  const templatesDir = join(options.config.root, 'Templates');
@@ -93,20 +93,35 @@
93
93
  "<%= config.bin %> <%= command.id %> backupTask --path \"C:\\backup.exe\" --arguments \"--full --dest D:\\backup\"",
94
94
  "<%= config.bin %> <%= command.id %> reportTask --path \"C:\\report.exe\" --arguments '-f json -o \"output.txt\"' --trigger weekly",
95
95
  "<%= config.bin %> <%= command.id %> psTask --path \"powershell.exe\" --arguments '-ExecutionPolicy Bypass -File \"C:\\scripts\\cleanup.ps1\"' --trigger daily",
96
- "<%= config.bin %> <%= command.id %> psInlineTask --path \"powershell.exe\" --arguments '-Command \"Get-ChildItem C:\\temp | Remove-Item -Recurse -Force\"' --trigger weekly"
96
+ "<%= config.bin %> <%= command.id %> psInlineTask --path \"powershell.exe\" --arguments '-Command \"Get-ChildItem C:\\temp | Remove-Item -Recurse -Force\"' --trigger weekly",
97
+ "<%= config.bin %> <%= command.id %> scriptTask --ps-script \"C:\\scripts\\cleanup.ps1\" --trigger daily"
97
98
  ],
98
99
  "flags": {
100
+ "path": {
101
+ "description": "可执行文件路径",
102
+ "name": "path",
103
+ "hasDynamicHelp": false,
104
+ "multiple": false,
105
+ "type": "option"
106
+ },
99
107
  "arguments": {
108
+ "dependsOn": [
109
+ "path"
110
+ ],
100
111
  "description": "执行参数",
101
112
  "name": "arguments",
102
113
  "hasDynamicHelp": false,
103
114
  "multiple": false,
104
115
  "type": "option"
105
116
  },
106
- "path": {
107
- "description": "可执行文件路径",
108
- "name": "path",
109
- "required": true,
117
+ "ps-script": {
118
+ "char": "p",
119
+ "description": "PowerShell 脚本路径,自动使用 powershell.exe 执行",
120
+ "exclusive": [
121
+ "path",
122
+ "arguments"
123
+ ],
124
+ "name": "ps-script",
110
125
  "hasDynamicHelp": false,
111
126
  "multiple": false,
112
127
  "type": "option"
@@ -121,19 +136,19 @@
121
136
  "hidden": {
122
137
  "description": "是否隐藏任务",
123
138
  "name": "hidden",
124
- "allowNo": false,
139
+ "allowNo": true,
125
140
  "type": "boolean"
126
141
  },
127
142
  "start-when-available": {
128
143
  "description": "错过启动时间后是否自动启动",
129
144
  "name": "start-when-available",
130
- "allowNo": false,
145
+ "allowNo": true,
131
146
  "type": "boolean"
132
147
  },
133
148
  "stop-on-battery": {
134
149
  "description": "使用电池供电时是否停止任务",
135
150
  "name": "stop-on-battery",
136
- "allowNo": false,
151
+ "allowNo": true,
137
152
  "type": "boolean"
138
153
  },
139
154
  "time": {
@@ -163,7 +178,7 @@
163
178
  "wake": {
164
179
  "description": "是否唤醒计算机运行任务",
165
180
  "name": "wake",
166
- "allowNo": false,
181
+ "allowNo": true,
167
182
  "type": "boolean"
168
183
  }
169
184
  },
@@ -225,7 +240,7 @@
225
240
  "multi": {
226
241
  "description": "使用多行格式显示任务详情",
227
242
  "name": "multi",
228
- "allowNo": false,
243
+ "allowNo": true,
229
244
  "type": "boolean"
230
245
  }
231
246
  },
@@ -246,5 +261,5 @@
246
261
  ]
247
262
  }
248
263
  },
249
- "version": "0.0.0"
264
+ "version": "0.1.0"
250
265
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lppx/taskmgr",
3
3
  "description": "定时任务管理器",
4
- "version": "0.0.0",
4
+ "version": "0.1.0",
5
5
  "author": "lppx",
6
6
  "bin": {
7
7
  "tm": "./bin/run.js"