How to ignore the parent "src" directory when transpiling using Babel watcher - webstorm

My code has the directory structure:
project-root/
└── src/
└── main.js
When I run the default Babel file watcher, the code is transpiled into a dist folder, including the src directory in it's path, like so:
project-root/
└── src/
├── main.js
dist/
└── src
└── main.dist.js
What I want instead is for the src to be excluded from the path - in other words, for the transpiled code in src to be "unwrapped" and compiled straight into dist, like the following:
project-root/
└── src/
├── main.js
dist/
└── main.dist.js
Is it be possible to change the watcher config to achieve this? I can't figure it out! Any help is much appreciated.

it's the --out-dir Babel CLI option behavior - it recreates the source folder structure (relative to working dir) in the destination directory.
You have 2 options here:
use --out-file instead
set src as your working directory
Possible setup for the first option:
Arguments: $FilePathRelativeToProjectRoot$ --out-file dist/$FileNameWithoutExtension$.js --source-maps --presets env
Output paths to refresh: dist\$FileNameWithoutExtension$.js:dist\$FileNameWithoutExtension$.js.map
For the second:
Arguments: $FileDirPathFromParent(src)$$FileName$ --out-dir $ProjectFileDir$/dist --source-maps --presets env
Output paths to refresh: $ProjectFileDir$/dist/$FileDirPathFromParent(src)$FileNameWithoutExtension$.js:$ProjectFileDir$/dist/$FileDirPathFromParent(src)$FileNameWithoutExtension$.js.map
Working directory: $ContentRoot$\src

Related

How to get unit tests (using CMake and GTest) to know where a folder of test data is?

I am using CMake and GTest to unit test a C++ program. One of my tests uses fopen() to open a file of test data.
I am struggling to figure out how to not get a "No such file or directory" error.
Directory Structure
├── CMakeLists.txt
├── build
├── src
│ └── myProgram.cxx
└── tests
├── CMakeLists.txt
├── data
│ ├── dataset1.txt
│ ├── dataset2.txt
│ ├── dataset3.txt
│ └── dataset4.txt
└── myProgramTests.cxx
Test Code
TEST(test, read_data_file) {
// Open test file
std::FILE *f = fopen("inputs/dataset1.txt", "r");
if (f == NULL){
perror ("Error opening file");
}
fclose(f);
}
This seems simple, but I can't figure out what to put here. I have tried "dataset1.txt", "inputs/dataset1.txt", "tests/inputs/dataset1.txt". What am I missing / is there a way for me into "include" these files via a line in CMakeLists.txt so I can just read them in with one of the strings I tried above?
Summary: How do I properly reference the location of files stored in a tests/data subdirectory within GTest?
Use ctest of cmake. Its add_test command has a useful property WORKING_DIRECTORY that are you looking for.
Paths that do not start with a / are relative to your current working directory, i.e the directory your shell is in when you run the tests.
For example, if your current working directory is the top-level directory of your project, then the relative path to dataset1.txt is tests/data/dataset1.txt

How do I import a package from the local filesystem using dub?

I have a project that uses dub. I want to use an external file vendored into my project, as a dependency. How do I do this? I don't want to have it in my project's source/ dir. I don't want to add it as a dub managed dependency, but I do want to be able to just import xxx.
The package is this one: https://github.com/gianm/d-json , it does not use dub or have a dub.json project file.
Alternative thing: make a third_party directory, put the file in there, then add that to the sourcePaths in your dub config (you'll probably specify both ["third_party", "source"] since the default source will be overridden if you don't list it too.
Convert the package to dub by adding a dub.json file in the root, with the following contents: {"name": "jsonx"}. Create a source folder, and move jsonx.d into it.
Put the folder anywhere you want, e.g. top-level next to your own project.
Add the following dependency to your dub.json:
"dependencies": {
...
"jsonx": {"path": "../jsonx/"}
}
You can now import the package anywhere using import jsonx;.
In conclusion, if your app is in a dir called app, your tree should look like this:
.
├── app
│   ├── dub.json
│   └── source
│      └── myapp.d
└── jsonx
├── dub.json
└── source
└── jsonx.d

Sublime Linter with clang can't find header file in header

I'm using sublime text with the sublime linter plugin especially with clang.
When I open a folder, it use the root of the folder as a header location, so if I have
src
├── World
│   ├── Chunk.cpp
│   ├── Chunk.hpp
│   ├── World.cpp
│   └── World.hpp
└── main.cpp
In World.cpp I need to include "World/World.hpp".
But if in World.hpp I include Chunk.hpp the same way ("World/Chunk.hpp"), I get an error but
in World.hpp I have no error. Error are only in file I include that include other file.
I had the same issue. You need to tell clang where to look for the files, i.e. which directories you want to include. Go Preferences --> Package Settings --> SublimeLinter --> Settings and add a new section for clang++:
// SublimeLinter Settings - User
{
"linters":
{
"clang++": {
"I" : [
"${folder}/src",
"${file_path}",
]
}
}
}
In your case the two include directories will actually point to the same path but in general, the first version is to include your source directory (e.g. you have a unit test from a different folder open which accesses code from you src directory) and the second line includes the location of your current file.
If you need different directories, find some more variables you can use here.

gitignore pattern to include all directories with a specific sub directory

I am trying to setup a .gitignore file for openFrameworks. I have a folder that contain project folders - each one has a src directory. I would like to include the folder itself and the src directory only for every project.
Here is my current .gitignore file
# ignore these files
# ignoring everything except spec items
*
# allow these files
!.gitignore
!/README.md
!/*/src
Any help would be greatly appreciated. Ideally I would like the committed folder structure to look something like this:
.
├── project_1
│   └── src
│   └── file.cpp
├── project_2
│   └── src
│   └── file.cpp
└── project_3
└── src
└── file.cpp
What am I missing? Thank you.
If you ignore files and folders (with '*'), you won't be able to exclude sub-folders.
The rule to remember remains:
It is not possible to re-include a file if a parent directory of that file is excluded.
Try instead ignoring files only.
**
Then you can exclude subfolders like src:
!.gitignore
!/README.md
!src/
# or, to be more specific
!/*/src
For any element that would be still ignored, check what rule is involved with:
git check-ignore -v -- an/ignored/element

C++ debugging with gdb & bazel (& emacs)

I want to debug an executable generated with Bazel. The gdb debugger is lost with the links generated by Bazel and is not able to show me the C++ source code. How to fix that?
The project root directory is /home/.../Cpp/
./Cpp/
├── bazel-bin -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bazel-Cpp -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bazel-genfiles -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bazel-out -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bin
│   ├── BUILD
│   └── main.cpp
├── MyLib
│   ├── BUILD
│   ├── ....hpp
│   ├── ...cpp
└── WORKSPACE
The first step is to generate executables using the debug mode:
bazel build ... --compilation_mode=dbg -s
(the -s option is not mandatory it only shows the executed commands, you can remove it if you want)
gdb debugging from the command line:
You can start gdb with this command (from your project root directory):
gdbtui bazel-bin/bin/main
-> everything is okay, you should see your C++ source code.
The error would be to do:
cd bazel-bin/bin/
gdbtui main
In that case, because of the links, gdb is not able to retrieve the source code.
gdb debugging from Emacs:
Do as usual
M-x gdb
In the emacs prompt define the complete absolute path to the executable:
gdb -i=mi /home/picaud/.../Cpp/bazel-bin/bin/main
Now in the gdb buffer you must tell gdb where to find source by defining your absolute path to the project root directory (where your WORKSPACE file is):
set directories /home/picaud/.../Cpp
Now the emacs gdb command should work properly and you can debug as usual.
(well this was an easy fix, just a note that maybe can help...)