-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (33 loc) · 1.24 KB
/
index.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
const { constants } = require('fs');
const fs = require('fs/promises');
const { stripIndent } = require('common-tags');
const { generateFields, writeFile } = require('./helpers');
module.exports = {
construct(self, options) {
self.addTask(
'export',
stripIndent`
Exports A2 schemas to A3 format by outputting a "schema.js" file in every module folder.
Option:
* --folder: folder name relative to root where to search for modules. By default, it is "lib/modules". Usage: --folder=src/lib/modules
`,
async(apos, argv) => {
const { folder = 'lib/modules' } = argv;
for (const aposModule of Object.values(apos.modules)) {
const unnecessaryModule = aposModule.__meta.name.includes('-auto-pages');
if (unnecessaryModule || !aposModule?.schema?.length) {
continue;
}
try {
const moduleName = aposModule.schema[0].moduleName;
await fs.access(`${folder}/${moduleName}`, constants.W_OK);
const fields = generateFields(aposModule.schema);
await writeFile(folder, moduleName, fields);
} catch {
// module not found at project level; skipping it
}
}
}
);
}
};