@codifycli/plugin-core 1.0.0-beta1 → 1.0.0-beta3
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/.github/workflows/unit-test-ci.yaml +11 -5
- package/CLAUDE.md +183 -0
- package/README.md +427 -0
- package/bin/build.js +1 -1
- package/dist/messages/handlers.js +1 -1
- package/dist/messages/sender.js +1 -1
- package/dist/plan/change-set.d.ts +1 -1
- package/dist/plan/change-set.js +1 -1
- package/dist/plan/plan-types.d.ts +1 -1
- package/dist/plan/plan.d.ts +1 -1
- package/dist/plan/plan.js +1 -1
- package/dist/plugin/plugin.d.ts +1 -1
- package/dist/pty/seqeuntial-pty.js +1 -1
- package/dist/resource/config-parser.d.ts +1 -1
- package/dist/resource/parsed-resource-settings.d.ts +1 -1
- package/dist/resource/resource-controller.d.ts +1 -1
- package/dist/resource/resource-controller.js +1 -1
- package/dist/resource/resource-settings.d.ts +1 -1
- package/dist/resource/resource.d.ts +1 -1
- package/dist/stateful-parameter/stateful-parameter-controller.d.ts +1 -1
- package/dist/stateful-parameter/stateful-parameter.d.ts +1 -1
- package/dist/utils/functions.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +25 -8
- package/src/messages/handlers.test.ts +1 -1
- package/src/messages/handlers.ts +3 -3
- package/src/messages/sender.ts +1 -1
- package/src/plan/change-set.test.ts +1 -1
- package/src/plan/change-set.ts +1 -1
- package/src/plan/plan-types.ts +1 -1
- package/src/plan/plan.test.ts +1 -1
- package/src/plan/plan.ts +1 -1
- package/src/plugin/plugin.test.ts +1 -1
- package/src/plugin/plugin.ts +2 -2
- package/src/pty/background-pty.test.ts +0 -1
- package/src/pty/index.test.ts +1 -1
- package/src/pty/seqeuntial-pty.ts +6 -1
- package/src/pty/sequential-pty.test.ts +2 -3
- package/src/resource/config-parser.ts +1 -1
- package/src/resource/parsed-resource-settings.test.ts +1 -1
- package/src/resource/parsed-resource-settings.ts +1 -1
- package/src/resource/resource-controller-stateful-mode.test.ts +1 -1
- package/src/resource/resource-controller.test.ts +1 -1
- package/src/resource/resource-controller.ts +3 -3
- package/src/resource/resource-settings.test.ts +1 -1
- package/src/resource/resource-settings.ts +1 -1
- package/src/resource/resource.ts +1 -1
- package/src/stateful-parameter/stateful-parameter-controller.test.ts +1 -1
- package/src/stateful-parameter/stateful-parameter-controller.ts +1 -1
- package/src/stateful-parameter/stateful-parameter.ts +1 -1
- package/src/utils/functions.ts +1 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/test-utils.test.ts +1 -1
- package/.github/workflows/release.yaml +0 -19
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
2
|
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
3
|
|
|
4
|
-
name:
|
|
4
|
+
name: Node.js CI
|
|
5
5
|
|
|
6
|
-
on: [ push ]
|
|
6
|
+
on: [ 'push' ]
|
|
7
7
|
|
|
8
8
|
jobs:
|
|
9
9
|
build-and-test:
|
|
10
|
-
runs-on:
|
|
10
|
+
runs-on: ${{ matrix.os }}
|
|
11
|
+
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
os: [ ubuntu-latest, macos-latest ]
|
|
15
|
+
|
|
11
16
|
steps:
|
|
12
17
|
- uses: actions/checkout@v4
|
|
13
|
-
-
|
|
18
|
+
- name: Use Node.js 22
|
|
19
|
+
uses: actions/setup-node@v4
|
|
14
20
|
with:
|
|
15
|
-
node-version: '
|
|
21
|
+
node-version: '22.x'
|
|
16
22
|
cache: 'npm'
|
|
17
23
|
- run: npm ci
|
|
18
24
|
- run: npm run test
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@codifycli/plugin-core` is a TypeScript library for building Codify plugins. Codify is an infrastructure-as-code tool
|
|
8
|
+
that manages system resources (applications, CLI tools, settings) through a declarative JSON configuration. This library
|
|
9
|
+
provides the core abstractions and runtime for implementing plugins that can create, modify, and destroy system
|
|
10
|
+
resources.
|
|
11
|
+
|
|
12
|
+
## Development Commands
|
|
13
|
+
|
|
14
|
+
### Testing
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Run all tests with Vitest
|
|
18
|
+
npm test
|
|
19
|
+
|
|
20
|
+
# Note: `npm test` also runs TypeScript compilation as a posttest step
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Building
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Compile TypeScript to dist/
|
|
27
|
+
npm run prepublishOnly
|
|
28
|
+
|
|
29
|
+
# Or just compile directly
|
|
30
|
+
npx tsc
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Linting
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Lint with ESLint (oclif + oclif-typescript + prettier configs)
|
|
37
|
+
npx eslint src/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### CLI Tool
|
|
41
|
+
|
|
42
|
+
The package includes a `codify-build` CLI tool (in `bin/build.js`) used by plugin implementations to generate
|
|
43
|
+
documentation and validate schemas.
|
|
44
|
+
|
|
45
|
+
## Architecture
|
|
46
|
+
|
|
47
|
+
### Core Concepts
|
|
48
|
+
|
|
49
|
+
**Plugin System Architecture:**
|
|
50
|
+
|
|
51
|
+
- **Plugin** (`src/plugin/plugin.ts`): Top-level container that manages multiple resource types and handles IPC
|
|
52
|
+
communication with the Codify CLI via the MessageHandler
|
|
53
|
+
- **Resource** (`src/resource/resource.ts`): Abstract base class representing a manageable system resource (e.g.,
|
|
54
|
+
homebrew, git config, applications). Each resource must implement:
|
|
55
|
+
- `refresh()`: Query current system state
|
|
56
|
+
- `create()`: Install/create the resource
|
|
57
|
+
- `destroy()`: Uninstall/remove the resource
|
|
58
|
+
- `modify()`: Update individual parameters (optional)
|
|
59
|
+
- **Plan** (`src/plan/plan.ts`): Represents a set of changes to transform current state into desired state, similar to
|
|
60
|
+
Terraform plans. Contains a ChangeSet with parameter-level operations (ADD/REMOVE/MODIFY/NO-OP) and resource-level
|
|
61
|
+
operation (CREATE/DESTROY/MODIFY/RECREATE/NO-OP)
|
|
62
|
+
- **ResourceController** (`src/resource/resource-controller.ts`): Orchestrates the full lifecycle: validation →
|
|
63
|
+
planning → application. Handles both stateful mode (tracks state between runs) and stateless mode (declarative only)
|
|
64
|
+
|
|
65
|
+
**Stateful vs Stateless Modes:**
|
|
66
|
+
|
|
67
|
+
- **Stateless**: Plans computed by comparing desired config against current system state. Only manages parameters
|
|
68
|
+
explicitly declared in config.
|
|
69
|
+
- **Stateful**: Tracks previous state. Enables destroy operations and more granular change detection. Plans compare
|
|
70
|
+
desired vs state, then match state to current system state.
|
|
71
|
+
|
|
72
|
+
**Stateful Parameters** (`src/stateful-parameter/stateful-parameter.ts`):
|
|
73
|
+
|
|
74
|
+
- Parameters that have their own lifecycle tied to the parent resource (e.g., homebrew formulas, nvm node versions)
|
|
75
|
+
- Implement their own `refresh()`, `add()`, `modify()`, `remove()` methods
|
|
76
|
+
- Can be array-based (`ArrayStatefulParameter`) for managing collections
|
|
77
|
+
|
|
78
|
+
**PTY Abstraction** (`src/pty/`):
|
|
79
|
+
|
|
80
|
+
- `BackgroundPty`: Executes commands asynchronously during refresh/plan operations. Multiple commands can run in
|
|
81
|
+
parallel. Killed after planning completes.
|
|
82
|
+
- `SequentialPty`: Executes commands synchronously during apply operations to ensure ordered execution and proper error
|
|
83
|
+
handling
|
|
84
|
+
- `getPty()`: Access current PTY from async local storage context
|
|
85
|
+
- All shell execution goes through this abstraction for consistent output handling and root privilege escalation
|
|
86
|
+
|
|
87
|
+
**IPC Communication** (`src/messages/`):
|
|
88
|
+
|
|
89
|
+
- `MessageHandler`: Processes messages from Codify CLI (initialize, plan, apply, validate, import, match)
|
|
90
|
+
- `MessageSender`: Sends responses and requests (e.g., sudo password prompts) back to CLI
|
|
91
|
+
- Messages validated against schemas from `@codifycli/schemas`
|
|
92
|
+
|
|
93
|
+
### Directory Structure
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
src/
|
|
97
|
+
├── plugin/ - Plugin class and main entry point
|
|
98
|
+
├── resource/ - Resource base class, settings, controller
|
|
99
|
+
├── plan/ - Plan calculation and change set logic
|
|
100
|
+
├── stateful-parameter/ - Stateful parameter abstractions
|
|
101
|
+
├── pty/ - Pseudo-terminal abstraction for shell commands
|
|
102
|
+
├── messages/ - IPC message handlers and senders
|
|
103
|
+
├── utils/ - File utilities, path resolution, debug logging
|
|
104
|
+
└── common/ - Shared errors and types
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Key Files
|
|
108
|
+
|
|
109
|
+
- `src/index.ts`: Main entry point with `runPlugin()` function
|
|
110
|
+
- `src/plugin/plugin.ts`: Core plugin implementation (~290 lines)
|
|
111
|
+
- `src/resource/resource.ts`: Abstract Resource class
|
|
112
|
+
- `src/resource/resource-controller.ts`: Resource lifecycle orchestration
|
|
113
|
+
- `src/resource/resource-settings.ts`: Configuration schema for resources (parameter settings, OS support, allow
|
|
114
|
+
multiple, etc.)
|
|
115
|
+
- `src/plan/plan.ts`: Plan calculation logic (~500 lines)
|
|
116
|
+
- `src/plan/change-set.ts`: Parameter-level diff algorithm
|
|
117
|
+
- `bin/build.js`: Documentation/schema builder for plugin implementations
|
|
118
|
+
|
|
119
|
+
### Resource Settings
|
|
120
|
+
|
|
121
|
+
Resources are configured via `ResourceSettings<T>` returned by `getSettings()`:
|
|
122
|
+
|
|
123
|
+
- `id`: Unique type identifier
|
|
124
|
+
- `schema`: JSON Schema or Zod schema for validation
|
|
125
|
+
- `operatingSystems`: Supported OS platforms (darwin/linux/win32)
|
|
126
|
+
- `linuxDistros`: Supported Linux distributions (optional)
|
|
127
|
+
- `allowMultiple`: Whether multiple instances can coexist (requires `matcher` function)
|
|
128
|
+
- `parameterSettings`: Per-parameter configuration (equals functions, transformations, stateful types, sensitivity)
|
|
129
|
+
- `isSensitive`: Marks resource as sensitive (prevents auto-import, hides values)
|
|
130
|
+
- `dependencies`: Resource IDs this resource depends on
|
|
131
|
+
- `canDestroy`: Whether resource can be destroyed (default: true)
|
|
132
|
+
|
|
133
|
+
## Implementation Notes
|
|
134
|
+
|
|
135
|
+
### Testing
|
|
136
|
+
|
|
137
|
+
- Uses Vitest with `pool: 'forks'` configuration for isolated test execution
|
|
138
|
+
- Test files use `.test.ts` suffix and are excluded from compilation
|
|
139
|
+
- TypeScript compilation runs as a posttest step to catch type errors
|
|
140
|
+
|
|
141
|
+
### Module System
|
|
142
|
+
|
|
143
|
+
- Uses ES modules (`"type": "module"` in package.json)
|
|
144
|
+
- Module resolution: `Node16` with `.js` extensions in imports (even for `.ts` files)
|
|
145
|
+
- Target: ES2022
|
|
146
|
+
- Requires Node.js >=22.0.0
|
|
147
|
+
|
|
148
|
+
### Parameter Matching and Filtering
|
|
149
|
+
|
|
150
|
+
Array parameters support custom matching logic:
|
|
151
|
+
|
|
152
|
+
- `isElementEqual`: Function to compare array elements
|
|
153
|
+
- `filterInStatelessMode`: Controls how current state is filtered against desired state in stateless mode
|
|
154
|
+
- Default behavior: filters current arrays to only include elements matching desired config (prevents spurious deletes)
|
|
155
|
+
|
|
156
|
+
### Path Handling
|
|
157
|
+
|
|
158
|
+
Utility functions in `src/utils/functions.ts`:
|
|
159
|
+
|
|
160
|
+
- `tildify()`: Convert absolute paths to use `~`
|
|
161
|
+
- `untildify()`: Expand `~` to home directory
|
|
162
|
+
- `resolvePathWithVariables()`: Resolve paths with variables like `$CODIFY_*`
|
|
163
|
+
- Path transformations are commonly used in `InputTransformation` for file/directory parameters
|
|
164
|
+
|
|
165
|
+
### CI/CD
|
|
166
|
+
|
|
167
|
+
GitHub Actions workflow (`.github/workflows/unit-test-ci.yaml`):
|
|
168
|
+
|
|
169
|
+
- Runs on push to any branch
|
|
170
|
+
- Tests on: `ubuntu-latest`, `macos-latest`
|
|
171
|
+
- Node.js version: 22.x
|
|
172
|
+
- Commands: `npm ci` → `npm run test`
|
|
173
|
+
|
|
174
|
+
### Dependencies
|
|
175
|
+
|
|
176
|
+
Key dependencies:
|
|
177
|
+
|
|
178
|
+
- `@codifycli/schemas`: Shared schema definitions and types
|
|
179
|
+
- `@homebridge/node-pty-prebuilt-multiarch`: PTY for shell command execution
|
|
180
|
+
- `ajv`: JSON Schema validation
|
|
181
|
+
- `zod`: Alternative schema validation (v4)
|
|
182
|
+
- `clean-deep`: Remove null/undefined from objects
|
|
183
|
+
- `lodash.isequal`: Deep equality checks
|
package/README.md
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
# @codifycli/plugin-core
|
|
2
|
+
|
|
3
|
+
Core library for building [Codify](https://github.com/codifycli) plugins. Codify is an infrastructure-as-code tool that
|
|
4
|
+
manages system resources (applications, CLI tools, and settings) through declarative JSON configuration files.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
This library provides the foundational abstractions and runtime for creating Codify plugins. Plugins extend Codify's
|
|
9
|
+
capabilities by implementing resources that can be created, modified, and destroyed on a system. Examples of resources
|
|
10
|
+
include:
|
|
11
|
+
|
|
12
|
+
- **CLI Tools**: Homebrew, Docker, Git
|
|
13
|
+
- **Applications**: Google Chrome, VS Code, Zoom
|
|
14
|
+
- **Settings**: Git configs, AWS profiles, system preferences
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @codifycli/plugin-core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Requirements:**
|
|
23
|
+
|
|
24
|
+
- Node.js >= 22.0.0
|
|
25
|
+
- TypeScript 5.x (for development)
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
Here's a minimal example of creating a plugin with a single resource:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Resource, ResourceSettings, Plugin, runPlugin, getPty } from '@codifycli/plugin-core';
|
|
33
|
+
import { StringIndexedObject } from '@codifycli/schemas';
|
|
34
|
+
|
|
35
|
+
// Define the resource configuration type
|
|
36
|
+
interface GitConfig extends StringIndexedObject {
|
|
37
|
+
userName?: string;
|
|
38
|
+
userEmail?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Implement the Resource abstract class
|
|
42
|
+
class GitConfigResource extends Resource<GitConfig> {
|
|
43
|
+
getSettings(): ResourceSettings<GitConfig> {
|
|
44
|
+
return {
|
|
45
|
+
id: 'git-config',
|
|
46
|
+
operatingSystems: ['darwin', 'linux'],
|
|
47
|
+
schema: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
userName: { type: 'string' },
|
|
51
|
+
userEmail: { type: 'string' }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async refresh(parameters: Partial<GitConfig>) {
|
|
58
|
+
const pty = getPty();
|
|
59
|
+
|
|
60
|
+
const nameResult = await pty.spawnSafe('git config --global user.name');
|
|
61
|
+
const emailResult = await pty.spawnSafe('git config --global user.email');
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
userName: nameResult.status === 'success' ? nameResult.data.trim() : undefined,
|
|
65
|
+
userEmail: emailResult.status === 'success' ? emailResult.data.trim() : undefined
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async create(plan) {
|
|
70
|
+
const pty = getPty();
|
|
71
|
+
const config = plan.desiredConfig!;
|
|
72
|
+
|
|
73
|
+
if (config.userName) {
|
|
74
|
+
await pty.spawn(`git config --global user.name "${config.userName}"`);
|
|
75
|
+
}
|
|
76
|
+
if (config.userEmail) {
|
|
77
|
+
await pty.spawn(`git config --global user.email "${config.userEmail}"`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async destroy(plan) {
|
|
82
|
+
const pty = getPty();
|
|
83
|
+
|
|
84
|
+
await pty.spawn('git config --global --unset user.name');
|
|
85
|
+
await pty.spawn('git config --global --unset user.email');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Create and run the plugin
|
|
90
|
+
const plugin = Plugin.create('my-plugin', [new GitConfigResource()]);
|
|
91
|
+
runPlugin(plugin);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Core Concepts
|
|
95
|
+
|
|
96
|
+
### Plugin
|
|
97
|
+
|
|
98
|
+
The top-level container that manages multiple resource types. Handles IPC communication with the Codify CLI.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const plugin = Plugin.create('plugin-name', [
|
|
102
|
+
new Resource1(),
|
|
103
|
+
new Resource2(),
|
|
104
|
+
// ... more resources
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
runPlugin(plugin);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Resource
|
|
111
|
+
|
|
112
|
+
The fundamental building block representing a manageable system entity. Resources must implement:
|
|
113
|
+
|
|
114
|
+
- **`getSettings()`**: Return resource configuration (id, schema, OS support, etc.)
|
|
115
|
+
- **`refresh(parameters, context)`**: Query the current system state
|
|
116
|
+
- **`create(plan)`**: Install/create the resource
|
|
117
|
+
- **`destroy(plan)`**: Uninstall/remove the resource
|
|
118
|
+
- **`modify(parameterChange, plan)`**: Update individual parameters (optional)
|
|
119
|
+
|
|
120
|
+
### Plan
|
|
121
|
+
|
|
122
|
+
Represents a set of changes needed to transform the current state into the desired state. Plans contain:
|
|
123
|
+
|
|
124
|
+
- **Resource Operation**: CREATE, DESTROY, MODIFY, RECREATE, or NOOP
|
|
125
|
+
- **Parameter Changes**: Individual parameter-level operations (ADD, REMOVE, MODIFY, NOOP)
|
|
126
|
+
|
|
127
|
+
The planning workflow:
|
|
128
|
+
|
|
129
|
+
1. **Validate**: Check user configuration against schema
|
|
130
|
+
2. **Plan**: Compare desired vs. current state, generate change set
|
|
131
|
+
3. **Apply**: Execute the plan to make changes
|
|
132
|
+
|
|
133
|
+
### Stateful vs Stateless Modes
|
|
134
|
+
|
|
135
|
+
**Stateless Mode** (default):
|
|
136
|
+
|
|
137
|
+
- Plans computed by comparing desired config against current system state
|
|
138
|
+
- Only manages parameters explicitly declared in config
|
|
139
|
+
- No destroy operations (removing from config = ignored by Codify)
|
|
140
|
+
|
|
141
|
+
**Stateful Mode**:
|
|
142
|
+
|
|
143
|
+
- Tracks previous state between runs
|
|
144
|
+
- Supports destroy operations
|
|
145
|
+
- Plans compare desired vs. state, then match state to current system
|
|
146
|
+
- Enables granular change detection
|
|
147
|
+
|
|
148
|
+
### Stateful Parameters
|
|
149
|
+
|
|
150
|
+
Parameters with their own lifecycle, tied to the parent resource. Examples:
|
|
151
|
+
|
|
152
|
+
- Homebrew formulas (can be installed/uninstalled within Homebrew)
|
|
153
|
+
- NVM Node versions (managed within NVM)
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { StatefulParameter } from '@codifycli/plugin-core';
|
|
157
|
+
|
|
158
|
+
class BrewFormulaParameter extends StatefulParameter<BrewConfig, string[]> {
|
|
159
|
+
async refresh(desired, config) {
|
|
160
|
+
const pty = getPty();
|
|
161
|
+
const result = await pty.spawn('brew list --formula');
|
|
162
|
+
return result.data.split('\n').filter(Boolean);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async add(formulas, plan) {
|
|
166
|
+
const pty = getPty();
|
|
167
|
+
await pty.spawn(`brew install --formula ${formulas.join(' ')}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async remove(formulas, plan) {
|
|
171
|
+
const pty = getPty();
|
|
172
|
+
await pty.spawn(`brew uninstall --formula ${formulas.join(' ')}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async modify(newValue, previousValue, plan) {
|
|
176
|
+
// Handle formula updates
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Register in resource settings:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
getSettings()
|
|
185
|
+
:
|
|
186
|
+
ResourceSettings < BrewConfig > {
|
|
187
|
+
return {
|
|
188
|
+
id: 'homebrew',
|
|
189
|
+
parameterSettings: {
|
|
190
|
+
formulas: {
|
|
191
|
+
type: 'stateful',
|
|
192
|
+
implementation: new BrewFormulaParameter()
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### PTY Abstraction
|
|
200
|
+
|
|
201
|
+
Execute shell commands through the PTY abstraction:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { getPty } from '@codifycli/plugin-core';
|
|
205
|
+
|
|
206
|
+
const pty = getPty();
|
|
207
|
+
|
|
208
|
+
// Spawn command (throws on non-zero exit)
|
|
209
|
+
const result = await pty.spawn('brew install jq');
|
|
210
|
+
|
|
211
|
+
// Spawn safely (returns result with status)
|
|
212
|
+
const safeResult = await pty.spawnSafe('which jq');
|
|
213
|
+
if (safeResult.status === 'success') {
|
|
214
|
+
console.log(safeResult.data);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// With options
|
|
218
|
+
await pty.spawn('npm install', {
|
|
219
|
+
cwd: '/path/to/project',
|
|
220
|
+
env: { NODE_ENV: 'production' },
|
|
221
|
+
interactive: true,
|
|
222
|
+
requiresRoot: false
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Two PTY implementations:
|
|
227
|
+
|
|
228
|
+
- **BackgroundPty**: Async execution during refresh/plan (killed after planning)
|
|
229
|
+
- **SequentialPty**: Sync execution during apply operations
|
|
230
|
+
|
|
231
|
+
## Resource Settings
|
|
232
|
+
|
|
233
|
+
Configure resource behavior via `ResourceSettings<T>`:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
getSettings()
|
|
237
|
+
:
|
|
238
|
+
ResourceSettings < MyConfig > {
|
|
239
|
+
return {
|
|
240
|
+
// Required: unique type identifier
|
|
241
|
+
id: 'my-resource',
|
|
242
|
+
|
|
243
|
+
// Required: supported operating systems
|
|
244
|
+
operatingSystems: ['darwin', 'linux', 'win32'],
|
|
245
|
+
|
|
246
|
+
// Optional: supported Linux distributions
|
|
247
|
+
linuxDistros: ['ubuntu', 'debian', 'fedora'],
|
|
248
|
+
|
|
249
|
+
// Schema for validation (JSON Schema or Zod)
|
|
250
|
+
schema: {
|
|
251
|
+
type: 'object',
|
|
252
|
+
properties: {
|
|
253
|
+
version: { type: 'string' },
|
|
254
|
+
path: { type: 'string' }
|
|
255
|
+
},
|
|
256
|
+
required: ['version']
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
// Allow multiple instances
|
|
260
|
+
allowMultiple: {
|
|
261
|
+
identifyingParameters: ['name', 'path'],
|
|
262
|
+
matcher: (desired, current) => desired.name === current.name
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
// Prevent resource from being destroyed
|
|
266
|
+
canDestroy: false,
|
|
267
|
+
|
|
268
|
+
// Mark as sensitive (prevents auto-import)
|
|
269
|
+
isSensitive: true,
|
|
270
|
+
|
|
271
|
+
// Resource dependencies
|
|
272
|
+
dependencies: ['other-resource-id'],
|
|
273
|
+
|
|
274
|
+
// Per-parameter settings
|
|
275
|
+
parameterSettings: {
|
|
276
|
+
path: {
|
|
277
|
+
inputTransformation: {
|
|
278
|
+
to: (input) => untildify(input), // Expand ~
|
|
279
|
+
from: (current) => tildify(current) // Convert to ~
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
apiKey: {
|
|
283
|
+
isSensitive: true // Hide in plan output
|
|
284
|
+
},
|
|
285
|
+
tags: {
|
|
286
|
+
type: 'array',
|
|
287
|
+
isElementEqual: (a, b) => a.name === b.name
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## API Reference
|
|
295
|
+
|
|
296
|
+
### Core Classes
|
|
297
|
+
|
|
298
|
+
#### `Plugin`
|
|
299
|
+
|
|
300
|
+
- `static create(name: string, resources: Resource[]): Plugin`
|
|
301
|
+
- `async initialize(data): Promise<InitializeResponseData>`
|
|
302
|
+
- `async plan(data): Promise<PlanResponseData>`
|
|
303
|
+
- `async apply(data): Promise<void>`
|
|
304
|
+
- `async validate(data): Promise<ValidateResponseData>`
|
|
305
|
+
- `async import(data): Promise<ImportResponseData>`
|
|
306
|
+
- `async match(data): Promise<MatchResponseData>`
|
|
307
|
+
|
|
308
|
+
#### `Resource<T>`
|
|
309
|
+
|
|
310
|
+
- `abstract getSettings(): ResourceSettings<T>`
|
|
311
|
+
- `async initialize(): Promise<void>`
|
|
312
|
+
- `async validate(parameters): Promise<void>`
|
|
313
|
+
- `abstract refresh(parameters, context): Promise<T | T[] | null>`
|
|
314
|
+
- `abstract create(plan: CreatePlan<T>): Promise<void>`
|
|
315
|
+
- `abstract destroy(plan: DestroyPlan<T>): Promise<void>`
|
|
316
|
+
- `async modify(change: ParameterChange<T>, plan: ModifyPlan<T>): Promise<void>`
|
|
317
|
+
|
|
318
|
+
#### `Plan<T>`
|
|
319
|
+
|
|
320
|
+
- `id: string`
|
|
321
|
+
- `changeSet: ChangeSet<T>`
|
|
322
|
+
- `coreParameters: ResourceConfig`
|
|
323
|
+
- `isStateful: boolean`
|
|
324
|
+
- `desiredConfig: T | null`
|
|
325
|
+
- `currentConfig: T | null`
|
|
326
|
+
- `requiresChanges(): boolean`
|
|
327
|
+
- `toResponse(): PlanResponseData`
|
|
328
|
+
|
|
329
|
+
#### `StatefulParameter<T, V>`
|
|
330
|
+
|
|
331
|
+
- `getSettings(): ParameterSetting`
|
|
332
|
+
- `abstract refresh(desired, config): Promise<V | null>`
|
|
333
|
+
- `abstract add(value, plan): Promise<void>`
|
|
334
|
+
- `abstract modify(newValue, previousValue, plan): Promise<void>`
|
|
335
|
+
- `abstract remove(value, plan): Promise<void>`
|
|
336
|
+
|
|
337
|
+
### Utility Functions
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
// PTY access
|
|
341
|
+
getPty()
|
|
342
|
+
:
|
|
343
|
+
IPty
|
|
344
|
+
|
|
345
|
+
// Path utilities
|
|
346
|
+
tildify(absolutePath
|
|
347
|
+
:
|
|
348
|
+
string
|
|
349
|
+
):
|
|
350
|
+
string
|
|
351
|
+
untildify(pathWithTilde
|
|
352
|
+
:
|
|
353
|
+
string
|
|
354
|
+
):
|
|
355
|
+
string
|
|
356
|
+
resolvePathWithVariables(path
|
|
357
|
+
:
|
|
358
|
+
string
|
|
359
|
+
):
|
|
360
|
+
string
|
|
361
|
+
addVariablesToPath(absolutePath
|
|
362
|
+
:
|
|
363
|
+
string
|
|
364
|
+
):
|
|
365
|
+
string
|
|
366
|
+
|
|
367
|
+
// File utilities
|
|
368
|
+
fileExists(path
|
|
369
|
+
:
|
|
370
|
+
string
|
|
371
|
+
):
|
|
372
|
+
Promise<boolean>
|
|
373
|
+
directoryExists(path
|
|
374
|
+
:
|
|
375
|
+
string
|
|
376
|
+
):
|
|
377
|
+
Promise<boolean>
|
|
378
|
+
|
|
379
|
+
// Array utilities
|
|
380
|
+
areArraysEqual<T>(a
|
|
381
|
+
:
|
|
382
|
+
T[], b
|
|
383
|
+
:
|
|
384
|
+
T[], isEqual ? : (a: T, b: T) => boolean
|
|
385
|
+
):
|
|
386
|
+
boolean
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Building Plugins
|
|
390
|
+
|
|
391
|
+
The library includes a `codify-build` CLI tool for plugin development:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Generate plugin documentation and validate schemas
|
|
395
|
+
npx codify-build
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
This tool expects a plugin implementation with a `src/resources/` directory structure.
|
|
399
|
+
|
|
400
|
+
## Development
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
# Install dependencies
|
|
404
|
+
npm install
|
|
405
|
+
|
|
406
|
+
# Run tests
|
|
407
|
+
npm test
|
|
408
|
+
|
|
409
|
+
# Build
|
|
410
|
+
npx tsc
|
|
411
|
+
|
|
412
|
+
# Lint
|
|
413
|
+
npx eslint src/
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Examples
|
|
417
|
+
|
|
418
|
+
See the `@codifycli/plugin-core` tests for more examples:
|
|
419
|
+
|
|
420
|
+
- `src/plugin/plugin.test.ts` - Plugin lifecycle
|
|
421
|
+
- `src/resource/resource-controller.test.ts` - Resource operations
|
|
422
|
+
- `src/plan/plan.test.ts` - Plan calculation
|
|
423
|
+
- `src/stateful-parameter/stateful-parameter-controller.test.ts` - Stateful parameters
|
|
424
|
+
|
|
425
|
+
## License
|
|
426
|
+
|
|
427
|
+
ISC
|
package/bin/build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { IpcMessageSchema, MessageStatus, ResourceSchema } from '@codifycli/schemas';
|
|
2
3
|
import { Ajv } from 'ajv';
|
|
3
|
-
import { IpcMessageSchema, MessageStatus, ResourceSchema } from 'codify-schemas';
|
|
4
4
|
import mergeJsonSchemas from 'merge-json-schemas';
|
|
5
5
|
import { fork } from 'node:child_process';
|
|
6
6
|
import fs from 'node:fs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ApplyRequestDataSchema, EmptyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, SetVerbosityRequestDataSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from '@codifycli/schemas';
|
|
1
2
|
import { Ajv } from 'ajv';
|
|
2
3
|
import addFormats from 'ajv-formats';
|
|
3
|
-
import { ApplyRequestDataSchema, EmptyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, SetVerbosityRequestDataSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
|
|
4
4
|
import { SudoError } from '../errors.js';
|
|
5
5
|
const SupportedRequests = {
|
|
6
6
|
'initialize': {
|
package/dist/messages/sender.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParameterOperation, ResourceOperation, StringIndexedObject } from '
|
|
1
|
+
import { ParameterOperation, ResourceOperation, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { ParsedParameterSetting } from '../resource/parsed-resource-settings.js';
|
|
3
3
|
import { ResourceSettings } from '../resource/resource-settings.js';
|
|
4
4
|
/**
|
package/dist/plan/change-set.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParameterOperation, ResourceOperation } from '
|
|
1
|
+
import { ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
2
2
|
// Change set will coerce undefined values to null because undefined is not valid JSON
|
|
3
3
|
export class ChangeSet {
|
|
4
4
|
operation;
|
package/dist/plan/plan.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplyRequestData, PlanResponseData, ResourceConfig, StringIndexedObject } from '
|
|
1
|
+
import { ApplyRequestData, PlanResponseData, ResourceConfig, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
|
|
3
3
|
import { ChangeSet } from './change-set.js';
|
|
4
4
|
/**
|
package/dist/plan/plan.js
CHANGED
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, SetVerbosityRequestData, ValidateRequestData, ValidateResponseData } from '
|
|
1
|
+
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, SetVerbosityRequestData, ValidateRequestData, ValidateResponseData } from '@codifycli/schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { BackgroundPty } from '../pty/background-pty.js';
|
|
4
4
|
import { Resource } from '../resource/resource.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CommandRequestResponseDataSchema, MessageCmd } from '@codifycli/schemas';
|
|
1
2
|
import pty from '@homebridge/node-pty-prebuilt-multiarch';
|
|
2
3
|
import { Ajv } from 'ajv';
|
|
3
|
-
import { CommandRequestResponseDataSchema, MessageCmd } from 'codify-schemas';
|
|
4
4
|
import { nanoid } from 'nanoid';
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
|
6
6
|
import stripAnsi from 'strip-ansi';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringIndexedObject } from '
|
|
1
|
+
import { StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
3
3
|
export declare class ConfigParser<T extends StringIndexedObject> {
|
|
4
4
|
private readonly desiredConfig;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
|
|
1
2
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
4
4
|
import { ArrayParameterSetting, DefaultParameterSetting, InputTransformation, ResourceSettings } from './resource-settings.js';
|
|
5
5
|
export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ResourceConfig, ResourceJson, StringIndexedObject, ValidateResponseData } from '@codifycli/schemas';
|
|
1
2
|
import { Ajv, ValidateFunction } from 'ajv';
|
|
2
|
-
import { ResourceConfig, ResourceJson, StringIndexedObject, ValidateResponseData } from 'codify-schemas';
|
|
3
3
|
import { Plan } from '../plan/plan.js';
|
|
4
4
|
import { ParsedResourceSettings } from './parsed-resource-settings.js';
|
|
5
5
|
import { Resource } from './resource.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
1
2
|
import { Ajv } from 'ajv';
|
|
2
3
|
import cleanDeep from 'clean-deep';
|
|
3
|
-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
4
4
|
import { Plan } from '../plan/plan.js';
|
|
5
5
|
import { ConfigParser } from './config-parser.js';
|
|
6
6
|
import { ParsedResourceSettings } from './parsed-resource-settings.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
|
|
1
2
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import { ZodObject } from 'zod';
|
|
4
4
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
5
5
|
import { ParsedResourceSettings } from './parsed-resource-settings.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringIndexedObject } from '
|
|
1
|
+
import { StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { ParameterChange } from '../plan/change-set.js';
|
|
3
3
|
import { CreatePlan, DestroyPlan, ModifyPlan } from '../plan/plan-types.js';
|
|
4
4
|
import { ResourceSettings } from './resource-settings.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringIndexedObject } from '
|
|
1
|
+
import { StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { ParsedParameterSetting } from '../resource/parsed-resource-settings.js';
|
|
4
4
|
import { ParameterSetting } from '../resource/resource-settings.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResourceConfig, StringIndexedObject } from '
|
|
1
|
+
import { ResourceConfig, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
export declare function splitUserConfig<T extends StringIndexedObject>(config: ResourceConfig & T): {
|
|
3
3
|
parameters: T;
|
|
4
4
|
coreParameters: ResourceConfig;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codifycli/plugin-core",
|
|
3
|
-
"version": "1.0.0-
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-beta3",
|
|
4
|
+
"description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -13,16 +13,33 @@
|
|
|
13
13
|
"bin": {
|
|
14
14
|
"codify-build": "./bin/build.js"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
|
|
16
|
+
"keywords": [
|
|
17
|
+
"codify",
|
|
18
|
+
"plugin",
|
|
19
|
+
"infrastructure-as-code",
|
|
20
|
+
"iac",
|
|
21
|
+
"system-management",
|
|
22
|
+
"resource-management",
|
|
23
|
+
"configuration-management",
|
|
24
|
+
"typescript",
|
|
25
|
+
"cli-tools",
|
|
26
|
+
"applications",
|
|
27
|
+
"system-resources",
|
|
28
|
+
"declarative",
|
|
29
|
+
"automation"
|
|
30
|
+
],
|
|
31
|
+
"author": "Kevin Wang <team@codifycli.com>",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/codifycli/codify-plugin-core.git"
|
|
35
|
+
},
|
|
18
36
|
"license": "ISC",
|
|
19
37
|
"dependencies": {
|
|
38
|
+
"@codifycli/schemas": "1.0.0",
|
|
20
39
|
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
|
|
21
|
-
"
|
|
22
|
-
"ajv": "^8.12.0",
|
|
40
|
+
"ajv": "^8.18.0",
|
|
23
41
|
"ajv-formats": "^2.1.1",
|
|
24
42
|
"clean-deep": "^3.4.0",
|
|
25
|
-
"codify-schemas": "1.0.86-beta11",
|
|
26
43
|
"lodash.isequal": "^4.5.0",
|
|
27
44
|
"nanoid": "^5.0.9",
|
|
28
45
|
"strip-ansi": "^7.1.0",
|
|
@@ -54,6 +71,6 @@
|
|
|
54
71
|
"vitest-mock-extended": "^1.3.1"
|
|
55
72
|
},
|
|
56
73
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
74
|
+
"node": ">=22.0.0"
|
|
58
75
|
}
|
|
59
76
|
}
|
|
@@ -3,7 +3,7 @@ import { Plugin } from '../plugin/plugin.js';
|
|
|
3
3
|
import { describe, expect, it } from 'vitest';
|
|
4
4
|
import { mock } from 'vitest-mock-extended'
|
|
5
5
|
import { Resource } from '../resource/resource.js';
|
|
6
|
-
import { MessageStatus, ResourceOperation } from '
|
|
6
|
+
import { MessageStatus, ResourceOperation } from '@codifycli/schemas';
|
|
7
7
|
import { TestResource } from '../utils/test-utils.test.js';
|
|
8
8
|
|
|
9
9
|
describe('Message handler tests', () => {
|
package/src/messages/handlers.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Ajv, SchemaObject, ValidateFunction } from 'ajv';
|
|
2
|
-
import addFormats from 'ajv-formats';
|
|
3
1
|
import {
|
|
4
2
|
ApplyRequestDataSchema,
|
|
5
3
|
EmptyResponseDataSchema,
|
|
@@ -22,7 +20,9 @@ import {
|
|
|
22
20
|
SetVerbosityRequestDataSchema,
|
|
23
21
|
ValidateRequestDataSchema,
|
|
24
22
|
ValidateResponseDataSchema
|
|
25
|
-
} from '
|
|
23
|
+
} from '@codifycli/schemas';
|
|
24
|
+
import { Ajv, SchemaObject, ValidateFunction } from 'ajv';
|
|
25
|
+
import addFormats from 'ajv-formats';
|
|
26
26
|
|
|
27
27
|
import { SudoError } from '../errors.js';
|
|
28
28
|
import { Plugin } from '../plugin/plugin.js';
|
package/src/messages/sender.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { IpcMessageV2, IpcMessageV2Schema, MessageCmd, PressKeyToContinueRequestData } from '@codifycli/schemas';
|
|
1
2
|
import { Ajv } from 'ajv';
|
|
2
|
-
import { IpcMessageV2, IpcMessageV2Schema, MessageCmd, PressKeyToContinueRequestData } from 'codify-schemas';
|
|
3
3
|
import { nanoid } from 'nanoid';
|
|
4
4
|
|
|
5
5
|
const ajv = new Ajv({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChangeSet } from './change-set.js';
|
|
2
|
-
import { ParameterOperation, ResourceOperation } from '
|
|
2
|
+
import { ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
3
3
|
import { describe, expect, it } from 'vitest';
|
|
4
4
|
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
|
|
5
5
|
|
package/src/plan/change-set.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParameterOperation, ResourceOperation, StringIndexedObject } from '
|
|
1
|
+
import { ParameterOperation, ResourceOperation, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
|
|
3
3
|
import { ParsedParameterSetting } from '../resource/parsed-resource-settings.js';
|
|
4
4
|
import { ResourceSettings } from '../resource/resource-settings.js';
|
package/src/plan/plan-types.ts
CHANGED
package/src/plan/plan.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Plan } from './plan.js';
|
|
3
|
-
import { OS, ParameterOperation, ResourceOperation } from '
|
|
3
|
+
import { OS, ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
4
4
|
import { TestConfig, TestResource } from '../utils/test-utils.test.js';
|
|
5
5
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
6
6
|
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
|
package/src/plan/plan.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Plugin } from './plugin.js';
|
|
3
|
-
import { ApplyRequestData, OS, ParameterOperation, ResourceOperation, StringIndexedObject } from '
|
|
3
|
+
import { ApplyRequestData, OS, ParameterOperation, ResourceOperation, StringIndexedObject } from '@codifycli/schemas';
|
|
4
4
|
import { Resource } from '../resource/resource.js';
|
|
5
5
|
import { Plan } from '../plan/plan.js';
|
|
6
6
|
import { spy } from 'sinon';
|
package/src/plugin/plugin.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { JSONSchemaType } from 'ajv';
|
|
2
1
|
import {
|
|
3
2
|
ApplyRequestData,
|
|
4
3
|
GetResourceInfoRequestData,
|
|
@@ -15,7 +14,8 @@ import {
|
|
|
15
14
|
ResourceJson, SetVerbosityRequestData,
|
|
16
15
|
ValidateRequestData,
|
|
17
16
|
ValidateResponseData
|
|
18
|
-
} from '
|
|
17
|
+
} from '@codifycli/schemas';
|
|
18
|
+
import { JSONSchemaType } from 'ajv';
|
|
19
19
|
|
|
20
20
|
import { ApplyValidationError } from '../common/errors.js';
|
|
21
21
|
import { Plan } from '../plan/plan.js';
|
package/src/pty/index.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TestConfig, TestResource } from '../utils/test-utils.test.js';
|
|
|
3
3
|
import { getPty, IPty } from './index.js';
|
|
4
4
|
import { Plugin } from '../plugin/plugin.js'
|
|
5
5
|
import { CreatePlan } from '../plan/plan-types.js';
|
|
6
|
-
import { OS, ResourceOperation } from '
|
|
6
|
+
import { OS, ResourceOperation } from '@codifycli/schemas';
|
|
7
7
|
import { ResourceSettings } from '../resource/resource-settings.js';
|
|
8
8
|
import { SequentialPty } from './seqeuntial-pty.js';
|
|
9
9
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommandRequestResponseData,
|
|
3
|
+
CommandRequestResponseDataSchema,
|
|
4
|
+
IpcMessageV2,
|
|
5
|
+
MessageCmd
|
|
6
|
+
} from '@codifycli/schemas';
|
|
1
7
|
import pty from '@homebridge/node-pty-prebuilt-multiarch';
|
|
2
8
|
import { Ajv } from 'ajv';
|
|
3
|
-
import { CommandRequestResponseData, CommandRequestResponseDataSchema, IpcMessageV2, MessageCmd } from 'codify-schemas';
|
|
4
9
|
import { nanoid } from 'nanoid';
|
|
5
10
|
import { EventEmitter } from 'node:events';
|
|
6
11
|
import stripAnsi from 'strip-ansi';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { SequentialPty } from './seqeuntial-pty.js';
|
|
3
3
|
import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
4
|
-
import { MessageStatus, SpawnStatus } from '
|
|
5
|
-
import { IpcMessageV2, MessageCmd } from '
|
|
4
|
+
import { MessageStatus, SpawnStatus } from '@codifycli/schemas/src/types/index.js';
|
|
5
|
+
import { IpcMessageV2, MessageCmd } from '@codifycli/schemas';
|
|
6
6
|
|
|
7
7
|
describe('SequentialPty tests', () => {
|
|
8
8
|
it('Can launch a simple command', async () => {
|
|
@@ -36,7 +36,6 @@ describe('SequentialPty tests', () => {
|
|
|
36
36
|
expect(resultFailed).toMatchObject({
|
|
37
37
|
status: 'error',
|
|
38
38
|
exitCode: 1,
|
|
39
|
-
data: 'sjkdhsakjdhjkash not found' // This might change on different os or shells. Keep for now.
|
|
40
39
|
})
|
|
41
40
|
});
|
|
42
41
|
|
|
@@ -3,7 +3,7 @@ import { ResourceSettings } from './resource-settings.js';
|
|
|
3
3
|
import { ParsedResourceSettings } from './parsed-resource-settings.js';
|
|
4
4
|
import { TestConfig } from '../utils/test-utils.test.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { OS } from '
|
|
6
|
+
import { OS } from '@codifycli/schemas';
|
|
7
7
|
|
|
8
8
|
describe('Resource options parser tests', () => {
|
|
9
9
|
it('Parses default values from options', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
|
|
1
2
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import { ZodObject, z } from 'zod';
|
|
4
4
|
|
|
5
5
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { OS, ParameterOperation, ResourceOperation } from '
|
|
2
|
+
import { OS, ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
3
3
|
import { TestConfig, TestResource, TestStatefulParameter } from '../utils/test-utils.test.js';
|
|
4
4
|
import { ResourceSettings } from './resource-settings.js';
|
|
5
5
|
import { ResourceController } from './resource-controller.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Resource } from './resource.js';
|
|
2
|
-
import { OS, ResourceOperation } from '
|
|
2
|
+
import { OS, ResourceOperation } from '@codifycli/schemas';
|
|
3
3
|
import { spy } from 'sinon';
|
|
4
4
|
import { describe, expect, it } from 'vitest'
|
|
5
5
|
import { ArrayParameterSetting, ParameterSetting, ResourceSettings } from './resource-settings.js';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Ajv, ValidateFunction } from 'ajv';
|
|
2
|
-
import cleanDeep from 'clean-deep';
|
|
3
1
|
import {
|
|
4
2
|
ParameterOperation,
|
|
5
3
|
ResourceConfig,
|
|
@@ -7,7 +5,9 @@ import {
|
|
|
7
5
|
ResourceOperation,
|
|
8
6
|
StringIndexedObject,
|
|
9
7
|
ValidateResponseData
|
|
10
|
-
} from '
|
|
8
|
+
} from '@codifycli/schemas';
|
|
9
|
+
import { Ajv, ValidateFunction } from 'ajv';
|
|
10
|
+
import cleanDeep from 'clean-deep';
|
|
11
11
|
|
|
12
12
|
import { ParameterChange } from '../plan/change-set.js';
|
|
13
13
|
import { Plan } from '../plan/plan.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { spy } from 'sinon';
|
|
4
|
-
import { OS, ParameterOperation, ResourceOperation } from '
|
|
4
|
+
import { OS, ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
5
5
|
import {
|
|
6
6
|
TestArrayStatefulParameter,
|
|
7
7
|
TestConfig,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
|
|
1
2
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import isObjectsEqual from 'lodash.isequal'
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { ZodObject } from 'zod';
|
package/src/resource/resource.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { spy } from 'sinon';
|
|
3
|
-
import { ParameterOperation, ResourceOperation } from '
|
|
3
|
+
import { ParameterOperation, ResourceOperation } from '@codifycli/schemas';
|
|
4
4
|
import {
|
|
5
5
|
TestArrayStatefulParameter,
|
|
6
6
|
TestConfig,
|
package/src/utils/functions.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OS, ResourceConfig, StringIndexedObject } from '
|
|
1
|
+
import { OS, ResourceConfig, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { ResourceSettings } from '../resource/resource-settings.js';
|
|
3
3
|
import { Plan } from '../plan/plan.js';
|
|
4
4
|
import { Resource } from '../resource/resource.js';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Release
|
|
5
|
-
|
|
6
|
-
on: workflow_dispatch
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
release:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v4
|
|
13
|
-
- uses: actions/setup-node@v4
|
|
14
|
-
with:
|
|
15
|
-
node-version: '20.x'
|
|
16
|
-
cache: 'npm'
|
|
17
|
-
- run: npm ci
|
|
18
|
-
- run: tsc
|
|
19
|
-
- run: npm publish
|