Skip to content

Commit

Permalink
chore: integrate ESLint (#3539)
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Sep 14, 2020
1 parent c9cd2ef commit d7bf775
Show file tree
Hide file tree
Showing 62 changed files with 553 additions and 474 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
cli/assets
dist
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/jest": "^26.0.4",
"@types/mock-fs": "^3.6.30",
"@types/open": "^6.1.0",
"@types/plist": "^3.0.2",
"@types/prompts": "^2.0.8",
"@types/semver": "^7.3.1",
"@types/slice-ansi": "^4.0.0",
Expand Down
7 changes: 4 additions & 3 deletions cli/src/android/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { homedir } from 'os';
import { join, relative } from 'path';

import c from '../colors';
import { Config } from '../config';
import { copyTemplate, runCommand, runTask, CheckFunction } from '../common';
import type { CheckFunction } from '../common';
import { copyTemplate, runCommand, runTask } from '../common';
import type { Config } from '../config';
import { existsAsync, writeFileAsync } from '../util/fs';

import { checkAndroidPackage } from './common';

export const addAndroidChecks: CheckFunction[] = [checkAndroidPackage];

export async function addAndroid(config: Config) {
export async function addAndroid(config: Config): Promise<void> {
const nativeRelDir = relative(config.app.rootDir, config.android.platformDir);
await runTask(
`Adding native android project in ${c.strong(nativeRelDir)}`,
Expand Down
16 changes: 10 additions & 6 deletions cli/src/android/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { mkdirs } from 'fs-extra';
import { join, resolve } from 'path';

import { checkCapacitorPlatform } from '../common';
import { Config } from '../config';
import type { Config } from '../config';
import { getIncompatibleCordovaPlugins } from '../cordova';
import { mkdirs } from 'fs-extra';
import type { Plugin } from '../plugin';
import { PluginType, getPluginPlatform } from '../plugin';
import {
convertToUnixPath,
copyAsync,
Expand All @@ -11,8 +15,6 @@ import {
removeAsync,
writeFileAsync,
} from '../util/fs';
import { join, resolve } from 'path';
import { Plugin, PluginType, getPluginPlatform } from '../plugin';

export async function checkAndroidPackage(
config: Config,
Expand All @@ -27,7 +29,7 @@ export function getAndroidPlugins(allPlugins: Plugin[]): Plugin[] {

export function resolvePlugin(plugin: Plugin): Plugin | null {
const platform = 'android';
if (plugin.manifest && plugin.manifest.android) {
if (plugin.manifest?.android) {
let pluginFilesPath = plugin.manifest.android.src
? plugin.manifest.android.src
: platform;
Expand Down Expand Up @@ -62,7 +64,9 @@ export function resolvePlugin(plugin: Plugin): Plugin | null {
* This is a little trickier for Android because the appId becomes
* the package name.
*/
export async function editProjectSettingsAndroid(config: Config) {
export async function editProjectSettingsAndroid(
config: Config,
): Promise<void> {
const appId = config.app.appId;
const appName = config.app.appName;

Expand Down
16 changes: 8 additions & 8 deletions cli/src/android/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { accessSync } from 'fs';
import { join } from 'path';

import c from '../colors';
import { check, logFatal, logSuccess, readXML } from '../common';
import type { Config } from '../config';
import { existsAsync, readFileAsync } from '../util/fs';
import { Config } from '../config';
import { join } from 'path';

export async function doctorAndroid(config: Config) {
export async function doctorAndroid(config: Config): Promise<void> {
try {
await check(config, [checkAndroidInstalled, checkGradlew, checkAppSrcDirs]);
logSuccess('Android looking great! 👌');
} catch (e) {
logFatal(e.stack ?? e);
}
return Promise.resolve();
}

async function checkAppSrcDirs(config: Config) {
Expand Down Expand Up @@ -186,13 +186,13 @@ async function checkPackage(
let checkPath = appSrcMainJavaDir;
const packageParts = packageId.split('.');

for (var i = 0; i < packageParts.length; i++) {
for (const packagePart of packageParts) {
try {
accessSync(join(checkPath, packageParts[i]));
checkPath = join(checkPath, packageParts[i]);
accessSync(join(checkPath, packagePart));
checkPath = join(checkPath, packagePart);
} catch (e) {
return (
`${c.strong(packageParts[i])} is missing in ${checkPath}.\n` +
`${c.strong(packagePart)} is missing in ${checkPath}.\n` +
`Please create a directory structure matching the Package ID ${c.input(
packageId,
)} within the ${appSrcMainJavaDir} directory.`
Expand Down
20 changes: 12 additions & 8 deletions cli/src/android/open.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Config } from '../config';
import { OS } from '../definitions';
import { runCommand } from '../common';
import { existsSync } from '../util/fs';
import open from 'open';

import { runCommand } from '../common';
import type { Config } from '../config';
import { OS } from '../definitions';
import { logger } from '../log';
import { existsSync } from '../util/fs';

export async function openAndroid(config: Config) {
export async function openAndroid(config: Config): Promise<void> {
logger.info(`Opening Android project at ${config.android.platformDir}.`);

const dir = config.android.platformDir;

switch (config.cli.os) {
case OS.Mac:
case OS.Mac: {
await open(dir, { app: 'android studio', wait: false });
break;
case OS.Windows:
}
case OS.Windows: {
let androidStudioPath = config.windows.androidStudioPath;
try {
if (!existsSync(androidStudioPath)) {
Expand Down Expand Up @@ -44,7 +46,8 @@ export async function openAndroid(config: Config) {
);
}
break;
case OS.Linux:
}
case OS.Linux: {
const linuxError = () => {
logger.error(
'Unable to launch Android Studio.\n' +
Expand All @@ -62,5 +65,6 @@ export async function openAndroid(config: Config) {
linuxError();
}
break;
}
}
}
50 changes: 26 additions & 24 deletions cli/src/android/update.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import { join, relative, resolve } from 'path';

import c from '../colors';
import { Config } from '../config';
import {
checkPlatformVersions,
logFatal,
resolveNode,
runTask,
} from '../common';
import { getAndroidPlugins } from './common';
import type { Config } from '../config';
import {
checkPluginDependencies,
handleCordovaPluginsJS,
writeCordovaAndroidManifest,
} from '../cordova';
import type { Plugin } from '../plugin';
import {
convertToUnixPath,
copySync,
existsSync,
readFileAsync,
removeSync,
writeFileAsync,
} from '../util/fs';
import { join, relative, resolve } from 'path';
import {
Plugin,
PluginType,
getAllElements,
getFilePath,
Expand All @@ -32,11 +24,21 @@ import {
getPlugins,
printPlugins,
} from '../plugin';
import {
convertToUnixPath,
copySync,
existsSync,
readFileAsync,
removeSync,
writeFileAsync,
} from '../util/fs';

import { getAndroidPlugins } from './common';

const platform = 'android';

export async function updateAndroid(config: Config) {
let plugins = await getPluginsTask(config);
export async function updateAndroid(config: Config): Promise<void> {
const plugins = await getPluginsTask(config);

const capacitorPlugins = plugins.filter(
p => getPluginType(p, platform) === PluginType.Core,
Expand Down Expand Up @@ -72,7 +74,7 @@ export async function installGradlePlugins(
config: Config,
capacitorPlugins: Plugin[],
cordovaPlugins: Plugin[],
) {
): Promise<void> {
const capacitorAndroidPath = resolveNode(
config,
'@capacitor/android',
Expand Down Expand Up @@ -107,9 +109,9 @@ project(':${getGradlePackageName(
})
.join('')}`;

let applyArray: Array<any> = [];
let frameworksArray: Array<any> = [];
let prefsArray: Array<any> = [];
const applyArray: any[] = [];
const frameworksArray: any[] = [];
let prefsArray: any[] = [];
cordovaPlugins.map(p => {
const relativePluginPath = convertToUnixPath(
relative(dependencyPath, p.rootPath),
Expand Down Expand Up @@ -175,16 +177,16 @@ if (hasProperty('postBuildExtras')) {
export async function handleCordovaPluginsGradle(
config: Config,
cordovaPlugins: Plugin[],
) {
): Promise<void> {
const pluginsFolder = resolve(
config.app.rootDir,
'android',
config.android.assets.pluginsFolderName,
);
const pluginsGradlePath = join(pluginsFolder, 'build.gradle');
let frameworksArray: Array<any> = [];
let prefsArray: Array<any> = [];
let applyArray: Array<any> = [];
const frameworksArray: any[] = [];
let prefsArray: any[] = [];
const applyArray: any[] = [];
applyArray.push(`apply from: "cordova.variables.gradle"`);
cordovaPlugins.map(p => {
const relativePluginPath = convertToUnixPath(
Expand Down Expand Up @@ -217,7 +219,7 @@ export async function handleCordovaPluginsGradle(
prefsArray,
frameworkString,
);
let applyString = applyArray.join('\n');
const applyString = applyArray.join('\n');
let buildGradle = await readFileAsync(pluginsGradlePath, 'utf8');
buildGradle = buildGradle.replace(
/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/,
Expand Down Expand Up @@ -315,7 +317,7 @@ async function getPluginsTask(config: Config) {

async function replaceFrameworkVariables(
config: Config,
prefsArray: Array<any>,
prefsArray: any[],
frameworkString: string,
) {
const variablesFile = resolve(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors } from '@ionic/cli-framework-output';
import type { Colors } from '@ionic/cli-framework-output';
import kleur from 'kleur';

export const strong = kleur.bold;
Expand Down
Loading

0 comments on commit d7bf775

Please sign in to comment.