Skip to content

Commit

Permalink
feat(explorer/build): allow building modules to specific targets (#1000)
Browse files Browse the repository at this point in the history
Co-authored-by: Ewan Harris <ewanharris93@gmail.com>
  • Loading branch information
DzzD and ewanharris authored Apr 27, 2023
1 parent 8eec067 commit 4af0313
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 80 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,18 +768,18 @@
},
{
"command": "titanium.build.run",
"when": "view == titanium.view.buildExplorer && viewItem =~ /DeviceNode|ModuleBuildNode/",
"when": "view == titanium.view.buildExplorer && viewItem =~ /PlatformNode|TargetNode|OSVerNode|DeviceNode|ModuleBuildNode/",
"group": "inline"
},
{
"command": "titanium.build.run",
"when": "view == titanium.view.buildExplorer && viewItem =~ /PlatformNode|TargetNode|OSVerNode|DeviceNode|ModuleBuildNode/"
},
{
"command": "titanium.build.debug",
"when": "view == titanium.view.buildExplorer && viewItem == DeviceNode",
"group": "inline"
},
{
"command": "titanium.build.run",
"when": "view == titanium.view.buildExplorer && viewItem =~ /PlatformNode|TargetNode|OSVerNode|DeviceNode|ModuleBuildNode/"
},
{
"command": "titanium.build.debug",
"when": "view == titanium.view.buildExplorer && viewItem == DeviceNode"
Expand Down
16 changes: 14 additions & 2 deletions src/commands/buildModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { handleInteractionError, InteractionError } from './common';

import { promptForWorkspaceFolder, selectPlatform } from '../quickpicks/common';
import { getBuildTask } from '../tasks/tasksHelper';
import { BuildTask } from '../tasks/buildTaskProvider';
import { ModuleBuildTask } from '../tasks/buildTaskProvider';
import { Platform } from '../types/common';

export async function buildModule (node?: DeviceNode | OSVerNode | PlatformNode | TargetNode, folder?: vscode.WorkspaceFolder): Promise<void> {
Expand All @@ -15,7 +15,7 @@ export async function buildModule (node?: DeviceNode | OSVerNode | PlatformNode
}
const platform = node?.platform as Platform || (await selectPlatform()).id as Platform;

const taskDefinition: BuildTask = {
const taskDefinition: ModuleBuildTask = {
definition: {
titaniumBuild: {
projectType: 'module',
Expand All @@ -34,6 +34,18 @@ export async function buildModule (node?: DeviceNode | OSVerNode | PlatformNode
scope: vscode.TaskScope.Workspace
};

if (node?.targetId) {
taskDefinition.definition.titaniumBuild.target = node.targetId as 'device' | 'emulator' | 'simulator';
}

if (node?.version) {
taskDefinition.definition.titaniumBuild.ios = { simulatorVersion: node.version };
}

if (node?.deviceId) {
taskDefinition.definition.titaniumBuild.deviceId = node.deviceId;
}

const task = await getBuildTask(taskDefinition);
await vscode.tasks.executeTask(task);
} catch (error) {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/generateTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import { enterAndroidKeystoreInfo, promptForWorkspaceFolder, selectiOSCertificat
import { TitaniumTaskDefinitionBase } from '../tasks/commandTaskProvider';
import { nameForPlatform, nameForTarget } from '../utils';
import { DeviceNode, DistributeNode } from '../explorer/nodes';
import { AppBuildTaskDefinitionBase } from '../tasks/buildTaskProvider';
import { AppBuildTaskDefinitionBase, ModuleBuildTaskDefinitionBase } from '../tasks/buildTaskProvider';
import { AppPackageTaskDefinitionBase } from '../tasks/packageTaskProvider';
import { ProjectType } from '../types/common';

function isAppBuild (type: ProjectType, task: Partial<TitaniumTaskDefinitionBase>): task is AppBuildTaskDefinitionBase {
return type === 'app';
}

function isModuleBuild (type: ProjectType, task: Partial<TitaniumTaskDefinitionBase>): task is ModuleBuildTaskDefinitionBase {
return type === 'module';
}

function isAppPackage (type: ProjectType, task: Partial<TitaniumTaskDefinitionBase>): task is AppPackageTaskDefinitionBase {
return type === 'app';
}
Expand Down Expand Up @@ -46,7 +50,7 @@ export async function generateTask (node: DeviceNode|DistributeNode): Promise<vo
}
};

if (node instanceof DeviceNode && isAppBuild(type, task)) {
if (node instanceof DeviceNode && (isAppBuild(type, task) || isModuleBuild(type, task))) {
task.type = 'titanium-build';
task.titaniumBuild.deviceId = node.deviceId;
task.titaniumBuild.target = node.targetId;
Expand Down
14 changes: 7 additions & 7 deletions src/explorer/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './nodes/baseNode';
export * from './nodes/blankNode';
export * from './nodes/commandNode';
export * from './nodes/deviceNode';
export * from './nodes/distributeNode';
export * from './nodes/osVerNode';
export * from './nodes/platformNode';
export * from './nodes/targetNode';
export * from './nodes/updateNode';
export * from './nodes/updatesNode';
export * from './nodes/build/deviceNode';
export * from './nodes/build/distributeNode';
export * from './nodes/build/osVerNode';
export * from './nodes/build/platformNode';
export * from './nodes/build/targetNode';
export * from './nodes/updates/updateNode';
export * from './nodes/updates/updatesNode';
export * from './nodes/urlNode';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';

import { TreeItemCollapsibleState } from 'vscode';
import { Platform } from '../../types/common';
import { DevelopmentTarget } from '../../types/cli';
import { Platform, ProjectType } from '../../../types/common';
import { DevelopmentTarget } from '../../../types/cli';

export class DeviceNode extends BaseNode {

Expand All @@ -15,9 +15,14 @@ export class DeviceNode extends BaseNode {
public readonly target: string,
public override readonly deviceId: string,
public override readonly targetId: DevelopmentTarget,
public override readonly version?: string
public override readonly version?: string,
public readonly projectType?: ProjectType
) {
super(label);

if (projectType === 'module') {
this.contextValue = 'ModuleDeviceNode';
}
}

get tooltip (): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';

import { TreeItemCollapsibleState } from 'vscode';
import { Platform } from '../../types/common';
import { DeploymentTarget } from '../../types/cli';
import { Platform } from '../../../types/common';
import { DeploymentTarget } from '../../../types/cli';

export class DistributeNode extends BaseNode {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../../baseNode';

import { TreeItemCollapsibleState } from 'vscode';
import { Platform } from '../../types/common';
import { } from '../../types/cli';
import { Platform } from '../../../../types/common';
import { } from '../../../../types/cli';

export class ModuleBuildNode extends BaseNode {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../../baseNode';

import { TreeItemCollapsibleState } from 'vscode';
import { Platform } from '../../types/common';
import { } from '../../types/cli';
import { Platform } from '../../../../types/common';
import { } from '../../../../types/cli';

export class ModulePackageNode extends BaseNode {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TreeItemCollapsibleState } from 'vscode';
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';
import { DeviceNode } from './deviceNode';

import { Platform } from '../../types/common';
import { targetForName } from '../../utils';
import { DevelopmentTarget, PrettyDevelopmentTarget } from '../../types/cli';
import { ExtensionContainer } from '../../container';
import { Platform, ProjectType } from '../../../types/common';
import { targetForName } from '../../../utils';
import { DevelopmentTarget, PrettyDevelopmentTarget } from '../../../types/cli';
import { ExtensionContainer } from '../../../container';

export class OSVerNode extends BaseNode {

Expand All @@ -17,7 +17,8 @@ export class OSVerNode extends BaseNode {
constructor (
public override readonly label: string,
public readonly platform: Platform,
public readonly target: PrettyDevelopmentTarget
public readonly target: PrettyDevelopmentTarget,
public readonly projectType?: ProjectType
) {
super(label);
this.version = label;
Expand All @@ -29,7 +30,7 @@ export class OSVerNode extends BaseNode {
if (this.platform === 'ios') {
const sims = ExtensionContainer.environment.iOSSimulators();
for (const sim of sims[this.version]) {
simulators.push(new DeviceNode(sim.name, this.platform, this.targetId, sim.udid, this.targetId, this.version));
simulators.push(new DeviceNode(sim.name, this.platform, this.targetId, sim.udid, this.targetId, this.version, this.projectType));
}
}
return simulators;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { BaseNode } from './baseNode';
import * as semver from 'semver';
import { BaseNode } from '../baseNode';
import { TargetNode } from './targetNode';
import { DistributeNode } from './distributeNode';
import { ModuleBuildNode } from './moduleBuildNode';
import { ModulePackageNode } from './modulePackageNode';
import { ModuleBuildNode } from '../build/module/moduleBuildNode';
import { ModulePackageNode } from '../build/module/modulePackageNode';

import { TreeItemCollapsibleState } from 'vscode';
import { Platform, PlatformPretty } from '../../types/common';
import { nameForPlatform } from '../../utils';
import { ExtensionContainer } from '../../container';
import { Platform, PlatformPretty } from '../../../types/common';
import { nameForPlatform } from '../../../utils';
import { ExtensionContainer } from '../../../container';

export class PlatformNode extends BaseNode {

Expand All @@ -20,19 +21,51 @@ export class PlatformNode extends BaseNode {
super(platform);
this.label = nameForPlatform(platform);
this.platform = platform;
this.contextValue = 'PlatformNode';
}

public override getChildren (): Array<DistributeNode|TargetNode>|Array<ModuleBuildNode|ModulePackageNode> {
public override getChildren (): Array<DistributeNode|TargetNode>|Array<ModuleBuildNode|ModulePackageNode|TargetNode> {
// Detect the first project to see whether we show the full explorer or a limited explorer
const project = Array.from(ExtensionContainer.projects.values())[0];
if (project.type === 'module') {
return this.getModuleChildrenNodes();
} else {
return this.getAppChildrenNodes();
}
}

get tooltip (): string {
return this.label;
}

private getModuleChildrenNodes() {
const selectedSDK = ExtensionContainer.environment.selectedSdk();

if (selectedSDK && semver.gte(selectedSDK.version, '12.1.0')) {
switch (this.platform) {
case 'android':
return [
new ModulePackageNode('Package', this.platform, this.label),
new TargetNode('Device', this.platform, 'module'),
new TargetNode('Emulator', this.platform, 'module'),
];
case 'ios':
return [
new ModulePackageNode('Package', this.platform, this.label),
new TargetNode('Device', this.platform, 'module'),
new TargetNode('Simulator', this.platform, 'module'),
];
default:
return [];
}
} else {
return [
new ModuleBuildNode('Build', this.platform, this.label),
new ModulePackageNode('Package', this.platform, this.label)
];
}
}

private getAppChildrenNodes() {
switch (this.platform) {
case 'android':
return [
Expand All @@ -52,8 +85,4 @@ export class PlatformNode extends BaseNode {
return [];
}
}

get tooltip (): string {
return this.label;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';

import { TreeItemCollapsibleState } from 'vscode';
import { ExtensionContainer } from '../../container';
import { ExtensionContainer } from '../../../container';
import { DeviceNode } from './deviceNode';
import { getDeviceNameFromId, nameForPlatform, nameForTarget } from '../../utils';
import { Platform as NewPlatform } from '../../types/common';
import { BlankNode } from './blankNode';
import { isDistributionAppBuild } from '../../tasks/tasksHelper';
import { GlobalState } from '../../constants';
import { getDeviceNameFromId, nameForPlatform, nameForTarget } from '../../../utils';
import { Platform as NewPlatform } from '../../../types/common';
import { BlankNode } from '../blankNode';
import { isDistributionAppBuild } from '../../../tasks/tasksHelper';
import { GlobalState } from '../../../constants';
import { DistributeNode } from './distributeNode';

export class RecentNode extends BaseNode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TreeItemCollapsibleState } from 'vscode';
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';
import { DeviceNode } from './deviceNode';
import { DistributeNode } from './distributeNode';
import { OSVerNode } from './osVerNode';

import { Platform } from '../../types/common';
import { targetForName } from '../../utils';
import { DevelopmentTarget, PrettyDevelopmentTarget } from '../../types/cli';
import { BlankNode } from '../nodes';
import { ExtensionContainer } from '../../container';
import { GlobalState } from '../../constants';
import { Platform, ProjectType } from '../../../types/common';
import { targetForName } from '../../../utils';
import { DevelopmentTarget, PrettyDevelopmentTarget } from '../../../types/cli';
import { BlankNode } from '../../nodes';
import { ExtensionContainer } from '../../../container';
import { GlobalState } from '../../../constants';

export class TargetNode extends BaseNode {

Expand All @@ -19,7 +19,8 @@ export class TargetNode extends BaseNode {

constructor (
public override readonly label: PrettyDevelopmentTarget,
public readonly platform: Platform
public readonly platform: Platform,
public readonly projectType?: ProjectType
) {
super(label);
this.targetId = targetForName(this.label) as DevelopmentTarget;
Expand All @@ -39,7 +40,7 @@ export class TargetNode extends BaseNode {
switch (this.label) {
case 'Simulator':
for (const simVer of ExtensionContainer.environment.iOSSimulatorVersions()) {
devices.push(new OSVerNode(simVer, this.platform, this.label));
devices.push(new OSVerNode(simVer, this.platform, this.label, this.projectType));
}
break;
case 'Device':
Expand All @@ -48,7 +49,7 @@ export class TargetNode extends BaseNode {
if (device.productVersion) {
label = `${label} (${device.productVersion})`;
}
devices.push(new DeviceNode(label, this.platform, this.label, device.udid, this.targetId));
devices.push(new DeviceNode(label, this.platform, this.label, device.udid, this.targetId, undefined, this.projectType));
}
break;
case 'Package' as PrettyDevelopmentTarget:
Expand All @@ -60,7 +61,7 @@ export class TargetNode extends BaseNode {
switch (this.label) {
case 'Device':
for (const device of ExtensionContainer.environment.androidDevices()) {
devices.push(new DeviceNode(device.name, this.platform, this.label, device.id, this.targetId));
devices.push(new DeviceNode(device.name, this.platform, this.label, device.id, this.targetId, undefined, this.projectType));
}
break;
case 'Emulator':
Expand All @@ -70,7 +71,7 @@ export class TargetNode extends BaseNode {
if (type === 'Genymotion') {
label = `${label} (Genymotion)`;
}
devices.push(new DeviceNode(label, this.platform, this.label, emulator.id, this.targetId));
devices.push(new DeviceNode(label, this.platform, this.label, emulator.id, this.targetId, undefined, this.projectType));
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseNode } from './baseNode';
import { BaseNode } from '../baseNode';

import { UpdateInfo } from 'titanium-editor-commons/updates';
import { TreeItemCollapsibleState } from 'vscode';
Expand Down
Loading

0 comments on commit 4af0313

Please sign in to comment.