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.
Related
I'm using the command standard-version each time I want to publish new version, but the yielded changes in the CHANGELOG.md look like this:
### [10.1.9](https://github.com/my-project-name/compare/v10.1.8...v10.1.9) (2021-03-29)
### [10.1.8](https://github.com/my-project-name/compare/v10.1.7...v10.1.8) (2021-03-29)
### [10.1.7](https://github.com/my-project-name/compare/v10.1.6...v10.1.7) (2021-03-29)
first the links do not work - the github url is not correct and i want to configure it to the right url, and second, I'd like to configure the link that's shown in the changeslog file (there are some types)
I tried to use this documentation but didn't find anything that can help me
https://github.com/conventional-changelog/conventional-changelog
so how do I configure the way standard-version works on the CHANGELOG.md ? can someone provide example?
yes.
according to doc:
You can configure standard-version either by:
Placing a standard-version stanza in your package.json (assuming your project is JavaScript).
Creating a .versionrc, .versionrc.json or .versionrc.js.
If you are using a .versionrc.js your default export must be a configuration object, or a function returning a configuration object.
Any of the command line parameters accepted by standard-version can instead be provided via configuration.
Please refer to the conventional-changelog-config-spec for details on available configuration options.
example:
.versionrc
{
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"hidden": true
},
{
"type": "docs",
"hidden": true
},
{
"type": "style",
"hidden": true
},
{
"type": "refactor",
"section": "Refactor"
},
{
"type": "perf",
"section": "Performance"
},
{
"type": "test",
"hidden": true
}
]
}
Background
I'm an absolute beginner in BuckleScript, and while I've downloaded packgages with npm before, I've never written a library.
Goal: installing my new package local package in my project using npm
I am trying to wrap some parts of the service worker api in JavaScript. I have started with a file bs-service-worker/src/ExtendableEvent.re like so
type _extendableEvent('a);
type extendableEvent_like('a) = Dom.event_like(_extendableEvent('a));
type extendableEvent = extendableEvent_like(Dom._baseClass);
[#bs.send] external waitUntil: (extendableEvent, Js.Promise.t('a)) => unit
= "waitUntil";
This compiles and produces ExtendableEvent.bs.js as expected.
Now, though, I'd like to go ahead and test what I have so far by creating a new npm project and importing what I have locally. I created a new sibling directory and did an npm install ../bs-service-worker. That succeeded, and then I did a sanity-check build on my new BuckleScript project. That also succeeded.
The issue: opening my module causes an error
When I add open ExtendableEvent; to Demo.re in the new project, I get the following error:
We've found a bug for you!
/home/el/workbench/bucklescript/bs-service-worker-examples/src/Demo.re 11:6-20
9 │
10 │ /**/
11 │ open ExtendableEvent;
12 │
13 │ /*
The module or file ExtendableEvent can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `bsb` instead of `bsb -make-world`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
What I've tried
I'm guessing I'm misusing BuckleScript here instead of npm because npm is so widely adopted and well documented that I think I'd have found the problem, but I'm definitely not ruling out the possibility that I'm misusing npm, too.
I do have "bs-service-worker" listed as a bs-dependency. I also tried "../bs-service-worker" in case BuckleScript didn't like the virtual directory, but it didn't seem to help.
My npm run build command is indeed npx bsb -make-world.
More code:
bs-service-worker/bs-config.json
{
"name": "bs-service-worker",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true,
"public": "all"
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}
bs-service-worker-examples/bsconfig.json
{
"name": "bs-service-worker-examples",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
"bs-service-worker",
"bs-fetch",
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}
bs-service-worker-examples/package.json
{
"name": "bs-service-worker-examples",
"version": "0.0.1",
"scripts": {
"build": "npx bsb -make-world",
"start": "npx bsb -make-world -w",
"clean": "npx bsb -clean-world"
},
"keywords": [
"BuckleScript"
],
"author": "Eleanor (https://webbureaucrat.bitbucket.io)",
"license": "MIT",
"devDependencies": {
"bs-platform": "^7.3.2"
},
"dependencies": {
"bs-fetch": "^0.6.1",
"bs-service-worker": "file:../bs-service-worker"
}
}
Easy Reproduction of the Issue
The fastest way to reproduce this would be to fork this repository and try to add it as a local npm dependency.
The problem seems to be that you have "namespace": true in your library's bsconfig.json, which will wrap all the modules in a namespace module with a silly generated name based on the name field. In this case it will be BsServiceWorker I think.
You could just remove that setting, or set it to false, but namespacing is a good idea to avoid collisions between modules from different libraries, or your own app, so I would recommend setting it to a custom, sensible name. For example:
"namespace": "ServiceWorker"
You can then open ExtendableEvent in the consumer project with:
open ServiceWorker.ExtendableEvent;
For more details, see the documentation on the namespace field.
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'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"
}
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.