-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
28 lines (22 loc) · 858 Bytes
/
test.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
import glob from 'glob'
import pascalcase from 'pascalcase'
import path from 'path'
import url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const pathnames = glob.sync(path.join(__dirname, 'svg/*.svg'))
const unauthorizedPathnames = pathnames.filter(pathname => {
const basename = path.basename(pathname, '.svg')
return !/^[A-Z][a-zA-Z]+$/.test(basename)
})
if (unauthorizedPathnames.length > 0) {
const errorMessage = `Incorrect naming for files:
${unauthorizedPathnames
.map(pathname => {
const relativePathname = path.relative(__dirname, pathname)
const dirname = path.dirname(relativePathname)
const basename = pascalcase(path.basename(pathname, '.svg'))
return `- ./${relativePathname} (must be ./${path.join(dirname, basename)}.svg)`
})
.join('\n')}`
throw new Error(errorMessage)
}