-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesdoc:config-sort-plugins.js
51 lines (43 loc) · 1.25 KB
/
esdoc:config-sort-plugins.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
import update from '../lib/update.js';
import {fixedOrder} from '../lib/order.js';
const filename = '.esdoc.json';
export const description = 'Sort plugins.';
export const commit = {
scope: filename,
subject: description,
};
const key = (x) => x.name;
const sortToTop = {
'esdoc-standard-plugin': 0,
'esdoc-inject-style-plugin': 1,
'esdoc-inject-script-plugin': 2,
};
const expected = Object.keys(sortToTop);
const order = fixedOrder(sortToTop, key);
export async function postcondition({readJSON, assert}) {
const {plugins} = await readJSON(filename);
assert.deepStrictEqual(
// eslint-disable-next-line unicorn/no-array-callback-reference
plugins.map(key).slice(0, expected.length),
expected,
);
}
export async function precondition({readJSON, assert}) {
const {plugins} = await readJSON(filename);
assert.notDeepStrictEqual(
// eslint-disable-next-line unicorn/no-array-callback-reference
plugins.map(key).slice(0, expected.length),
expected,
);
}
export async function apply({readJSON, writeJSON}) {
await update({
read: () => readJSON(filename),
write: (config) => writeJSON(filename, config),
edit: (config) => {
config.plugins.sort(order);
return config;
},
});
}
export const dependencies = ['esdoc:format-config-file'];