Skip to content

Commit

Permalink
Merge pull request #31 from gamunu/submenu
Browse files Browse the repository at this point in the history
Improve explorer context menu for package.json files
  • Loading branch information
gamunu authored Feb 21, 2022
2 parents 428dc6d + 38e8981 commit 736b51f
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 133 deletions.
46 changes: 46 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
],
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/class-name-casing": [
"off",
"always"
],
"curly": "error",
"eqeqeq": [
"error",
"always"
],
"no-redeclare": "error",
"no-unused-expressions": "error",
"prefer-const": "error"
}
};
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
## 2.0 - 07th of Augest, 2021
## 2.1.0 - 21st of February, 2022

* Add Explorer context menu submenus for additional Yarn commands.
`Install Packages`, `Test`, `Build`, `Start`, `Run Script`, `Add & Save Package`, `Add & Save Dev Package`, `Remove Package`, `Publish`, `Outdated`

## 2.0.0 - 07th of August, 2021

* Add WSL support
* Add Multi-Workspace support

## 1.7 - 08th of December, 2019
## 1.7.0 - 08th of December, 2019

* Fix for [Issue 11](https://github.com/gamunu/vscode-yarn/issues/11)
* Add touchbar assets and update package.json.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2018 Gamunu Balagalla
Copyright (c) 2016-2022 Gamunu Balagalla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ git clone [email protected]:gamunu/vscode-yarn.git gamunu.vscode-yarn

### Explorer context menu

`yarn install` also available in the `package.json` file's explorer context menu.
Few `yarn` commands also available in the `package.json` file's explorer context menu.

![Context menu](images/context.png)

Expand Down
Binary file modified images/context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 77 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-yarn",
"displayName": "yarn",
"description": "Yarn commands for VSCode",
"version": "2.0.0",
"version": "2.1.0",
"publisher": "gamunu",
"icon": "yarn_icon.png",
"engines": {
Expand Down Expand Up @@ -57,43 +57,43 @@
},
{
"command": "yarn-script.terminate",
"title": "Terminate Running Yarn Script",
"title": "Terminate Running Script",
"category": "Yarn"
},
{
"command": "yarn-script.installPackages",
"title": "Install Yarn Packages",
"title": "Install Packages",
"category": "Yarn",
"icon": "./assets/install.png"
},
{
"command": "yarn-script.addPackage",
"title": "Add and Save Dependency",
"title": "Add & Save Dependency",
"category": "Yarn"
},
{
"command": "yarn-script.addPackageDev",
"title": "Add and Save dev. Dependency",
"title": "Add & Save dev. Dependency",
"category": "Yarn"
},
{
"command": "yarn-script.runScript",
"title": "Run Yarn Script",
"title": "Run Script",
"category": "Yarn"
},
{
"command": "yarn-script.runScriptLast",
"title": "Run Last Yarn Script",
"title": "Run Last Script",
"category": "Yarn"
},
{
"command": "yarn-script.init",
"title": "Initialize Yarn Package",
"title": "Initialize Package",
"category": "Yarn"
},
{
"command": "yarn-script.outdated",
"title": "Run outdated",
"title": "Outdated",
"category": "Yarn"
},
{
Expand All @@ -103,7 +103,7 @@
},
{
"command": "yarn-script.build",
"title": "Run Build",
"title": "Build",
"category": "Yarn",
"icon": "./assets/build.png"
},
Expand All @@ -114,16 +114,68 @@
},
{
"command": "yarn-script.raw",
"title": "Raw Yarn Command",
"title": "Raw Command",
"category": "Yarn"
}
],
"menus": {
"explorer/context": [
{
"when": "resourceFilename == 'package.json'",
"group": "navigation@1",
"submenu": "vscode.yarn"
}
],
"vscode.yarn": [
{
"command": "yarn-script.installPackages",
"group": "navigation@+1"
"group": "navigation@1",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.test",
"group": "navigation@2",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.build",
"group": "navigation@3",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.start",
"group": "navigation@4",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.runScript",
"group": "navigation@5",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.addPackage",
"group": "navigation@6",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.addPackageDev",
"group": "navigation@7",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.removePackage",
"group": "navigation@8",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.publish",
"group": "navigation@9",
"submenu": "vscode.yarn"
},
{
"command": "yarn-script.outdated",
"group": "navigation@10",
"submenu": "vscode.yarn"
}
],
"touchBar": [
Expand All @@ -149,6 +201,12 @@
}
]
},
"submenus": [
{
"id": "vscode.yarn",
"label": "Yarn"
}
],
"keybindings": [
{
"command": "yarn-script.runScript",
Expand Down Expand Up @@ -216,16 +274,17 @@
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"test-compile": "tsc -p ./",
"eslint": "eslint src/ .ts,.tsx"
"eslint": "eslint -c .eslintrc.js --ext .ts src/*.ts"
},
"devDependencies": {
"@types/vscode": "^1.58.1",
"@types/node": "^12.12.0",
"@types/mocha": "^2.2.42",
"@typescript-eslint/eslint-plugin": "^4.16.0",
"typescript": "^4.3.5",
"ts-loader": "^7.0.5",
"@types/node": "^12.12.0",
"@types/vscode": "^1.58.1",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^7.0.5",
"ts-loader": "^7.0.5",
"typescript": "^4.5.5",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.0"
},
Expand Down
32 changes: 14 additions & 18 deletions src/add.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import { window as Window } from 'vscode';
import { packageExists, pickPackageJson } from './utils';
import { window as Window, Uri } from 'vscode';
import { getPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

export async function yarnAddPackages() {
let packageJson = await pickPackageJson()
if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
}
export async function yarnAddPackages(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

if (packageJson === null) { return; }

runCommand(['add'], packageJson);
}

export function yarnAddPackage() {
return _addPackage(false);
export function yarnAddPackage(arg: Uri) {
return _addPackage(false, arg);
}

export function yarnAddPackageDev() {
return _addPackage(true);
export function yarnAddPackageDev(arg: Uri) {
return _addPackage(true, arg);
}

const _addPackage = async function (dev: boolean) {
let packageJson = await pickPackageJson()
if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
}
const _addPackage = async function (dev: boolean, arg: Uri) {
const packageJson: string = await getPackageJson(arg);

if (packageJson === null) { return; }

Window.showInputBox({
prompt: 'Package to add',
Expand Down
4 changes: 2 additions & 2 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Messages from './messages';
import { packageExists, pickPackageJson } from './utils';

export default async function () {
let packageJson = await pickPackageJson()
const packageJson = await pickPackageJson();

if (packageJson == null) {
if (packageJson === null) {
Messages.noProjectOpenError();
return;
}
Expand Down
19 changes: 5 additions & 14 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { packageExists, CommandArgument, pickPackageJson } from './utils';
import * as Messages from './messages';
import { getPackageJson } from './utils';
import { Uri } from 'vscode';
import { runCommand } from './run-command';

export async function yarnInstallPackages(arg: CommandArgument) {
let packageJson = null
export async function yarnInstallPackages(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

// context menu wins always
if (arg !== undefined) {
packageJson = arg.fsPath;
} else { // fall back to pick
packageJson = await pickPackageJson()
}
if (packageJson === null) { return; }

if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
}
runCommand(['install'], packageJson);
}
14 changes: 6 additions & 8 deletions src/outdated.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { packageExists, pickPackageJson } from './utils';
import * as Messages from './messages';
import { getPackageJson } from './utils';
import { Uri } from 'vscode';
import { runCommand } from './run-command';

export async function yarnOutdated() {
let packageJson = await pickPackageJson()
if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
}
export async function yarnOutdated(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

if (packageJson === null) { return; }

runCommand(['outdated'], packageJson);
}
17 changes: 6 additions & 11 deletions src/publish.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { window as Window } from 'vscode';
import { packageExists, pickPackageJson } from './utils';
import { window as Window, Uri } from 'vscode';
import { getPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

export function yarnPublish() {
_do('publish');
}
export async function yarnPublish(arg: Uri) {
const cmd: string = 'publish';
const packageJson: string = await getPackageJson(arg);

const _do = async function (cmd: string) {
let packageJson = await pickPackageJson()
if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
}
if (packageJson === null) { return; }

Window.showInputBox({
prompt: 'Optional tag (enter to skip tag)',
Expand Down
2 changes: 1 addition & 1 deletion src/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Messages from './messages';
import { runCommand } from './run-command';

export async function yarnRawCommand() {
let packageJson = await pickPackageJson()
const packageJson = await pickPackageJson();
if (!packageExists(packageJson)) {
Messages.noPackageError();
return;
Expand Down
Loading

0 comments on commit 736b51f

Please sign in to comment.