-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
48 lines (41 loc) · 1.53 KB
/
index.ts
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
import { globbySync } from "globby";
import { development } from "./src/development.js";
import { production } from "./src/production.js";
/**
* @param js The list of Javascript files to be processed, or a glob.
* @param css The list of CSS files to be processed, or a glob.
* @see https://github.com/sindresorhus/globby#globbing-patterns
*/
const main = (js: string[] | string, css: string[] | string) => {
// If `js` or `css` is a string, we process it with globbySync to return a list of files.
const jsFiles =
typeof js === "string"
? globbySync(js.split(",").map((str) => str.replace(/ /g, "")))
: js;
const cssFiles =
typeof css === "string"
? globbySync(css.split(",").map((str) => str.replace(/ /g, "")))
: css;
const args = process.argv;
const sourcemap = args.includes("--map");
const isProduction = args.includes("--prod");
let notice = "";
notice =
typeof js === "string"
? `Javascript files defined via a glob pattern.`
: `Javascript files passed as an array.`;
notice =
typeof css === "string"
? `${notice}\nCSS files defined via a glob pattern.`
: `${notice}\nCSS files passed as an array.`;
if (typeof js === "string" || typeof css === "string") {
notice = `${notice}\nRead more on glob patterns at: https://github.com/sindresorhus/globby#globbing-patterns\n`;
}
console.log(notice);
if (!isProduction) {
development([...jsFiles, ...cssFiles]);
} else {
production([...jsFiles, ...cssFiles], sourcemap);
}
};
export { main as default };