@@ -8,22 +8,47 @@ import { existsSync } from "node:fs";
88import { join } from "node:path" ;
99import { baseEnvSchema , addCommonOptions } from "./common-environment" ;
1010
11- const safeParseEnvSchema = baseEnvSchema . extend ( {
12- txzPath : z . string ( ) . refine ( ( val ) => val . endsWith ( ".txz" ) , {
13- message : "TXZ Path must end with .txz" ,
14- } ) ,
11+ const basePluginSchema = baseEnvSchema . extend ( {
12+ txzPath : z
13+ . string ( )
14+ . refine ( ( val ) => val . endsWith ( ".txz" ) , {
15+ message : "TXZ Path must end with .txz" ,
16+ } )
17+ . optional ( ) ,
1518 pluginVersion : z . string ( ) . regex ( / ^ \d { 4 } \. \d { 2 } \. \d { 2 } \. \d { 4 } $ / , {
1619 message : "Plugin version must be in the format YYYY.MM.DD.HHMM" ,
1720 } ) ,
1821 releaseNotesPath : z . string ( ) . optional ( ) ,
1922} ) ;
2023
21- const pluginEnvSchema = safeParseEnvSchema . extend ( {
22- releaseNotes : z . string ( ) . nonempty ( "Release notes are required" ) ,
23- txzSha256 : z . string ( ) . refine ( ( val ) => val . length === 64 , {
24- message : "TXZ SHA256 must be 64 characters long" ,
25- } ) ,
26- } ) ;
24+ const safeParseEnvSchema = basePluginSchema . transform ( ( data ) => ( {
25+ ...data ,
26+ txzPath :
27+ data . txzPath ||
28+ getTxzPath ( {
29+ startingDir : process . cwd ( ) ,
30+ version : data . apiVersion ,
31+ build : data . buildNumber . toString ( ) ,
32+ } ) ,
33+ } ) ) ;
34+
35+ const pluginEnvSchema = basePluginSchema
36+ . extend ( {
37+ releaseNotes : z . string ( ) . nonempty ( "Release notes are required" ) ,
38+ txzSha256 : z . string ( ) . refine ( ( val ) => val . length === 64 , {
39+ message : "TXZ SHA256 must be 64 characters long" ,
40+ } ) ,
41+ } )
42+ . transform ( ( data ) => ( {
43+ ...data ,
44+ txzPath :
45+ data . txzPath ||
46+ getTxzPath ( {
47+ startingDir : process . cwd ( ) ,
48+ version : data . apiVersion ,
49+ build : data . buildNumber . toString ( ) ,
50+ } ) ,
51+ } ) ) ;
2752
2853export type PluginEnv = z . infer < typeof pluginEnvSchema > ;
2954
@@ -36,7 +61,11 @@ export type PluginEnv = z.infer<typeof pluginEnvSchema>;
3661 * @returns Object containing the resolved txz path and SHA256 hash
3762 * @throws Error if no valid txz file can be found
3863 */
39- export const resolveTxzPath = async ( txzPath : string , apiVersion : string , isCi ?: boolean ) : Promise < { path : string , sha256 : string } > => {
64+ export const resolveTxzPath = async (
65+ txzPath : string ,
66+ apiVersion : string ,
67+ isCi ?: boolean
68+ ) : Promise < { path : string ; sha256 : string } > => {
4069 if ( existsSync ( txzPath ) ) {
4170 await access ( txzPath , constants . F_OK ) ;
4271 console . log ( "Reading txz file from:" , txzPath ) ;
@@ -46,43 +75,45 @@ export const resolveTxzPath = async (txzPath: string, apiVersion: string, isCi?:
4675 }
4776 return {
4877 path : txzPath ,
49- sha256 : getSha256 ( txzFile )
78+ sha256 : getSha256 ( txzFile ) ,
5079 } ;
5180 }
5281
5382 console . log ( `TXZ path not found at: ${ txzPath } ` ) ;
5483 console . log ( `Attempting to find TXZ using apiVersion: ${ apiVersion } ` ) ;
55-
84+
5685 // Try different formats of generated TXZ name
5786 const deployDir = join ( process . cwd ( ) , "deploy" ) ;
58-
87+
5988 // Try with exact apiVersion format
6089 const alternativePaths = [
6190 join ( deployDir , `dynamix.unraid.net-${ apiVersion } -x86_64-1.txz` ) ,
6291 ] ;
63-
92+
6493 // In CI, we sometimes see unusual filenames, so try a glob-like approach
6594 if ( isCi ) {
6695 console . log ( "Checking for possible TXZ files in deploy directory" ) ;
67-
96+
6897 try {
6998 // Using node's filesystem APIs to scan the directory
70- const fs = require ( 'fs' ) ;
99+ const fs = require ( "fs" ) ;
71100 const deployFiles = fs . readdirSync ( deployDir ) ;
72-
101+
73102 // Find any txz file that contains the apiVersion
74103 for ( const file of deployFiles ) {
75- if ( file . endsWith ( '.txz' ) &&
76- file . includes ( 'dynamix.unraid.net' ) &&
77- file . includes ( apiVersion . split ( '+' ) [ 0 ] ) ) {
104+ if (
105+ file . endsWith ( ".txz" ) &&
106+ file . includes ( "dynamix.unraid.net" ) &&
107+ file . includes ( apiVersion . split ( "+" ) [ 0 ] )
108+ ) {
78109 alternativePaths . push ( join ( deployDir , file ) ) ;
79110 }
80111 }
81112 } catch ( error ) {
82113 console . log ( `Error scanning deploy directory: ${ error } ` ) ;
83114 }
84115 }
85-
116+
86117 // Check each path
87118 for ( const path of alternativePaths ) {
88119 if ( existsSync ( path ) ) {
@@ -96,14 +127,16 @@ export const resolveTxzPath = async (txzPath: string, apiVersion: string, isCi?:
96127 }
97128 return {
98129 path,
99- sha256 : getSha256 ( txzFile )
130+ sha256 : getSha256 ( txzFile ) ,
100131 } ;
101132 }
102133 console . log ( `Could not find TXZ at: ${ path } ` ) ;
103134 }
104-
135+
105136 // If we get here, we couldn't find a valid txz file
106- throw new Error ( `Could not find any valid TXZ file. Tried original path: ${ txzPath } and alternatives.` ) ;
137+ throw new Error (
138+ `Could not find any valid TXZ file. Tried original path: ${ txzPath } and alternatives.`
139+ ) ;
107140} ;
108141
109142export const validatePluginEnv = async (
@@ -127,7 +160,11 @@ export const validatePluginEnv = async (
127160 }
128161
129162 // Resolve and validate the txz path
130- const { path, sha256 } = await resolveTxzPath ( safeEnv . txzPath , safeEnv . apiVersion , safeEnv . ci ) ;
163+ const { path, sha256 } = await resolveTxzPath (
164+ safeEnv . txzPath ,
165+ safeEnv . apiVersion ,
166+ safeEnv . ci
167+ ) ;
131168 envArgs . txzPath = path ;
132169 envArgs . txzSha256 = sha256 ;
133170
@@ -142,8 +179,9 @@ export const validatePluginEnv = async (
142179
143180export const getPluginVersion = ( ) => {
144181 const now = new Date ( ) ;
145-
146- const formatUtcComponent = ( component : number ) => String ( component ) . padStart ( 2 , '0' ) ;
182+
183+ const formatUtcComponent = ( component : number ) =>
184+ String ( component ) . padStart ( 2 , "0" ) ;
147185
148186 const year = now . getUTCFullYear ( ) ;
149187 const month = formatUtcComponent ( now . getUTCMonth ( ) + 1 ) ;
@@ -162,13 +200,12 @@ export const setupPluginEnv = async (argv: string[]): Promise<PluginEnv> => {
162200
163201 // Add common options
164202 addCommonOptions ( program ) ;
165-
203+
166204 // Add plugin-specific options
167205 program
168206 . option (
169207 "--txz-path <path>" ,
170- "Path to built package, will be used to generate the SHA256 and renamed with the plugin version" ,
171- getTxzPath ( { startingDir : process . cwd ( ) , pluginVersion : process . env . API_VERSION } )
208+ "Path to built package, will be used to generate the SHA256 and renamed with the plugin version"
172209 )
173210 . option (
174211 "--plugin-version <version>" ,
0 commit comments