How do I prevent the generated Javascript files from being edited in a TypeScript project?

Is it possible in a Visual Studio 2012 project to enforce a rule that prevents developers from trying to directly edit (accidentally / old habit) JavaScript files generated by TypeScript files?

I have a project with a lot of TypeScript files, which in turn generate a lot of JavaScript files that need to be included in the project. However, I'm picking JavaScript files myself out of habit, rather than picking the version of the TypeScript file to edit. I would like to prevent this. Since these TypeScript / JavaScript files are related to each other, I cannot nest them.

The project is a Windows Store app with WinJS. It has three different Windows Store projects and a set of Solution Shared Folders that include the bulk of the TypeScript / JavaScript files that are linked to projects using the syntax below in the project files:

<Content Include="..\Shared\**\*.*">
  <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

      

This allows me to include all files in the shared directory and subdirectories as auto-linked files. This is really handy for sharing linked files, but it means I can nest individual files because the recursive file linking will break.

My original control is git. So I suppose there is a way to prevent git from editing .js files? Look for suggestions.

+2


source to share


3 answers


So I suppose there is a way to prevent git from editing .js files?

We have .js files excluded from the repo with .gitignore

. These js files are re-created as part of the build / deployment.



This is similar to how you didn't include files *.exe

/ *.dll

in the git repository.

+6


source


I recently started using Visual Studio Code. In user settings, you can hide js files completely.

Choose:

File | Settings | User Settings



add to the editor on the right side (you cannot change the default settings).

"files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/*.js": true,
    "**/*.js.map":true
}

      

I'm not sure if you need the first two lines, but they were in the default settings that I just copied. Obviously, if you want to view JavaScript files again, just switch true to false.

+1


source


I'm not sure if there is a way to block direct editing of JS files as they are in your project.

You can use Gulp, for example, to view all your files and generate a JS file from its TS file if there is a modification in the JS file.

It's not perfect, but it stopped the developer from printing things in the JS file.

https://www.npmjs.com/package/gulp-watch

0


source







All Articles