-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathci.ts
67 lines (46 loc) · 1.83 KB
/
ci.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as fs from "fs"
import { Message } from "~/modules/messages/message"
import { MessageService } from "~/modules/messages/message-service"
let messageIds: string[] = fs.readdirSync("app/messages")
let messageService: MessageService = new MessageService()
messageIds.forEach((messageId) => {
console.log(`Checks for message: ${messageId}`)
if(messageId.includes(" ")){
throw "❌ File name contains spaces"
}
if(!messageId.match(/^[-a-zA-Z0-9]+$/g)){
throw "❌ File name should only contain letters, numbers and dashes (-). Eg. 'my-message'"
}
console.log("✅ File name is in the correct format.")
let file = fs.readFileSync(`app/messages/${messageId}`).toString()
let fileLines: string[] = file.split("\n")
if(fileLines.length < 3){
throw "❌ File should be at least 3 lines long."
}
console.log("✅ File is at least 3 lines long.")
if(!fileLines[0].startsWith("By: ")){
throw "❌ First line doesn't start with 'By: '"
}
console.log("✅ First line starts with 'By: '")
if(fileLines[1] !== ''){
throw "❌ Second line should be blank"
}
console.log("✅ Second line is blank.")
if(fileLines[2].length === 0){
throw "❌ Third line is blank"
}
console.log("✅ Third line is not blank")
let message: Message = messageService.getMessageById(messageId)
if(message.author.trim().length === 0){
throw "❌ Author field is blank"
}
console.log("✅ Author field is not blank")
if(message.message.join().trim().length === 0){
throw "❌ Message field is blank"
}
console.log("✅ Message field is not blank")
if(message.message.join().trim().length > 400){
throw "❌ Message is too long"
}
console.log("✅ Message is under 400 characters long")
})