Skip to content

Commit f98fa38

Browse files
committed
feat: Modified the deploy script to deploy each resource directly to the db as well. Modified the build script to build the original json schema. Bump to version 1.1.0
1 parent 76fd562 commit f98fa38

8 files changed

Lines changed: 135 additions & 56 deletions

File tree

.fleet/run.json

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

.fleet/settings.json

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

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {
@@ -68,7 +68,8 @@
6868
"@rollup/plugin-replace": "^6.0.2",
6969
"@rollup/plugin-terser": "^0.4.4",
7070
"@rollup/plugin-typescript": "^11.1.6",
71-
"@types/chalk": "^2.2.0",
71+
"@supabase/supabase-js": "^2.103.3",
72+
"@types/chalk": "^2.2.0",
7273
"@types/commander": "^2.12.2",
7374
"@types/debug": "4.1.12",
7475
"@types/lodash.isequal": "^4.5.8",
@@ -78,6 +79,7 @@
7879
"@types/semver": "^7.5.4",
7980
"@types/uuid": "10.0.0",
8081
"commander": "^12.1.0",
82+
"dotenv": "^17.4.2",
8183
"eslint": "^10.0.3",
8284
"eslint-config-oclif": "^6.0.156",
8385
"eslint-config-prettier": "^10.1.8",

scripts/build.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSONSchema } from '@apidevtools/json-schema-ref-parser';
2+
import { createRequire } from 'node:module';
23
import { Ajv } from 'ajv';
34
import { VerbosityLevel } from '@codifycli/plugin-core';
45
import { SequentialPty } from '@codifycli/plugin-core/dist/pty/seqeuntial-pty';
@@ -97,9 +98,22 @@ await $.spawn('npm run rollup', { interactive: true }); // re-run rollup without
9798

9899
console.log('Generated JSON Schemas for all resources')
99100

101+
const require = createRequire(import.meta.url);
102+
const rawSchema = require('./raw-codify-schema.json');
103+
104+
const codifySchema = {
105+
...rawSchema,
106+
items: {
107+
oneOf: [
108+
...rawSchema.items.oneOf,
109+
...mergedSchemas,
110+
]
111+
}
112+
};
113+
100114
const distFolder = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'dist');
101115
const schemaOutputPath = path.resolve(distFolder, 'schemas.json');
102-
fs.writeFileSync(schemaOutputPath, JSON.stringify(mergedSchemas, null, 2));
116+
fs.writeFileSync(schemaOutputPath, JSON.stringify(codifySchema, null, 2));
103117

104118
console.log('Successfully wrote schema to ./dist/schemas.json')
105119

scripts/deploy.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as cp from 'node:child_process';
22
import path from 'node:path';
33
import * as url from 'node:url';
4+
import { createRequire } from 'node:module';
5+
import 'dotenv/config'
6+
import { createClient } from '@supabase/supabase-js';
7+
8+
const require = createRequire(import.meta.url);
49

510
const isBeta = process.env.BETA === 'true';
611

@@ -21,3 +26,56 @@ console.log(`Uploading plugin ${name}, version ${version} to cloudflare!`)
2126

2227
const outputFilePath = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'dist', 'index.js')
2328
cp.spawnSync(`source ~/.zshrc; npx wrangler r2 object put plugins/${name}/${version}/index.js --file=${outputFilePath} --remote`, { shell: 'zsh', stdio: 'inherit' });
29+
30+
if (!isBeta) {
31+
await uploadResources();
32+
}
33+
34+
async function uploadResources() {
35+
const CodifySchema = require('../dist/schemas.json');
36+
37+
const client = createClient(
38+
process.env.SUPABASE_URL!,
39+
process.env.SUPABASE_SERVICE_ROLE_KEY!,
40+
);
41+
42+
console.log('Adding default plugin');
43+
const defaultPlugin = await client.from('registry_plugins').upsert({
44+
name: 'default',
45+
}, { onConflict: 'name' })
46+
.select()
47+
.throwOnError();
48+
49+
const { id: pluginId, name: pluginName } = defaultPlugin.data![0];
50+
const resources = CodifySchema.items.oneOf;
51+
52+
for (const resource of resources) {
53+
const type = resource.properties.type.const;
54+
55+
console.log(`Adding resource ${type}`)
56+
const resourceRow = await client.from('registry_resources').upsert({
57+
type,
58+
plugin_id: pluginId,
59+
plugin_name: pluginName,
60+
schema: JSON.stringify(resource),
61+
documentation_url: resource.$comment,
62+
}, { onConflict: ['type', 'plugin_id'] })
63+
.select()
64+
.throwOnError();
65+
66+
const { id: resourceId } = resourceRow.data![0];
67+
68+
const parameters = Object.entries(resource.properties)
69+
.filter(([k]) => k !== 'type')
70+
.map(([key, property]) => ({
71+
type: property.type,
72+
name: key,
73+
resource_id: resourceId,
74+
schema: property,
75+
}))
76+
77+
await client.from('registry_resource_parameters')
78+
.upsert(parameters, { onConflict: ['name', 'resource_id'] })
79+
.throwOnError();
80+
}
81+
}

scripts/raw-codify-schema.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.codifycli.com/codify-schema.json",
4+
"title": "JSON schema for Codify configuration files",
5+
"type": "array",
6+
"items": {
7+
"oneOf": [
8+
{
9+
"type": "object",
10+
"properties": {
11+
"type": {
12+
"description": "All project configs are of the type project",
13+
"type": "string",
14+
"const": "project"
15+
},
16+
"version": {
17+
"description": "Semver version. Codify will throw an error if this is not satisfied",
18+
"type": "string",
19+
"pattern": "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$"
20+
},
21+
"plugins": {
22+
"type": "object",
23+
"patternProperties": {
24+
".*": {
25+
"type": "string"
26+
}
27+
}
28+
},
29+
"description": {
30+
"description": "An optional description of the codify project",
31+
"type": "string"
32+
}
33+
},
34+
"required": [
35+
"type"
36+
],
37+
"additionalProperties": false
38+
}
39+
]
40+
}
41+
}

src/resources/ruby/rbenv/completions/rbenv.rubyVersions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export default async function loadRubyVersions(): Promise<string[]> {
33
const data = await response.json() as { name: string }[]
44

55
return data.map((entry) => entry.name)
6-
}
6+
}

0 commit comments

Comments
 (0)