forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-style.js
More file actions
36 lines (32 loc) · 974 Bytes
/
Copy pathcode-style.js
File metadata and controls
36 lines (32 loc) · 974 Bytes
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
const fs = require('fs-extra');
const globby = require('globby');
const prettier = require('prettier');
const {getDestDir} = require('./paths');
const {log} = require('./utils');
const options = {
arrowParens: 'always',
bracketSpacing: false,
endOfLine: 'crlf',
printWidth: 80,
quoteProps: 'consistent',
singleQuote: false,
tabWidth: 4,
trailingComma: 'none',
};
const extensions = ['html', 'css', 'js'];
async function codeStyle({production}) {
const dir = getDestDir({production});
const files = await globby(extensions.map((ext) => `${dir}/**/*.${ext}`));
for (const file of files) {
const code = await fs.readFile(file, 'utf8');
const formatted = prettier.format(code, {
...options,
filepath: file,
});
if (code !== formatted) {
await fs.outputFile(file, formatted);
!production && log.ok(file);
}
}
}
module.exports = codeStyle;