Update localization support in myTemplateGenerator extension. Added English and Russian settings for the configuration interface, modified default language to English, and removed unnecessary .vscode directory from .gitignore. Updated @types/vscode dependency version in package files. Added VSCode configuration files for better development experience.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,7 +41,6 @@ build/Release
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
.vscode/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher", "ms-vscode.extension-test-runner"]
|
||||
}
|
||||
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/dist/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false, // set this to true to hide the "out" folder with the compiled JS files
|
||||
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true, // set this to false to include "out" folder in search results
|
||||
"dist": true // set this to false to include "dist" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
||||
40
.vscode/tasks.json
vendored
Normal file
40
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$ts-webpack-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch-tests",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "tasks: watch-tests",
|
||||
"dependsOn": [
|
||||
"npm: watch",
|
||||
"npm: watch-tests"
|
||||
],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -13,7 +13,7 @@
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "20.x",
|
||||
"@types/vscode": "^1.102.0",
|
||||
"@types/vscode": "^1.60.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
@@ -485,9 +485,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/vscode": {
|
||||
"version": "1.102.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.102.0.tgz",
|
||||
"integrity": "sha512-V9sFXmcXz03FtYTSUsYsu5K0Q9wH9w9V25slddcxrh5JgORD14LpnOA7ov0L9ALi+6HrTjskLJ/tY5zeRF3TFA==",
|
||||
"version": "1.60.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.60.0.tgz",
|
||||
"integrity": "sha512-wZt3VTmzYrgZ0l/3QmEbCq4KAJ71K3/hmMQ/nfpv84oH8e81KKwPEoQ5v8dNCxfHFVJ1JabHKmCvqdYOoVm1Ow==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"displayName": "myTemplateGenerator",
|
||||
"description": "Generate files and folders from customizable templates with variable substitution in VSCode.",
|
||||
"version": "0.0.1",
|
||||
"publisher": "MyTemplateGenerator",
|
||||
"author": "Sergey Gromov",
|
||||
"url": "https://github.com/gormov1122/MyTemplateGenerator",
|
||||
"engines": {
|
||||
@@ -68,7 +69,7 @@
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "20.x",
|
||||
"@types/vscode": "^1.102.0",
|
||||
"@types/vscode": "^1.60.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
|
||||
358
src/extension.ts
358
src/extension.ts
@@ -268,6 +268,29 @@ const I18N_DICTIONARIES: Record<string, Record<string, string>> = {
|
||||
}
|
||||
};
|
||||
|
||||
const SETTINGS_I18N: Record<string, Record<string, string>> = {
|
||||
ru: {
|
||||
title: 'Настройки myTemplateGenerator',
|
||||
templatesPath: 'Путь к шаблонам:',
|
||||
overwriteFiles: 'Перезаписывать существующие файлы',
|
||||
inputMode: 'Способ ввода переменных:',
|
||||
inputModeWebview: 'Webview (форма)',
|
||||
inputModeInputBox: 'InputBox (по одной)',
|
||||
language: 'Язык интерфейса:',
|
||||
save: 'Сохранить'
|
||||
},
|
||||
en: {
|
||||
title: 'myTemplateGenerator Settings',
|
||||
templatesPath: 'Templates path:',
|
||||
overwriteFiles: 'Overwrite existing files',
|
||||
inputMode: 'Variable input method:',
|
||||
inputModeWebview: 'Webview (form)',
|
||||
inputModeInputBox: 'InputBox (one by one)',
|
||||
language: 'Interface language:',
|
||||
save: 'Save'
|
||||
}
|
||||
};
|
||||
|
||||
interface MyTemplateGeneratorConfig {
|
||||
templatesPath: string;
|
||||
overwriteFiles: boolean;
|
||||
@@ -279,7 +302,7 @@ const DEFAULT_CONFIG: MyTemplateGeneratorConfig = {
|
||||
templatesPath: 'templates',
|
||||
overwriteFiles: false,
|
||||
inputMode: 'webview',
|
||||
language: 'ru',
|
||||
language: 'en',
|
||||
};
|
||||
|
||||
function getConfigPath(): string | undefined {
|
||||
@@ -313,175 +336,183 @@ function writeConfig(config: MyTemplateGeneratorConfig) {
|
||||
|
||||
async function showConfigWebview(context: vscode.ExtensionContext) {
|
||||
const config = readConfig();
|
||||
let language = config.language || 'ru';
|
||||
return new Promise<void>((resolve) => {
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
'mytemplategeneratorConfig',
|
||||
'Настройки myTemplateGenerator',
|
||||
SETTINGS_I18N[language]?.title || SETTINGS_I18N['ru'].title,
|
||||
vscode.ViewColumn.Active,
|
||||
{ enableScripts: true }
|
||||
);
|
||||
panel.webview.html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; style-src 'unsafe-inline';">
|
||||
<title>Настройки myTemplateGenerator</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f7f7fa;
|
||||
--panel-bg: #fff;
|
||||
--text: #222;
|
||||
--label: #555;
|
||||
--input-bg: #f0f0f3;
|
||||
--input-border: #d0d0d7;
|
||||
--input-focus: #1976d2;
|
||||
--button-bg: #1976d2;
|
||||
--button-text: #fff;
|
||||
--button-hover: #1565c0;
|
||||
--border-radius: 8px;
|
||||
--shadow: 0 2px 12px rgba(0,0,0,0.07);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #181a1b;
|
||||
--panel-bg: #23272e;
|
||||
--text: #f3f3f3;
|
||||
--label: #b0b0b0;
|
||||
--input-bg: #23272e;
|
||||
--input-border: #33363b;
|
||||
--input-focus: #90caf9;
|
||||
--button-bg: #1976d2;
|
||||
--button-text: #fff;
|
||||
--button-hover: #1565c0;
|
||||
--border-radius: 8px;
|
||||
--shadow: 0 2px 12px rgba(0,0,0,0.25);
|
||||
}
|
||||
}
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.config-container {
|
||||
max-width: 420px;
|
||||
margin: 48px auto;
|
||||
background: var(--panel-bg);
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 32px 36px 28px 36px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.config-container h2 {
|
||||
margin: 0 0 18px 0;
|
||||
font-size: 1.5em;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
label {
|
||||
color: var(--label);
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
input[type="text"], select {
|
||||
background: var(--input-bg);
|
||||
color: var(--text);
|
||||
border: 1.5px solid var(--input-border);
|
||||
border-radius: var(--border-radius);
|
||||
padding: 8px 10px;
|
||||
font-size: 1em;
|
||||
transition: border 0.2s, box-shadow 0.2s;
|
||||
outline: none;
|
||||
}
|
||||
input[type="text"]:focus, select:focus {
|
||||
border-color: var(--input-focus);
|
||||
box-shadow: 0 0 0 2px var(--input-focus)33;
|
||||
}
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
input[type="checkbox"] {
|
||||
accent-color: var(--input-focus);
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
button {
|
||||
margin-top: 10px;
|
||||
background: var(--button-bg);
|
||||
color: var(--button-text);
|
||||
border: none;
|
||||
border-radius: var(--border-radius);
|
||||
padding: 10px 0;
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s, box-shadow 0.2s;
|
||||
box-shadow: 0 1px 4px rgba(25, 118, 210, 0.08);
|
||||
}
|
||||
button:hover, button:focus {
|
||||
background: var(--button-hover);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const vscode = acquireVsCodeApi();
|
||||
document.getElementById('configForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const templatesPath = document.getElementById('templatesPath').value;
|
||||
const overwriteFiles = document.getElementById('overwriteFiles').checked;
|
||||
const inputMode = document.getElementById('inputMode').value;
|
||||
const language = document.getElementById('language').value;
|
||||
vscode.postMessage({ type: 'save', data: { templatesPath, overwriteFiles, inputMode, language } });
|
||||
function setHtml() {
|
||||
const dict = SETTINGS_I18N[language] || SETTINGS_I18N['ru'];
|
||||
panel.webview.html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="${language}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; style-src 'unsafe-inline';">
|
||||
<title>${dict.title}</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f7f7fa;
|
||||
--panel-bg: #fff;
|
||||
--text: #222;
|
||||
--label: #555;
|
||||
--input-bg: #f0f0f3;
|
||||
--input-border: #d0d0d7;
|
||||
--input-focus: #1976d2;
|
||||
--button-bg: #1976d2;
|
||||
--button-text: #fff;
|
||||
--button-hover: #1565c0;
|
||||
--border-radius: 8px;
|
||||
--shadow: 0 2px 12px rgba(0,0,0,0.07);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #181a1b;
|
||||
--panel-bg: #23272e;
|
||||
--text: #f3f3f3;
|
||||
--label: #b0b0b0;
|
||||
--input-bg: #23272e;
|
||||
--input-border: #33363b;
|
||||
--input-focus: #90caf9;
|
||||
--button-bg: #1976d2;
|
||||
--button-text: #fff;
|
||||
--button-hover: #1565c0;
|
||||
--border-radius: 8px;
|
||||
--shadow: 0 2px 12px rgba(0,0,0,0.25);
|
||||
}
|
||||
}
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.config-container {
|
||||
max-width: 420px;
|
||||
margin: 48px auto;
|
||||
background: var(--panel-bg);
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 32px 36px 28px 36px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.config-container h2 {
|
||||
margin: 0 0 18px 0;
|
||||
font-size: 1.5em;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
label {
|
||||
color: var(--label);
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
input[type="text"], select {
|
||||
background: var(--input-bg);
|
||||
color: var(--text);
|
||||
border: 1.5px solid var(--input-border);
|
||||
border-radius: var(--border-radius);
|
||||
padding: 8px 10px;
|
||||
font-size: 1em;
|
||||
transition: border 0.2s, box-shadow 0.2s;
|
||||
outline: none;
|
||||
}
|
||||
input[type="text"]:focus, select:focus {
|
||||
border-color: var(--input-focus);
|
||||
box-shadow: 0 0 0 2px var(--input-focus)33;
|
||||
}
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
input[type="checkbox"] {
|
||||
accent-color: var(--input-focus);
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
button {
|
||||
margin-top: 10px;
|
||||
background: var(--button-bg);
|
||||
color: var(--button-text);
|
||||
border: none;
|
||||
border-radius: var(--border-radius);
|
||||
padding: 10px 0;
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s, box-shadow 0.2s;
|
||||
box-shadow: 0 1px 4px rgba(25, 118, 210, 0.08);
|
||||
}
|
||||
button:hover, button:focus {
|
||||
background: var(--button-hover);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const vscode = acquireVsCodeApi();
|
||||
document.getElementById('configForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const templatesPath = document.getElementById('templatesPath').value;
|
||||
const overwriteFiles = document.getElementById('overwriteFiles').checked;
|
||||
const inputMode = document.getElementById('inputMode').value;
|
||||
const language = document.getElementById('language').value;
|
||||
vscode.postMessage({ type: 'save', data: { templatesPath, overwriteFiles, inputMode, language } });
|
||||
});
|
||||
document.getElementById('language').addEventListener('change', (e) => {
|
||||
vscode.postMessage({ type: 'changeLanguage', language: e.target.value });
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="config-container">
|
||||
<h2>Настройки myTemplateGenerator</h2>
|
||||
<form id="configForm">
|
||||
<div class="form-group">
|
||||
<label for="templatesPath">Путь к шаблонам:</label>
|
||||
<input type="text" id="templatesPath" value="${config.templatesPath}" />
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="config-container">
|
||||
<h2>${dict.title}</h2>
|
||||
<form id="configForm">
|
||||
<div class="form-group">
|
||||
<label for="templatesPath">${dict.templatesPath}</label>
|
||||
<input type="text" id="templatesPath" value="${config.templatesPath || ''}"/>
|
||||
</div>
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="overwriteFiles" ${config.overwriteFiles ? 'checked' : ''}/>
|
||||
<label for="overwriteFiles">${dict.overwriteFiles}</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputMode">${dict.inputMode}</label>
|
||||
<select id="inputMode">
|
||||
<option value="webview" ${config.inputMode === 'webview' ? 'selected' : ''}>${dict.inputModeWebview}</option>
|
||||
<option value="inputBox" ${config.inputMode === 'inputBox' ? 'selected' : ''}>${dict.inputModeInputBox}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="language">${dict.language}</label>
|
||||
<select id="language">
|
||||
<option value="ru" ${language === 'ru' ? 'selected' : ''}>Русский</option>
|
||||
<option value="en" ${language === 'en' ? 'selected' : ''}>English</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" style="padding: 10px 15px">${dict.save}</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="overwriteFiles" ${config.overwriteFiles ? 'checked' : ''}/>
|
||||
<label for="overwriteFiles">Перезаписывать существующие файлы</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputMode">Способ ввода переменных:</label>
|
||||
<select id="inputMode">
|
||||
<option value="webview" ${config.inputMode === 'webview' ? 'selected' : ''}>Webview (форма)</option>
|
||||
<option value="inputBox" ${config.inputMode === 'inputBox' ? 'selected' : ''}>InputBox (по одной)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="language">Язык интерфейса:</label>
|
||||
<select id="language">
|
||||
<option value="ru" ${config.language === 'ru' ? 'selected' : ''}>Русский</option>
|
||||
<option value="en" ${config.language === 'en' ? 'selected' : ''}>English</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit">Сохранить</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
setHtml();
|
||||
panel.webview.onDidReceiveMessage(
|
||||
message => {
|
||||
if (message.type === 'save') {
|
||||
@@ -489,6 +520,9 @@ async function showConfigWebview(context: vscode.ExtensionContext) {
|
||||
vscode.window.showInformationMessage('Настройки myTemplateGenerator сохранены!');
|
||||
panel.dispose();
|
||||
resolve();
|
||||
} else if (message.type === 'changeLanguage') {
|
||||
language = message.language;
|
||||
setHtml();
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
|
||||
Reference in New Issue
Block a user