-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
75 lines (68 loc) · 1.94 KB
/
rollup.config.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
64
65
66
67
68
69
70
71
72
73
74
75
import typescript from 'rollup-plugin-typescript2';
import { join } from 'path';
import { readdirSync } from 'fs';
import del from 'rollup-plugin-delete';
import cleanup from 'rollup-plugin-cleanup';
import { spawnSync } from 'child_process';
const cliConfig = require('./config/cliConfig.json');
/**
* Deep searches for files within a directory
*
* @param {string} fileExtension filter for extension
* @param {string} localDirectory root directory
* @returns {string[]} file list
*/
const deepDirectorySearch = (fileExtension, localDirectory) => {
const path = join(__dirname, localDirectory);
const locations = readdirSync(path, { withFileTypes: true });
// This should be a flatMap with a filter but JS auto targets ES2015. flatMap
// is part of ES2018. I've implemented a flatMap using the underlying
// functions. This should be fixed by force the target to >= ES2018 or wait
// for default target to be updated.
return locations
.map((value) => {
const localisedPath = join(localDirectory, value.name);
if (value.isDirectory()) {
return deepDirectorySearch(fileExtension, localisedPath);
}
return localisedPath;
})
.reduce(
(acc, value) => [
...acc,
...(typeof value === 'string' ? [value] : value),
],
[]
)
.filter((value) => value.endsWith('.ts'));
};
/**
* Rollup global plugins
*/
const plugins = [
typescript({
typescript: require('typescript'),
}),
cleanup(),
];
export default [
{
input: 'src/index.ts',
output: {
file: `dist/${cliConfig.name}`,
format: 'cjs',
banner: '#!/usr/bin/env node',
},
plugins: [
...plugins,
// add execute permission to the executable
{
name: 'writeBundle',
writeBundle: () => {
spawnSync(`chmod`, ['u+x', `dist/${cliConfig.name}`]);
},
},
!process.env.ROLLUP_WATCH ? del({ targets: 'dist/**/*' }) : undefined,
],
},
];