Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): Support workspace.json for non Angular workspaces #926

Merged
merged 3 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## Contributing to Angular Console
## Contributing to Nx Console

We would love for you to contribute to Angular Console! Read this document to see how to do it.
We would love for you to contribute to Nx Console! Read this document to see how to do it.

## Got a Question?

We are trying to keep GitHub issues for bug reports and feature requests. Stack Overflow is a much better place to ask general questions about how to use Angular Console.
We are trying to keep GitHub issues for bug reports and feature requests. Stack Overflow is a much better place to ask general questions about how to use Nx Console.

## Two Platforms

Angular Console runs on two platforms:
Nx Console runs on two platforms:

- VSCode
- IntelliJ

The two versions of Angular Console share most of the code, but they are bundled differently.
The two versions of Nx Console share most of the code, but they are bundled differently.

## Building the VSCode Plugin

Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# The UI for the Angular CLI

[![Angular Console Website](https://img.shields.io/badge/Angular-Console-blue.png)](https://angularconsole.org/)
[![Nx Console Website](https://img.shields.io/badge/Angular-Console-blue.png)](https://angularconsole.org/)
[![License](https://img.shields.io/npm/l/@nrwl/schematics.png)](https://opensource.org/licenses/MIT)

<hr>
Expand All @@ -15,42 +15,42 @@

Angular CLI transformed the Angular ecosystem. With it, you can get a full-stack application up and running in minutes, no need to figure out source maps, webpack, test runners. It all works out of the box. Angular CLI also helps you enforce consistent development practices by generating components, services, and state management modules.

## Why Angular Console?
## Why Nx Console?

Professional developers use both command-line tools and user interfaces. They commit in the terminal, but resolve conflicts in VSCode or WebStorm. They use the right tool for the job.

Angular CLI is a command-line tool, which works great when you want to serve an application or generate a simple component. But it falls short once you start doing advanced things.

For instance:

- Exploring custom schematic collections is hard in the terminal, but it's easy using Angular Console.
- Using rarely-used flags is challenging. Do you pass absolute or relative paths? You don't have to remember any flags, names, or paths -- Angular Console will help you by providing autocompletion and validating your inputs.
- Finding the right Angular CLI extension can take a long time. When using Angular Console, you can find and install an extension in minutes.
- Exploring custom schematic collections is hard in the terminal, but it's easy using Nx Console.
- Using rarely-used flags is challenging. Do you pass absolute or relative paths? You don't have to remember any flags, names, or paths -- Nx Console will help you by providing autocompletion and validating your inputs.
- Finding the right Angular CLI extension can take a long time. When using Nx Console, you can find and install an extension in minutes.

Angular Console does all that and more!
Nx Console does all that and more!

## Download

For VSCode users, you can install the [Angular Console VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console) from Marketplace.
For VSCode users, you can install the [Nx Console VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console) from Marketplace.

## True UI for the Angular CLI

Angular Console is an UI for the Angular CLI. It will work for any schematic or any architect commands. Angular Console does not have a specific UI for, say, generating a component. Instead, Angular Console does what the command-line version of the Angular CLI does--it analyzes the same meta information to create the needed UI. This means that anything you can do with the Angular CLI, you can do with Angular Console. After all, Angular Console is the UI for the Angular CLI.
Nx Console is an UI for the Angular CLI. It will work for any schematic or any architect commands. Nx Console does not have a specific UI for, say, generating a component. Instead, Nx Console does what the command-line version of the Angular CLI does--it analyzes the same meta information to create the needed UI. This means that anything you can do with the Angular CLI, you can do with Nx Console. After all, Nx Console is the UI for the Angular CLI.

## Useful for Both Experts and Beginners

Even though we started building Angular Console as a tool for expert, we also aimed to make Angular Console a great tool for developers who are new to Angular or Angular CLI. You can create projects, interact with your editor, run generators and commands, install extensions without ever touching the terminal or having to install any node packages globally. If you get a new laptop, you can install Angular Console and start building Angular apps. Also, Angular Console highlights the properties you are likely to use for build-in generators and commands . So if you haven't used the CLI, you don't get overwhelmed.
Even though we started building Nx Console as a tool for expert, we also aimed to make Nx Console a great tool for developers who are new to Angular or Angular CLI. You can create projects, interact with your editor, run generators and commands, install extensions without ever touching the terminal or having to install any node packages globally. If you get a new laptop, you can install Nx Console and start building Angular apps. Also, Nx Console highlights the properties you are likely to use for build-in generators and commands . So if you haven't used the CLI, you don't get overwhelmed.

## Great for Windows Users

A lot of Windows users are terminal shy and cannot take full advantage of tools like the Angular CLI and [Nrwl Nx](http://nrwl.io/nx). By using Angular Console, Windows users can start using the powerful capabilities these tools provide via an easy-to-use UI. They can create new projects, generate components, build, test, deploy Angular apps without having to even open the terminal.
A lot of Windows users are terminal shy and cannot take full advantage of tools like the Angular CLI and [Nrwl Nx](http://nrwl.io/nx). By using Nx Console, Windows users can start using the powerful capabilities these tools provide via an easy-to-use UI. They can create new projects, generate components, build, test, deploy Angular apps without having to even open the terminal.

# Learn More

- [angularconsole.com](http://angularconsole.com) - the official site of the project
- [Watch Angular Console 5-minute overview video by Angular Firebase folks](https://www.youtube.com/watch?time_continue=18&v=d2K2Cp8BJx0)
- [Angular CLI course by John Papa](https://www.pluralsight.com/courses/angular-cli) - the Angular CLI course by John Papa has a video on Angular Console
- [Learn more about the team at Nrwl](https://www.nrwl.io) - The team at Nrwl led the development of Angular Console, after working with many Enterprise clients.
- [Watch Nx Console 5-minute overview video by Angular Firebase folks](https://www.youtube.com/watch?time_continue=18&v=d2K2Cp8BJx0)
- [Angular CLI course by John Papa](https://www.pluralsight.com/courses/angular-cli) - the Angular CLI course by John Papa has a video on Nx Console
- [Learn more about the team at Nrwl](https://www.nrwl.io) - The team at Nrwl led the development of Nx Console, after working with many Enterprise clients.

# Contribute

Expand All @@ -70,7 +70,7 @@ Pick one of the issues from the [good first issue](https://github.com/nrwl/angul
[fk]: https://avatars0.githubusercontent.com/u/17149942?s=150&v=4
[kk]: https://avatars1.githubusercontent.com/u/8167190?s=150&v=4

The following folks from the Angular team at Google are working with the Angular Console team.
The following folks from the Angular team at Google are working with the Nx Console team.

| Alex Eagle | Stephen Fluin | Matias Niemelä |
| ----------------- | -------------------- | --------------------- |
Expand Down
2 changes: 1 addition & 1 deletion apps/vscode-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NgModule } from '@angular/core';
import {
VscodeUiFeatureTaskExecutionFormModule,
TaskExecutionFormComponent
} from '@angular-console/vscode-ui/feature-task-execution-form';
} from '@nx-console/vscode-ui/feature-task-execution-form';
import { environment } from '../environments/environment';

@NgModule({
Expand Down
2 changes: 1 addition & 1 deletion apps/vscode-ui/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TASK_EXECUTION_SCHEMA } from '@angular-console/vscode-ui/feature-task-execution-form';
import { TASK_EXECUTION_SCHEMA } from '@nx-console/vscode-ui/feature-task-execution-form';

// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
Expand Down
21 changes: 9 additions & 12 deletions apps/vscode/src/app/cli-task/cli-task-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { CliTaskProvider } from './cli-task-provider';
import { CliTaskQuickPickItem } from './cli-task-quick-pick-item';
import { selectFlags } from './select-flags';
import { Option } from '@angular-console/schema';
import { Option } from '@nx-console/schema';
import { OptionType } from '@angular/cli/models/interface';
const CLI_COMMAND_LIST = [
'build',
Expand Down Expand Up @@ -48,14 +48,14 @@ export function registerCliTaskCommands(
});

commands.registerCommand(`ng.generate`, () =>
selectSchematicAndPromptForFlags(n.getWorkspacePath()!)
selectSchematicAndPromptForFlags(n.getWorkspaceJsonPath())
);

commands.registerCommand(`ng.generate.ui`, () =>
selectCliCommandAndShowUi('generate', context.extensionPath)
);
commands.registerCommand(`nx.generate`, () =>
selectSchematicAndPromptForFlags(n.getWorkspacePath()!)
selectSchematicAndPromptForFlags(n.getWorkspaceJsonPath())
);

commands.registerCommand(`nx.generate.ui`, () =>
Expand All @@ -67,7 +67,7 @@ function selectCliCommandAndShowUi(command: string, extensionPath: string) {
const workspacePath = cliTaskProvider.getWorkspacePath();
if (!workspacePath) {
window.showErrorMessage(
'Angular Console requires a workspace be set to perform this action'
'Nx Console requires a workspace be set to perform this action'
);
return;
}
Expand All @@ -78,10 +78,7 @@ function selectCliCommandAndShowUi(command: string, extensionPath: string) {
extensionPath
);

commands.executeCommand(
'angularConsole.revealWebViewPanel',
workspaceTreeItem
);
commands.executeCommand('nxConsole.revealWebViewPanel', workspaceTreeItem);
}

async function selectCliCommandAndPromptForFlags(command: string) {
Expand Down Expand Up @@ -133,16 +130,16 @@ async function selectCliCommandAndPromptForFlags(command: string) {
}
}

async function selectSchematicAndPromptForFlags(workspacePath: string) {
async function selectSchematicAndPromptForFlags(workspaceJsonPath: string) {
const { validWorkspaceJson, workspaceType } = verifyWorkspaceJson(
workspacePath
workspaceJsonPath
);

if (!validWorkspaceJson) {
return;
}

const selection = await selectSchematic(workspacePath);
const selection = await selectSchematic(workspaceJsonPath);
if (!selection) {
return;
}
Expand Down Expand Up @@ -181,7 +178,7 @@ export function selectCliProject(command: string, json: any) {

if (!items.length) {
window.showInformationMessage(
`None of your projects support ng ${command}`
`No projects have an architect command for ${command}`
);

return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Option } from '@angular-console/schema';
import { Option } from '@nx-console/schema';
import { QuickPickItem } from 'vscode';

export class CliTaskFlagQuickPickItem implements QuickPickItem {
Expand Down
6 changes: 3 additions & 3 deletions apps/vscode/src/app/cli-task/cli-task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CliTaskDefinition } from './cli-task-definition';
import { Task, TaskGroup, TaskScope } from 'vscode';
import { getShellExecutionForConfig } from './shell-execution';
import { findClosestNg, findClosestNx } from '@angular-console/server';
import { findClosestNg, findClosestNx } from '@nx-console/server';
import { join } from 'path';

export class CliTask extends Task {
Expand All @@ -26,10 +26,10 @@ export class CliTask extends Task {
: `ng ${args.join(' ')}`;

const task = new CliTask(
{ ...definition, type: 'ng' }, // definition
{ ...definition, type: useNxCli ? 'nx' : 'ng' }, // definition
TaskScope.Workspace, // scope
displayCommand, // name
'angular-console', // source
'nx-console', // source
// execution
getShellExecutionForConfig({
displayCommand,
Expand Down
4 changes: 2 additions & 2 deletions apps/vscode/src/app/cli-task/nx-task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Task, TaskScope } from 'vscode';
import { getShellExecutionForConfig } from './shell-execution';
import { findClosestNx } from '@angular-console/server';
import { findClosestNx } from '@nx-console/server';

export interface NxTaskDefinition {
positional: string;
Expand All @@ -19,7 +19,7 @@ export class NxTask extends Task {
{ ...definition, type: 'nx' }, // definition
TaskScope.Workspace, // scope
displayCommand, // name
'angular-console', // source
'nx-console', // source
// execution
getShellExecutionForConfig({
displayCommand,
Expand Down
2 changes: 1 addition & 1 deletion apps/vscode/src/app/cli-task/select-flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Option } from '@angular-console/schema';
import { Option } from '@nx-console/schema';
import { QuickPickItem, window } from 'vscode';
import { CliTaskFlagQuickPickItem } from './cli-task-flag-quick-pick-item';

Expand Down
135 changes: 135 additions & 0 deletions apps/vscode/src/app/nx-task/nx-task-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { Option } from '@nx-console/schema';
import { OptionType } from '@angular/cli/models/interface';
import { commands, ExtensionContext, window, tasks } from 'vscode';

import { ProjectDef } from '../cli-task/cli-task-definition';
import { CliTaskProvider } from '../cli-task/cli-task-provider';
import { selectFlags } from '../cli-task/select-flags';
import { verifyWorkspaceJson } from '../verify-workspace/verify-angular-json';
import { getTelemetry } from '../telemetry';
import { NxTask } from './nx-task';

let cliTaskProvider: CliTaskProvider;
export function registerNxCommands(
context: ExtensionContext,
n: CliTaskProvider
) {
cliTaskProvider = n;
context.subscriptions.push(
commands.registerCommand(`nx.affected`, async () => {
const target = await promptForTarget();
if (!target) {
return;
}
promptForAffectedFlags(target);
}),
commands.registerCommand(`nx.affected.test`, () =>
promptForAffectedFlags('test')
),
commands.registerCommand(`nx.affected.e2e`, () =>
promptForAffectedFlags('e2e')
),
commands.registerCommand(`nx.affected.lint`, () =>
promptForAffectedFlags('lint')
)
);
}

async function promptForTarget(): Promise<string | undefined> {
const { validWorkspaceJson, json } = verifyWorkspaceJson(
cliTaskProvider.getWorkspaceJsonPath()
);

if (!validWorkspaceJson || !json) {
return;
}

const validTargets = Array.from(
new Set(
Object.entries<ProjectDef>(json.projects)
.map(([_, project]) => Object.keys(project.architect || {}))
.flat()
)
).sort();

if (!validTargets.length) {
window.showErrorMessage(
'None of your workspace projects have an architect command'
);
return;
}

return window.showQuickPick(validTargets);
}

const AFFECTED_OPTIONS: Option[] = [
{
name: 'base',
type: OptionType.String,
description: 'Base of the current branch (usually master)'
},
{
name: 'head',
type: OptionType.String,
description: 'Latest commit of the current branch (usually HEAD)'
},
{
name: 'parallel',
type: OptionType.Boolean,
description: 'Parallelize the command',
default: 'false'
},
{
name: 'maxParallel',
type: OptionType.Number,
description: 'Max number of parallel processes',
default: 3
},
{
name: 'only-failed',
type: OptionType.Boolean,
description: 'Isolate projects which previously failed',
default: 'false'
},
{ name: 'all', type: OptionType.Boolean, description: 'All projects' },
{
name: 'configuration',
type: OptionType.String,
description:
'This is the configuration to use when performing tasks on projects'
},
{
name: 'exclude',
type: OptionType.String,
description: 'Exclude certain projects from being processed'
},
{
name: 'files',
type: OptionType.Array,
description: 'Manually specify changed files, delimited by commas'
}
].map(v => ({ ...v, aliases: [] }));

async function promptForAffectedFlags(target: string) {
const flags = await selectFlags(
'affected',
`--target=${target}`,
AFFECTED_OPTIONS,
'nx'
);

const telemetry = getTelemetry();
telemetry.featureUsed('affected-cli');

if (flags !== undefined) {
const task = NxTask.create(
{
command: 'affected',
flags,
positional: `--target=${target}`
},
cliTaskProvider.getWorkspacePath()
);
tasks.executeTask(task);
}
}
Loading