Skip to content

Commit

Permalink
calculate homedir, sketches dir, and downloads dir. remove from setti…
Browse files Browse the repository at this point in the history
…ngs.js
  • Loading branch information
Joshua Marinacci committed Jun 23, 2014
1 parent fdcf712 commit fe968b4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 28 deletions.
2 changes: 1 addition & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function doCompile(code,board,sketch, cb) {
OPTIONS.platform = platform.getDefaultPlatform();
OPTIONS.platform.installIfNeeded(function() {
OPTIONS.name = sketch;
compile.compile(sketchpath,outpath,OPTIONS, publishEvent, path.join(settings.usersketches, sketch), cb);
compile.compile(sketchpath,outpath,OPTIONS, publishEvent, path.join(OPTIONS.platform.getUserSketchesDir(), sketch), cb);
});
}

Expand Down
28 changes: 15 additions & 13 deletions libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ var fs = require('fs');
var spawn = require('child_process').spawn;
var http = require('http');
var AdmZip = require('adm-zip');
var platform = require('./platform');



var settings = require('./settings.js');
var master = null;
var libs = null;
var plat = platform.getDefaultPlatform();


function isInstalled() {
console.log('checking if',this.id,'is installed');
if(this.source == 'ide') return true;
var path = settings.repos+'/'+this.id;
var path = plat.getReposPath()+'/'+this.id;
console.log('checking if path exists',path);
if(fs.existsSync(settings.repos+'/'+this.id)) return true;
if(fs.existsSync(plat.getReposPath()+'/'+this.id)) return true;
return false;
}

function getIncludePaths(platform) {
if(this.source == 'ide') {
var path = platform.getArduinoLibrariesPath()+'/'+this.location;
var path = platform.getStandardLibraryPath()+'/'+this.location;
//console.log("files = ",fs.readdirSync(path));
var paths = [];
paths.push(path);
Expand All @@ -36,14 +38,14 @@ function getIncludePaths(platform) {
return paths;
}
if(this.path) {
return [settings.repos+'/'+this.id+'/'+this.path];
return [plat.getReposPath()+'/'+this.id+'/'+this.path];
}
return [settings.repos+'/'+this.id];
return [plat.getReposPath()+'/'+this.id];
}

function install(cb) {
if(!fs.existsSync(settings.repos)) {
fs.mkdirSync(settings.repos);
if(!fs.existsSync(plat.getReposPath())) {
fs.mkdirSync(plat.getReposPath());
}

console.log('installing',this.id);
Expand All @@ -52,7 +54,7 @@ function install(cb) {
var cmd = [
'clone',
this.location,
settings.repos+'/'+this.id,
plat.getReposPath()+'/'+this.id,
];
console.log("execing",bin,cmd);
var proc = spawn(bin,cmd);
Expand All @@ -70,8 +72,8 @@ function install(cb) {

if(this.source == 'http'){
console.log("source is http",this.location);
var outpath = settings.repos;
var outfile = settings.repos+'/'+this.location.substring(this.location.lastIndexOf('/')+1);
var outpath = plat.getReposPath();
var outfile = plat.getReposPath()+'/'+this.location.substring(this.location.lastIndexOf('/')+1);
console.log("output file = ",outfile);
var req = http.get(this.location)
.on('response',function(res){
Expand All @@ -83,9 +85,9 @@ function install(cb) {
var rootpath = zipEntries[0].entryName;
rootpath = rootpath.substring(0,rootpath.indexOf('/'));
console.log("rootpath of the zip is",rootpath);
zip.extractAllTo(settings.repos,true);
console.log('done extracting from ',outfile, 'to',settings.repos);
fs.renameSync(settings.repos+'/'+rootpath, settings.repos+'/'+rootpath.toLowerCase());
zip.extractAllTo(plat.getReposPath(),true);
console.log('done extracting from ',outfile, 'to',plat.getReposPath());
fs.renameSync(plat.getReposPath()+'/'+rootpath, plat.getReposPath()+'/'+rootpath.toLowerCase());
if(cb) cb(null);
});
});
Expand Down
29 changes: 25 additions & 4 deletions platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,31 @@ function Platform() {
this.os = process.platform;
console.log("os = ",this.os);

this.root = settings.repos + '/platforms/1.0.5/'+this.os;

this.getUserHome = function() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
}

this.getReposPath = function() {
if(this.os == 'darwin') {
return this.getUserHome() + '/Library/ElectronIDE/downloads';
}
return this.getUserHome() + '/ElectronIDE/downloads';
}

this.getUserSketchesDir = function() {
if(settings.usersketches) return settings.usersketches;

if(this.os == 'darwin') {
return this.getUserHome()+'/Documents/Arduino';
}
if(this.os == 'window') {
return this.getUserHome()+'/My Documents/Arduino';
}
return this.getUserHome() + '/Sketchbook';
}

this.root = this.getReposPath() + '/platforms/1.0.5/'+this.os;
console.log("root should be ", this.root);

this.getStandardLibraryPath = function() {
Expand All @@ -34,9 +58,6 @@ function Platform() {
this.getAvrDudeConf = function(device) {
return this.root + '/hardware/tools/avr/etc/avrdude.conf';
}
this.getArduinoLibrariesPath = function() {
return this.root + '/libraries';
}
this.isInstalled = function() {
return fs.existsSync(this.root);
}
Expand Down
10 changes: 6 additions & 4 deletions settings.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//where your sketches live
exports.usersketches = "/Users/josh/Documents/Arduino/";
//set only if you want to change the default
//exports.usersketches = "/Users/josh/Documents/Arduino/";

//where your personal libraries live. new libs will *not* go here
exports.userlibs = "/Users/josh/Documents/Arduino/Libraries";
//set only if you want to change the default
//exports.userlibs = "/Users/josh/Documents/Arduino/Libraries";

// root of the regular Arduino IDE app
exports.root = "/Applications/Arduino.app/Contents/Resources/Java";

//where new libs will be downlaoded to
exports.repos = "/Users/josh/projects/junkrepos";
//set only if you want to change the default
//exports.repos = "/Users/josh/projects/junkrepos";

// ==============
// you shouldn't need to modify anything below this line
Expand Down
14 changes: 8 additions & 6 deletions sketches.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
var fs = require('fs');

var settings = require('./settings.js');
var platform = require('./platform');
var plat = platform.getDefaultPlatform();

exports.makeNewSketch = function(name,cb) {
var dir = settings.usersketches+'/'+name;
var dir = plat.getUserSketchesDir()+'/'+name;
if(fs.existsSync(dir)) {
if(cb)cb(null);
return;
}
fs.mkdirSync(dir);
var example = fs.readFileSync(settings.sketchtemplate).toString();
fs.writeFileSync(settings.usersketches+'/'+name+'/'+name+'.ino',example);
fs.writeFileSync(plat.getUserSketchesDir()+'/'+name+'/'+name+'.ino',example);
if(cb) cb(name,example);
}

exports.deleteSketch = function(name, cb) {
var dir = settings.usersketches+'/'+name;
var dir = plat.getUserSketchesDir()+'/'+name;
fs.readdirSync(dir).forEach(function(file) {
console.log("deleting file = ",file);
fs.unlinkSync(dir+'/'+file);
Expand All @@ -25,7 +27,7 @@ exports.deleteSketch = function(name, cb) {
}

exports.listSketches = function(cb) {
var list = fs.readdirSync(settings.usersketches);
var list = fs.readdirSync(plat.getUserSketchesDir());
list = list.filter(function(file) {
if(file.toLowerCase() == 'libraries') return false;
if(file.toLowerCase() == '.ds_store') return false;
Expand All @@ -35,7 +37,7 @@ exports.listSketches = function(cb) {
}

exports.getSketch = function(name, cb) {
var dir = settings.usersketches + '/' + name;
var dir = plat.getUserSketchesDir() + '/' + name;
var obj = {
name:name,
files:[]
Expand Down Expand Up @@ -63,7 +65,7 @@ exports.getSketch = function(name, cb) {

exports.saveSketch = function(name, code, cb) {
console.log("saving to ",name);
var dir = settings.usersketches + '/' + name;
var dir = plat.getUserSketchesDir() + '/' + name;
console.log("dir = ",dir);
var file = dir+'/'+name+'.ino';
console.log("file = ",file);
Expand Down

0 comments on commit fe968b4

Please sign in to comment.