forked from daviseford/aos-reminders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.js
71 lines (67 loc) · 2.82 KB
/
clean.js
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
68
69
70
71
const replace = require('replace-in-file')
const replaceOptions = {
files: ['src/factions/**/*.*(ts|tsx)', 'src/generic_rules/*.*(ts|tsx)'],
from: [
/[‘’]/g, // Replace special apostrophes
/[“”]/g, // Replace special quotes
/[‑–—]/g, // Replace special dashes
/ /g, // Remove non ASCII-spaces
/½/g, // Remove 1/2 character
// eslint-disable-next-line no-control-regex
/[^\x00-\x7F]/g, // Remove all other non-ASCII characters
/[.] {2,5}/g, // Replace extra spaces after punctuation
/[:] {2,5}/g, // Replace extra spaces after punctuation
/[,] {2,5}/g, // Replace extra spaces after punctuation
/(?<=[name|desc|tag]: )` +(?=.+`)/g, // Remove leading whitespaces
/(?<!:)(?<=[name|desc|tag]: `.+) +`/g, // Remove trailing whitespaces
/(?<!:)(?<=desc: `.+[\w()])[,(/#!$^&;=\-_~]`/g, // Replace trailing punctuation with periods in descriptions
/(?<!:)(?<=desc: `.+\w)`/g, // Add a period to descriptions
/(?<=[desc]: `)[\w' ]+ has a casting value of+(?=.+`)/g, // Shorten casting descriptions
/(?<=\. )If successfully cast, pick+(?=.+`)/g, // Shorten casting descriptions
/(?<=[desc]: `)[\w' ]+ is a prayer that has an answer value of+(?=.+`)/g, // Shorten prayer descriptions
/R[eE] ?- ?[rR][oO][lL]{2}/g, // Handle "Re - roll" -> "Reroll"
/r[eE] ?- ?[rR][oO][lL]{2}/g, // Handle "re-roll" -> "reroll"
],
to: [
`'`, // Replace special apostrophes
`"`, // Replace special quotes
'-', // Replace special dashes
' ', // Remove non ASCII-spaces
'1/2', // Remove 1/2 character
'', // Remove all other non-ASCII characters
'. ', // Replace extra spaces after punctuation
': ', // Replace extra spaces after punctuation
', ', // Replace extra spaces after punctuation
'`', // Remove leading whitespaces
'`', // Remove leading whitespaces
'.`', // Replace trailing punctuation with periods in descriptions
'.`', // Add a period to descriptions
`Casting value of`, // Shorten casting descriptions
`Pick`, // Shorten casting descriptions
`Answer value of`, // Shorten prayer descriptions
`Reroll`, // Handle "Re - roll" -> "Reroll"
`reroll`, // Handle "re-roll" -> "reroll"
],
}
/**
*
* @param results - { file: string; hasChanged: boolean }[]
*/
const getChanged = results => results.filter(x => x.hasChanged).map(x => x.file)
const run = async () => {
try {
const results = await replace(replaceOptions)
const changed = getChanged(results)
if (changed.length) {
console.log('Files modified:', changed)
process.exit(1) // Throw an error to stop a git commit from finishing
} else {
console.log('No files were modified.')
}
} catch (error) {
console.error('Error occurred:', error)
process.exit(1) // Throw an error to stop a git commit from finishing
}
}
// Go!
run()