@lppx/taskmgr 0.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/README.md +340 -0
- package/TaskScheduler.2.12.2/.signature.p7s +0 -0
- package/TaskScheduler.2.12.2/TaskScheduler.2.12.2.nupkg +0 -0
- package/TaskScheduler.2.12.2/TaskService.md +72 -0
- package/TaskScheduler.2.12.2/lib/net45/Microsoft.Win32.TaskScheduler.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/Microsoft.Win32.TaskScheduler.xml +7855 -0
- package/TaskScheduler.2.12.2/lib/net45/de/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/es/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/fr/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/it/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/ja/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/pl/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/ru/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/sv/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/tr/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/zh-CN/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/lib/net45/zh-Hant/Microsoft.Win32.TaskScheduler.resources.dll +0 -0
- package/TaskScheduler.2.12.2/tsnew48.png +0 -0
- package/Templates//344/274/221/347/234/240/350/204/232/346/234/254.ps1 +3 -0
- package/Templates//345/200/222/350/256/241/346/227/266/344/274/221/347/234/240/350/204/232/346/234/254.ps1 +68 -0
- package/Templates//345/200/222/350/256/241/346/227/266/345/205/263/346/234/272/350/204/232/346/234/254.ps1 +66 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/scripts/add.d.ts +9 -0
- package/dist/commands/scripts/add.js +28 -0
- package/dist/commands/scripts/list.d.ts +6 -0
- package/dist/commands/scripts/list.js +25 -0
- package/dist/commands/scripts/open.d.ts +6 -0
- package/dist/commands/scripts/open.js +19 -0
- package/dist/commands/tsk/add.d.ts +20 -0
- package/dist/commands/tsk/add.js +70 -0
- package/dist/commands/tsk/del.d.ts +9 -0
- package/dist/commands/tsk/del.js +14 -0
- package/dist/commands/tsk/list.d.ts +9 -0
- package/dist/commands/tsk/list.js +46 -0
- package/dist/hooks/init.d.ts +3 -0
- package/dist/hooks/init.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/task-scheduler.d.ts +37 -0
- package/dist/lib/task-scheduler.js +371 -0
- package/oclif.manifest.json +250 -0
- package/package.json +92 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
package/bin/dev.cmd
ADDED
package/bin/dev.js
ADDED
package/bin/run.cmd
ADDED
package/bin/run.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Add extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
path: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
export default class Add extends Command {
|
|
5
|
+
static args = {
|
|
6
|
+
path: Args.string({
|
|
7
|
+
description: '脚本文件路径',
|
|
8
|
+
required: true,
|
|
9
|
+
}),
|
|
10
|
+
};
|
|
11
|
+
static description = '添加脚本到用户配置目录';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> <%= command.id %> ./script.ps1',
|
|
14
|
+
];
|
|
15
|
+
async run() {
|
|
16
|
+
const { args } = await this.parse(Add);
|
|
17
|
+
const scriptPath = args.path;
|
|
18
|
+
const scriptsDir = join(this.config.configDir, 'scripts');
|
|
19
|
+
if (!existsSync(scriptsDir)) {
|
|
20
|
+
mkdirSync(scriptsDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
const fileName = basename(scriptPath);
|
|
23
|
+
const destPath = join(scriptsDir, fileName);
|
|
24
|
+
copyFileSync(scriptPath, destPath);
|
|
25
|
+
this.log(`脚本已添加: ${fileName}`);
|
|
26
|
+
this.log(`保存位置: ${destPath}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export default class List extends Command {
|
|
5
|
+
static description = '列出用户配置目录下的所有脚本';
|
|
6
|
+
static examples = [
|
|
7
|
+
'<%= config.bin %> <%= command.id %>',
|
|
8
|
+
];
|
|
9
|
+
async run() {
|
|
10
|
+
const scriptsDir = join(this.config.configDir, 'scripts');
|
|
11
|
+
const files = readdirSync(scriptsDir);
|
|
12
|
+
this.log('脚本目录: ' + scriptsDir);
|
|
13
|
+
this.log('');
|
|
14
|
+
if (files.length === 0) {
|
|
15
|
+
this.log('暂无脚本');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const filePath = join(scriptsDir, file);
|
|
20
|
+
const stats = statSync(filePath);
|
|
21
|
+
const size = (stats.size / 1024).toFixed(2);
|
|
22
|
+
this.log(` ${file} (${size} KB)`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
export default class Open extends Command {
|
|
6
|
+
static description = '打开脚本文件目录';
|
|
7
|
+
static examples = [
|
|
8
|
+
'<%= config.bin %> <%= command.id %>',
|
|
9
|
+
];
|
|
10
|
+
async run() {
|
|
11
|
+
const scriptsDir = join(this.config.configDir, 'scripts');
|
|
12
|
+
if (!existsSync(scriptsDir)) {
|
|
13
|
+
mkdirSync(scriptsDir, { recursive: true });
|
|
14
|
+
this.log(`已创建脚本目录: ${scriptsDir}`);
|
|
15
|
+
}
|
|
16
|
+
spawn('explorer', [scriptsDir], { detached: true, stdio: 'ignore' }).unref();
|
|
17
|
+
this.log(`正在打开: ${scriptsDir}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Add extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
taskName: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
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>;
|
|
11
|
+
description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
hidden: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
'start-when-available': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
'stop-on-battery': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
time: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
trigger: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
wake: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import { createScheduledTask } from '../../lib/task-scheduler.js';
|
|
3
|
+
export default class Add extends Command {
|
|
4
|
+
static args = {
|
|
5
|
+
taskName: Args.string({ description: '任务名称', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = '创建定时任务';
|
|
8
|
+
static examples = [
|
|
9
|
+
String.raw `<%= config.bin %> <%= command.id %> myTask --path "C:\app.exe" --trigger daily --time "09:00"`,
|
|
10
|
+
String.raw `<%= config.bin %> <%= command.id %> backupTask --path "C:\backup.exe" --arguments "--full --dest D:\backup"`,
|
|
11
|
+
String.raw `<%= config.bin %> <%= command.id %> reportTask --path "C:\report.exe" --arguments '-f json -o "output.txt"' --trigger weekly`,
|
|
12
|
+
String.raw `<%= config.bin %> <%= command.id %> psTask --path "powershell.exe" --arguments '-ExecutionPolicy Bypass -File "C:\scripts\cleanup.ps1"' --trigger daily`,
|
|
13
|
+
String.raw `<%= config.bin %> <%= command.id %> psInlineTask --path "powershell.exe" --arguments '-Command "Get-ChildItem C:\temp | Remove-Item -Recurse -Force"' --trigger weekly`,
|
|
14
|
+
];
|
|
15
|
+
static flags = {
|
|
16
|
+
arguments: Flags.string({
|
|
17
|
+
description: '执行参数'
|
|
18
|
+
}),
|
|
19
|
+
path: Flags.string({
|
|
20
|
+
description: '可执行文件路径',
|
|
21
|
+
required: true
|
|
22
|
+
}),
|
|
23
|
+
description: Flags.string({
|
|
24
|
+
description: '任务描述'
|
|
25
|
+
}),
|
|
26
|
+
hidden: Flags.boolean({
|
|
27
|
+
default: true,
|
|
28
|
+
description: '是否隐藏任务'
|
|
29
|
+
}),
|
|
30
|
+
'start-when-available': Flags.boolean({
|
|
31
|
+
default: false,
|
|
32
|
+
description: '错过启动时间后是否自动启动'
|
|
33
|
+
}),
|
|
34
|
+
'stop-on-battery': Flags.boolean({
|
|
35
|
+
default: false,
|
|
36
|
+
description: '使用电池供电时是否停止任务'
|
|
37
|
+
}),
|
|
38
|
+
time: Flags.string({
|
|
39
|
+
default: '09:00',
|
|
40
|
+
description: '任务开始时间 (HH:mm)'
|
|
41
|
+
}),
|
|
42
|
+
trigger: Flags.string({
|
|
43
|
+
default: 'daily',
|
|
44
|
+
description: '触发类型: daily, weekly, monthly, once, boot, logon',
|
|
45
|
+
options: ['boot', 'daily', 'logon', 'monthly', 'once', 'weekly'],
|
|
46
|
+
}),
|
|
47
|
+
wake: Flags.boolean({
|
|
48
|
+
default: true,
|
|
49
|
+
description: '是否唤醒计算机运行任务'
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
async run() {
|
|
53
|
+
const { args, flags } = await this.parse(Add);
|
|
54
|
+
const result = await createScheduledTask({
|
|
55
|
+
arguments: flags.arguments,
|
|
56
|
+
description: flags.description,
|
|
57
|
+
disallowStartIfOnBatteries: false,
|
|
58
|
+
enabled: true,
|
|
59
|
+
executablePath: flags.path,
|
|
60
|
+
hidden: flags.hidden,
|
|
61
|
+
startTime: flags.time,
|
|
62
|
+
startWhenAvailable: flags['start-when-available'],
|
|
63
|
+
stopIfGoingOnBatteries: flags['stop-on-battery'],
|
|
64
|
+
taskName: args.taskName,
|
|
65
|
+
triggerType: flags.trigger,
|
|
66
|
+
wakeToRun: flags.wake,
|
|
67
|
+
});
|
|
68
|
+
this.log(result);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Del extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
taskName: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import { deleteScheduledTask } from '../../lib/task-scheduler.js';
|
|
3
|
+
export default class Del extends Command {
|
|
4
|
+
static args = {
|
|
5
|
+
taskName: Args.string({ description: '任务名称', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = '删除定时任务';
|
|
8
|
+
static examples = [`<%= config.bin %> <%= command.id %> myTask`];
|
|
9
|
+
async run() {
|
|
10
|
+
const { args } = await this.parse(Del);
|
|
11
|
+
const result = await deleteScheduledTask(args.taskName);
|
|
12
|
+
this.log(result);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { getAllTasks } from '../../lib/task-scheduler.js';
|
|
3
|
+
export default class List extends Command {
|
|
4
|
+
static description = '列出所有定时任务';
|
|
5
|
+
static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --multi'];
|
|
6
|
+
static flags = {
|
|
7
|
+
multi: Flags.boolean({
|
|
8
|
+
default: false,
|
|
9
|
+
description: '使用多行格式显示任务详情',
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
async run() {
|
|
13
|
+
const { flags } = await this.parse(List);
|
|
14
|
+
const result = await getAllTasks();
|
|
15
|
+
if (!result || typeof result === 'string') {
|
|
16
|
+
this.log(result ?? '获取任务列表失败');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const tasks = result;
|
|
20
|
+
if (tasks.length === 0) {
|
|
21
|
+
this.log('暂无定时任务');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.log('');
|
|
25
|
+
this.log('任务列表:');
|
|
26
|
+
this.log('');
|
|
27
|
+
if (flags.multi) {
|
|
28
|
+
for (const task of tasks) {
|
|
29
|
+
this.log(` ${task.name}`);
|
|
30
|
+
this.log(` 路径: ${task.path}`);
|
|
31
|
+
this.log(` 状态: ${task.state} | 启用: ${task.enabled ? '是' : '否'}`);
|
|
32
|
+
this.log(` 上次运行: ${task.lastRunTime}`);
|
|
33
|
+
this.log(` 下次运行: ${task.nextRunTime}`);
|
|
34
|
+
this.log(` 运行结果: ${task.lastTaskResult} | 错过次数: ${task.numberOfMissedRuns}`);
|
|
35
|
+
this.log(` 触发器: ${task.triggers.join(', ') || '无'}`);
|
|
36
|
+
this.log(` 操作: ${task.actions.join(', ') || '无'}`);
|
|
37
|
+
this.log('');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
for (const task of tasks) {
|
|
42
|
+
this.log(` ${task.name} | 状态: ${task.state} | 上次运行: ${task.lastRunTime} | 下次运行: ${task.nextRunTime}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const hook = async function (options) {
|
|
4
|
+
const scriptsDir = join(options.config.configDir, 'scripts');
|
|
5
|
+
if (!existsSync(scriptsDir)) {
|
|
6
|
+
mkdirSync(scriptsDir, { recursive: true });
|
|
7
|
+
const templatesDir = join(options.config.root, 'Templates');
|
|
8
|
+
for (const file of readdirSync(templatesDir)) {
|
|
9
|
+
copyFileSync(join(templatesDir, file), join(scriptsDir, file));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default hook;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from '@oclif/core';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface CreateTaskOptions {
|
|
2
|
+
arguments?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
disallowStartIfOnBatteries?: boolean;
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
executablePath: string;
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
startTime?: string;
|
|
9
|
+
startWhenAvailable?: boolean;
|
|
10
|
+
stopIfGoingOnBatteries?: boolean;
|
|
11
|
+
taskName: string;
|
|
12
|
+
triggerType?: 'boot' | 'daily' | 'logon' | 'monthly' | 'once' | 'weekly';
|
|
13
|
+
wakeToRun?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface TaskInfo {
|
|
16
|
+
actions: string[];
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
lastRunTime: string;
|
|
19
|
+
lastTaskResult: number;
|
|
20
|
+
name: string;
|
|
21
|
+
nextRunTime: string;
|
|
22
|
+
numberOfMissedRuns: number;
|
|
23
|
+
path: string;
|
|
24
|
+
state: string;
|
|
25
|
+
triggers: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface TaskDetail extends TaskInfo {
|
|
28
|
+
definition: {
|
|
29
|
+
actions: string[];
|
|
30
|
+
triggers: string[];
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare function createScheduledTask(options: CreateTaskOptions): Promise<string>;
|
|
34
|
+
export declare function deleteScheduledTask(taskName: string): Promise<string>;
|
|
35
|
+
export declare function getAllTasks(): Promise<string | TaskInfo[]>;
|
|
36
|
+
export declare function getScheduledTask(taskName: string): Promise<string | TaskDetail>;
|
|
37
|
+
export declare function runScheduledTask(taskName: string): Promise<string>;
|