Skip to content

Commit

Permalink
1.63 (#99)
Browse files Browse the repository at this point in the history
* fix: logging filter

* fix: Update peer dependencies when migrating Angular or Capacitor

* fix: questions on peer check

* feat: gradle flavors

* feat: support android flavors

* chore: bump version
  • Loading branch information
dtarnawsky authored Dec 11, 2023
1 parent cb98244 commit 38c5217
Show file tree
Hide file tree
Showing 20 changed files with 277 additions and 102 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### Version 1.63

- Fix peer dependencies when migrating Angular or Capacitor
- Support for Android Flavors

### Version 1.62

- Fix task queueing issue when a dialog is left to timeout
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ionic",
"displayName": "Ionic",
"description": "Official extension for Ionic and Capacitor development",
"version": "1.62.0",
"version": "1.63.0",
"icon": "media/ionic.png",
"publisher": "Ionic",
"keywords": [
Expand Down
6 changes: 5 additions & 1 deletion src/capacitor-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ async function verifySettings(
return undefined;
}
if (selection == 'Open Android Studio') {
await runWithProgress(capacitorOpen(project, platform), 'Opening Android Studio...', project.projectFolder());
await runWithProgress(
await capacitorOpen(project, platform),
'Opening Android Studio...',
project.projectFolder(),
);
return undefined;
}
const path = await window.showOpenDialog({
Expand Down
9 changes: 5 additions & 4 deletions src/capacitor-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path';
import { exists, isLess, isVersionGreaterOrEqual } from './analyzer';
import { clearOutput, showOutput, write, writeError, writeIonic, writeWarning } from './logging';
import { npmInstall, npmUninstall, npmUpdate } from './node-commands';
import { Project } from './project';
import { inspectProject, Project } from './project';
import { getRunOutput, getStringFrom, plural, pluralize, run, setAllStringIn, showProgress } from './utilities';
import { capacitorSync } from './capacitor-sync';
import { ActionResult } from './command-name';
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function migrateCapacitor5(
if (res === openStudio) {
await run(
project.folder,
capacitorOpen(project, CapacitorPlatform.android),
await capacitorOpen(project, CapacitorPlatform.android),
undefined,
[],
undefined,
Expand Down Expand Up @@ -68,7 +68,8 @@ export async function migrateCapacitor5(
queueFunction();
let report: PeerReport;
await showProgress(`Checking plugins in your project...`, async () => {
report = await checkPeerDependencies(project.folder, '@capacitor/core', versionFull);
await inspectProject(ionicState.rootFolder, ionicState.context, undefined);
report = await checkPeerDependencies(project.folder, [{ name: '@capacitor/core', version: versionFull }], []);
});

// Set of minimum versions for dependencies
Expand Down Expand Up @@ -417,7 +418,7 @@ export async function migrateCapacitor(
}

// Ran Cap Sync
await project.run2(capacitorSync(project), true);
await project.run2(await capacitorSync(project), true);

writeIonic('Capacitor 4 Migration Completed.');

Expand Down
4 changes: 2 additions & 2 deletions src/capacitor-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { join } from 'path';
* @param {CapacitorPlatform} platform ios or android
* @returns string
*/
export function capacitorOpen(project: Project, platform: CapacitorPlatform): string {
export async function capacitorOpen(project: Project, platform: CapacitorPlatform): Promise<string> {
const ionicCLI = useIonicCLI();

if (platform == CapacitorPlatform.android) {
Expand Down Expand Up @@ -68,7 +68,7 @@ function checkAndroidStudioJDK(folder: string): void {
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>`
</project>`,
);
}
}
Expand Down
53 changes: 42 additions & 11 deletions src/capacitor-run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { existsSync } from 'fs';

import { exists, isLess } from './analyzer';
import { getConfigurationArgs } from './build-configuration';
import { CapacitorPlatform } from './capacitor-platform';
Expand All @@ -11,16 +10,18 @@ import { certPath, liveReloadSSL } from './live-reload';
import { MonoRepoType } from './monorepo';
import { npx, PackageManager, preflightNPMCheck } from './node-commands';
import { Project } from './project';
import { gradleToJson } from './gradle-to-json';
import { ExtensionSetting, getExtSetting, getSetting, WorkspaceSetting } from './workspace-state';
import { workspace } from 'vscode';
import { window, workspace } from 'vscode';
import { join } from 'path';

/**
* Creates the command line to run for Capacitor
* @param {CapacitorPlatform} platform
* @param {Project} project
* @returns string
*/
export function capacitorRun(project: Project, platform: CapacitorPlatform): string {
export async function capacitorRun(project: Project, platform: CapacitorPlatform): Promise<string> {
let preop = '';
let rebuilt = false;
let noSync = false;
Expand All @@ -46,7 +47,7 @@ export function capacitorRun(project: Project, platform: CapacitorPlatform): str
case MonoRepoType.yarn:
case MonoRepoType.lerna:
case MonoRepoType.npm:
return preop + capRun(platform, project.repoType, rebuilt, noSync, project);
return preop + (await capRun(platform, project.repoType, rebuilt, noSync, project));
case MonoRepoType.nx:
return preop + nxRun(platform, project.repoType, rebuilt, noSync, project);
default:
Expand All @@ -66,13 +67,13 @@ export function useIonicCLI(): boolean {
return exists('@ionic/cli');
}

function capRun(
async function capRun(
platform: CapacitorPlatform,
repoType: MonoRepoType,
noBuild: boolean,
noSync: boolean,
project: Project
): string {
project: Project,
): Promise<string> {
let liveReload = getSetting(WorkspaceSetting.liveReload);
const externalIP = !getExtSetting(ExtensionSetting.internalAddress);
const httpsForWeb = getSetting(WorkspaceSetting.httpsForWeb);
Expand Down Expand Up @@ -120,6 +121,10 @@ function capRun(

capRunFlags += getConfigurationArgs();

const flavors = await getFlavors(platform, project);
if (flavors == undefined) return;
capRunFlags += flavors;

capRunFlags += InternalCommand.publicHost;
if (httpsForWeb) {
if (capRunFlags.length >= 0) capRunFlags += ' ';
Expand Down Expand Up @@ -147,18 +152,44 @@ function capRun(
} ${capRunFlags}`;
}

function nxRun(
async function nxRun(
platform: CapacitorPlatform,
repoType: MonoRepoType,
noBuild: boolean,
noSync: boolean,
project: Project
): string {
project: Project,
): Promise<string> {
if (project.monoRepo?.isNXStandalone) {
return capRun(platform, repoType, noBuild, noSync, project);
return await capRun(platform, repoType, noBuild, noSync, project);
}
// Note: This may change, see: https://github.com/nxtend-team/nxtend/issues/490
return `${npx(project.packageManager)} nx run ${project.monoRepo.name}:cap --cmd "run ${platform} --target=${
InternalCommand.target
}"`;
}

async function getFlavors(platform: CapacitorPlatform, prj: Project): Promise<string | undefined> {
if (platform == CapacitorPlatform.ios) {
return '';
}

if (ionicState.flavors == undefined) {
ionicState.flavors = [];
const buildGradle = join(prj.projectFolder(), 'android', 'app', 'build.gradle');
const data = gradleToJson(buildGradle);
if (data?.android?.productFlavors) {
const list = Object.keys(data.android.productFlavors);
if (list?.length == 0) {
return '';
}
ionicState.flavors = list;
}
}
if (ionicState.flavors.length == 0) {
return '';
}

const selection = await window.showQuickPick(ionicState.flavors, { placeHolder: 'Select the Android Flavor to run' });
if (!selection) return undefined;
return ` --flavor=${selection}`;
}
2 changes: 1 addition & 1 deletion src/capacitor-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useIonicCLI } from './capacitor-run';
* @param {Project} project
* @returns string
*/
export function capacitorSync(project: Project): string {
export async function capacitorSync(project: Project): Promise<string> {
const preop = preflightNPMCheck(project);

const ionicCLI = useIonicCLI();
Expand Down
14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function fixIssue(
ionicProvider?: IonicTreeProvider,
tip?: Tip,
successMessage?: string,
title?: string
title?: string,
) {
const hasRunPoints = tip && tip.runPoints && tip.runPoints.length > 0;

Expand Down Expand Up @@ -156,7 +156,7 @@ export async function fixIssue(
ionicProvider,
undefined,
undefined,
tip.data
tip.data,
);
} catch (err) {
retry = false;
Expand All @@ -169,7 +169,7 @@ export async function fixIssue(
}
}
return true;
}
},
);
if (ionicProvider) {
ionicProvider.refresh();
Expand Down Expand Up @@ -216,7 +216,7 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(
window.registerWebviewViewProvider('ionic-devserver', ionicDevServerProvider, {
webviewOptions: { retainContextWhenHidden: false },
})
}),
);

ionicState.view = view;
Expand Down Expand Up @@ -436,7 +436,7 @@ async function runAction(tip: Tip, ionicProvider: IonicTreeProvider, rootPath: s
markActionAsRunning(tip);
ionicProvider.refresh();
}
tip.generateCommand();
await tip.generateCommand();
tip.generateTitle();
if (tip.command) {
let command = tip.command;
Expand Down Expand Up @@ -477,12 +477,12 @@ async function fix(
tip: Tip,
rootPath: string,
ionicProvider: IonicTreeProvider,
context: ExtensionContext
context: ExtensionContext,
): Promise<void> {
if (await waitForOtherActions(tip)) {
return; // Canceled
}
tip.generateCommand();
await tip.generateCommand();
tip.generateTitle();
if (tip.command) {
const urlBtn = tip.url ? 'Info' : undefined;
Expand Down
37 changes: 37 additions & 0 deletions src/gradle-to-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { existsSync, readFileSync } from 'fs';
import { replaceAll } from './utilities';

export function gradleToJson(filename: string): any | undefined {
if (!existsSync(filename)) {
return undefined;
}
try {
const lines = readFileSync(filename, 'utf8').split('\n');
const result = {};
let at = result;
const stack = [at];
for (const line of lines) {
if (line.trim().endsWith('{')) {
const key = replaceAll(line, '{', '').trim();
at[key] = {};
stack.push(at);
at = at[key];
} else if (line.trim().endsWith('}')) {
at = stack.pop();
} else if (line.trim() !== '') {
const kv = line.trim().split(' ');
if (kv.length == 2) {
at[kv[0]] = kv[1];
} else {
at[kv[0]] = [];
for (let i = 1; i < kv.length; i++) {
at[kv[0]].push(kv[i]);
}
}
}
}
return result;
} catch {
return undefined;
}
}
8 changes: 6 additions & 2 deletions src/ionic-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { workspace } from 'vscode';
* @param {Project} project
* @returns string
*/
export function ionicBuild(project: Project, configurationArg?: string, platform?: CapacitorPlatform): string {
export async function ionicBuild(
project: Project,
configurationArg?: string,
platform?: CapacitorPlatform,
): Promise<string> {
const preop = preflightNPMCheck(project);

ionicState.projectDirty = false;
Expand Down Expand Up @@ -48,7 +52,7 @@ function ionicCLIBuild(
prod: boolean,
project: Project,
configurationArg?: string,
platform?: CapacitorPlatform
platform?: CapacitorPlatform,
): string {
let cmd = `${npx(project.packageManager)} ionic build`;
if (configurationArg) {
Expand Down
2 changes: 1 addition & 1 deletion src/ionic-serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { window, workspace } from 'vscode';
* Create the ionic serve command
* @returns string
*/
export function ionicServe(project: Project, dontOpenBrowser: boolean): string {
export async function ionicServe(project: Project, dontOpenBrowser: boolean): Promise<string> {
ionicState.lastRun = undefined;
switch (project.repoType) {
case MonoRepoType.none:
Expand Down
2 changes: 2 additions & 0 deletions src/ionic-tree-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface IonicState {
project: string; // Angular project name
nvm: string; // If .nvmrc is used will contain its contents
rootFolder: string; // The folder to inspect
flavors: string[]; // Android Flavors
runIOS: Tip;
runAndroid: Tip;
runWeb: Tip;
Expand Down Expand Up @@ -66,6 +67,7 @@ export const ionicState: IonicState = {
runAndroid: undefined,
runWeb: undefined,
nvm: undefined,
flavors: undefined,
rootFolder: undefined,
lastRun: undefined,
projectRef: undefined,
Expand Down
Loading

0 comments on commit 38c5217

Please sign in to comment.