[android] installed packages list

This commit is contained in:
2019-11-10 17:05:03 +03:00
parent 85f2cb8ff7
commit 4f3ffe1181
3 changed files with 26 additions and 5 deletions

View File

@@ -61,12 +61,33 @@ class Android extends Sdk {
sdkmanager(packages) {
this.log.i('sdkmanager: *%s*', packages.join(', '));
const installedFile = path.join(this.path, '.installed');
const installed = new Set(
fs.existsSync(installedFile) ?
fs.readFileSync(installedFile, {encoding: 'utf8'}).split('\n') :
[]
);
const install = new Set(packages);
for (const key of installed) {
if (install.has(key)) {
install.delete(key);
}
}
if (install.size === 0) {
return Promise.resolve();
}
const androidBin = path.join(this.path, 'tools/bin/sdkmanager');
if (fs.existsSync(androidBin)) {
fs.chmodSync(androidBin, 0o755);
}
const yes = '(while sleep 3; do echo "y"; done)';
return exec('.', [yes, '|', androidBin].concat(packages.map(name => `"${name}"`)).join(' '));
const command = [yes, '|', androidBin].concat(Array.from(install).map(name => `"${name}"`)).join(' ');
return exec('.', command).then(() => {
for (const key of install) {
installed.add(key);
}
fs.writeFileSync(installedFile, Array.from(installed).join('\n'), {encoding: 'utf8'});
});
}
activate() {