Skip to content

Commit 6bcd7fb

Browse files
committed
feat: includesAny support for options
1 parent fa7bee6 commit 6bcd7fb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/main.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ import { terser } from "rollup-plugin-terser";
77
// @ts-ignore
88
import autoExternal from "rollup-plugin-auto-external";
99

10+
export type Plugin =
11+
| "js"
12+
| "ts"
13+
| "coffee"
14+
| "json"
15+
| "css"
16+
| "babel"
17+
| ["ts", typeof typescript]
18+
| ["babel", typeof babel]
19+
| ["coffee", typeof coffeescript]
20+
| ["json", typeof json]
21+
| ["css", typeof cssOnly];
22+
23+
// function to check if the first array has any of the second array
24+
// first array can have `[string, object]` as their input
25+
function includesAny(
26+
arr1: Array<string | [string, Object]>,
27+
arr2: Array<string>
28+
): null | number {
29+
for (let index = 0; index < arr1.length; index++) {
30+
const elm = arr1[index];
31+
let name: string;
32+
if (typeof elm === "string") {
33+
// plugin name only
34+
name = elm;
35+
} else {
36+
// plugin with options
37+
name = elm[0];
38+
}
39+
if (arr2.includes(name)) {
40+
return index;
41+
}
42+
}
43+
return null;
44+
}
1045
export function createPlugins(
1146
languages: Array<string> = ["ts", "js", "json", "coffee"],
1247
babel: boolean = true,

0 commit comments

Comments
 (0)