Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New commands & refactoring #134

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ To generate a new API token in Crowdin, go to your Account Settings.

This extension contributes the following settings:

* `tms.autoRefresh`: enable/disable auto refresh of the file tree after each change in the Crowdin configuration file
* `crowdin.autoRefresh`: enable/disable auto refresh of the file tree after each change in the Crowdin configuration file

* `tms.stringsCompletion`: enable/disable autocompletion of strings keys
* `crowdin.stringsCompletion`: enable/disable autocompletion of strings keys

* `tms.stringsCompletionFileExtensions`: Comma-separated list of file extensions for which autocomplete should be active. By default, strings autocomplete will be active in all files
* `crowdin.stringsCompletionFileExtensions`: Comma-separated list of file extensions for which autocomplete should be active. By default, strings autocomplete will be active in all files

* `tms.useGitBranch`: enable/disable the use of a Git branch as a Crowdin branch.
* `crowdin.useGitBranch`: enable/disable the use of a Git branch as a Crowdin branch.

## Known Issues

Expand Down
103 changes: 63 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
"contributes": {
"configuration": [
{
"title": "Crowdin Explorer",
"title": "Crowdin",
"properties": {
"tms.autoRefresh": {
"crowdin.autoRefresh": {
"type": "boolean",
"default": "true",
"description": "Enables or disables auto refresh after each change in Crowdin configuration file.",
"scope": "window"
},
"tms.stringsCompletion": {
"crowdin.stringsCompletion": {
"type": "boolean",
"default": "true",
"description": "Enables or disables auto completion of strings keys.",
"scope": "window"
},
"tms.stringsCompletionFileExtensions": {
"crowdin.stringsCompletionFileExtensions": {
"type": "string",
"default": "*",
"description": "Comma-separated list of file extensions for which autocomplete should be active. By default strings autocomplete will be active in all files.",
"scope": "window"
},
"tms.useGitBranch": {
"crowdin.useGitBranch": {
"type": "boolean",
"default": "false",
"description": "Use a Git branch as a Crowdin branch",
Expand All @@ -59,17 +59,17 @@
"viewsContainers": {
"activitybar": [
{
"id": "crowdin-explorer",
"title": "Crowdin Explorer",
"id": "crowdin",
"title": "Crowdin",
"icon": "resources/icon.svg"
}
]
},
"views": {
"crowdin-explorer": [
"crowdin": [
{
"id": "tmsFiles",
"name": "TMS Files"
"id": "files",
"name": "Files"
},
{
"id": "translationProgress",
Expand All @@ -79,47 +79,65 @@
},
"commands": [
{
"command": "tmsFiles.refresh",
"command": "config.create",
"title": "Create configuration",
"category": "Crowdin"
},
{
"command": "config.open",
"title": "Open configuration",
"category": "Crowdin"
},
{
"command": "files.refresh",
"title": "Refresh",
"icon": {
"light": "resources/light/refresh.svg",
"dark": "resources/dark/refresh.svg"
}
},
{
"command": "tmsFiles.downloadAll",
"title": "Download translations",
"command": "files.downloadAll",
"title": "Download all translations",
"icon": {
"light": "resources/light/download.svg",
"dark": "resources/dark/download.svg"
}
},
{
"command": "tmsFiles.download",
"title": "Download translations",
"command": "files.download",
"title": "Download project translations",
"icon": {
"light": "resources/light/download.svg",
"dark": "resources/dark/download.svg"
}
},
{
"command": "tmsFiles.saveAll",
"title": "Upload source files",
"command": "files.saveAll",
"title": "Upload all source files",
"icon": {
"light": "resources/light/upload.svg",
"dark": "resources/dark/upload.svg"
}
},
{
"command": "tmsFiles.save",
"title": "Upload source files",
"command": "files.saveFolder",
"title": "Upload source folder",
"icon": {
"light": "resources/light/upload.svg",
"dark": "resources/dark/upload.svg"
}
},
{
"command": "tmsFiles.edit",
"command": "files.saveFile",
"title": "Upload source file",
"icon": {
"light": "resources/light/upload.svg",
"dark": "resources/dark/upload.svg"
}
},
{
"command": "files.edit",
"title": "Edit configuration",
"icon": {
"light": "resources/light/settings.svg",
Expand All @@ -135,15 +153,15 @@
}
},
{
"command": "tmsFiles.updateSourceFolder",
"command": "files.updateSourceFolder",
"title": "Download source files",
"icon": {
"light": "resources/light/download_source.svg",
"dark": "resources/dark/download_source.svg"
}
},
{
"command": "tmsFiles.updateSourceFile",
"command": "files.updateSourceFile",
"title": "Download source file",
"icon": {
"light": "resources/light/download_source.svg",
Expand All @@ -154,23 +172,23 @@
"menus": {
"view/title": [
{
"command": "tmsFiles.refresh",
"when": "view == tmsFiles",
"command": "files.refresh",
"when": "view == files",
"group": "navigation@0"
},
{
"command": "tmsFiles.saveAll",
"when": "view == tmsFiles",
"command": "files.saveAll",
"when": "view == files",
"group": "navigation@1"
},
{
"command": "tmsFiles.downloadAll",
"when": "view == tmsFiles",
"command": "files.downloadAll",
"when": "view == files",
"group": "navigation@2"
},
{
"command": "tmsFiles.updateSourceFolder",
"when": "view == tmsFiles",
"command": "files.updateSourceFolder",
"when": "view == files",
"group": "navigation@3"
},
{
Expand All @@ -181,28 +199,33 @@
],
"view/item/context": [
{
"command": "tmsFiles.edit",
"when": "view == tmsFiles && viewItem == tmsRoot",
"command": "files.edit",
"when": "view == files && viewItem == root",
"group": "inline@0"
},
{
"command": "tmsFiles.save",
"when": "view == tmsFiles",
"command": "files.saveFolder",
"when": "view == files && viewItem == folder",
"group": "inline@1"
},
{
"command": "files.saveFile",
"when": "view == files && viewItem == file",
"group": "inline@1"
},
{
"command": "tmsFiles.download",
"when": "view == tmsFiles && viewItem == tmsRoot",
"command": "files.download",
"when": "view == files && viewItem == root",
"group": "inline@2"
},
{
"command": "tmsFiles.updateSourceFolder",
"when": "view == tmsFiles && viewItem == tmsRoot",
"command": "files.updateSourceFolder",
"when": "view == files && viewItem == root",
"group": "inline@3"
},
{
"command": "tmsFiles.updateSourceFile",
"when": "view == tmsFiles && viewItem == tmsFile",
"command": "files.updateSourceFile",
"when": "view == files && viewItem == file",
"group": "inline@4"
}
]
Expand Down
27 changes: 27 additions & 0 deletions src/config/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,40 @@
import { FileModel, Scheme } from './fileModel';

const asyncFileExists = util.promisify(fs.exists);
const asyncWriteFile = util.promisify(fs.writeFile);
const asyncReadFile = util.promisify(fs.readFile);

const DEFAULT_CONFIG = `"project_id_env": "CROWDIN_PROJECT_ID"
"api_token_env": "CROWDIN_PERSONAL_TOKEN"

"files": [
{
"source": "",
"translation": ""
}
]
`;

export class ConfigProvider {
private static readonly crowdinFileNames = ['crowdin.yml', 'crowdin.yaml'];

constructor(public readonly workspace: vscode.WorkspaceFolder) {}

async create(): Promise<{ file: string; isNew: boolean }> {
let filePath = await this.getFile();

if (filePath) {
return { file: filePath, isNew: false };
}

const fileName = this.fileNames()[0];
const file = path.join(this.workspace.uri.fsPath, fileName);

await asyncWriteFile(file, DEFAULT_CONFIG);

return { file, isNew: true };
}

async load(): Promise<ConfigModel> {
let filePath = await this.getFile();

Expand Down Expand Up @@ -179,23 +206,23 @@
}

interface PrivateConfigModel {
project_id: string;

Check warning on line 209 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `project_id` must match one of the following formats: camelCase

Check warning on line 209 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `project_id` must match one of the following formats: camelCase
project_id_env: string;

Check warning on line 210 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `project_id_env` must match one of the following formats: camelCase

Check warning on line 210 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `project_id_env` must match one of the following formats: camelCase
base_url?: string;

Check warning on line 211 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_url` must match one of the following formats: camelCase

Check warning on line 211 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_url` must match one of the following formats: camelCase
base_url_env?: string;

Check warning on line 212 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_url_env` must match one of the following formats: camelCase

Check warning on line 212 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_url_env` must match one of the following formats: camelCase
api_token: string;

Check warning on line 213 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `api_token` must match one of the following formats: camelCase

Check warning on line 213 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `api_token` must match one of the following formats: camelCase
api_token_env: string;

Check warning on line 214 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `api_token_env` must match one of the following formats: camelCase

Check warning on line 214 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `api_token_env` must match one of the following formats: camelCase
branch?: string;
base_path?: string;

Check warning on line 216 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path` must match one of the following formats: camelCase

Check warning on line 216 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path` must match one of the following formats: camelCase
base_path_env?: string;

Check warning on line 217 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path_env` must match one of the following formats: camelCase

Check warning on line 217 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path_env` must match one of the following formats: camelCase
files: PrivateFileModel[];
}

interface PrivateFileModel {
source: string;
translation: string;
update_option?: string;

Check warning on line 224 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `update_option` must match one of the following formats: camelCase

Check warning on line 224 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `update_option` must match one of the following formats: camelCase
excluded_target_languages?: string[];

Check warning on line 225 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `excluded_target_languages` must match one of the following formats: camelCase

Check warning on line 225 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `excluded_target_languages` must match one of the following formats: camelCase
labels?: string[];
scheme?: string;
dest?: string;
Expand Down
29 changes: 24 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@ import * as vscode from 'vscode';

export class Constants {
static EXTENSION_CONTEXT: vscode.ExtensionContext;
static readonly OPEN_TMS_FILE_COMMAND = 'extension.openTmsFile';
static readonly AUTO_REFRESH_PROPERTY = 'tms.autoRefresh';
static readonly STRINGS_COMPLETION_PROPERTY = 'tms.stringsCompletion';
static readonly STRINGS_COMPLETION_FILES_FILTER_PROPERTY = 'tms.stringsCompletionFileExtensions';
static readonly USE_GIT_BRANCH_PROPERTY = 'tms.useGitBranch';
//tree providers
static readonly FILES = 'files';
static readonly PROGRESS = 'translationProgress';
//commands
static readonly VSCODE_OPEN_FILE = 'vscode.open';
static readonly CREATE_CONFIG_COMMAND = 'config.create';
static readonly OPEN_CONFIG_COMMAND = 'config.open';
static readonly OPEN_FILE_COMMAND = 'extension.openFile';
static readonly REFRESH_PROGRESS_COMMAND = 'translationProgress.refresh';
static readonly DOWNLOAD_ALL_COMMAND = 'files.downloadAll';
static readonly SAVE_ALL_COMMAND = 'files.saveAll';
static readonly SAVE_FOLDER_COMMAND = 'files.saveFolder';
static readonly SAVE_FILE_COMMAND = 'files.saveFile';
static readonly DOWNLOAD_COMMAND = 'files.download';
static readonly EDIT_COMMAND = 'files.edit';
static readonly REFRESH_COMMAND = 'files.refresh';
static readonly UPDATE_SOURCE_FOLDER_COMMAND = 'files.updateSourceFolder';
static readonly UPDATE_SOURCE_FILE_COMMAND = 'files.updateSourceFile';
//properties
static readonly AUTO_REFRESH_PROPERTY = 'crowdin.autoRefresh';
static readonly STRINGS_COMPLETION_PROPERTY = 'crowdin.stringsCompletion';
static readonly STRINGS_COMPLETION_FILES_FILTER_PROPERTY = 'crowdin.stringsCompletionFileExtensions';
static readonly USE_GIT_BRANCH_PROPERTY = 'crowdin.useGitBranch';
//general
static readonly CROWDIN_PATH_SEPARATOR = '/';
static readonly PLUGIN_VERSION = '1.5.1';
static readonly CLIENT_RETRIES = 5;
Expand Down
Loading
Loading