Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download _alloy_ db #1410

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Alloy/alloy.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ program.command('purgetss')
.option('--modules', 'Copy or generate the corresponding CommonJS module into `./app/lib/` folder.')
.option('--vendor <arguments>', 'Use any of the following arguments to copy specific vendors: fa = Font Awesome, md = Material Design or f7 = Framework7 Icons');

program.command('db')
.description('Fetches the default alloy database (_alloy_) from the device')
.option('get', 'Downloads the _alloy_ database to your app folder');

program.command('info [type]', { hidden: true });

program.command('debugger', { hidden: true });
Expand Down
49 changes: 49 additions & 0 deletions Alloy/commands/db/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const {
exec
} = require('child_process');
const U = require('../../utils');
const tiapp = require('../../tiapp');
const fs = require('fs');
const os = require('os');

module.exports = async function(args, program) {

try {
if (args.length === 0) {
execCommand('db');
} else {
args.forEach(command => {
switch (command) {
case 'get':
tiapp.init();
var adbPath = 'adb';
if (os.platform() === 'darwin') {
adbPath = '~/Library/Android/sdk/platform-tools/adb';
var testPath = path.join(adbPath);
if (!fs.existsSync(testPath)) {
console.error('adb not found at ' + adbPath);
return;
}
}
console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db');
execCommand(adbPath + ' shell "run-as ' + tiapp.getBundleId() + ' cat /data/data/' + tiapp.getBundleId() + '/databases/_alloy_" > ' + tiapp.getBundleId() + '.db');
break;
}
});
}
} catch (error) {
//
}
};

function execCommand(currentCommand) {
exec(currentCommand, (error, response) => {
if (error) {
console.error(error);
}
if (response) {
console.log(response);
}
return true;
});
}
28 changes: 28 additions & 0 deletions Alloy/tiapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ tiapp.getSdkVersion = function() {
}
};

tiapp.getBundleId = function() {
var elems = doc.documentElement.getElementsByTagName('id');
if (elems && elems.length > 0) {
var bundleId = U.XML.getNodeText(elems.item(elems.length - 1));
var isForced = false;
for (var i = 0; i < elems.length; i++) {
if (elems.item(i).getAttribute('platform') === 'android') {
// platform specific ID
isForced = true;
bundleId = U.XML.getNodeText(elems.item(i));
} else if (elems.item(i).getAttribute('platform') === '' && !isForced) {
// normal ID - only if no platform specific was set already
bundleId = U.XML.getNodeText(elems.item(i));
}
}
return bundleId;
}
};

function getSdkSelectVersion() {
var homeDir = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'],
file = path.join(homeDir, '.titanium', 'config.json');
if (!fs.existsSync(file)) {
U.die('Titanium configuration file does not exist at "' + file + '"');
}
var ticonfig = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'}));
return ticonfig.sdk.selected;
}

// Get the value of a property from the tiapp.xml
tiapp.getProperty = function(name) {
Expand Down
Loading