@@ -7,10 +7,11 @@ import { createClient } from '@supabase/supabase-js';
77
88const require = createRequire ( import . meta. url ) ;
99
10-
1110// This should run the build
1211cp . spawnSync ( 'source ~/.zshrc; npm run build' , { shell : 'zsh' , stdio : 'inherit' } ) ;
1312
13+ const PluginManifest : { minSupportedCliVersion : string | null } = require ( '../dist/plugin-manifest.json' ) ;
14+
1415const version = process . env . npm_package_version ;
1516if ( ! version ) {
1617 throw new Error ( 'Unable to find version' ) ;
@@ -31,6 +32,35 @@ console.log(`Uploading plugin ${name}, version ${version} to cloudflare!`)
3132const outputFilePath = path . resolve ( path . dirname ( url . fileURLToPath ( import . meta. url ) ) , '..' , 'dist' , 'index.js' )
3233cp . spawnSync ( `source ~/.zshrc; npx wrangler r2 object put plugins/${ name } /${ version } /index.js --file=${ outputFilePath } --remote` , { shell : 'zsh' , stdio : 'inherit' } ) ;
3334
35+ const client = createClient (
36+ process . env . SUPABASE_URL ! ,
37+ process . env . SUPABASE_SERVICE_ROLE_KEY ! ,
38+ ) ;
39+
40+ console . log ( 'Adding default plugin' ) ;
41+ const defaultPlugin = await client . from ( 'registry_plugins' ) . upsert ( {
42+ name : 'default' ,
43+ display_name : 'Default Plugin' ,
44+ homepage : 'https://codifycli.com' ,
45+ repository_url : 'https://github.com/codifycli/default-plugin' ,
46+ license : 'ISC' ,
47+ } , { onConflict : 'name' } )
48+ . select ( )
49+ . throwOnError ( ) ;
50+
51+ const { id : pluginId , name : pluginName } = defaultPlugin . data ! [ 0 ] ;
52+
53+ console . log ( 'Upserting plugin version' ) ;
54+ const versionRow = await client . from ( 'registry_plugin_versions' ) . upsert ( {
55+ plugin_id : pluginId ,
56+ version,
57+ bundle_url : `https://plugins.codifycli.com/${ name } /${ version } /index.js` ,
58+ min_cli_version : PluginManifest . minSupportedCliVersion ,
59+ published_at : new Date ( ) . toISOString ( ) ,
60+ } , { onConflict : 'plugin_id,version' } )
61+ . select ( )
62+ . throwOnError ( ) ;
63+
3464if ( ! isBeta ) {
3565 await uploadResources ( ) ;
3666
@@ -45,19 +75,13 @@ async function uploadResources() {
4575
4676 const metadataByType = new Map ( Metadata . map ( ( m ) => [ m . type , m ] ) ) ;
4777
48- const client = createClient (
49- process . env . SUPABASE_URL ! ,
50- process . env . SUPABASE_SERVICE_ROLE_KEY ! ,
51- ) ;
78+ const { id : versionId } = versionRow . data ! [ 0 ] ;
5279
53- console . log ( 'Adding default plugin' ) ;
54- const defaultPlugin = await client . from ( 'registry_plugins' ) . upsert ( {
55- name : 'default' ,
56- } , { onConflict : 'name' } )
57- . select ( )
80+ console . log ( 'Updating latest version pointer' ) ;
81+ await client . from ( 'registry_plugins' )
82+ . update ( { latest_version : version , latest_version_id : versionId } )
83+ . eq ( 'id' , pluginId )
5884 . throwOnError ( ) ;
59-
60- const { id : pluginId , name : pluginName } = defaultPlugin . data ! [ 0 ] ;
6185 const resources = CodifySchema . items . oneOf ;
6286
6387 for ( const resource of resources ) {
0 commit comments