-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
48 lines (44 loc) · 1.73 KB
/
Copy pathcli.js
File metadata and controls
48 lines (44 loc) · 1.73 KB
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
#!/usr/bin/env node
/**
* CLI for polyfillme module
*/
const path = require("path");
const polyfillme = require("./src/index");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv))
.option("ecmaVersion", { type: "string", demandOption: true, describe: "Target ES/ECMA version (e.g., es3, es2018)" })
.option("files", { type: "array", demandOption: true, describe: "File globs to scan" })
.option("includedPolyfills", { type: "array", default: [], describe: "Already included polyfills" })
.option("additionalPolyfills", { type: "array", default: [], describe: "Additional polyfills to include" })
.option("source", { type: "string", default: "core-js", describe: "Polyfill source (core-js, polyfill.io)" })
.option("filePath", { type: "string", describe: "Output file path for polyfills" })
.help().argv;
(async () => {
try {
const result = await polyfillme({
ecmaVersion: argv.ecmaVersion,
files: argv.files,
includedPolyfills: argv.includedPolyfills,
additionalPolyfills: argv.additionalPolyfills,
source: argv.source,
writeToFile: !!argv.filePath,
filePath: argv.filePath
});
// Output shim/sham and not-found info from main module
if (result.notFound && result.notFound.length) {
console.log("Warning: The following features were not found in core-js:", result.notFound);
}
if (result.shams && result.shams.length) {
console.log("Note: The following features are shams (not true shims):", result.shams);
}
if (argv.filePath) {
console.log(`Polyfill output written to ${path.resolve(argv.filePath)}`);
} else {
console.log(result.content);
}
} catch (err) {
console.error("Error:", err.message);
process.exit(1);
}
})();