Skip to content

Commit

Permalink
Extended readme
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Nov 12, 2023
1 parent 18005fd commit 05e5735
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 69 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ When the extension detects a Piral instance or pilet folder opened it automatica

![Scaffold Pilet](./docs/workspace.png)

### Tasks

You can add provided tasks for your Piral instances or pilets.

- `piral: debug` - a build (watch) task to debug the Piral instance
- `piral: build` - a build task to build the Piral instance
- `piral: validate` - a test task to validate the Piral instance
- `piral: declaration` - a build task to generate the declaration for the Piral instance
- `pilet: debug` - a build (watch) task to debug the pilet
- `pilet: build` - a build task to build the pilet
- `pilet: validate` - a test task to validate the pilet
- `pilet: pack` - a build task to pack the pilet

You can either run these tasks manually or use them, e.g., in a *launch.json*:

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:1234",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "pilet: debug"
}
]
}
```

### Problem Matcher

If you make your own task using the `piral-cli` you can use the `$piral-cli-debug` problem matcher to monitor the `piral debug` / `pilet debug` commands.

### Command Palette

All commands that are relevant to Piral can be run from the command palette.
Expand Down
2 changes: 1 addition & 1 deletion src/extension/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function debugPilet() {
}

function buildPilet() {
runCommand('npx pilet build', RepoType.Pilet);
runCommand('npx pilet build', RepoType.Pilet);
}

function publishPilet() {
Expand Down
9 changes: 6 additions & 3 deletions src/extension/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export function readJson(filePath: string) {
}
}

export function getRepoType(): RepoType {
const workspaceFolder = getWorkspaceRoot();

export function getRepoTypeOf(workspaceFolder: vscode.WorkspaceFolder | undefined) {
if (workspaceFolder !== undefined) {
const packageJson = readJson(resolve(workspaceFolder.uri.fsPath, 'package.json'));
const piralJson = readJson(resolve(workspaceFolder.uri.fsPath, 'piral.json'));
Expand All @@ -43,6 +41,11 @@ export function getRepoType(): RepoType {
return RepoType.Undefined;
}

export function getRepoType(): RepoType {
const workspaceFolder = getWorkspaceRoot();
return getRepoTypeOf(workspaceFolder);
}

export function getWorkspaceRoot() {
return vscode.workspace.workspaceFolders?.[0];
}
Expand Down
3 changes: 2 additions & 1 deletion src/extension/providers/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class CommandTreeItem extends vscode.TreeItem {
label,
children === undefined ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Expanded,
);
this.contextValue = target !== undefined ? target != '' ? 'showFullContextPlugin' : 'showWebLinkContextPlugin' : undefined;
this.contextValue =
target !== undefined ? (target != '' ? 'showFullContextPlugin' : 'showWebLinkContextPlugin') : undefined;
this.children = children;
this.commandName = commandName;
this.target = target;
Expand Down
113 changes: 81 additions & 32 deletions src/extension/providers/piletTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { RepoType, getRepoTypeOf, getWorkspaceRoot } from '../helpers';

export class PiletTaskProvider implements vscode.TaskProvider {
static Type = 'pilet';
Expand All @@ -14,18 +15,7 @@ export class PiletTaskProvider implements vscode.TaskProvider {
}

public resolveTask(_task: vscode.Task): vscode.Task | undefined {
const flags = _task.definition.flags || [];
const command = ['npx', 'pilet', 'debug', ...flags].join(' ');
const definition = _task.definition;

return new vscode.Task(
definition,
_task.scope ?? vscode.TaskScope.Workspace,
'debug',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
['$piral-cli-debug'],
);
return undefined;
}
}

Expand All @@ -36,29 +26,88 @@ interface PiletTaskDefinition extends vscode.TaskDefinition {
flags?: Array<string>;
}

function createDebugTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiletTaskDefinition = {
type: PiletTaskProvider.Type,
flags: [],
};
const command = ['npx', 'pilet', 'debug', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'debug',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
['$piral-cli-debug'],
);
task.isBackground = true;
task.group = vscode.TaskGroup.Build;
return task;
}

function createBuildTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiletTaskDefinition = {
type: PiletTaskProvider.Type,
flags: [],
};
const command = ['npx', 'pilet', 'build', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'build',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
);
task.group = vscode.TaskGroup.Build;
return task;
}

function createValidateTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiletTaskDefinition = {
type: PiletTaskProvider.Type,
flags: [],
};
const command = ['npx', 'pilet', 'validate', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'validate',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
);
task.group = vscode.TaskGroup.Test;
return task;
}

function createPackTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiletTaskDefinition = {
type: PiletTaskProvider.Type,
flags: [],
};
const command = ['npx', 'pilet', 'pack', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'pack',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
);
task.group = vscode.TaskGroup.Build;
return task;
}

async function getPiletTasks(): Promise<vscode.Task[]> {
const workspaceFolders = vscode.workspace.workspaceFolders;
const workspaceFolder = getWorkspaceRoot();
const repoType = getRepoTypeOf(workspaceFolder);
const result: vscode.Task[] = [];

if (workspaceFolders?.length) {
for (const workspaceFolder of workspaceFolders) {
const kind: PiletTaskDefinition = {
type: PiletTaskProvider.Type,
flags: [],
};
const command = ['npx', 'pilet', 'debug', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'debug',
PiletTaskProvider.Type,
new vscode.ShellExecution(command),
['$piral-cli-debug'],
);
task.isBackground = true;
task.group = vscode.TaskGroup.Build;
result.push(task);
}
if (workspaceFolder && repoType === RepoType.Pilet) {
result.push(
createDebugTask(workspaceFolder),
createBuildTask(workspaceFolder),
createValidateTask(workspaceFolder),
createPackTask(workspaceFolder),
);
}

return result;
Expand Down
90 changes: 58 additions & 32 deletions src/extension/providers/piralTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { RepoType, getRepoTypeOf, getWorkspaceRoot } from '../helpers';

export class PiralTaskProvider implements vscode.TaskProvider {
static Type = 'piral';
Expand All @@ -14,18 +15,7 @@ export class PiralTaskProvider implements vscode.TaskProvider {
}

public resolveTask(_task: vscode.Task): vscode.Task | undefined {
const flags = _task.definition.flags || [];
const command = ['npx', 'piral', 'debug', ...flags].join(' ');
const definition = _task.definition;

return new vscode.Task(
definition,
_task.scope ?? vscode.TaskScope.Workspace,
'debug',
PiralTaskProvider.Type,
new vscode.ShellExecution(command),
['$piral-cli-debug'],
);
return undefined;
}
}

Expand All @@ -36,29 +26,65 @@ interface PiralTaskDefinition extends vscode.TaskDefinition {
flags?: Array<string>;
}

function createDebugTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiralTaskDefinition = {
type: PiralTaskProvider.Type,
flags: [],
};
const command = ['npx', 'piral', 'debug', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(kind, workspaceFolder, 'debug', 'piral', new vscode.ShellExecution(command), [
'$piral-cli-debug',
]);
task.isBackground = true;
task.group = vscode.TaskGroup.Build;
return task;
}

function createBuildTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiralTaskDefinition = {
type: PiralTaskProvider.Type,
flags: [],
};
const command = ['npx', 'piral', 'build', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(kind, workspaceFolder, 'build', 'piral', new vscode.ShellExecution(command));
task.group = vscode.TaskGroup.Build;
return task;
}

function createValidateTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiralTaskDefinition = {
type: PiralTaskProvider.Type,
flags: [],
};
const command = ['npx', 'piral', 'validate', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(kind, workspaceFolder, 'validate', 'piral', new vscode.ShellExecution(command));
task.group = vscode.TaskGroup.Test;
return task;
}

function createDeclarationTask(workspaceFolder: vscode.WorkspaceFolder) {
const kind: PiralTaskDefinition = {
type: PiralTaskProvider.Type,
flags: [],
};
const command = ['npx', 'piral', 'declaration', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(kind, workspaceFolder, 'declaration', 'piral', new vscode.ShellExecution(command));
task.group = vscode.TaskGroup.Build;
return task;
}

async function getPiralTasks(): Promise<vscode.Task[]> {
const workspaceFolders = vscode.workspace.workspaceFolders;
const workspaceFolder = getWorkspaceRoot();
const repoType = getRepoTypeOf(workspaceFolder);
const result: vscode.Task[] = [];

if (workspaceFolders?.length) {
for (const workspaceFolder of workspaceFolders) {
const kind: PiralTaskDefinition = {
type: PiralTaskProvider.Type,
flags: [],
};
const command = ['npx', 'piral', 'debug', ...(kind.flags || [])].join(' ');
const task = new vscode.Task(
kind,
workspaceFolder,
'debug',
'piral',
new vscode.ShellExecution(command),
['$piral-cli-debug'],
);
task.isBackground = true;
task.group = vscode.TaskGroup.Build;
result.push(task);
}
if (workspaceFolder && repoType === RepoType.Piral) {
result.push(
createDebugTask(workspaceFolder),
createBuildTask(workspaceFolder),
createValidateTask(workspaceFolder),
createDeclarationTask(workspaceFolder),
);
}

return result;
Expand Down

0 comments on commit 05e5735

Please sign in to comment.