Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
npm tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 29, 2017
1 parent 62aa478 commit 363818e
Show file tree
Hide file tree
Showing 13 changed files with 673 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log (vscode-deploy-reloaded)

## 0.7.0 (December 29th, 2017; npm)

* bugfixes
* code improvements
* added `initNodeModules` [setting](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--), which runs `npm install` inside the workspace folder on startup, if a `package.json` file exists and NO `node_modules` sub folder has been found
* added [tools](https://github.com/mkloubert/vscode-deploy-reloaded#npm-helpers-) for Node Package Manager ([npm](https://www.npmjs.com/package/npm))
* added global and context based event properties (`events` and `globalEvents`) to [ScriptArguments](https://mkloubert.github.io/vscode-deploy-reloaded/interfaces/_contracts_.scriptarguments.html)

## 0.6.0 (December 28th, 2017; bugfixes)

* fixed [folder mappings](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/folder_mappings)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The extension supports the following destinations:
* [Tools](#tools-)
* [Quick code execution](#quick-code-execution-)
* [Send files to other editors](#send-files-to-other-editors-)
* [NPM helpers](#npm-helpers-)
2. [Preview](#preview-)
3. [Install](#install-)
4. [How to use](#how-to-use-)
Expand Down Expand Up @@ -82,6 +83,12 @@ The following demo shows, how you can send a file to another VS Code instance ov

![Demo Send files to other editors](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo8.gif)

#### NPM helpers [[↑](#tools-)]

Provides some helpers for handling [npm](https://www.npmjs.com/package/npm):

![Demo NPM helpers](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo9.gif)

## Preview [[↑](#table-of-contents)]

Keep in mind, that this is a preview extension, which is in a good beta state.
Expand Down
Binary file added img/demo9.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.6.0",
"version": "0.7.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down Expand Up @@ -298,6 +298,11 @@
}
]
},
"initNodeModules": {
"description": "Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' has been found.",
"type": "boolean",
"default": false
},
"language": {
"description": "The custom ID of the language to use (e.g. 'en', 'de').",
"type": "string"
Expand Down
4 changes: 4 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export interface Configuration extends deploy_values.WithValueItems {
* A list of imports.
*/
readonly imports?: ImportType | ImportType[];
/**
* Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' has been found.
*/
readonly initNodeModules?: boolean;
/**
* The custom ID of the language to use (e.g. 'en', 'de').
*/
Expand Down
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as deploy_plugins from './plugins';
import * as deploy_switch from './switch';
import * as deploy_targets from './targets';
import * as deploy_tools from './tools';
import * as deploy_tools_npm from './tools/npm';
import * as deploy_tools_quick_execution from './tools/quickexecution';
import * as deploy_tools_send_file from './tools/sendfile';
import * as deploy_workflows from './workflows';
Expand Down Expand Up @@ -1185,6 +1186,15 @@ async function activateExtension(context: vscode.ExtensionContext) {
label: '$(broadcast) ' + i18.t('tools.sendOrReceiveFile.label'),
description: i18.t('tools.sendOrReceiveFile.description'),
state: 4,
},

{
action: async () => {
await deploy_tools_npm.showNPMTools(context);
},
label: '$(package) ' + i18.t('tools.npm.label'),
description: i18.t('tools.npm.description'),
state: 5,
}
];

Expand Down Expand Up @@ -1338,6 +1348,8 @@ async function activateExtension(context: vscode.ExtensionContext) {
deploy_packages.resetPackageUsage(context);
deploy_targets.resetTargetUsage(context);
deploy_tools.resetToolUsage(context);
deploy_tools_npm.resetNPMToolsUsage(context);
deploy_workspaces.resetWorkspaceUsage(context);

onDidChangeConfiguration(e).then(() => {
}).catch((err) => {
Expand Down
57 changes: 57 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ import * as URL from 'url';
import * as vscode from 'vscode';


/**
* Result of an execution.
*/
export interface ExecResult {
/**
* The output from 'standard error' stream.
*/
readonly stdErr: string;
/**
* The output from 'standard output' stream.
*/
readonly stdOut: string;
/**
* The underlying process.
*/
readonly process: ChildProcess.ChildProcess;
}

/**
* Options for 'invokeForTempFile' function.
*/
Expand Down Expand Up @@ -623,6 +641,45 @@ export function doesMatch(val: any, patterns: string | string[], options?: Minim
return false;
}

/**
* Executes something.
*
* @param {string} command The thing / command to execute.
* @param {ChildProcess.ExecOptions} [opts] Custom options.
*
* @return {Promise<ExecResult>} The promise with the result.
*/
export async function exec(command: string, opts?: ChildProcess.ExecOptions) {
command = toStringSafe(command);

return new Promise<ExecResult>((resolve, reject) => {
const COMPLETED = createCompletedAction(resolve, reject);

try {
const RESULT: ExecResult = {
stdErr: undefined,
stdOut: undefined,
process: undefined,
};

(<any>RESULT)['process'] = ChildProcess.exec(command, opts, (err, stdout, stderr) => {
if (err) {
COMPLETED(err);
}
else {
(<any>RESULT)['stdErr'] = stderr;
(<any>RESULT)['stdOut'] = stdout;

COMPLETED(null, RESULT);
}
});
}
catch (e) {
COMPLETED(e);
}
});
}

/**
* Promise version of 'FS.exists()' function.
*
Expand Down
34 changes: 34 additions & 0 deletions src/i18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,30 @@ export interface Translation {
errors?: {
operationFailed?: string;
};
npm?: {
description?: string;
executing?: string;
label?: string;
runInstall?: {
description?: string;
enterModuleName?: string;
label?: string;
};
runLink?: {
description?: string;
enterModuleName?: string;
label?: string;
};
runUninstall?: {
description?: string;
errors?: {
loadingPackageFileFailed?: string;
};
packageFileContainsNoModules?: string;
packageFileNotFound?: string;
label?: string;
};
},
quickExecution?: {
description?: string;
errors?: {
Expand Down Expand Up @@ -447,17 +471,27 @@ export interface Translation {
errors?: {
selectWorkspaceFailed?: string;
};
noneFound?: string;
selectWorkspace?: string;
};
errors?: {
cannotDetectMappedPathInfoForFile?: string;
cannotDetectPathInfoForFile?: string;
cannotUseTargetForFile?: string;
initNodeModulesFailed?: string;
notInitialized?: string;
};
initializing?: string;
noneFound?: string;
noSelected?: string;
npm?: {
install?: {
errors?: {
failed?: string;
};
running?: string;
}
};
removing?: string;
selectWorkspace?: string;
};
Expand Down
34 changes: 34 additions & 0 deletions src/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,30 @@ export const translation: Translation = {
errors: {
operationFailed: "Konnte Funktion nicht ausführen (s. Debugkonsole 'STRG + SHIFT + Y')!",
},
npm: {
description: "Werkzeuge für das einfache Arbeiten mit 'npm'",
executing: "Führe{0:trim,surround,leading_space} aus ...",
label: "Node Paket Manager (npm)",
runInstall: {
description: "Führt den Befehl 'npm install' im aktuellen Arbeitsbereich aus",
enterModuleName: "Geben Sie den Namen des NPM-Moduls an ...",
label: "'npm install' ausführen ...",
},
runLink: {
description: "Führt den Befehl 'npm link' im aktuellen Arbeitsbereich aus",
enterModuleName: "Geben Sie den Namen des NPM-Moduls an ...",
label: "'npm link' ausführen ...",
},
runUninstall: {
description: "Führt den Befehl 'npm uninstall' im aktuellen Arbeitsbereich aus",
errors: {
loadingPackageFileFailed: "Das Laden von{0:trim,surround,leading_space} ist fehlgeschlagen:{1:trim,surround,leading_space}",
},
packageFileContainsNoModules: "{0:trim,surround,ending_space} beinhaltet keine Module!",
packageFileNotFound: "Es wurde keine 'package.json'-Datei in{0:trim,surround,leading_space} gefunden!",
label: "'npm UNinstall' ausführen ...",
},
},
quickExecution: {
description: "Führt JavaScript-Code aus",
errors: {
Expand Down Expand Up @@ -441,17 +465,27 @@ export const translation: Translation = {
errors: {
selectWorkspaceFailed: "Das Selektieren des aktiven Arbeitsbereiches ist fehlgeschlagen (s. Debugkonsole 'STRG + SHIFT + Y')!",
},
noneFound: "Keine aktiven Arbeitsbereiche gefunden!",
selectWorkspace: "Wählen Sie den aktiven Arbeitsbereich aus ...",
},
errors: {
cannotDetectMappedPathInfoForFile: "Gemappte Pfad-Informationen konnten für die Datei{0:trim,surround,leading_space} nicht ermittelt werden!",
cannotDetectPathInfoForFile: "Pfad-Informationen konnten für die Datei{0:trim,surround,leading_space} nicht ermittelt werden!",
cannotUseTargetForFile: "Kann das Ziel{0:trim,surround,leading_space} nicht für die Datei{1:trim,surround,leading_space} verwenden!",
initNodeModulesFailed: "Der Aufruf von 'npm install' ist fehlgeschlagen:{0:trim,surround,leading_space}",
notInitialized: "Der Arbeitsbereich{0:trim,surround,leading_space} wurde nicht initialisiert!",
},
initializing: "Initialisiere Arbeitsbereich{0:trim,surround,leading_space} ...",
noneFound: "Keine Arbeitsbereiche gefunden!",
noSelected: "kein Arbeitsbereich ausgewählt",
npm: {
install: {
errors: {
failed: "'npm install' konnte nicht ausgeführt werden:{0:trim,surround,leading_space}",
},
running: "Führe 'npm install' in{0:trim,surround,leading_space} aus ..."
}
},
removing: "Schliesse Arbeitsbereich{0:trim,surround,leading_space} ...",
selectWorkspace: "Wählen Sie einen Arbeitsbereich ...",
},
Expand Down
34 changes: 34 additions & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,30 @@ export const translation: Translation = {
errors: {
operationFailed: "Tool operation failed (s. debug output 'CTRL + SHIFT + Y')!",
},
npm: {
description: "Tools for simple use of 'npm'",
executing: "Running{0:trim,surround,leading_space} ...",
label: "Node Package Manager (npm)",
runInstall: {
description: "Runs 'npm install' inside the current workspace",
enterModuleName: "Enter the name of the NPM module ...",
label: "Run 'npm install' ...",
},
runLink: {
description: "Runs 'npm link' inside the current workspace",
enterModuleName: "Enter the name of the NPM module ...",
label: "Run 'npm link' ...",
},
runUninstall: {
description: "Runs 'npm uninstall' inside the current workspace",
errors: {
loadingPackageFileFailed: "Loading{0:trim,surround,leading_space} failed:{1:trim,surround,leading_space}",
},
packageFileContainsNoModules: "{0:trim,surround,ending_space} contains no modules!",
packageFileNotFound: "No 'package.json' file found in{0:trim,surround,leading_space}!",
label: "Run 'npm UNinstall' ...",
},
},
quickExecution: {
description: "Executes JavaScript code",
errors: {
Expand Down Expand Up @@ -442,17 +466,27 @@ export const translation: Translation = {
errors: {
selectWorkspaceFailed: "Selecting active workspace failed (s. debug output 'CTRL + SHIFT + Y')!",
},
noneFound: "No active workspaces found!",
selectWorkspace: "Select the active workspace ...",
},
errors: {
cannotDetectMappedPathInfoForFile: "Cannot detect mapped path information for file{0:trim,surround,leading_space}!",
cannotDetectPathInfoForFile: "Cannot detect path information for file{0:trim,surround,leading_space}!",
cannotUseTargetForFile: "Cannot use target{0:trim,surround,leading_space} for file{1:trim,surround,leading_space}!",
initNodeModulesFailed: "Execution of 'npm install' failed:{0:trim,surround,leading_space}",
notInitialized: "Workspace{0:trim,surround,leading_space} has not been initialized!",
},
initializing: "Initializing workspace{0:trim,surround,leading_space} ...",
noneFound: "No workspaces found!",
noSelected: "no workspace selected",
npm: {
install: {
errors: {
failed: "'npm install' failed:{0:trim,surround,leading_space}",
},
running: "Running 'npm install' in{0:trim,surround,leading_space} ..."
}
},
removing: "Closing workspace{0:trim,surround,leading_space} ...",
selectWorkspace: "Select a workspace ...",
},
Expand Down
Loading

0 comments on commit 363818e

Please sign in to comment.