feat(cli): support default cross-compilation targets from npmextra.json

This commit is contained in:
2026-02-09 20:24:57 +00:00
parent 97cfcac82f
commit 32e3928d19
7 changed files with 41 additions and 6 deletions

View File

@@ -40,13 +40,20 @@ function friendlyName(triple: string): string {
return triple.replace(/-/g, '_');
}
interface ITsrustConfig {
targets?: string[];
}
export class TsRustCli {
private cli: plugins.smartcli.Smartcli;
private cwd: string;
private config: ITsrustConfig;
constructor(cwd: string = process.cwd()) {
this.cwd = cwd;
this.cli = new plugins.smartcli.Smartcli();
const npmextraInstance = new plugins.npmextra.Npmextra(this.cwd);
this.config = npmextraInstance.dataFor<ITsrustConfig>('@git.zone/tsrust', { targets: [] });
this.registerCommands();
}
@@ -99,11 +106,11 @@ export class TsRustCli {
const distDir = path.join(this.cwd, 'dist_rust');
const profile = isDebug ? 'debug' : 'release';
// Parse --target flag (can appear multiple times)
const rawTargets = (argvArg as any).target;
const targets: string[] = rawTargets
? Array.isArray(rawTargets) ? rawTargets : [rawTargets]
: [];
// Parse --target flag (can appear multiple times), fall back to npmextra.json config
const cliTargets = (argvArg as any).target;
const targets: string[] = cliTargets
? (Array.isArray(cliTargets) ? cliTargets : [cliTargets])
: this.config.targets || [];
if (targets.length > 0) {
// Cross-compilation mode