Skip to content

Commit dbd54fd

Browse files
committed
feat: Added alias resource and syncthing
1 parent afa7938 commit dbd54fd

5 files changed

Lines changed: 164 additions & 0 deletions

File tree

src/resources/shell/alias/alias-resource.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
getPty,
56
ModifyPlan,
67
ParameterChange,
@@ -20,10 +21,40 @@ export interface AliasConfig extends StringIndexedObject {
2021
value: string;
2122
}
2223

24+
const defaultConfig: Partial<AliasConfig> = {
25+
alias: '<Replace me here!>',
26+
value: '<Replace me here!>'
27+
}
28+
29+
const exampleGitAlias: ExampleConfig = {
30+
title: 'Git alias',
31+
description: 'A single shortcut for a common Git operation.',
32+
configs: [{
33+
type: 'alias',
34+
alias: 'gs',
35+
value: 'git status',
36+
}]
37+
}
38+
39+
const exampleSystemAlias: ExampleConfig = {
40+
title: 'System alias',
41+
description: 'A single alias for a common system task or safer default.',
42+
configs: [{
43+
type: 'alias',
44+
alias: 'rm',
45+
value: 'rm -i',
46+
}]
47+
}
48+
2349
export class AliasResource extends Resource<AliasConfig> {
2450
getSettings(): ResourceSettings<AliasConfig> {
2551
return {
2652
id: 'alias',
53+
defaultConfig,
54+
exampleConfigs: {
55+
example1: exampleGitAlias,
56+
example2: exampleSystemAlias,
57+
},
2758
operatingSystems: [OS.Darwin, OS.Linux],
2859
schema: Schema,
2960
parameterSettings: {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ExampleConfigs } from '@codifycli/plugin-core';
2+
3+
export const exampleSyncthingConfigs: ExampleConfigs = {
4+
example2: {
5+
title: 'Example Syncthing setup with two devices',
6+
description: 'Install Syncthing, register a peer device, and sync the ~/Documents folder between two machines.',
7+
configs: [
8+
{
9+
type: 'syncthing',
10+
launchAtStartup: true,
11+
globalAnnounceEnabled: true,
12+
localAnnounceEnabled: true,
13+
relaysEnabled: true,
14+
natEnabled: true,
15+
startBrowser: false,
16+
urAccepted: -1,
17+
},
18+
{
19+
type: 'syncthing-device',
20+
deviceId: '<Replace with peer device ID>',
21+
deviceName: 'My Second Machine',
22+
addresses: ['dynamic'],
23+
autoAcceptFolders: false,
24+
paused: false,
25+
compression: 'metadata',
26+
},
27+
{
28+
type: 'syncthing-folder',
29+
id: 'my-docs',
30+
path: '~/Documents',
31+
label: 'My Documents',
32+
folderType: 'sendreceive',
33+
devices: ['<Replace with peer device ID>'],
34+
fsWatcherEnabled: true,
35+
rescanIntervalS: 3600,
36+
maxConflicts: 10,
37+
paused: false,
38+
},
39+
]
40+
},
41+
}

src/resources/syncthing/syncthing-device.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
ModifyPlan,
56
ParameterChange,
67
Resource,
@@ -12,6 +13,7 @@ import {
1213
import { OS } from '@codifycli/schemas';
1314

1415
import { isDaemonRunning } from './syncthing-utils.js';
16+
import { exampleSyncthingConfigs } from './examples.js';
1517

1618
const schema = z
1719
.object({
@@ -56,6 +58,27 @@ const schema = z
5658

5759
export type SyncthingDeviceConfig = z.infer<typeof schema>;
5860

61+
const defaultConfig: Partial<SyncthingDeviceConfig> = {
62+
addresses: ['dynamic'],
63+
autoAcceptFolders: false,
64+
paused: false,
65+
compression: 'metadata',
66+
}
67+
68+
const exampleConfig: ExampleConfig = {
69+
title: 'Example Syncthing device',
70+
description: 'Add a remote peer device by its device ID. Use dynamic addressing for automatic discovery, metadata compression, and auto-accept any folders the peer shares.',
71+
configs: [{
72+
type: 'syncthing-device',
73+
deviceId: '<Replace me here!>',
74+
deviceName: 'My Laptop',
75+
addresses: ['dynamic'],
76+
autoAcceptFolders: true,
77+
paused: false,
78+
compression: 'metadata',
79+
}]
80+
}
81+
5982
/** Raw JSON shape returned by `syncthing cli config devices <id>` */
6083
interface RawDevice {
6184
deviceID: string;
@@ -72,6 +95,11 @@ export class SyncthingDeviceResource extends Resource<SyncthingDeviceConfig> {
7295
getSettings(): ResourceSettings<SyncthingDeviceConfig> {
7396
return {
7497
id: 'syncthing-device',
98+
defaultConfig,
99+
exampleConfigs: {
100+
example1: exampleConfig,
101+
...exampleSyncthingConfigs
102+
},
75103
operatingSystems: [OS.Darwin, OS.Linux],
76104
dependencies: ['syncthing'],
77105
schema,

src/resources/syncthing/syncthing-folder.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
ModifyPlan,
56
ParameterChange,
67
Resource,
@@ -12,6 +13,7 @@ import {
1213
import { OS } from '@codifycli/schemas';
1314

1415
import { isDaemonRunning } from './syncthing-utils.js';
16+
import { exampleSyncthingConfigs } from './examples.js';
1517

1618
const FOLDER_TYPES = ['sendreceive', 'sendonly', 'receiveonly', 'receiveencrypted'] as const;
1719

@@ -61,6 +63,31 @@ const schema = z
6163

6264
export type SyncthingFolderConfig = z.infer<typeof schema>;
6365

66+
const defaultConfig: Partial<SyncthingFolderConfig> = {
67+
folderType: 'sendreceive',
68+
fsWatcherEnabled: true,
69+
rescanIntervalS: 3600,
70+
maxConflicts: 10,
71+
paused: false,
72+
}
73+
74+
const exampleConfig: ExampleConfig = {
75+
title: 'Example Syncthing folder',
76+
description: 'Share a local directory with one or more peer devices. Uses sendreceive mode so changes flow in both directions, with filesystem watching for fast change detection.',
77+
configs: [{
78+
type: 'syncthing-folder',
79+
id: 'my-docs',
80+
path: '~/Documents',
81+
label: 'My Documents',
82+
folderType: 'sendreceive',
83+
devices: ['<Replace with device ID>'],
84+
fsWatcherEnabled: true,
85+
rescanIntervalS: 3600,
86+
maxConflicts: 10,
87+
paused: false,
88+
}]
89+
}
90+
6491
/** Raw JSON shape returned by `syncthing cli config folders <id>` */
6592
interface RawFolder {
6693
id: string;
@@ -78,6 +105,11 @@ export class SyncthingFolderResource extends Resource<SyncthingFolderConfig> {
78105
getSettings(): ResourceSettings<SyncthingFolderConfig> {
79106
return {
80107
id: 'syncthing-folder',
108+
defaultConfig,
109+
exampleConfigs: {
110+
example1: exampleConfig,
111+
...exampleSyncthingConfigs
112+
},
81113
operatingSystems: [OS.Darwin, OS.Linux],
82114
dependencies: ['syncthing'],
83115
schema,

src/resources/syncthing/syncthing.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
ModifyPlan,
56
ParameterChange,
67
Resource,
@@ -12,6 +13,7 @@ import {
1213
import { OS } from '@codifycli/schemas';
1314

1415
import { Utils } from '../../utils/index.js';
16+
import { exampleSyncthingConfigs } from './examples.js';
1517
import {
1618
getCliConfigBool,
1719
getCliConfigNumber,
@@ -74,6 +76,31 @@ const schema = z
7476

7577
export type SyncthingConfig = z.infer<typeof schema>;
7678

79+
const defaultConfig: Partial<SyncthingConfig> = {
80+
launchAtStartup: true,
81+
globalAnnounceEnabled: true,
82+
localAnnounceEnabled: true,
83+
relaysEnabled: true,
84+
natEnabled: true,
85+
startBrowser: false,
86+
urAccepted: -1,
87+
}
88+
89+
const exampleConfig: ExampleConfig = {
90+
title: 'Example Syncthing config',
91+
description: 'Install Syncthing with sensible defaults: launch at startup, local and global discovery enabled, relays on, no browser auto-open, and usage reporting opted out.',
92+
configs: [{
93+
type: 'syncthing',
94+
launchAtStartup: true,
95+
globalAnnounceEnabled: true,
96+
localAnnounceEnabled: true,
97+
relaysEnabled: true,
98+
natEnabled: true,
99+
startBrowser: false,
100+
urAccepted: -1,
101+
}]
102+
}
103+
77104
// Maps schema key → syncthing CLI config path (without trailing "get/set <value>")
78105
// Syncthing v2 uses kebab-case subcommands
79106
const OPTION_CLI_PATHS: Partial<Record<keyof SyncthingConfig, string>> = {
@@ -92,6 +119,11 @@ export class SyncthingResource extends Resource<SyncthingConfig> {
92119
getSettings(): ResourceSettings<SyncthingConfig> {
93120
return {
94121
id: 'syncthing',
122+
defaultConfig,
123+
exampleConfigs: {
124+
example1: exampleConfig,
125+
...exampleSyncthingConfigs,
126+
},
95127
operatingSystems: [OS.Darwin, OS.Linux],
96128
schema,
97129
parameterSettings: {

0 commit comments

Comments
 (0)