Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Adjust multi-platform CLI invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
filipbudisa committed Sep 24, 2020
1 parent 3950c85 commit ec95067
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
19 changes: 19 additions & 0 deletions core/compiler/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ArduinoCompiler, {InstallInfo} from "./compiler";
import * as os from "os";
import * as child_process from "child_process";

export class CLI {

public static run(args?: string[], info?: InstallInfo){
if(info == undefined){
info = ArduinoCompiler.checkInstall();
if(info == null) return;
}

const command = os.type() == "Windows_NT"
? "arduino-cli.exe"
: "./arduino-cli";

return child_process.execFileSync(command, args, { encoding: "utf8", cwd: info.cli });
}
}
7 changes: 4 additions & 3 deletions core/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ export default class ArduinoCompiler {
return;
}

this.process = childProcess.execFile("arduino-cli" + (os.type() == 'Windows_NT' ? '.exe' : ''),
['daemon'],
{ cwd: this.installInfo.cli });
const cliCommand = os.type() == "Windows_NT"
? "arduino-cli.exe"
: "./arduino-cli";
this.process = childProcess.execFile(cliCommand, ['daemon'], { cwd: this.installInfo.cli });

const req = new InitReq();
req.setLibraryManagerOnly(false);
Expand Down
20 changes: 6 additions & 14 deletions core/compiler/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ArduinoCompiler, { InstallInfo } from './compiler';
import * as util from './util';
import logger from "../files/logger";
import {isNewer} from "./util";
import {CLI} from "./cli";

export default class Installer {
private readonly PLATFORM: string;
Expand Down Expand Up @@ -137,9 +138,9 @@ export default class Installer {

private cliInit(path, callback: (error) => void) {
try{
childProcess.execFileSync("arduino-cli" + (this.PLATFORM == "Windows_NT" ? ".exe" : ""), ['config', 'init'], { cwd: path });
childProcess.execFileSync("arduino-cli" + (this.PLATFORM == "Windows_NT" ? ".exe" : ""), ['core', 'update-index'], { cwd: path });
childProcess.execFileSync("arduino-cli" + (this.PLATFORM == "Windows_NT" ? ".exe" : ""), ['lib', 'update-index'], { cwd: path });
CLI.run(['config', 'init']);
CLI.run(['core', 'update-index']);
CLI.run(['lib', 'update-index']);
}catch(e){
logger.log("CLI init error", e);
callback(e);
Expand Down Expand Up @@ -484,20 +485,14 @@ export default class Installer {
}

private installPlatforms(callback: (err) => void, info: InstallInfo, stage?: (string) => void) {
const cliPath =
this.PLATFORM === 'Windows_NT'
? path.join(os.homedir(), 'AppData', 'Local', 'ArduinoCLI')
: path.join(os.homedir(), '.arduino');
const PLATFORM = this.PLATFORM;

try{
const additionals = [
this.downloads.ringo.manager,
this.downloads.nibble.manager
].join(",");

function execCli(args: string[]){
childProcess.execFileSync("arduino-cli" + (PLATFORM == "Windows_NT" ? ".exe" : ""), args, { cwd: cliPath })
CLI.run(args, info);
}

execCli(['--additional-urls', additionals, 'core', 'update-index']);
Expand Down Expand Up @@ -571,10 +566,7 @@ export default class Installer {
private checkCliUpdate(callback: (err) => void, info: InstallInfo, stage?: (string) => void){
const cliPath = path.join(info.cli, "arduino-cli" + (this.PLATFORM == "Windows_NT" ? ".exe" : ""));

const cliData = JSON.parse(
childProcess.execFileSync("arduino-cli" + (this.PLATFORM == "Windows_NT" ? ".exe" : ""),
[ "--format", "json", "version" ],
{ encoding: "utf8", cwd: info.cli }));
const cliData = JSON.parse(CLI.run([ "--format", "json", "version" ], info));

if(isNewer(this.versions.cli, cliData.VersionString)){
console.log("Updating CLI");
Expand Down

0 comments on commit ec95067

Please sign in to comment.