Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Created May 8, 2014 13:51
Show Gist options
  • Save AdamMagaluk/e5c12b6303272d16ff25 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/e5c12b6303272d16ff25 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var cpr = require('cpr');
var libDir = '/Applications/Arduino.app/Contents/Resources/Java/libraries/';
function parseProp(data){
var r = {};
data.split('\n').forEach(function(line){
line = line.split('=');
if(!line[1])
return;
r[line[0]] = line[1].replace('\r','');
});
if(r.dependencies){
r.dependencies = r.dependencies.split(',').map(function(f){return f.trim().toLowerCase() + '.ino';});
}else{
r.dependencies = [];
}
return r;
}
var basePackageJson = {
"name": "",
"version": "0.0.0",
"description": "Arduino library for leo build system.",
"main": "",
"scripts": {},
"bin": { },
"keywords": ["arduino","avr","gcc","make","ino","yun","uno","leo"],
"contributors": "Adam Magaluk <[email protected]>",
"license": "MIT",
"dependencies": { },
"directories": {"example": "examples","src": "src"},
"bugs": {
"url": "https://github.com/AdamMagaluk/leo/issues"
},
"homepage": ""
};
fs.readdirSync(libDir).forEach(function(name){
var localDir = path.join('.','libs',name);
var fullDir = path.join(libDir,name);
/*
{ name: 'WiFi',
author: 'Arduino',
email: '[email protected]',
sentence: 'Libary for the Arduino WiFi shield.',
paragraph: 'With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The shield can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS.',
url: 'http:http://arduino.cc/en/Reference/WiFi',
architectures: 'avr,sam',
version: '1.2',
dependencies: 'SPI',
'core-dependencies': 'arduino (>',
*/
function initDir(){
fs.mkdirSync(localDir);
var prop = parseProp(fs.readFileSync(path.join(fullDir,'library.properties')).toString());
console.log(prop)
var json = basePackageJson;
json.name = name.toLowerCase()+'.ino';
json.description = prop.sentence + ' Packaged for the leo build system.';
json.homepage = prop.url;
json.leoarchitectures = prop.architectures;
json.author = prop.email;
json.version = '0.'+prop.version
json.dependencies = {};
prop.dependencies.forEach(function(d){
json.dependencies[d] = "*";
});
fs.writeFileSync(path.join(localDir,'package.json'),JSON.stringify(json,null,2));
}
if(!fs.existsSync(localDir)){
initDir();
}
cpr(fullDir, localDir, {
}, function(err, files) {
if(err)
console.log(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment