@@ -71,6 +71,31 @@ function checkCodename(codename)
71
71
core . warning ( "It looks like you are using `codename` similar to official Voxelite ones, please choose a different prefix" ) ;
72
72
}
73
73
}
74
+ function validateNonPrintCharacter ( field , value )
75
+ {
76
+ for ( let i = 0 ; i < value . length ; i ++ )
77
+ {
78
+ const c = value . charCodeAt ( i ) ;
79
+ if ( c < 32 /* space character */ )
80
+ {
81
+ if ( c === 13 /* \r */ || c === 10 /* \n */ )
82
+ {
83
+ core . error ( field + " cannot contain a new line" ) ;
84
+ return ;
85
+ }
86
+ else if ( c === 9 /* \t */ )
87
+ {
88
+ core . error ( field + " cannot contain tab character" ) ;
89
+ return ;
90
+ }
91
+ else
92
+ {
93
+ core . error ( field + " cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
94
+ return ;
95
+ }
96
+ }
97
+ }
98
+ }
74
99
function checkName ( name )
75
100
{
76
101
if ( typeof name !== "string" )
@@ -97,28 +122,7 @@ function checkName(name)
97
122
if ( name . indexOf ( " " ) !== - 1 )
98
123
core . warning ( "`name` should not contain multiple consecutive space characters" ) ;
99
124
100
- for ( let i = 0 ; i < name . length ; i ++ )
101
- {
102
- const c = name . charCodeAt ( i ) ;
103
- if ( c < 32 /* space character */ )
104
- {
105
- if ( c === 13 /* \r */ || c === 10 /* \n */ )
106
- {
107
- core . error ( "`name` cannot contain a new line" ) ;
108
- return ;
109
- }
110
- else if ( c === 9 /* \t */ )
111
- {
112
- core . error ( "`name` cannot contain tab character" ) ;
113
- return ;
114
- }
115
- else
116
- {
117
- core . error ( "`name` cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
118
- return ;
119
- }
120
- }
121
- }
125
+ validateNonPrintCharacter ( '`name`' , name ) ;
122
126
}
123
127
function checkVersion ( version )
124
128
{
@@ -170,28 +174,7 @@ function checkDescription(description)
170
174
if ( description . indexOf ( " " ) !== - 1 )
171
175
core . warning ( "`description` should not contain multiple consecutive space characters" ) ;
172
176
173
- for ( let i = 0 ; i < description . length ; i ++ )
174
- {
175
- const c = description . charCodeAt ( i ) ;
176
- if ( c < 32 /* space character */ )
177
- {
178
- if ( c === 13 /* \r */ || c === 10 /* \n */ )
179
- {
180
- core . error ( "`description` cannot contain a new line" ) ;
181
- return ;
182
- }
183
- else if ( c === 9 /* \t */ )
184
- {
185
- core . error ( "`description` cannot contain tab character" ) ;
186
- return ;
187
- }
188
- else
189
- {
190
- core . error ( "`description` cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
191
- return ;
192
- }
193
- }
194
- }
177
+ validateNonPrintCharacter ( '`description`' , description ) ;
195
178
}
196
179
function checkWebsite ( website )
197
180
{
@@ -225,29 +208,7 @@ function checkWebsite(website)
225
208
if ( website . startsWith ( "http://" ) )
226
209
core . warning ( "Consider using `https://` instead of `http://` for `website`" ) ;
227
210
228
- for ( let i = 0 ; i < website . length ; i ++ )
229
- {
230
- const c = website . charCodeAt ( i ) ;
231
- if ( c < 32 /* space character */ )
232
- {
233
- if ( c === 13 /* \r */ || c === 10 /* \n */ )
234
- {
235
- core . error ( "`website` cannot contain a new line" ) ;
236
- return ;
237
- }
238
- else if ( c === 9 /* \t */ )
239
- {
240
- core . error ( "`website` cannot contain tab character" ) ;
241
- return ;
242
- }
243
- else
244
- {
245
- core . error ( "`website` cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
246
- return ;
247
- }
248
- }
249
- }
250
-
211
+ validateNonPrintCharacter ( '`website`' , website ) ;
251
212
252
213
if ( website . includes ( 'voxelite.net' ) )
253
214
{
@@ -282,28 +243,7 @@ function checkAuthor(author)
282
243
if ( author . indexOf ( " " ) !== - 1 )
283
244
core . warning ( "`author` should not contain multiple consecutive space characters" ) ;
284
245
285
- for ( let i = 0 ; i < author . length ; i ++ )
286
- {
287
- const c = author . charCodeAt ( i ) ;
288
- if ( c < 32 /* space character */ )
289
- {
290
- if ( c === 13 /* \r */ || c === 10 /* \n */ )
291
- {
292
- core . error ( "`author` cannot contain a new line" ) ;
293
- return ;
294
- }
295
- else if ( c === 9 /* \t */ )
296
- {
297
- core . error ( "`author` cannot contain tab character" ) ;
298
- return ;
299
- }
300
- else
301
- {
302
- core . error ( "`author` cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
303
- return ;
304
- }
305
- }
306
- }
246
+ validateNonPrintCharacter ( '`author`' , author ) ;
307
247
308
248
if ( author === 'vl' || author === 'voxelite' )
309
249
{
@@ -337,28 +277,7 @@ function checkPermission(permission)
337
277
338
278
//TODO Check against list of known permissions
339
279
340
- for ( let i = 0 ; i < permission . length ; i ++ )
341
- {
342
- const c = permission . charCodeAt ( i ) ;
343
- if ( c < 32 /* space character */ )
344
- {
345
- if ( c === 13 /* \r */ || c === 10 /* \n */ )
346
- {
347
- core . error ( "`permissions` item cannot contain a new line" ) ;
348
- return ;
349
- }
350
- else if ( c === 9 /* \t */ )
351
- {
352
- core . error ( "`permissions` item cannot contain tab character" ) ;
353
- return ;
354
- }
355
- else
356
- {
357
- core . error ( "`permissions` item cannot contain non-printable character (first 32 ASCII characters) - found character " + c ) ;
358
- return ;
359
- }
360
- }
361
- }
280
+ validateNonPrintCharacter ( '`permission`' , permission ) ;
362
281
363
282
{
364
283
const regex = / ^ ( [ a - z ] ( [ _ a - z 0 - 9 ] ? [ a - z 0 - 9 ] ) * ) ( \. ( [ a - z ] ( [ _ a - z 0 - 9 ] ? [ a - z 0 - 9 ] ) * ) ) * $ /
@@ -373,6 +292,11 @@ function checkPermission(permission)
373
292
try
374
293
{
375
294
const filename = core . getInput ( 'file' ) ;
295
+ if ( ! fs . existsSync ( filename ) )
296
+ {
297
+ core . error ( "Input file not found" ) ;
298
+ return ;
299
+ }
376
300
377
301
fs . readFile (
378
302
filename ,
@@ -386,76 +310,60 @@ try
386
310
const json = JSON . parse ( data ) ;
387
311
388
312
// api_version
389
- {
390
- if ( ! json . hasOwnProperty ( "api_version" ) )
391
- core . error ( 'Missing `api_version`' ) ;
392
- else
393
- checkApiVersion ( json [ 'api_version' ] ) ;
394
- }
313
+ if ( ! json . hasOwnProperty ( "api_version" ) )
314
+ core . error ( 'Missing `api_version`' ) ;
315
+ else
316
+ checkApiVersion ( json [ 'api_version' ] ) ;
395
317
// codename
318
+ if ( ! json . hasOwnProperty ( "codename" ) )
319
+ core . error ( 'Missing `codename`' ) ;
320
+ else
396
321
{
397
- if ( ! json . hasOwnProperty ( "codename" ) )
398
- core . error ( 'Missing `codename`' ) ;
399
- else
400
- {
401
- checkCodename ( json [ 'codename' ] ) ;
402
- core . setOutput ( 'codename' , json [ 'codename' ] ) ;
403
- }
322
+ checkCodename ( json [ 'codename' ] ) ;
323
+ core . setOutput ( 'codename' , json [ 'codename' ] ) ;
404
324
}
405
325
// version
326
+ if ( ! json . hasOwnProperty ( "version" ) )
327
+ core . error ( 'Missing `version`' ) ;
328
+ else
406
329
{
407
- if ( ! json . hasOwnProperty ( "version" ) )
408
- core . error ( 'Missing `version`' ) ;
409
- else
410
- {
411
- checkVersion ( json [ 'version' ] ) ;
412
- core . setOutput ( 'version' , json [ 'version' ] ) ;
413
- }
330
+ checkVersion ( json [ 'version' ] ) ;
331
+ core . setOutput ( 'version' , json [ 'version' ] ) ;
414
332
}
415
333
// name
416
- {
417
- if ( ! json . hasOwnProperty ( "name" ) )
418
- core . warning ( 'Missing `name`, `codename` will be used instead' ) ;
419
- else
420
- checkName ( json [ 'name' ] ) ;
421
- }
334
+ if ( ! json . hasOwnProperty ( "name" ) )
335
+ core . warning ( 'Missing `name`, `codename` will be used instead' ) ;
336
+ else
337
+ checkName ( json [ 'name' ] ) ;
422
338
// description
423
- {
424
- if ( json . hasOwnProperty ( "description" ) )
425
- checkDescription ( json [ 'description' ] ) ;
426
- }
339
+ if ( json . hasOwnProperty ( "description" ) )
340
+ checkDescription ( json [ 'description' ] ) ;
427
341
// website
428
- {
429
- if ( json . hasOwnProperty ( "website" ) )
430
- checkWebsite ( json [ 'website' ] ) ;
431
- }
342
+ if ( json . hasOwnProperty ( "website" ) )
343
+ checkWebsite ( json [ 'website' ] ) ;
432
344
// author
345
+ if ( json . hasOwnProperty ( "author" ) )
433
346
{
434
- if ( json . hasOwnProperty ( "author" ) )
347
+ const jsonAuthor = json [ "author" ] ;
348
+ if ( typeof jsonAuthor === "string" )
349
+ checkAuthor ( jsonAuthor )
350
+ else if ( Array . isArray ( jsonAuthor ) && jsonAuthor . every ( item => typeof item === "string" ) )
435
351
{
436
- const jsonAuthor = json [ "author" ] ;
437
- if ( typeof jsonAuthor === "string" )
438
- checkAuthor ( jsonAuthor )
439
- else if ( Array . isArray ( jsonAuthor ) && jsonAuthor . every ( item => typeof item === "string" ) )
440
- {
441
- jsonAuthor . forEach ( ( author ) => checkAuthor ( author ) ) ;
442
- }
443
- else
444
- console . error ( "Unsupported data type for `author` - use a string or an array of strings" )
352
+ jsonAuthor . forEach ( ( author ) => checkAuthor ( author ) ) ;
445
353
}
354
+ else
355
+ console . error ( "Unsupported data type for `author` - use a string or an array of strings" )
446
356
}
447
357
// permissions
358
+ if ( json . hasOwnProperty ( "permissions" ) )
448
359
{
449
- if ( json . hasOwnProperty ( "permissions" ) )
360
+ const jsonPermissions = json [ "permissions" ] ;
361
+ if ( Array . isArray ( jsonPermissions ) && jsonPermissions . every ( item => typeof item === "string" ) )
450
362
{
451
- const jsonPermissions = json [ "permissions" ] ;
452
- if ( Array . isArray ( jsonPermissions ) && jsonPermissions . every ( item => typeof item === "string" ) )
453
- {
454
- jsonPermissions . forEach ( ( permission ) => checkPermission ( permission ) ) ;
455
- }
456
- else
457
- console . error ( "Unsupported data type for `permissions` - use an array of strings" )
363
+ jsonPermissions . forEach ( ( permission ) => checkPermission ( permission ) ) ;
458
364
}
365
+ else
366
+ console . error ( "Unsupported data type for `permissions` - use an array of strings" )
459
367
}
460
368
}
461
369
}
0 commit comments