-
Notifications
You must be signed in to change notification settings - Fork 42
/
taskfile.js
56 lines (49 loc) · 1.76 KB
/
taskfile.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
'use strict';
/* eslint-disable camelcase -- cli */
const path = require('path');
const { sync: requireResolve } = require('resolve');
const packages = [];
const fromEsmToCjs = (packageName, overrideSource = null) => {
const taskName = `ncc_${packageName.replaceAll('@', '__').replaceAll('-', '_').replaceAll('/', '_')}`;
const source = overrideSource || path.relative(__dirname, require.resolve(packageName));
const targetDir = `src/compiled/${packageName}`;
packages.push(packageName);
module.exports[taskName] = async function build(task, _opts) {
const externals = packages.reduce((prev, currentPackageName) => {
if (currentPackageName !== packageName) {
prev[currentPackageName] = path.relative(
path.resolve(__dirname, targetDir),
path.resolve(__dirname, `src/compiled/${currentPackageName}`)
);
}
return prev;
}, {});
await task
.source(source)
.ncc({ packageName, externals })
.target(targetDir);
};
return taskName;
};
const tasks = [
fromEsmToCjs('unified'),
fromEsmToCjs('@mdx-js/mdx'),
fromEsmToCjs('remark-gfm'),
fromEsmToCjs('remark-unwrap-images'),
fromEsmToCjs('rehype-external-links'),
fromEsmToCjs('github-slugger'),
fromEsmToCjs('mdast-util-to-string'),
fromEsmToCjs('unist-util-visit'),
fromEsmToCjs('satori', path.relative(__dirname, requireResolve('satori/dist/index.js')))
];
module.exports.write_compiled_ts_declaration = async function write_compiled_ts_declaration(task, _opts) {
await task
.source('src/types/compiled.d.ts')
.dts({ packages })
.target('src/types');
};
async function ncc(task, opts) {
await task.clear('src/compiled').parallel(tasks, opts);
await task.start('write_compiled_ts_declaration');
}
module.exports.ncc = ncc;