I'm new to Grunt (and fairly new to sublime Text), but I've downloaded the excellent grunt build system and it works well every time I save. I'm on Win8 by the way.
The only problem is that it runs all tasks/targets. I have separated my tasks into "dist" and "dev" targets and I would like it to run only the dev tasks when I use it on save.
I'd then like to create a separate build task which I would use when building for production. Is this a sensible strategy?
Anyway, I just need to know how to modify the following build system file to just run tasks with the "dev" target....
{
"cmd": ["grunt", "--no-color"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"selector": "Gruntfile.js",
"windows":
{
"cmd": ["grunt.cmd", "--no-color"]
},
"variants":
[
{
"name": "Gruntfile",
"cmd": ["grunt", "--no-color"],
"windows":
{
"cmd": ["grunt.cmd", "--no-color"]
}
}
]
}
You first need to create an task that runs all the dev targets:
grunt.registerTask('dev', ['task:dev', 'task2:dev']);
This can be run from the command-line using: grunt dev
As for the Sublime build config, "cmd" is just an array of command-line arguments.
So it would end up like this:
{
"cmd": ["grunt", "dev", "--no-color"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"selector": "Gruntfile.js",
"windows":
{
"cmd": ["grunt.cmd", "dev", "--no-color"]
},
"variants":
[
{
"name": "Gruntfile",
"cmd": ["grunt", "dev", "--no-color"],
"windows":
{
"cmd": ["grunt.cmd", "dev", "--no-color"]
}
}
]
}
All you need to do is call Grunt by specifying it's complete path. Calling grunt alone fails, even though you have the grunt-cli installed and working from the cmd prompt. Note you need to have the environment variable for nodejs set.
Windows users create your my-project.sublime-builder file and put it in C:\Users\yourname\AppData\Roaming\Sublime Text\Packages\User. Apple/Unix location will be different.
The my-project.sublime-builder file looks like:
{
"cmd": "C:\\Users\\ronni\\AppData\\Roaming\\npm\\grunt.cmd",
"working_dir": "C:\\Users\\ronni\\documents\\my-project"
}
Related
I installed the Mochawesome results reporting add-on to Cypress. The problem is that every time I finish all the tests, I only have the html file with the last one in the reports folder. Do you know how to make a report from the whole set of tests?
However, only one file is created each time, and it is the last one
and in my cypress.json I have this:
Code and tests in cypress.json:
{
"projectId": "fi4fhz",
"viewportHeight": 1080,
"viewportWidth": 1920,
"testFiles": [
"settings.js",
"test1.js",
"test2.js",
"test3.js",
"test4.js",
"test5.js",
"test6.js",
"test7.js",
"test8.js",
"test9.js",
"test10.js",
],
"env": {
"numTestsKeptInMemory": 0,
"projectUrl": "https://testlocal:6001/",
"settings": {
"SP": {
"tenant": "k.online",
"clientId": "3a15528c",
"clientSecret": ".u4L",
"administrationUrl": ""
}
},
"reporter": "mochawesome",
"reporterOptions": {
"charts": true,
"overwrite": false,
"html": false,
"json": true,
"reportDir": "cypress/report/mochawesome-report"
},
your configuration seems correct, but try to change reportDir to cypress/report and follow this steps:
After running all tests, you should find multiple "mochawesome.json" files, 1 for each spec. To create a single html report, you need one more package.
Install mochawesome-merge package (npm i mochawesome-merge)
Run mochawesome-merge "cypress/report/*.json" > mochawesome.json, this will create a single JSON file that contains all the tests.
Now run the command marge mochawesome.json (marge means MochAwesome Report GEnerator) and the mochawesome-report directory will be created where there will be an html with all your tests. Here you can see an example of my report
I've set up a tasks.json file for building a project on multiple platforms. All platforms see the same content of the project repository. This is done either via disk sharing, because of running another platform in a VM, or via sync with the Git repository.
So far so good, they all see the same task.json. However some command lines are rather long and those long lines are identical for most part.
for example:
"rm -rf build; mkdir build; cd build; ../configure --with-bash-malloc=no CFLAGS=\"-O3 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free\" LDFLAGS=-L/usr/local/lib LIBS=\"-ltcmalloc -lcurl\" CC=clang
Similar lines are there for the different platforms.
The configure part is always the same for the different platforms, so it would be nice to factor out this common part. Thus the question is if it is possible to define your own variables, so you can use them similar to ${workspaceRoot}.
Thus define somewhere
"win_dir": "build_windows",
"linux_dir": "build",
"osx_dir": "build_osx",
"configure": "../configure --with-bash-malloc=no CFLAGS=\"-O3 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free\" LDFLAGS=-L/usr/local/lib LIBS=\"-ltcmalloc -lcurl\" CC=clang"
And then write
"tasks": [
{
"taskName": "configure",
"command": "bash",
"windows": {
"args": ["-c", "rm -rf ${win_dir}; mkdir ${win_dir}; cd ${win_dir}; ${configure}"]
},
"linux": {
"args": ["-c", "rm -rf ${linux_dir}; mkdir ${linux_dir}; cd ${linux_dir}; ${configure}"]
},
"osx": {
"args": ["-c", "rm -rf ${osx_dir}; mkdir ${osx_dir}; cd ${osx_dir}; ${configure}"]
},
"isBuildCommand": true,
"problemMatcher": "$make-compile"
},
... others tasks using the variables
When making changes to the build directory or arguments passed to configure etc, then the tasks.json file needs only editing at one place, instead of many.
Perhaps it is already possible but I'm unable to find out how. I tried to do something with the declares block, but that seems to be hard tied to problemMatcher. You can find some examples, but I could not find clear documentation of of the elements of the tasks.json file and how they interact.
Perhaps I'm missing something, please educate me!
Adam Parkin's answer won't work because, at least on windows, the shell will not substitute environment variables given as arguments. ${env:...} variables as suggested in a comment on that answer won't be substituted using environment variables set in tasks.json itself, only preexisting ones. You can however add custom settings in settings.json, and reference those in tasks.json using ${config:...}.
e.g. settings.json:
{
"win_dir": "build_windows",
"linux_dir": "build",
"osx_dir": "build_osx",
"configure": "../configure --with-bash-malloc=no CFLAGS=\"-O3 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free\" LDFLAGS=-L/usr/local/lib LIBS=\"-ltcmalloc -lcurl\" CC=clang"
}
in tasks.json:
{
"tasks": [
{
"taskName": "configure",
"command": "bash",
"windows": {
"args": ["-c", "rm -rf ${config:win_dir}; mkdir ${config:win_dir}; cd ${config:win_dir}; ${config:configure}"]
},
"linux": {
"args": ["-c", "rm -rf ${config:linux_dir}; mkdir ${config:linux_dir}; cd ${config:linux_dir}; ${config:configure}"]
},
"osx": {
"args": ["-c", "rm -rf ${config:osx_dir}; mkdir ${config:osx_dir}; cd ${config:osx_dir}; ${config:configure}"]
},
"isBuildCommand": true,
"problemMatcher": "$make-compile"
},
// ... other tasks using the variables
]
}
Thus the question is if it is possible to define your own variables, so you can use them similar to ${workspaceRoot}.
You could define environment variables in your tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"env": {
"win_dir": "build_windows",
"linux_dir": "build",
"osx_dir": "build_osx",
"configure": "../configure --with-bash-malloc=no CFLAGS=\"-O3 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free\" LDFLAGS=-L/usr/local/lib LIBS=\"-ltcmalloc -lcurl\" CC=clang"
}
},
"tasks": [
{
"label": "Example",
"type": "shell",
"command": "echo win_dir is $win_dir"
},
]
}
With that, you could then also use the environment matching to refer to the relevant environment variables.
I am taking a different approach.
tasks.json
{
"version": "2.0.0",
"params":{
"git_version":"2.30.0",
"node_version":"14.13.6",
"python_version":"3.8"
},
"tasks": [
{
"label":"Process Task.json",
"type":"shell",
"command":"python process_tasks.py",
"group":"build",
"isBackground":true
},
{
"label":"Test process_tasks.py",
"type":"shell",
"command":"echo $[params.git_version]",
"group":"test",
"presentation": {
"reveal": "always"
}
}
]
}
Rather than making env variables, we can follow the flowing steps:
Step 1:
Make a task in tasks.json as follows
{
"label":"Process Task.json",
"type":"shell",
"command":"python process_tasks.py",
"group":"build",
"isBackground":true
},
Step 2:
process_tasks.py is a Python file that will replace variables in tasks.json with the actual value:
import json
import os
import re
if __name__ == "__main__":
# Get the path to the JSON file
json_path = os.path.join(".vscode/tasks.json")
with open(json_path, "r") as f:
data = json.load(f)
with open(json_path, "r") as f:
lines = f.readlines()
new_lines = []
#regex to find text between $[]
regex = re.compile(r"\$\[(.*?)\]")
for line in lines:
#regex in line:
match = regex.search(line)
if match:
#get the text between $[]
text = match.group(1)
keys = text.split(".")
buffer_data = data
for key in keys:
buffer_data = buffer_data[key]
#replace the text with the value of the environment variable
line = line.replace(f"$[{text}]", buffer_data)
new_lines.append(line)
with open(json_path, "w") as f:
f.writelines(new_lines)
Step 3:
Add a test task to verify your result
{
"label":"Test process_tasks.py",
"type":"shell",
"command":"echo $[params.git_version]",
"group":"test",
"presentation": {
"reveal": "always"
}
},
Note:
Making this "Process Task.json" as a global task and adding the correct path of the process.py file in the build task will reduce a lot of work.
Thus we can define our own variables inside tasks.json and access them using $[params.git_version].
After executing the "Process Task.json" task, all variables in $[] format will be replaced by its corresponding value.
I am trying to use browserify to build a new project that my team is working on, but it does not recognize the transform from the package.json. It will build on 2 machines, but on 2 others it will not build.
Here is the relevant piece of my package.json.
"dependencies": {},
"devDependencies": {
....
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browser": {
"angular": "./src/main/webapp/js/lib/angular.js",
"angular-route": "./src/main/webapp/js/lib/angular-route.js",
"underscore": "./src/main/webapp/js/lib/lodash.compat.js",
"restangular": "./src/main/webapp/js/lib/restangular.js"
},
"browserify-shim": {
"angular": {},
"angular-route": {
"depends": [
"angular"
]
},
"underscore": {
"exports": "_"
},
"restangular": {
"depends": [
"underscore",
"angular"
]
}
}
I am running browserify from the command line. I have 4 computers on my team and it is working on a Mac and a Windows machine, but I have 2 Windows machine that it does not work on. We have all pulled from the same repo, all of our browserify and npm versions are the same. What should I do next?
The Windows machines were running the command from git bash. The command would not work with on git bash. After we switched to the command prompt, then all of the commands run fine.
I've got both Leiningen & Clojure working on Windows 8 separately from Sublime Text (e.g. I can get a repl working in Windows PowerShell).
My problem is that I can't get the SublimeREPL working in SublimeText (the REPL loads up but doesn't then do anything). Are there any simple traps that I might be missing or, failing that, are there a series of steps I could follow to troubleshoot?
Please see this SublimeREPL issue for instructions on how I got a Clojure REPL to work, at least on XP (I haven't tried it on Win7 or 8 yet). Basically, I edited the menu file for Clojure, and changed the command from lein repl to lein trampoline run -m clojure.main, which for some reason did the trick. I also changed the path to $file so you can open up a REPL while your project.clj is the current tab in Sublime, and the REPL should inherit the project's settings.
For reference, the complete Packages/User/SublimeREPL/config/Clojure/Main.sublime-menu file (Packages is accessible via Preferences -> Browse Packages...) is as follows:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Clojure",
"id": "Clojure",
"children":[
{"command": "repl_open",
"caption": "Clojure Trampoline",
"id": "repl_clojure",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": {"windows": ["lein.bat", "trampoline", "run", "-m", "clojure.main"],
"linux": ["lein", "repl"],
"osx": ["lein", "repl"]},
"soft_quit": "\n(. System exit 0)\n",
"cwd": {"windows":"$file_path",
"linux": "$file_path",
"osx": "$file_path"},
"syntax": "Packages/Clojure/Clojure.tmLanguage",
"external_id": "clojure",
"extend_env": {"INSIDE_EMACS": "1"}
}
},
{"command": "clojure_auto_telnet_repl",
"id": "repl_clojure_telnet",
"caption": "Clojure-Telnet"}]}
]
}]
}
]
I solved this problem with Git Bash Shell. I have used the shell script version of leiningen instead of lein.bat
This is the command I use:
["C:\\Program Files\\Git\\bin\\sh.exe", "-l", "--", "/d/lein.sh", "repl"]
assuming lein.sh is in d:\
lein trampoline command sometimes behaves differently from lein repl and could fail due to unknown reasons.
I'm trying to get Durandal.js optimizer working on my test project, but it seems to generate nothing to main-built.js. I use the following command from node.js command prompt, in durandal/amd folder:
optimizer.exe --verbose true
Result is
Using default base configuration.
Configuring for deploy with almond (custom).
{
"name": "durandal/amd/almond-custom",
"inlineText": true,
"stubModules": [
"durandal/amd/text"
],
"paths": {
"text": "durandal/amd/text"
},
"baseUrl": "C:\\Users\\Tommi Gustafsson\\Documents\\Visual Studio 2012\\Projects\\DurandalTests\\DurandalTest1\\TestApp",
"mainConfigFile": "C:\\Users\\Tommi Gustafsson\\Documents\\Visual Studio 2012\\Projects\\DurandalTests\\DurandalTest1\\TestApp\\main.js",
"include": [
"main-built",
"main",
"bindings/tinymce-binding",
"durandal/app",
"durandal/composition",
"durandal/events",
"durandal/http",
"text!durandal/messageBox.html",
"durandal/messageBox",
"durandal/modalDialog",
"durandal/system",
"durandal/viewEngine",
"durandal/viewLocator",
"durandal/viewModel",
"durandal/viewModelBinder",
"durandal/widget",
"durandal/plugins/router",
"durandal/transitions/entrance",
"raphael-amd/eve.0.3.4",
"raphael-amd/raphael.2.1.0.amd",
"raphael-amd/raphael.2.1.0.core",
"raphael-amd/raphael.2.1.0.svg",
"raphael-amd/raphael.2.1.0.vml",
"viewmodels/flickr",
"viewmodels/modal1",
"viewmodels/myPage",
"viewmodels/shell",
"viewmodels/welcome",
"text!views/detail.html",
"text!views/flickr.html",
"text!views/modal1.html",
"text!views/myPage.html",
"text!views/shell.html",
"text!views/welcome.html"
],
"exclude": [],
"keepBuildDir": true,
"optimize": "uglify2",
"out": "C:\\Users\\Tommi Gustafsson\\Documents\\Visual Studio 2012\\Projects\\DurandalTests\\DurandalTest1\\TestApp\\main-built.js",
"pragmas": {
"build": true
},
"wrap": true,
"insertRequire": [
"main"
]
}
Deleting old output file.
Tracing dependencies for: durandal/amd/almond-custom
Then, when I check main-built.js, it is empty. Can anyone help me what is the problem? I have several AMD modules in the test project, including Raphael.js AMD modules.
My requirejs configuration looks like this:
requirejs.config({
paths: {
'text': 'durandal/amd/text',
'eve': './raphael-amd/eve.0.3.4',
'raphael.core': './raphael-amd/raphael.2.1.0.core',
'raphael.svg': './raphael-amd/raphael.2.1.0.svg',
'raphael.vml': './raphael-amd/raphael.2.1.0.vml',
'raphael': './raphael-amd/raphael.2.1.0.amd',
'tinymce': "../Scripts/tinymce/jquery.tinymce.min"
}
});
In the same amd folder, where optimizer is stored, try running node r.js -o app.build.js. I've seen r.js sometimes choke about some dependencies, which resolves without problem when loading via require.js. For whatever reason the error messages won't show up when using optimizer --verbose. Typically the error message provides enough information to see where this occurs and if you've to update require.contig.paths or a specific define dependency.