-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
124 lines (108 loc) · 3.17 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
const vscode = require('vscode');
const Utils = require('./src/utils');
const FileManager = require('./src/android_file_manager');
const ShManager = require('./src/sh_manager');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let disposable = vscode.commands.registerCommand('extension.locate_apk', async function () {
const rootDir = Utils.getProjectRootPath();
_findAndroidManifests(rootDir)
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() { }
async function _findAndroidManifests(projRootDir) {
let manifestsInProj = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Scanning project files... 🔍🤔'
},
async () => {
return await FileManager.findManifests([], projRootDir, true)
}
);
if (!Utils.isEmptyArray(manifestsInProj)) {
_getProjectOutputDirPath(manifestsInProj)
} else {
_showError(
'Cannot find any AndroidManifest file in project 😮🤷.'
+ '\nAre you sure this is an Android project? 👀'
);
}
}
async function _getProjectOutputDirPath(manifestsInProj) {
let outputDir = await FileManager.getProjectOutputDirPath(manifestsInProj)
if (outputDir) {
_getApkDirPath(outputDir)
} else {
_showError('Cannot find project output directory 😮🤷');
}
}
async function _getApkDirPath(outputDir) {
let apkDir = await FileManager.getApkDirPath(outputDir)
if (apkDir) {
_retrieveBuildDir(apkDir)
} else {
vscode.window.showErrorMessage(
'Cannot find Apk directory 🤷.'
+ '\nThis directory is generated only after you make a build 👀'
);
}
}
/**
* Android projects could have flavors (eg. develop,staging,production).
* If so each flavor contains its buildTypes (eg. debug, release),
* otherwise buildTypes are placed directly inside
* apk folder.
*
* @param {*} currentDir
*/
async function _retrieveBuildDir(currentDir) {
let subDirs = await FileManager.getSubDirPaths(currentDir, true)
if (!Utils.isEmptyArray(subDirs)) {
let selectedFolder = await _selectBuildTypeDir(subDirs)
let containsApk = await FileManager.dirContainsApk(selectedFolder)
if (containsApk) {
_onBuildDirRetrieved(selectedFolder)
} else {
_retrieveBuildDir(selectedFolder)
}
} else {
_showError('Cannot find apk in the selected directory 😮🤷')
}
}
/**
* Show picker dialog only if there's more than one @param {Array} subDirs
*/
async function _selectBuildTypeDir(subDirs) {
let selectedFolder = null
if (subDirs.length === 1) {
selectedFolder = subDirs[0]
} else {
selectedFolder = await Utils.showPickerDialog("Pick one:", subDirs)
}
return selectedFolder
}
async function _onBuildDirRetrieved(buildFolder) {
let success = await ShManager.openFolder(buildFolder)
if (success) {
_showMessage('Done! 🚀🎉\nYour build folder has been opened!')
} else {
_showError('Cannot open build folder 😵☹️')
}
}
function _showMessage(message) {
vscode.window.showInformationMessage(message);
}
function _showError(message) {
vscode.window.showErrorMessage(message)
}
module.exports = {
activate,
deactivate
}