-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
generate-indexes.js
33 lines (28 loc) · 1.19 KB
/
generate-indexes.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
'use strict';
const { readdir, writeFile } = require('fs').promises;
const { green } = require('chalk');
const compat = require('core-js-compat/src/data');
const modules = Object.keys(compat);
async function generateNamespaceIndex(ns, filter) {
return writeFile(`./packages/core-js/${ ns }/index.js`, `${ modules
.filter(it => filter.test(it))
.map(it => `require('../modules/${ it }');\n`)
.join('') }\nmodule.exports = require('../internals/path');\n`);
}
async function generateTestsIndex(name, pkg) {
const dir = `./tests/${ name }`;
const files = await readdir(dir);
return writeFile(`${ dir }/index.js`, `${ files
.filter(it => /^(?:es|esnext|web)\./.test(it))
.map(it => `import './${ it.slice(0, -3) }';\n`)
.join('') }\nimport core from '${ pkg }';\ncore.globalThis.core = core;\n`);
}
(async () => {
await generateNamespaceIndex('es', /^es\./);
await generateNamespaceIndex('stable', /^(es|web)\./);
await generateNamespaceIndex('features', /^(es|esnext|web)\./);
await generateTestsIndex('tests', 'core-js');
await generateTestsIndex('pure', 'core-js-pure');
// eslint-disable-next-line no-console -- output
console.log(green('indexes generated'));
})();