@@ -28,26 +28,26 @@ function checkApiVersion(api_version)
28
28
break ;
29
29
}
30
30
}
31
- function checkCodename ( codename )
31
+ function validateCodename ( field , value )
32
32
{
33
- if ( typeof codename !== "string" )
33
+ if ( typeof value !== "string" )
34
34
{
35
- core . error ( "`codename` must be a string") ;
35
+ core . error ( field + " must be a string") ;
36
36
return ;
37
37
}
38
38
39
- if ( codename . length === 0 )
39
+ if ( value . length === 0 )
40
40
{
41
- core . error ( "`codename` cannot be empty") ;
41
+ core . error ( field + " cannot be empty") ;
42
42
return ;
43
43
}
44
- else if ( codename . length < 2 )
44
+ else if ( value . length < 2 )
45
45
{
46
- core . error ( "`codename` must be at least 2 characters") ;
46
+ core . error ( field + " must be at least 2 characters") ;
47
47
return ;
48
48
}
49
- else if ( codename . length < 8 )
50
- core . warning ( "`codename` should be at least 8 characters") ;
49
+ else if ( value . length < 8 )
50
+ core . warning ( field + " should be at least 8 characters") ;
51
51
52
52
{
53
53
// - Only alphanumeric characters
@@ -56,19 +56,56 @@ function checkCodename(codename)
56
56
// - No number at the beginning (but may be at the end)
57
57
const regex_req = / ^ [ a - z A - Z ] ( [ _ a - z A - Z 0 - 9 ] ? [ a - z A - Z 0 - 9 ] ) * $ / ;
58
58
const regex_min = / ^ [ a - z ] ( [ _ a - z 0 - 9 ] ? [ a - z 0 - 9 ] ) * $ / ;
59
- if ( ! regex_req . test ( codename ) )
59
+ if ( ! regex_req . test ( value ) )
60
60
{
61
- core . error ( "`codename` does not match required format - only alphanumeric characters with optional underscore") ;
61
+ core . error ( field + " does not match required format - only alphanumeric characters with optional underscore") ;
62
62
return ;
63
63
}
64
- else if ( ! regex_min . test ( codename ) )
65
- core . warning ( "`codename` does not match expected format - only lowercase letters, numbers and optional underscores") ;
64
+ else if ( ! regex_min . test ( value ) )
65
+ core . warning ( field + " does not match expected format - only lowercase letters, numbers and optional underscores") ;
66
66
}
67
67
68
- if ( codename . startsWith ( 'vl_' ) || codename . startsWith ( 'VL_' ) || codename . startsWith ( 'voxelite_' ) || codename . startsWith ( 'VOXELITE_' ) )
68
+ if ( value . startsWith ( 'vl_' ) || value . startsWith ( 'VL_' ) || value . startsWith ( 'voxelite_' ) || value . startsWith ( 'VOXELITE_' ) )
69
69
{
70
70
if ( ! voxeliteOfficial )
71
- core . warning ( "It looks like you are using `codename` similar to official Voxelite ones, please choose a different prefix" ) ;
71
+ core . warning ( "It looks like you are using " + field + " similar to official Voxelite ones, please choose a different prefix" ) ;
72
+ }
73
+ }
74
+ function checkCodename ( codename )
75
+ {
76
+ validateCodename ( "`codename`" , codename ) ;
77
+ }
78
+ function checkAlias ( alias )
79
+ {
80
+ validateCodename ( `alias '${ alias } '` , alias ) ;
81
+ }
82
+ function checkAliases ( alias )
83
+ {
84
+ switch ( typeof alias )
85
+ {
86
+ case "string" :
87
+ {
88
+ checkAlias ( alias ) ;
89
+ return [ alias ] ;
90
+ }
91
+ case "object" :
92
+ {
93
+ if ( Array . isArray ( alias ) && alias . every ( item => typeof item === "string" ) )
94
+ {
95
+ alias . forEach ( value => {
96
+ checkAlias ( value ) ;
97
+ } ) ;
98
+ return alias ;
99
+ }
100
+ else
101
+ {
102
+ core . error ( "`alias` should be a string or an array" ) ;
103
+ return [ ] ;
104
+ }
105
+ }
106
+ default :
107
+ core . error ( "`alias` should be a string or an array" ) ;
108
+ return [ ] ;
72
109
}
73
110
}
74
111
function validateNonPrintCharacter ( field , value )
@@ -288,6 +325,40 @@ function checkPermission(permission)
288
325
}
289
326
}
290
327
}
328
+ function checkPluginRelations ( field , value , allowRelative )
329
+ {
330
+ if ( typeof value == "object" && Object . keys ( value ) . every ( item => typeof item === "string" ) && Object . values ( value ) . every ( item => typeof item === "string" ) )
331
+ {
332
+ const versionRegex = / ^ ( [ 0 - 9 ] + ( \. [ 0 - 9 ] + ) { 0 , 2 } ) ? $ /
333
+
334
+ let pluginNames = new Set ( ) ;
335
+ Object . keys ( value ) . forEach ( key => {
336
+ let keyValue = value [ key ] ;
337
+
338
+ validateCodename ( `${ field } plugin` , key ) ;
339
+ pluginNames . add ( key ) ;
340
+
341
+ // Validate version in `value` with `allowRelative` option
342
+ if ( allowRelative )
343
+ {
344
+ if ( keyValue . startsWith ( '<' ) || keyValue . startsWith ( '>' ) || keyValue . startsWith ( '=' ) )
345
+ keyValue = keyValue . substring ( 1 ) ;
346
+ if ( keyValue . startsWith ( '<=' ) || keyValue . startsWith ( '>=' ) )
347
+ keyValue = keyValue . substring ( 2 ) ;
348
+ }
349
+ if ( ! versionRegex . test ( keyValue ) )
350
+ core . error ( "Invalid version string: " + keyValue ) ;
351
+
352
+ //TODO Check for colliding dependencies (same plugin but incompatible versions)
353
+ } ) ;
354
+ return pluginNames ;
355
+ }
356
+ else
357
+ {
358
+ core . error ( field + " plugin should be a string or an array" ) ;
359
+ return new Set ( ) ;
360
+ }
361
+ }
291
362
292
363
try
293
364
{
322
393
checkCodename ( json [ 'codename' ] ) ;
323
394
core . setOutput ( 'codename' , json [ 'codename' ] ) ;
324
395
}
396
+ // alias
397
+ if ( json . hasOwnProperty ( "alias" ) )
398
+ {
399
+ const alias = checkAliases ( json [ 'alias' ] ) ;
400
+ core . setOutput ( 'alias' , alias . join ( ',' ) ) ;
401
+ }
325
402
// version
326
403
if ( ! json . hasOwnProperty ( "version" ) )
327
404
core . error ( 'Missing `version`' ) ;
365
442
else
366
443
console . error ( "Unsupported data type for `permissions` - use an array of strings" )
367
444
}
445
+ // Relations with other plugins
446
+ {
447
+ let mentionedPlugins = new Set ( ) ;
448
+ if ( json . hasOwnProperty ( "depends" ) )
449
+ {
450
+ checkPluginRelations ( "`depends`" , json [ "depends" ] , true ) . forEach ( item => mentionedPlugins . add ( item ) ) ;
451
+ core . setOutput ( "depends" , Array . from ( mentionedPlugins ) . join ( ',' ) ) ;
452
+ }
453
+ if ( json . hasOwnProperty ( "recommends" ) )
454
+ {
455
+ checkPluginRelations ( "`recommends`" , json [ "recommends" ] , true ) . forEach ( item => mentionedPlugins . add ( item ) ) ;
456
+ }
457
+ if ( json . hasOwnProperty ( "suggests" ) )
458
+ {
459
+ checkPluginRelations ( "`suggests`" , json [ "suggests" ] , true ) . forEach ( item => mentionedPlugins . add ( item ) ) ;
460
+ }
461
+ if ( json . hasOwnProperty ( "breaks" ) )
462
+ {
463
+ checkPluginRelations ( "`breaks`" , json [ "breaks" ] , true ) . forEach ( item => mentionedPlugins . add ( item ) ) ;
464
+ }
465
+ if ( json . hasOwnProperty ( "replaces" ) )
466
+ {
467
+ checkPluginRelations ( "`replaces`" , json [ "replaces" ] , false ) . forEach ( item => mentionedPlugins . add ( item ) ) ;
468
+ }
469
+
470
+ core . setOutput ( "other_plugins" , Array . from ( mentionedPlugins ) . join ( ',' ) ) ;
471
+ }
368
472
}
369
473
}
370
474
) ;
0 commit comments