YeomanとVSCode拡張ジェネレータのインストール

npm install -g yo generator-code

作成したいフォルダへ移動

フォルダ作成し、そのフォルダへ移動

mkdir ext001
cd ext001

VSCode拡張機能のひな形を作成

yo code

※質問に応じて適宜答えてひな形を作成する

こんな感じ

初期状態のコード(extention.js)は以下のとおり

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "ext001" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with  registerCommand
	// The commandId parameter must match the command field in package.json
	const disposable = vscode.commands.registerCommand('ext001.helloWorld', function () {
		// The code you place here will be executed every time your command is executed

		// Display a message box to the user
		vscode.window.showInformationMessage('Hello World from ext001!');
	});

	context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
	activate,
	deactivate
}

registerCommandにext001.helloWorldが登録されていてこれが実行されると
初期状態のコードでは、 Hello World form ext001! と表示することになります。

なお、この機能をよびだすためには、package.jsonでcommandsの項目でコマンド名とそのタイトルを設定するところがあり
タイトルの名称がコマンドパレットで入力する名称になります。

  "contributes": {
    "commands": [{
      "command": "ext001.helloWorld",
      "title": "Hello World"
    }]
  },

F5を実行するとデバッグ用に本拡張機能が組み込まれた状態の別のVSCodeウィンドウがたちあがる
Shift + Ctrl + P でコマンドパレットを開き Hello Worldを入力

実行すると

メッセージが表示されます

パッケージ

vsceのインストール

 npm install -g vsce

現在のバージョンは2.15.0とのこと

vsce --version
2.15.0

オフィシャルに公開するのではなく、業務する人たちなど限られた人に公開したい場合packageを作成しそれを渡してインストールしてもらう
package を作成

vsce package
 ERROR  Make sure to edit the README.md file before you package or publish your extension.

Errorがでます。
どうやら、READMEのデフォルトのままだと、ある行をチェックしそのまま残っているとエラーとしているようです。
3行目の内容が残っているとチェックでひっかかるらしい

This is the README for your extension "ext001". After writing up a brief description, we recommend including the following sections.

後で項目追加しなさいよ!って書いてあるのにそのまま残っていると何もしてないからだめねということなんでしょうかねぇ。
とりあえず実行したいだけなので、3行目をとっぱらって、しまいます。

あらためてpackage

vsce package
 WARNING  A 'repository' field is missing from the 'package.json' manifest file.
Do you want to continue? [y/N] y
 WARNING  LICENSE.md, LICENSE.txt or LICENSE not found
Do you want to continue? [y/N] y
 DONE  Packaged: C:\develop\VSCode\ext001\ext001\ext001-0.0.1.vsix (6 files, 3.45KB)

インストールは、拡張機能からVSIXのインストールのメニューがあるのでそちらからファイル選択ダイアログからファイルを選択

投稿日時: 2024-11-10 04:55:10
更新日時: 2024-11-10 05:17:10

NVM(Node Version Manager)は、Node.jsを複数インストールして使い分けるためのソフトウェアで、Aboutには以下のような記載があります

nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.

windowsでは、WSLでしかどうさしないです
そのため、windowsでは直接公式のnvmを使うことができないです

そこで変わりのものとして、nvm-windowsが有名なようなので、そちらをインストールしてみました
自分は、nvm-setup.zipでインストールしました

現在のバージョンは以下の通り

c:\>nvm --version
1.1.12

使い方のメモ

ヘルプ

c:\>nvm --helop

Running version 1.1.12.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm debug                    : Check the NVM4W process for known problems (troubleshooter).
  nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
                                 to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
                                 Add --insecure to the end of this command to bypass SSL validation of the remote download server.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
  nvm uninstall <version>      : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
                                 "newest" is the latest installed version. Optionally specify 32/64bit architecture.
                                 nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If <path> is not set, the current root will be displayed.
  nvm [--]version              : Displays the current running version of nvm for Windows. Aliased as v.

バージョン

c:\>nvm --version
1.1.12

インストール可能な一覧

c:\>nvm list available

|   CURRENT    |     LTS      |  OLD STABLE  | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
|    23.1.0    |   22.11.0    |   0.12.18    |   0.11.16    |
|    23.0.0    |   20.18.0    |   0.12.17    |   0.11.15    |
|   22.10.0    |   20.17.0    |   0.12.16    |   0.11.14    |
|    22.9.0    |   20.16.0    |   0.12.15    |   0.11.13    |
|    22.8.0    |   20.15.1    |   0.12.14    |   0.11.12    |
|    22.7.0    |   20.15.0    |   0.12.13    |   0.11.11    |
|    22.6.0    |   20.14.0    |   0.12.12    |   0.11.10    |
|    22.5.1    |   20.13.1    |   0.12.11    |    0.11.9    |
|    22.5.0    |   20.13.0    |   0.12.10    |    0.11.8    |
|    22.4.1    |   20.12.2    |    0.12.9    |    0.11.7    |
|    22.4.0    |   20.12.1    |    0.12.8    |    0.11.6    |
|    22.3.0    |   20.12.0    |    0.12.7    |    0.11.5    |
|    22.2.0    |   20.11.1    |    0.12.6    |    0.11.4    |
|    22.1.0    |   20.11.0    |    0.12.5    |    0.11.3    |
|    22.0.0    |   20.10.0    |    0.12.4    |    0.11.2    |
|    21.7.3    |    20.9.0    |    0.12.3    |    0.11.1    |
|    21.7.2    |   18.20.4    |    0.12.2    |    0.11.0    |
|    21.7.1    |   18.20.3    |    0.12.1    |    0.9.12    |
|    21.7.0    |   18.20.2    |    0.12.0    |    0.9.11    |
|    21.6.2    |   18.20.1    |   0.10.48    |    0.9.10    |

This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases

全てが見たい場合は、https://nodejs.org/en/download/releasesとのこと

インストールしたいバージョンが特に決まっていなければこちらから選ぶ形になります

インストール

22.11.0のバージョンをインストールしてみます

c:\>nvm install 22.11.0
Downloading node.js version 22.11.0 (64-bit)...
Extracting node and npm...
Complete
npm v10.9.0 installed successfully.


Installation complete. If you want to use this version, type

nvm use 22.11.0

インストールしてあるnode.jsの一覧

c:\>nvm list

    22.11.0
  * 20.18.0 (Currently using 64-bit executable)
  • がついているのが現在選択されているnode.jsのバージョンです

バージョンの切り替え

c:\>nvm use 22.11.0
Now using node v22.11.0 (64-bit)

※プロンプトを管理者権限ありで起動していないと、変更時にユーザーアカウント制御のダイアログが表示されます

選択中のバージョン

c:\>nvm current
v22.11.0
投稿日時: 2024-11-09 11:16:09
更新日時: 2024-11-09 11:57:09

最近の投稿

最近のコメント

タグ

アーカイブ

その他