I am looking to compile a single .ts file to stdout, something like this:
tsc foo.ts > foo.js
is this possible somehow? I want to control where the output goes without using a tsconfig.json file.
tsc foo.ts --out /dev/stdout | another-program
It comes from this discussion.
Related
I have following setup under my project:
/assets/scss has many SCSS files organized under different subdirectories; including a root global.scss file. As you can imagine, global.scss will only have #imports.
/assets/css is set as output directory. I am trying to output only one file under this folder - global.css.
package.json has this command
"scripts": {
"scss": "node-sass --watch assets/scss/styleguide.scss -o assets/css --recursive"
}
When I run npm run scss it outputs subdirectory CSS files as well. Does anyone know how to avoid output of subdirectory sass files?
Thanks in advance!
You are passing the --recursive argument to node-sass. That will mean that node-sass will search recursively on every directory under assets/scss and will compile all the scss files found. To avoid that behavior just remove the --recursive option:
"scripts": {
"scss": "node-sass --watch assets/scss/styleguide.scss -o assets/css"
}
More about node-sass usages and options can be found here.
Simple one, but could not find the answer anywhere online! Installed sass globally (npm install -g sass) on my Mac.
This works as expected:
sass style.scss style.css
Then I try:
sass --watch style.scss:style.css
And get:
Could not find an option named "watch".
Usage: sass <input> [output]
--[no-]stdin Read the stylesheet from stdin.
--[no-]indented Use the indented syntax for input from stdin.
-I, --load-path=<PATH> A path to use when resolving imports.
May be passed multiple times.
-s, --style=<NAME> Output style.
[expanded (default), compressed]
-c, --[no-]color Whether to emit terminal colors.
-q, --[no-]quiet Don't print warnings.
--[no-]trace Print full Dart stack traces for exceptions.
-h, --help Print this usage information.
--version Print the version of Dart Sass.
What am I missing??
Thanks!!
First create the SASS's folder, and in there create your SASS's file. Example:
sass/styles.sass
In your project root folder, open the console and type the command:
sass --watch sass/styles.sass:css/styles.css
This command will create your CSS's folder and CSS's file. In addition to compiling your .sass content for your .css.
In the end, I gave up on sass as tried above, and went for a solution with webpack.
Another option I tried which worked was to use node-sass.
I solved running this command on your terminal
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
i hope that help
I have this (in gulpfile.js):
var gulp = require("gulp");
var mocha = require("gulp-mocha");
gulp.task("test", function() {
gulp
.src(["./**/*_test.js", "!./node_modules/**/*.js"]);
});
and it works.
I want to replicate the same behavior, excluding "node_modules" folder, from mocha command, running npm test (in package.json):
"scripts": {
"test": "mocha **\\*_test.js !./node_modules/**/*.js*",
}
and it doesn't work.
I'm using Windows.
Any suggestion?
I was able to solve this using globbing patterns in the argument to mocha. Like you I didn't want to put all my tests under a single tests folder. I wanted them in the same directory as the class they were testing. My file structure looked like this:
project
|- lib
|- class1.js
|- class1.test.js
|- node_modules
|- lots of stuff...
Running this from the project folder worked for me:
mocha './{,!(node_modules)/**}/*.test.js'
Which match any *.test.js file in the tree, so long is its path isn't rooted at ./node_modules/.
This is an online tool for testing glob patterns that I found useful.
You can exclude files in mocha by passing opts
mocha -h|grep -i exclude
--exclude <file> a file or glob pattern to ignore (default: )
mocha --exclude **/*-.jest.js
Additionally, you can also create a test/mocha.opts file and add it there
# test/mocha.opts
--exclude **/*-test.jest.js
--require ./test/setup.js
If you want to exclude a particular file type you could do something like this
// test/setup.js
require.extensions['.graphql'] = function() {
return null
}
This is useful when processing extensions with a module loader such as webpack that mocha does not understand.
For Windows users
This script will run perfectly
"test": "mocha \"./{,!(node_modules)/**/}*.test.js\"",
I hope this will help.
cheers!
I'm not a guru on mocha or ant-style pattern but maybe it isn't possible escluding specific path in the mocha command line.
You can put all your test files under a test folder, and set your package.json like this:
"scripts": {
"test": "mocha ./test/**/*_test.js"
}
You can also provide more than one starting folder:
"scripts": {
"test": "mocha ./test/**/*_test.js ./another_test_folder/**/*_test.js"
}
As of 2019 the modern way of configuring Mocha under Node is via config file in your project root (e.g. via .mocharc.js).
Here is the example of the .mocharc.js that
rederfines the default test directory (spec key) and
excludes the example (or can be any experimental tests) from the overall suite (exclude key).
module.exports = {
'spec': 'src/front/js/tests/**/*.spec.js',
'exclude': 'src/front/js/tests/examples/*.spec.js',
'reporter': 'dot'
};
As you may see there can be more options used in the config. In part they are just replicas of Mocha CLI options. Just look up ones what you like and try to use within .mocharc.js (use camelCase for dash-comprising CLI options). Or see the config examples.
As suggested in a comment by #thebearingedge, in the end I put ALL the source files (with the relative test files) in a new "src" dir.
In this way I can define the root for tests with a path that exclude by default the "node_modules" folder.
.
├── src
├── fileA.js
├── fileA_test.js
├── fileB.js
├── fileB_test.js
├── node_modules
├── ...
I had to update the path in the package.json, gulpfile.js and in some batch files that I use as utilities.
Changes in gulpfile.js:
.src(["./src/**/*_test.js"]);
and in package.json:
"test": "mocha src\\**\\*_test.js",
Simple change and it works.
I'm free to choose whatever naming conventions I like.
Each test files remain close to the relative JS file.
I had a spec directory containing all my specs. Within that directory, I had several sub-directories, one of which was the e2e specs directory. In that scenario, I used the mocha specs $(find specs -name '*.js' -not -path "specs/e2e/*") command to run all my tests ignoring those within the e2e directory.
I've run browserify like this:
browserify js/app.js -d | exorcist js/bundle.js.map > js/bundle.js
When I load this in Chrome, the sources map file is fine. When I uglify it like this:
uglifyjs js/bundle.js --in-source-map js/bundle.js.map --source-map-url bundle2.js.map --source-map js/bundle2.js.map -o js/bundle2.js -p 1
The sources map file does not work. It tries to load sources from /js/js, instead of just from /js. I have fiddled with the -p parameter, and every other parameter that is documented on the commandline here:
https://github.com/mishoo/UglifyJS2
The only way I could get this to work was to cd into the js directory and run the commands from there. Lame, but it works.
-p relative
fixed the issue for me
I'm using CMake to genenerate my Makefile's however I cannot generate the .clang_complete using the standard
make CC='~/.vim/bin/cc_args.py gcc' CXX='~/.vim/bin/cc_args.py g++' -B
nothing gets generated...
the tree structure looks like so
Root
|
|_core
| |_src
| | |_main.cpp
| | |_CMakeLists.txt (1)
| |_inc
| |_CMakeLists.txt (2)
|
|_lib
| |_rtaudio
|
|_CMakeLists.txt (3)
CMakeLists.txt (1) file:
include_directories("${Dunkel_SOURCE_DIR}/core/inc")
include_directories("${Dunkel_SOURCE_DIR}/lib/")
link_directories("${Dunkel_SOURCE_DIR}/lib/rtaudio")
add_executable(Dunkel main.cpp)
target_link_libraries(Dunkel rtaudio)
CMakeLists.txt (2) file:
subdirs(src)
CMakeLists.txt (3) file:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(Dunkel)
SUBDIRS(core)
set(CMAKE_CXX_FLAGS "-g")
What am I doing wrong here?
Looks like contrary to make cmake doesn't expand tilde, hence it treats is as part of the path. To make it work as expected either use absolute path to the cc_args.py script or do two simple changes in the command:
Replace the tilde with $HOME.
Replace single quotes with double quotes.
After the changes your command should look like this:
CXX="$HOME/.vim/bin/cc_args.py g++" cmake ..
And it should work.
You should run (in your build directory)
CXX='~/.vim/bin/cc_args.py g++' cmake ..
and then run make as usual. Note that this will run the cc_args.py script every time you build the project with make, if you want to disable this, re-run cmake again.
The file .clang_complete will be created in the build directory, move it if needed.
See also Vim: Creating .clang_complete using CMake
It is important to use $HOME/.vim/bin/cc_args.py and not ~/.vim/bin/cc_args.py, because ~ might not get expanded when quoted.
Also, verify the presence of the python script with:
$ ls -l $HOME/.vim/bin/cc_args.py
-rwxr-xr-x 1 myself staff 2270 Sep 19 16:11 /home/myself/.vim/bin/cc_args.py
if not found, adjust the python script path as necessary.
Run make clean in the build dir.
As suggested by #xaizek, start with an empty build directory (assuming the build directory is a subdir of the source dir):
CXX="$HOME/.vim/bin/cc_args.py g++" cmake ..
followed by:
make
at this point, make will be building the project, but calling cc_args.py (which will call g++), instead of directly calling g++.
However this part for me is failing to work, and no .clang_complete file is created in the build directory or anywhere else.
In fact, there is no occurrence of "cc_args" in the generated CMakeCache.txt / Makefile, so I suspect CXX is not the correct variable name to pass to cmake.
When finished, copy .clang_complete to the parent dir.
Here is what worked for me
sudo chmod a+x $HOME/.vim/bin/cc_args.py
CXX="$HOME/.vim/bin/cc_args.py g++" sudo cmake ..
sudo make
and then ls -a shows my .clang_complete file but still emtyp though.