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

Webpack changes with eslint changes #84

Merged
merged 4 commits into from
Feb 9, 2024
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
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"./tsconfig.json"
]
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-var": "off",
"prefer-const": "off",
"quotes": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
},
"ignorePatterns": [
"src/**/*.test.ts",
"src/test/**/*ts"
]
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to the **ResxPress** extension will be documented in this fi

---

## 6.0.1 - 08-Feb-2024

- Fixed an issue where webpack did not export webpanelScript.js
- Updated es-lint

## 6.0.0 - 08-Feb-2024

- Custom editor is set to *optional* now to be compatible with git diff. You can still open ResxEditor from editor context menu for resx files. Right click on file -> Open with -> select ResXpress Editor.
Expand Down
15 changes: 0 additions & 15 deletions eslint.json

This file was deleted.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"color": "#123456",
"theme": "dark"
},
"version": "6.0.0",
"version": "6.0.1",
"engines": {
"vscode": "^1.69.0"
},
Expand Down Expand Up @@ -108,7 +108,7 @@
"markdown": "standard",
"scripts": {
"compile": "tsc -p ./",
"lint": "eslint src --ext ts",
"lint": "eslint -c .eslintrc.json --ext .ts ./src",
"watch": "tsc -watch -p ./",
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
Expand All @@ -121,11 +121,13 @@
"@types/node": "^18.11.18",
"@types/vscode": "^1.69.0",
"@types/xml-js": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"glob": "^8.0.3",
"mocha": "^10.2.0",
"ts-loader": "^9.2.3",
"tslint": "^6.1.3",
"typescript": "^4.1.5",
"typescript": "*",
"vscode-test": "^1.5.1",
"webpack": "^5.23.0",
"webpack-cli": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/dispose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import * as vscode from "vscode";

export function disposeAll(disposables: vscode.Disposable[]): void {
while (disposables.length) {
Expand Down
184 changes: 86 additions & 98 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as vscode from 'vscode';
import * as vscode from "vscode";

import { promises as fsPromises } from 'fs';
import { promises as fsPromises } from "fs";
import { PreviewEditPanel } from "./previewEditPanel";
import * as path from "path";
import * as xmljs from "xml-js";
import { ResxEditorProvider } from './resxEditorProvider';
import { NotificationService } from './notificationService';
import * as childProcess from 'child_process';
import { ResxEditor } from './resxEditor';
import { ResxEditorProvider } from "./resxEditorProvider";
import { NotificationService } from "./notificationService";
import * as childProcess from "child_process";
import { FileHelper } from "./fileHelper";


let currentContext: vscode.ExtensionContext;
var shouldGenerateStronglyTypedResourceClassOnSave: boolean = false

Expand All @@ -26,7 +24,7 @@ export function activate(context: vscode.ExtensionContext) {
currentContext = context;
loadConfiguration();

vscode.workspace.onDidChangeConfiguration((configChangeEvent: vscode.ConfigurationChangeEvent) => {
vscode.workspace.onDidChangeConfiguration(() => {
loadConfiguration();
});

Expand Down Expand Up @@ -110,77 +108,60 @@ function loadConfiguration() {
}

export async function runResGenAsync(fileName: string): Promise<void> {
try {
if (process.platform == "win32") {
let pathFile = path.parse(fileName);
let fileNameNoExt = pathFile.name;

//best effort to get existing resource class file name
let files = await vscode.workspace.findFiles(`**/${fileNameNoExt}.Designer.*`, '**/*.dll', 1)

var resourceFileName = "";
var ext = "cs"
if (files.length === 1) {
let filePath = path.parse(files[0].path);
ext = filePath.ext.substring(1)
resourceFileName = `${path.join(pathFile.dir, filePath.name)}.${ext}`
}
else {
resourceFileName = `${path.join(pathFile.dir, pathFile.name)}.Designer.${ext}`
}
let filename = FileHelper.getFileName();
let csharpFileName = "Resources.cs";
if (filename !== null) {
csharpFileName = `${filename}.Designer.cs`;
}

let nameSpace = path.basename(path.dirname(fileName));
let parameter = `/str:${ext},${nameSpace},,${resourceFileName}`
console.log('Parameter: ' + parameter);
const cli = childProcess.spawn('ResGen', [`${fileName}`, '/useSourcePath', parameter], { stdio: ['pipe'] });
let nameSpace = await FileHelper.tryGetNamespace();
if (nameSpace === null || nameSpace === "") {
nameSpace = path.basename(path.dirname(fileName));
}

var stdOutData = "";
var stdErrData = "";
cli.stdout.setEncoding("utf8");
cli.stdout.on("data", data => {
stdOutData += data;
});
if (process.platform == "win32") {

cli.stderr.setEncoding("utf8");
cli.stderr.on("data", data => {
stdErrData += data;
});
var ext = "cs";

let promise = new Promise<void>((resolve, reject) => {
cli.on("close", (exitCode: Number) => {
if (exitCode !== 0) {
reject();
console.log(stdErrData)
}
else {
resolve();
console.log(stdOutData)
}
});
});
return promise;
}
else {
let filename = FileHelper.getFileName();
var csharpFileName = "Resources.cs";
if (filename !== null) {
csharpFileName = `${filename}.Designer.cs`;
}
let parameter = `/str:${ext},${nameSpace},,${csharpFileName}`
console.log("Parameter: " + parameter);
const cli = childProcess.spawn("ResGen", [`${fileName}`, "/useSourcePath", parameter], { stdio: ["pipe"] });

let documentText = FileHelper.getActiveDocumentText();
if (documentText != "") {
var jsObj = xmljs.xml2js(documentText);
var resourceCSharpClassText = "";
let accessModifier = "public";
let workspacePath = FileHelper.getDirectory();

var namespace = PreviewEditPanel.namespace;
if (namespace === undefined || namespace === "" || namespace === null) {
if (workspacePath !== null) {
namespace = path.basename(workspacePath);
}
var stdOutData = "";
var stdErrData = "";
cli.stdout.setEncoding("utf8");
cli.stdout.on("data", data => {
stdOutData += data;
});

cli.stderr.setEncoding("utf8");
cli.stderr.on("data", data => {
stdErrData += data;
});

let promise = new Promise<void>((resolve, reject) => {
cli.on("close", (exitCode: number) => {
if (exitCode !== 0) {
reject();
console.log(stdErrData)
}
else {
resolve();
console.log(stdOutData)
}
resourceCSharpClassText += `namespace ${namespace}
});
});
return promise;
}
else {
let documentText = FileHelper.getActiveDocumentText();
if (documentText != "") {
var jsObj = xmljs.xml2js(documentText);
var resourceCSharpClassText = "";
let accessModifier = "public";
let workspacePath = FileHelper.getDirectory();

resourceCSharpClassText += `namespace ${nameSpace}
{
using System;

Expand Down Expand Up @@ -239,34 +220,32 @@ export async function runResGenAsync(fileName: string): Promise<void> {

`;

jsObj.elements[0].elements.forEach((element: any) => {
if (element.name === "data") {
resourceCSharpClassText += `
jsObj.elements[0].elements.forEach((element: any) => {
if (element.name === "data") {
let name = element.attributes.name.replace(" ", "_");
resourceCSharpClassText += `

/// <summary>
/// Looks up a localized string similar to ${element.elements[0].text}.
/// </summary>
${accessModifier} static string ${element.attributes.name} => ResourceManager.GetString("${element.attributes.name}", resourceCulture);
${accessModifier} static string ${name} => ResourceManager.GetString("${element.attributes.name}", resourceCulture);

`;
}
}

});
});

resourceCSharpClassText += `}
resourceCSharpClassText += `}
}`;
console.log(resourceCSharpClassText);
console.log(resourceCSharpClassText);


if (workspacePath != null) {
let pathToWrite = path.join(workspacePath, csharpFileName);
await FileHelper.writeToFile(pathToWrite, resourceCSharpClassText);
}
if (workspacePath != null) {
let pathToWrite = path.join(workspacePath, csharpFileName);
await FileHelper.writeToFile(pathToWrite, resourceCSharpClassText);
}
}
}
catch (error) {
throw error;
}
}

// this method is called when your extension is deactivated
Expand Down Expand Up @@ -306,8 +285,8 @@ function sortKeyValuesResx(reverse?: boolean) {
var text = vscode.window.activeTextEditor?.document?.getText() ?? "";
var jsObj = xmljs.xml2js(text);

var dataList = new Array();
var sorted = new Array();
var dataList: any = [];
var sorted: any = [];
jsObj.elements[0].elements.forEach((x: any) => {
if (x.name === "data") {
dataList.push(x);
Expand All @@ -318,14 +297,23 @@ function sortKeyValuesResx(reverse?: boolean) {
});

var dataListsorted = dataList.sort((x1: any, x2: any) => {
return x1.attributes.name < x2.attributes.name
? -1
: x1.attributes.name > x2.attributes.name
? 1
: 0;
if (reverse) {
return x1.attributes.name > x2.attributes.name
? -1
: x1.attributes.name < x2.attributes.name
? 1
: 0;
} else {
return x1.attributes.name < x2.attributes.name
? -1
: x1.attributes.name > x2.attributes.name
? 1
: 0;
}

});

sorted.push.apply(sorted, dataListsorted);
sorted.push(...dataListsorted);
jsObj.elements[0].elements = sorted;

var xml = xmljs.js2xml(jsObj, { spaces: 4 });
Expand Down Expand Up @@ -353,8 +341,8 @@ function getDataJs(): any[] {
async function newPreview() {
var text = vscode.window.activeTextEditor?.document?.getText() ?? "";
var jsObj = xmljs.xml2js(text);
var dataList = new Array();
var sorted = new Array();
var dataList: any = [];
var sorted = [];
jsObj.elements[0].elements.forEach((x: any) => {
if (x.name === "data") {
dataList.push(x);
Expand Down
Loading
Loading