Skip to content

Commit 99b144e

Browse files
committed
Switched asdf and file to zod schema
1 parent 0ac06d9 commit 99b144e

File tree

10 files changed

+153
-204
lines changed

10 files changed

+153
-204
lines changed

package-lock.json

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
"ajv": "^8.12.0",
2727
"ajv-formats": "^2.1.1",
2828
"chalk": "^5.3.0",
29-
"codify-plugin-lib": "1.0.182-beta27",
29+
"codify-plugin-lib": "1.0.182-beta31",
3030
"codify-schemas": "1.0.86-beta7",
3131
"debug": "^4.3.4",
3232
"lodash.isequal": "^4.5.0",
3333
"nanoid": "^5.0.9",
3434
"plist": "^3.1.0",
3535
"semver": "^7.6.0",
3636
"strip-ansi": "^7.1.0",
37-
"trash": "^10.0.0"
37+
"trash": "^10.0.0",
38+
"zod": "^4.2.1"
3839
},
3940
"devDependencies": {
4041
"@apidevtools/json-schema-ref-parser": "^11.7.2",

src/resources/asdf/asdf-install-schema.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/resources/asdf/asdf-install.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@ import {
66
SpawnStatus,
77
getPty,
88
} from 'codify-plugin-lib';
9-
import { OS, ResourceConfig } from 'codify-schemas';
9+
import { OS } from 'codify-schemas';
1010
import * as fs from 'node:fs/promises';
1111
import path from 'node:path';
12+
import z from 'zod';
1213

1314
import { FileUtils } from '../../utils/file-utils.js';
14-
import AsdfInstallSchema from './asdf-install-schema.json';
15-
16-
export interface AsdfInstallConfig extends ResourceConfig {
17-
plugin?: string;
18-
versions?: string[];
19-
directory?: string;
20-
}
2115

16+
const schema = z.object({
17+
plugin: z
18+
.string()
19+
.describe('Asdf plugin name')
20+
.optional(),
21+
versions: z
22+
.array(z.string())
23+
.describe('A list of versions to install')
24+
.optional(),
25+
directory: z
26+
.string()
27+
.describe('The directory to run the install command')
28+
.optional(),
29+
});
30+
31+
export type AsdfInstallConfig = z.infer<typeof schema>;
2232
const CURRENT_VERSION_REGEX = /^([^ ]+?)\s+([^ ]+?)\s+.*/;
2333
const TOOL_VERSIONS_REGEX = /^([^ ]+) +([^ ]+)$/;
2434

@@ -29,7 +39,7 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
2939
id: 'asdf-install',
3040
operatingSystems: [OS.Darwin, OS.Linux],
3141
dependencies: ['asdf'],
32-
schema: AsdfInstallSchema,
42+
schema,
3343
parameterSettings: {
3444
directory: { type: 'directory' },
3545
versions: { type: 'array' }
@@ -51,7 +61,7 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
5161
}
5262

5363
if (parameters.directory && !(await FileUtils.checkDirExistsOrThrowIfFile(parameters.directory))) {
54-
throw new Error(`Directory ${parameters.local} does not exist`);
64+
throw new Error(`Directory ${parameters.directory} does not exist`);
5565
}
5666
}
5767

src/resources/asdf/asdf-plugin-schema.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/resources/asdf/asdf-plugin.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
import { CreatePlan, DestroyPlan, getPty, Resource, ResourceSettings, SpawnStatus, untildify } from 'codify-plugin-lib';
2-
import { OS, ResourceConfig } from 'codify-schemas';
1+
import { CreatePlan, DestroyPlan, Resource, ResourceSettings, SpawnStatus, getPty, untildify } from 'codify-plugin-lib';
2+
import { OS } from 'codify-schemas';
3+
import z from 'zod';
34

4-
import { codifySpawn } from '../../utils/codify-spawn.js';
5-
import AsdfPluginSchema from './asdf-plugin-schema.json';
65
import { AsdfPluginVersionsParameter } from './version-parameter.js';
76

8-
export interface AsdfPluginConfig extends ResourceConfig {
9-
plugin: string;
10-
gitUrl: string;
11-
versions: string[];
12-
}
7+
const schema = z
8+
.object({
9+
plugin: z.string().describe('Asdf plugin name'),
10+
versions: z
11+
.array(z.string())
12+
.describe('A list of versions to install')
13+
.optional(),
14+
gitUrl: z
15+
.string()
16+
.describe('The gitUrl of the plugin')
17+
.optional()
18+
})
19+
export type AsdfPluginConfig = z.infer<typeof schema>;
1320

1421
const PLUGIN_LIST_REGEX = /^([^ ]+?)\s+([^ ]+)/
1522

@@ -19,7 +26,7 @@ export class AsdfPluginResource extends Resource<AsdfPluginConfig> {
1926
id: 'asdf-plugin',
2027
operatingSystems: [OS.Darwin, OS.Linux],
2128
dependencies: ['asdf'],
22-
schema: AsdfPluginSchema,
29+
schema,
2330
parameterSettings: {
2431
versions: { type: 'stateful', definition: new AsdfPluginVersionsParameter() }
2532
},

src/resources/asdf/asdf-schema.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)