Skip to content

Commit 9a82208

Browse files
committed
style: reformat code
1 parent a7d71a0 commit 9a82208

File tree

3 files changed

+76
-76
lines changed

3 files changed

+76
-76
lines changed

lib/android-tools-info.ts

+61-61
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as _ from "lodash";
1111
export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
1212
public readonly ANDROID_TARGET_PREFIX = "android";
1313
public getSupportedTargets(projectDir: string) {
14-
const runtimeVersion = this.getRuntimeVersion({projectDir});
14+
const runtimeVersion = this.getRuntimeVersion({ projectDir });
1515
let baseTargets = [
1616
"android-17",
1717
"android-18",
@@ -126,7 +126,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
126126
if (semver.lt(installedJavaCompilerSemverVersion, AndroidToolsInfo.MIN_JAVA_VERSION) || semver.gte(installedJavaCompilerSemverVersion, AndroidToolsInfo.MAX_JAVA_VERSION)) {
127127
warning = `Javac version ${installedJavaCompilerVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION} and below ${AndroidToolsInfo.MAX_JAVA_VERSION}.`;
128128
} else {
129-
runtimeVersion = this.getRuntimeVersion({runtimeVersion, projectDir});
129+
runtimeVersion = this.getRuntimeVersion({ runtimeVersion, projectDir });
130130
if (runtimeVersion) {
131131
// get the item from the dictionary that corresponds to our current Javac version:
132132
let runtimeMinVersion: string = null;
@@ -200,7 +200,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
200200
return errors;
201201
}
202202

203-
public validateMinSupportedTargetSdk({targetSdk, projectDir}: NativeScriptDoctor.ITargetValidationOptions): NativeScriptDoctor.IWarning[] {
203+
public validateMinSupportedTargetSdk({ targetSdk, projectDir }: NativeScriptDoctor.ITargetValidationOptions): NativeScriptDoctor.IWarning[] {
204204
const errors: NativeScriptDoctor.IWarning[] = [];
205205
const newTarget = `${this.ANDROID_TARGET_PREFIX}-${targetSdk}`;
206206
const supportedTargets = this.getSupportedTargets(projectDir);
@@ -212,7 +212,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
212212

213213
if (!targetSupported && targetSdk && (targetSdk < minSupportedVersion)) {
214214
errors.push({
215-
warning:`The selected Android target SDK ${newTarget} is not supported. You must target ${minSupportedVersion} or later.`,
215+
warning: `The selected Android target SDK ${newTarget} is not supported. You must target ${minSupportedVersion} or later.`,
216216
additionalInformation: "",
217217
platforms: [Constants.ANDROID_PLATFORM_NAME]
218218
});
@@ -222,14 +222,14 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
222222
return errors;
223223
}
224224

225-
public validataMaxSupportedTargetSdk({targetSdk, projectDir}: NativeScriptDoctor.ITargetValidationOptions): NativeScriptDoctor.IWarning[] {
225+
public validataMaxSupportedTargetSdk({ targetSdk, projectDir }: NativeScriptDoctor.ITargetValidationOptions): NativeScriptDoctor.IWarning[] {
226226
const errors: NativeScriptDoctor.IWarning[] = [];
227227
const newTarget = `${this.ANDROID_TARGET_PREFIX}-${targetSdk}`;
228228
const targetSupported = _.includes(this.getSupportedTargets(projectDir), newTarget);
229229

230230
if (!targetSupported && !targetSdk || targetSdk > this.getMaxSupportedVersion(projectDir)) {
231231
errors.push({
232-
warning:`Support for the selected Android target SDK ${newTarget} is not verified. Your Android app might not work as expected.`,
232+
warning: `Support for the selected Android target SDK ${newTarget} is not verified. Your Android app might not work as expected.`,
233233
additionalInformation: "",
234234
platforms: [Constants.ANDROID_PLATFORM_NAME]
235235
});
@@ -369,68 +369,68 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
369369

370370
private getAndroidRuntimePackageFromProjectDir(projectDir: string): { name: string, version: string } {
371371
if (!projectDir || !this.fs.exists(projectDir)) {
372-
return null
373-
}
372+
return null;
373+
}
374374
const pathToPackageJson = path.join(projectDir, Constants.PACKAGE_JSON);
375375

376-
if(!this.fs.exists(pathToPackageJson)) {
377-
return null
378-
}
376+
if (!this.fs.exists(pathToPackageJson)) {
377+
return null;
378+
}
379379

380-
const content = this.fs.readJson<INativeScriptProjectPackageJson>(pathToPackageJson);
380+
const content = this.fs.readJson<INativeScriptProjectPackageJson>(pathToPackageJson);
381381

382-
if(!content) {
383-
return null
384-
}
382+
if (!content) {
383+
return null;
384+
}
385385

386386
// in case we have a nativescript key and a runtime with a version
387-
// we are dealing with a legacy project and should respect the values
388-
// in the nativescript key
389-
if(content && content.nativescript && content.nativescript['tns-android'] && content.nativescript['tns-android'].version) {
390-
return {
391-
name: Constants.ANDROID_OLD_RUNTIME,
392-
version: content.nativescript && content.nativescript['tns-android'] && content.nativescript['tns-android'].version
393-
};
394-
}
395-
396-
if(content && content.devDependencies) {
397-
const foundRuntime = Object.keys(content.devDependencies).find(depName => {
398-
return depName === Constants.ANDROID_SCOPED_RUNTIME || depName === Constants.ANDROID_OLD_RUNTIME
399-
})
400-
401-
if(foundRuntime) {
402-
let version = content.devDependencies[foundRuntime]
403-
404-
if(version.includes('tgz')) {
405-
try {
406-
const packagePath = require.resolve(`${foundRuntime}/package.json`, {
407-
paths: [projectDir]
408-
})
409-
version = require(packagePath).version;
410-
} catch (err) {
411-
version = '*';
412-
}
413-
}
414-
415-
return {
416-
name: foundRuntime,
417-
version
418-
}
419-
}
420-
}
421-
422-
return null
387+
// we are dealing with a legacy project and should respect the values
388+
// in the nativescript key
389+
if (content && content.nativescript && content.nativescript['tns-android'] && content.nativescript['tns-android'].version) {
390+
return {
391+
name: Constants.ANDROID_OLD_RUNTIME,
392+
version: content.nativescript && content.nativescript['tns-android'] && content.nativescript['tns-android'].version
393+
};
394+
}
395+
396+
if (content && content.devDependencies) {
397+
const foundRuntime = Object.keys(content.devDependencies).find(depName => {
398+
return depName === Constants.ANDROID_SCOPED_RUNTIME || depName === Constants.ANDROID_OLD_RUNTIME;
399+
});
400+
401+
if (foundRuntime) {
402+
let version = content.devDependencies[foundRuntime];
403+
404+
if (version.includes('tgz')) {
405+
try {
406+
const packagePath = require.resolve(`${foundRuntime}/package.json`, {
407+
paths: [projectDir]
408+
});
409+
version = require(packagePath).version;
410+
} catch (err) {
411+
version = '*';
412+
}
413+
}
414+
415+
return {
416+
name: foundRuntime,
417+
version
418+
};
419+
}
420+
}
421+
422+
return null;
423423
}
424424

425-
private getRuntimeVersion({ runtimeVersion, projectDir } : { runtimeVersion?: string, projectDir?: string}): string {
426-
let runtimePackage = {
427-
name: Constants.ANDROID_SCOPED_RUNTIME,
428-
version: runtimeVersion
429-
}
430-
if(!runtimeVersion) {
431-
runtimePackage = this.getAndroidRuntimePackageFromProjectDir(projectDir)
432-
runtimeVersion = runtimePackage?.version;
433-
}
425+
private getRuntimeVersion({ runtimeVersion, projectDir }: { runtimeVersion?: string, projectDir?: string }): string {
426+
let runtimePackage = {
427+
name: Constants.ANDROID_SCOPED_RUNTIME,
428+
version: runtimeVersion
429+
};
430+
if (!runtimeVersion) {
431+
runtimePackage = this.getAndroidRuntimePackageFromProjectDir(projectDir);
432+
runtimeVersion = runtimePackage && runtimePackage.version;
433+
}
434434

435435
if (runtimeVersion) {
436436
// Check if the version is not "next" or "rc", i.e. tag from npm
@@ -454,7 +454,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
454454
return runtimeVersion;
455455
}
456456

457-
private getMaxSupportedCompileVersion(config: Partial<NativeScriptDoctor.IProjectDir> & { runtimeVersion?: string}): number {
457+
private getMaxSupportedCompileVersion(config: Partial<NativeScriptDoctor.IProjectDir> & { runtimeVersion?: string }): number {
458458
if (config.runtimeVersion && semver.lt(semver.coerce(config.runtimeVersion), "6.1.0")) {
459459
return 28;
460460
}

lib/declarations.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ interface INativeScriptNode {
7777
}
7878

7979
interface INativeScriptProjectPackageJson {
80-
nativescript: INativeScriptNode;
81-
dependencies?: any;
82-
devDependencies?: { [name: string]: string };
80+
nativescript: INativeScriptNode;
81+
dependencies?: any;
82+
devDependencies?: { [name: string]: string };
8383
}

test/android-tools-info.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ describe("androidToolsInfo", () => {
3333
"tns-android": {
3434
version: runtimeVersion
3535
}
36-
},
37-
devDependencies: {
38-
"@nativescript/android": runtimeVersion
39-
}
36+
},
37+
devDependencies: {
38+
"@nativescript/android": runtimeVersion
39+
}
4040
} : null;
4141
},
4242
readDirectory: (path: string) => {
@@ -65,14 +65,14 @@ describe("androidToolsInfo", () => {
6565
describe("getToolsInfo", () => {
6666
it("runtime 6.0.0", () => {
6767
const androidToolsInfo = getAndroidToolsInfo("6.0.0");
68-
const toolsInfo = androidToolsInfo.getToolsInfo({projectDir: "test"});
68+
const toolsInfo = androidToolsInfo.getToolsInfo({ projectDir: "test" });
6969

7070
assert.equal(toolsInfo.compileSdkVersion, 28);
7171
});
7272

7373
it("runtime 6.1.0", () => {
7474
const androidToolsInfo = getAndroidToolsInfo("6.1.0");
75-
const toolsInfo = androidToolsInfo.getToolsInfo({projectDir: "test"});
75+
const toolsInfo = androidToolsInfo.getToolsInfo({ projectDir: "test" });
7676

7777
assert.equal(toolsInfo.compileSdkVersion, 29);
7878
});
@@ -86,8 +86,8 @@ describe("androidToolsInfo", () => {
8686
const androidToolsInfo = getAndroidToolsInfo("6.5.0");
8787
const supportedTargets = androidToolsInfo.getSupportedTargets("test");
8888
for (let i = 0; i < supportedTargets.length; i++) {
89-
assert.equal(supportedTargets[i], `android-${min+i}`);
90-
cnt = min+i;
89+
assert.equal(supportedTargets[i], `android-${min + i}`);
90+
cnt = min + i;
9191
}
9292
assert.equal(cnt, max);
9393
});
@@ -234,10 +234,10 @@ describe("androidToolsInfo", () => {
234234
"tns-android": {
235235
version: runtimeVersion
236236
}
237-
},
238-
devDependencies: {
239-
"@nativescript/android": runtimeVersion
240-
}
237+
},
238+
devDependencies: {
239+
"@nativescript/android": runtimeVersion
240+
}
241241
})
242242
};
243243

0 commit comments

Comments
 (0)