How to set a .rc file conditionally - shell

I am using babel and have a .babelrc file for its configuration:
{
"stage": 0,
"ignore": [
"node_modules",
"bower_components",
"testing",
"test"
]
}
However, when I'm developing locally, having this .babelrc file disallows me from running Babel's CLI babel-node in the testing folder (see: babel-node no longer working in different directory )
That said, when I push to Heroku, I need this configuration because I need to make sure the testing folder isn't compiled.
How can I conditionally set a .babelrc file that doesn't involve me having to remember to switch it back to the production version everytime I want to push to Heroku?

You can set conditional things using the env option in your .babelrc
from their docs:
{
"stage": 0,
"env": {
"development": {
"ignore": [
"node_modules",
"bower_components",
"testing",
"test"
]
}
}
}
Then, in your package.json
"scripts": {
"start": "NODE_ENV=production node index.js",
"dev": "NODE_ENV=development node index.js"
}
it checks BABEL_ENV, then NODE_ENV

Related

Yarn does not see workspaces

I have the following configuration in a root workspace. The strange thing is that for backend it works, but for frontend - doesn't, no matter how I rename this
{
"private": true,
"name": "root",
"workspaces": [
"packages/frontend",
"packages/backend"
],
"scripts": {
"client": "yarn workspace frontend start",
"client-test": "yarn workspace frontend test",
"server": "yarn workspace backend start",
"start": "conc --kill-others-on-fail \"yarn client\" \"yarn server\""
},
"devDependencies": {
"concurrently": "^7.6.0"
}
}
And it always says: $ yarn workspace frontend test
error Unknown workspace "frontend".
info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tried to start from all directories, nothing works
The thing is that it does not matter how folders are called inside of "packages", the important thing is that package.json of each workspace should be called correspondingly:
{
"name": "frontend",
"version": "1.0.0",
"private": true,
...
}

Heroku CI with Postgres postgis extension

I'm using a postgis extension to my database on Heroku. In production this works just fine; I'm mapping like a boss.
But, I can't get my app to build on HerokuCI because the database addon in the test environment doesn't have GDAL installed (part of the postgis extension):
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
-----> test command `python manage.py migrate --noinput && python manage.py test` failed with exit status 1
I can't find out how to create extensions in the heroku CI environment. Heroku's app json schema say nothing about how to create extensions on the test databases.
I know that I can't use in-dyno database for CI, as postgis is not an available extension for that, but I'm not using an in-dyno one, I'm using a plan...
Here's my app schema:
{
"name": "mymegaapp",
"scripts": {
"heroku-prebuild": "create extension postgis",
"heroku-postbuild": "echo heroku-postbuild script runs here."
},
"env": {
},
"formation": {
},
"addons": [
],
"buildpacks": [
{
"url": "heroku/python"
},
{
"url": "heroku/nodejs"
}
],
"environments": {
"test": {
"scripts": {
"test": "python manage.py migrate --noinput && python manage.py test"
},
"env": {
"DJANGO_DEBUG": "1"
},
"addons":[
{
"plan": "heroku-postgresql",
"options": {
"version": "11"
}
},
"heroku-redis:hobby-dev"
]
}
}
}
Note that I've tried to create the postgis extension in the prebuild script, which doesn't make a difference.
I've also tried invoking the creation before the test script:
"scripts": {
"test": "heroku create extension postgis && python manage.py migrate --noinput && python manage.py test"
},
which doesn't work because the heroku cli isn't installed in the dyno.
The key questions:
How can I create extensions in HerokuCI?
Is postgis an allowable extension at all in HerokuCI?
You've almost got it. There's no first class support for creating pg extensions directly from the CLI. However, you can pass a statement into psql.
Try this in your postdeploy or test setup script:
psql -c "create extension postgis" $DATABASE_URL As you're aware, you'll need to do this with a real database, not in-dyno. If you've attached the database as something other than DATABASE_URL, you will need to update that in the script.
[Edit by OP to add useful info] In this case, GDAL libraries will also be needed, which can be installed by setting the BUILD_WITH_GEO_LIBRARIES environment variable to 1. The final working solution in app.json will be:
"environments": {
"test": {
"scripts": {
"postdeploy": "psql -c \"create extension postgis\" $DATABASE_URL",
"test": "python manage.py migrate --noinput && python manage.py test"
},
"env": {
"DJANGO_DEBUG": "1",
"BUILD_WITH_GEO_LIBRARIES": "1"
},
"addons":[
{
"plan": "heroku-postgresql",
"options": {
"version": "11"
}
}
]
}
}
Here a 2021 update as the setting BUILD_WITH_GEO_LIBRARIES is now deprecated and unsupported by Heroku:
This app.json worked for my CI setup with Django / Heroku:
{
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-geo-buildpack.git"
},
{
"url": "heroku/python"
}
],
"environments": {
"test": {
"scripts": {
"test": "python3 manage.py migrate --noinput && python3 manage.py test --keepdb"
},
"env": {
"DJANGO_DEBUG": "1"
}
}
}
}

Istanbul test coverage report show that i'm covering only one file

This is the first time that I'm using Istanbul 2.0, but the reports shows that I'm covering only one file, and this file doesn't matter enough.
In my package.json I put the following settings
"nyc": {
"check-coverage": true,
"include": [
"src/**/*.js"
],
"exclude": [
"src/config/*.js",
"src/adapter/*.js"
]
},
"scripts": {
"start": "npm install && nodemon src/server",
"test": "nyc --reporter=html mocha --recursive"
}
UPDATE
When I change de package JSON puting the reporter in lcov, it works.
"test": "nyc --reporter=lcov mocha --recursive"
VS Code
Istanbul HTML Report

How can I get vs code debugger to find map files for debugging angular-cli webpack project

I am working on an angular-cli v1.0.5 (angular 4) project. Below is the output of the ng -v command.
#angular/cli: 1.0.5
node: 6.10.3
os: win32 x64
#angular/common: 4.1.3
#angular/compiler: 4.1.3
#angular/core: 4.1.3
#angular/forms: 4.1.3
#angular/http: 4.1.3
#angular/platform-browser: 4.1.3
#angular/platform-browser-dynamic: 4.1.3
#angular/router: 4.1.3
#angular/cli: 1.0.5
#angular/compiler-cli: 4.1.3
I am also using;
Typescript version 2.3.4
Webpack version 2.2.1
Chrome Version 58.0.3029.110 (64-bit)
Windows 10
VS Code version 1.13.0
Debugger for Chrome version 3.1.2
I am trying to get debugging to work in VS Code but all of my breakpoints are dimmed and when I hover over them, I get the message "Breakpoint ignored because generated code was not found."
Directory Structure - My project starts in the masclient folder. This is where my package.json and angular-cli.json files are at. Within the masclient folder, I have a src folder and within the src folder, I have an app folder. My angular 4 app.module.ts is in this folder. All of my components are in their own folders below the app folder. The specific typescript file I am trying to debug is in the masclient\src\app\bulk-labels\create-bulk-labels folder
My launch.json file is shown below;
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src",
"diagnosticLogging": false,
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
},
{
"name": "AttachChrome",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///*": "/*"
}
}
]
}
My angular-cli.json is shown below;
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"project": {
"name": "masclient"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "masc",
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles/vendor.scss",
"styles/main.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/tether/dist/js/tether.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"component": {}
}
}
My tsconfig.json file is shown below;
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2016",
"dom"
]
}
}
I have gone through several recommendations I have found on Google with no luck. Most seem to refer to the process before angular-cli switched to webpack. There seem to be a lot of variation of property settings in the launch.json file. As I read through the posts before deciding to post my own question here, it seems that the issue may be related to the fact that the ng serve process keeps all of the compiled files in memory rather than pulling the map files from a ./dist folder... but I am not sure how that would change the location settings in the launch.json file.
I start debugging using the following process;
Run ng serve from the command line to start the web server
From within VS Code, I go to the Debug section and click on the green arrow next to "Launch Chrome" ( or press F5)
I have also tried this process;
Run ng serve from the command line to start the web server
Launch chrome.exe --remote-debugging-port=9222 from an admin level command prompt.
In the instance of Chrome that launched, navigate to locaohost:4200
From within VS Code, I go to the Debug section and click on the green arrow next to "Launch Chrome" ( or press F5)
With either of the startup methods listed above, wile viewing my source code *.ts files in the VS Code editor, I can see that my breakpoints are grayed out as soon as the debugger starts.
I am sure it probably just a matter of getting my settings in the various config files synced properly, but after several hours of research, the actual solution has eluded me.
Any help would be greatly appreciated.

How to generate documentation for other projects within solution using DocFx

I am using DocFx to automatically generate documentation in Visual Studio 2015.
Per the Getting Started instructions, I added an empty ASP.NET 4 Web Application and used the Nuget Console to install the DocFx build package (e.g. Install-Package docfx.msbuild). I built the site and it it generated documentation for code within the project.
I was wondering how to configure docfx.json to get DocFx to document code in other projects within the solution.
In docfx.json, there is an array of metadata. The example metadata has a src object with files and exclude properties.
To point to another project in your solution, add a cwd property to metadata and change folders (i.e. "../Another.Project").
{
"metadata": [
{
"src": [
{
"files": [ "**/*.csproj" ],
"exclude": [ "**/bin/**", "**/obj/**", "_site/**" ],
"cwd": "../Another.Project"
}
],
"dest": "obj/api"
}
],
"build": ...
}
This worked for me.
directory structure
+---ClassLibrary
| \---ClassLibrary.csproj
\---DocFxProject
\---docfx.json
docfx.json contents
cwd and src are synonyms for the same property
{
"metadata":
[
{
"src":
[
{
"files": [ "**/ClassLibrary.csproj" ],
"src": "..",
"exclude": [ "**/obj/**", "**/bin/**" ]
}
],
"dest": "obj/api"
}
],
"build": { ... }
}

Resources