mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-31 06:03:29 +08:00
114 lines
3.5 KiB
JavaScript
114 lines
3.5 KiB
JavaScript
'use strict';
|
|
|
|
const LEGACY_INSTALL_TARGETS = ['claude', 'cursor', 'antigravity'];
|
|
|
|
function dedupeStrings(values) {
|
|
return [...new Set((Array.isArray(values) ? values : []).map(value => String(value).trim()).filter(Boolean))];
|
|
}
|
|
|
|
function parseInstallArgs(argv) {
|
|
const args = argv.slice(2);
|
|
const parsed = {
|
|
target: null,
|
|
dryRun: false,
|
|
json: false,
|
|
help: false,
|
|
configPath: null,
|
|
profileId: null,
|
|
moduleIds: [],
|
|
includeComponentIds: [],
|
|
excludeComponentIds: [],
|
|
languages: [],
|
|
};
|
|
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
const arg = args[index];
|
|
|
|
if (arg === '--target') {
|
|
parsed.target = args[index + 1] || null;
|
|
index += 1;
|
|
} else if (arg === '--config') {
|
|
parsed.configPath = args[index + 1] || null;
|
|
index += 1;
|
|
} else if (arg === '--profile') {
|
|
parsed.profileId = args[index + 1] || null;
|
|
index += 1;
|
|
} else if (arg === '--modules') {
|
|
const raw = args[index + 1] || '';
|
|
parsed.moduleIds = raw.split(',').map(value => value.trim()).filter(Boolean);
|
|
index += 1;
|
|
} else if (arg === '--with') {
|
|
const componentId = args[index + 1] || '';
|
|
if (componentId.trim()) {
|
|
parsed.includeComponentIds.push(componentId.trim());
|
|
}
|
|
index += 1;
|
|
} else if (arg === '--without') {
|
|
const componentId = args[index + 1] || '';
|
|
if (componentId.trim()) {
|
|
parsed.excludeComponentIds.push(componentId.trim());
|
|
}
|
|
index += 1;
|
|
} else if (arg === '--dry-run') {
|
|
parsed.dryRun = true;
|
|
} else if (arg === '--json') {
|
|
parsed.json = true;
|
|
} else if (arg === '--help' || arg === '-h') {
|
|
parsed.help = true;
|
|
} else if (arg.startsWith('--')) {
|
|
throw new Error(`Unknown argument: ${arg}`);
|
|
} else {
|
|
parsed.languages.push(arg);
|
|
}
|
|
}
|
|
|
|
return parsed;
|
|
}
|
|
|
|
function normalizeInstallRequest(options = {}) {
|
|
const config = options.config && typeof options.config === 'object'
|
|
? options.config
|
|
: null;
|
|
const profileId = options.profileId || config?.profileId || null;
|
|
const moduleIds = dedupeStrings([...(config?.moduleIds || []), ...(options.moduleIds || [])]);
|
|
const includeComponentIds = dedupeStrings([
|
|
...(config?.includeComponentIds || []),
|
|
...(options.includeComponentIds || []),
|
|
]);
|
|
const excludeComponentIds = dedupeStrings([
|
|
...(config?.excludeComponentIds || []),
|
|
...(options.excludeComponentIds || []),
|
|
]);
|
|
const languages = Array.isArray(options.languages) ? [...options.languages] : [];
|
|
const target = options.target || config?.target || 'claude';
|
|
const hasManifestBaseSelection = Boolean(profileId) || moduleIds.length > 0 || includeComponentIds.length > 0;
|
|
const usingManifestMode = hasManifestBaseSelection || excludeComponentIds.length > 0;
|
|
|
|
if (usingManifestMode && languages.length > 0) {
|
|
throw new Error(
|
|
'Legacy language arguments cannot be combined with --profile, --modules, --with, --without, or manifest config selections'
|
|
);
|
|
}
|
|
|
|
if (!options.help && !hasManifestBaseSelection && languages.length === 0) {
|
|
throw new Error('No install profile, module IDs, included components, or legacy languages were provided');
|
|
}
|
|
|
|
return {
|
|
mode: usingManifestMode ? 'manifest' : 'legacy',
|
|
target,
|
|
profileId,
|
|
moduleIds,
|
|
includeComponentIds,
|
|
excludeComponentIds,
|
|
languages,
|
|
configPath: config?.path || options.configPath || null,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
LEGACY_INSTALL_TARGETS,
|
|
normalizeInstallRequest,
|
|
parseInstallArgs,
|
|
};
|