compile-hero icon indicating copy to clipboard operation
compile-hero copied to clipboard

variable support settings.json

Open hakantr opened this issue 4 years ago • 3 comments

Support for "-output-directory" for $ {folderPath} and $ {workspaceFolder} variables can be added.

hakantr avatar Dec 08 '20 21:12 hakantr

Support for "-output-directory" for $ {folderPath} and $ {workspaceFolder} variables can be added.

This is a good suggestion, but at present the underlying layer of vscode does not seem to support this feature. I will consider improving it and let vscode support this feature.

Wscats avatar Dec 09 '20 02:12 Wscats

Hello there, It can help the following code example.

export const readFileName = async ({ fileName, selectedText }: { fileName: string; selectedText?: string }) => {
    let workspaceRootPath = vscode.workspace.rootPath; 
   +let fileWorkspaceFolder = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0] : undefined;
    let fileSuffix: FileSuffix = fileType(fileName);
.
.
.
.
.
.
    let compileOptions: CompileOptions = {
        generateMinifiedHtml: config.get<boolean>("generate-minified-html"),
        generateMinifiedCss: config.get<boolean>("generate-minified-css"),
        generateMinifiedJs: config.get<boolean>("generate-minified-javascript"),
    };

    if (!compileStatus[fileSuffix]) return;
   
 +  let veriableError: string;

 +  if (outputDirectoryPath[fileSuffix].indexOf("}/") < 0 &&
        (outputDirectoryPath[fileSuffix].length - outputDirectoryPath[fileSuffix].indexOf("}")) > 1) {
 +      veriableError = fileSuffix + "; '/' must be used at the end of the variable or '}' must be the last character.";
 +      vscode.window.showErrorMessage(veriableError);
 +      return;
 +  } else if (outputDirectoryPath[fileSuffix].indexOf("${workspaceFolder}") >= 0) {
 +      outputDirectoryPath[fileSuffix] = outputDirectoryPath[fileSuffix].replace("${workspaceFolder}", String(fileWorkspaceFolder?.uri.fsPath));
 +  } else if (outputDirectoryPath[fileSuffix].indexOf("${folderPath}") >= 0) {
 +      outputDirectoryPath[fileSuffix] = outputDirectoryPath[fileSuffix].replace("${folderPath}", String(fileWorkspaceFolder?.uri.fsPath));
 +  } else if (outputDirectoryPath[fileSuffix].indexOf("$") >= 0) {
 +      let findStartNumber: number = outputDirectoryPath[fileSuffix].indexOf("$");
 +      let findEndNumber: number;
 +      if (outputDirectoryPath[fileSuffix].indexOf("}") < 0) {
 +          if (outputDirectoryPath[fileSuffix].indexOf("/") < 0) {
 +              findEndNumber = outputDirectoryPath[fileSuffix].length;
 +          } else {
 +              findEndNumber = outputDirectoryPath[fileSuffix].indexOf("/");
 +          }
 +      } else {
 +          findEndNumber = outputDirectoryPath[fileSuffix].indexOf("}");
 +      }
 +      findEndNumber++;
 +      console.log(outputDirectoryPath[fileSuffix].indexOf("}"));
 +      veriableError = fileSuffix + "; Output directory unsupported variable: " +
                        outputDirectoryPath[fileSuffix].slice(findStartNumber, findEndNumber);
 +      vscode.window.showErrorMessage(veriableError);
 +      return;
 +  }   

    let outputPath = path.resolve(fileName, "../", outputDirectoryPath[fileSuffix]);

hakantr avatar Dec 13 '20 00:12 hakantr

Thank you very much for your code ideas, you can submit it in the pull request, if merge successful, I will add your name in the contributor column.

Wscats avatar Dec 13 '20 01:12 Wscats