Skip to content

Commit

Permalink
chore: Update code comments (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
gamunu authored Apr 28, 2023
1 parent 93bc64e commit 6f18600
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { getPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

/**
* Add packages to the project using yarn add command
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnAddPackages(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand All @@ -11,14 +17,33 @@ export async function yarnAddPackages(arg: Uri) {
runCommand(['add'], packageJson);
}

/**
* Add packages to the project using yarn add command
*
* @param arg path to the file where command orignated
* @returns void
*/
export function yarnAddPackage(arg: Uri) {
return _addPackage(false, arg);
}

/**
* Add packages to the project using yarn add command
* with --dev option
* @param arg path to the file where command orignated
* @returns void
*/
export function yarnAddPackageDev(arg: Uri) {
return _addPackage(true, arg);
}

/**
* Add packages to the project using yarn add command with --dev option
*
* @param dev boolean
* @param arg path to the file where command orignated
* @returns void
*/
const _addPackage = async function (dev: boolean, arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand Down
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { yarnRawCommand } from './raw';
import yarnTerminate from './terminate';
import { yarnOutdated } from './outdated';

/**
* Activate the extension and register all commands and events
*
* @param context ExtensionContext
*/
export const activate = function (context: ExtensionContext) {
const disposables = [
Commands.registerCommand('yarn-script.installPackages', yarnInstallPackages),
Expand All @@ -33,6 +38,11 @@ export const activate = function (context: ExtensionContext) {
context.subscriptions.push(...disposables, outputChannel);
};

/**
* Deactivate the extension
* @returns void
* @export deactivate
*/
export function deactivate() {
if (terminal) {
terminal.dispose();
Expand Down
5 changes: 5 additions & 0 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { workspace as Workspace, window as Window } from 'vscode';
import * as Messages from './messages';
import { packageExists, pickPackageJson } from './utils';

/**
* Initialize a new package.json file
*
* @returns void
*/
export default async function () {
const packageJson = await pickPackageJson();

Expand Down
6 changes: 6 additions & 0 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { getPackageJson } from './utils';
import { Uri } from 'vscode';
import { runCommand } from './run-command';

/**
* Install packages to the project using yarn install command
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnInstallPackages(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand Down
6 changes: 6 additions & 0 deletions src/outdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { getPackageJson } from './utils';
import { Uri } from 'vscode';
import { runCommand } from './run-command';

/**
* Run yarn outdated command
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnOutdated(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand Down
6 changes: 6 additions & 0 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { getPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

/**
* Publish package to the registry using yarn publish command
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnPublish(arg: Uri) {
const cmd: string = 'publish';
const packageJson: string = await getPackageJson(arg);
Expand Down
5 changes: 5 additions & 0 deletions src/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { packageExists, pickPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

/**
* Run yarn command
*
* @returns void
*/
export async function yarnRawCommand() {
const packageJson = await pickPackageJson();
if (!packageExists(packageJson)) {
Expand Down
6 changes: 6 additions & 0 deletions src/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { getPackageJson } from './utils';
import * as Messages from './messages';
import { runCommand } from './run-command';

/**
* Remove packages from the project using yarn remove command
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnRemovePackage(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand Down
6 changes: 6 additions & 0 deletions src/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function runCommandInIntegratedTerminal(args: string[], cwd: string): void {
terminal.sendText(cmd_args.join(' '));
}

/**
* Run command in output window
*
* @param args command arguments
* @param cwd current working directory
*/
function runCommandInOutputWindow(args: string[], cwd: string) {
const cmd = getYarnBin() + ' ' + args.join(' ');

Expand Down
12 changes: 12 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ let lastScript: {
script: string;
};

/**
* Read scripts from package.json file
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnRunScript(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand All @@ -32,6 +38,12 @@ export async function yarnRunScript(arg: Uri) {
});
}

/**
* Read scripts from package.json file
*
* @param arg path to the file where command orignated
* @returns void
*/
export async function yarnTest(arg: Uri) {
const packageJson: string = await getPackageJson(arg);

Expand Down
6 changes: 6 additions & 0 deletions src/terminate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { childs, terminate } from './run-command';
import { useTerminal } from './utils';
import { window as Window, QuickPickItem } from 'vscode';

/**
* Item for quick pick menu
*/
class Item implements QuickPickItem {
constructor(public label: string,
public description: string,
public pid: number) {
}
}

/**
* Read scripts from package.json file and return them as an object
*/
export default function () {
if (useTerminal()) {
Window.showInformationMessage('Killing is only supported when the setting "runInTerminal" is "false"');
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ interface PackageJsonRoot {
name: string;
}

/**
* Read scripts from package.json file and return them as an object
*
* @returns object
*/
export async function pickPackageJson(): Promise<Readonly<string>> {
// if active text editor is a package.json turn the path for it
const editor = Window.activeTextEditor;
Expand Down

0 comments on commit 6f18600

Please sign in to comment.