@lppx/taskmgr 0.0.0 → 0.0.1

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
@@ -7,7 +7,8 @@ export default class Add extends Command {
7
7
  static examples: string[];
8
8
  static flags: {
9
9
  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>;
10
+ path: import("@oclif/core/interfaces").OptionFlag<string | undefined, 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,14 +11,18 @@ 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 = {
16
17
  arguments: Flags.string({
17
18
  description: '执行参数'
18
19
  }),
19
20
  path: Flags.string({
20
- description: '可执行文件路径',
21
- required: true
21
+ description: '可执行文件路径'
22
+ }),
23
+ 'ps-script': Flags.string({
24
+ char: 'p',
25
+ description: 'PowerShell 脚本路径,自动使用 powershell.exe 执行'
22
26
  }),
23
27
  description: Flags.string({
24
28
  description: '任务描述'
@@ -51,12 +55,21 @@ export default class Add extends Command {
51
55
  };
52
56
  async run() {
53
57
  const { args, flags } = await this.parse(Add);
58
+ if (!flags.path && !flags['ps-script']) {
59
+ this.error('必须指定 --path 或 --ps-script');
60
+ }
61
+ let executablePath = flags.path;
62
+ let execArguments = flags.arguments;
63
+ if (flags['ps-script']) {
64
+ executablePath = 'powershell.exe';
65
+ execArguments = `-ExecutionPolicy Bypass -File "${flags['ps-script']}"`;
66
+ }
54
67
  const result = await createScheduledTask({
55
- arguments: flags.arguments,
68
+ arguments: execArguments,
56
69
  description: flags.description,
57
70
  disallowStartIfOnBatteries: false,
58
71
  enabled: true,
59
- executablePath: flags.path,
72
+ executablePath: executablePath,
60
73
  hidden: flags.hidden,
61
74
  startTime: flags.time,
62
75
  startWhenAvailable: flags['start-when-available'],
@@ -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,7 +93,8 @@
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": {
99
100
  "arguments": {
@@ -106,7 +107,14 @@
106
107
  "path": {
107
108
  "description": "可执行文件路径",
108
109
  "name": "path",
109
- "required": true,
110
+ "hasDynamicHelp": false,
111
+ "multiple": false,
112
+ "type": "option"
113
+ },
114
+ "ps-script": {
115
+ "char": "p",
116
+ "description": "PowerShell 脚本路径,自动使用 powershell.exe 执行",
117
+ "name": "ps-script",
110
118
  "hasDynamicHelp": false,
111
119
  "multiple": false,
112
120
  "type": "option"
@@ -246,5 +254,5 @@
246
254
  ]
247
255
  }
248
256
  },
249
- "version": "0.0.0"
257
+ "version": "0.0.1"
250
258
  }
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.0.1",
5
5
  "author": "lppx",
6
6
  "bin": {
7
7
  "tm": "./bin/run.js"