-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathce-plugin.mjs
More file actions
66 lines (59 loc) · 1.68 KB
/
Copy pathce-plugin.mjs
File metadata and controls
66 lines (59 loc) · 1.68 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
import path from 'node:path';
import {
buildPlugin,
checkPlugin,
discoverAllPlugins,
discoverPlugin,
} from '@itharbors/kit-cli';
function parseArgs(argv) {
const [command, target] = argv;
return { command, target };
}
function ensureTarget(target) {
if (!target) {
throw new Error('Expected <plugin-dir|--all|--framework>');
}
return target;
}
async function discoverTargets(command, target) {
const resolvedTarget = ensureTarget(target);
if (resolvedTarget !== '--all' && resolvedTarget !== '--framework') {
return [target];
}
let plugins;
if (resolvedTarget === '--framework') {
const frameworkPluginRoot = `${path.resolve(process.cwd(), 'plugins')}${path.sep}`;
plugins = discoverAllPlugins(process.cwd()).filter((plugin) =>
`${path.resolve(plugin)}${path.sep}`.startsWith(frameworkPluginRoot));
} else {
plugins = discoverAllPlugins(process.cwd());
}
if (plugins.length === 0) {
throw new Error('No plugins found');
}
return plugins;
}
async function run(command, target) {
switch (command) {
case 'check':
for (const pluginDir of await discoverTargets(command, target)) {
checkPlugin(discoverPlugin(pluginDir));
}
return;
case 'build':
for (const pluginDir of await discoverTargets(command, target)) {
buildPlugin(discoverPlugin(pluginDir));
}
return;
default:
throw new Error(`Unknown command: ${command ?? '<missing>'}`);
}
}
try {
const { command, target } = parseArgs(process.argv.slice(2));
await run(command, target);
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}