-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathcomponent-helper.js
executable file
·63 lines (54 loc) · 2.29 KB
/
component-helper.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
#!/usr/bin/env node
/**
* Copyright (c) Moodle Pty Ltd.
*
* Moodle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Moodle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/
const { program } = require('commander');
const { writeFile } = require('fs/promises');
const { getLogger, getNormalizedPath } = require('./utils');
const logger = getLogger();
const getSpellingHeader = () => `
# This file contains cspell exceptions relating to Moodle components.
# It is automatically generated by the component-helper spelling command.
# Please do not make manual modifications to this file as they will be overwritten.
`.trimStart();
const getSpellingFileContent = (validSpellings) => `${getSpellingHeader()}
${validSpellings.join('\n')}
# End of spelling list
`;
program
.name('component-helper')
.description('CLI to help with information stored about Moodle components')
.version('1.0.0');
program
.command('spelling')
.description('Generate useful spelling exception lists')
.action(async () => {
logger.info('Loading component data');
// eslint-disable-next-line global-require, import/no-dynamic-require
const components = await require(getNormalizedPath('data', 'main', 'components.json'));
const validSpellings = [
// Note: We use a Set here to remove duplicates easily.
...new Set([
...Object.keys(components.plugintypes),
...Object.keys(components.subsystems),
].sort()),
];
const spellingContent = getSpellingFileContent(validSpellings);
const spellingFile = getNormalizedPath('data', 'component-spelling.txt');
logger.info(`Writing ${validSpellings.length} files to ${spellingFile}`);
writeFile(spellingFile, spellingContent);
});
program.parse();