how to use react-native-config to set environment variable in nx? - react-native

I want to use react-native-config to set environment variable with nx. Is it possible to combine this two package together to achieve the goal? or just use nx environment variable setting. Any suggestion is appreciated.Thanks.
I want to use #nrwl/workspace:run-commands to run my customize script.
"customCommand": {
"executor": "nx:run-commands",
"options": {
"command": "react-native run-android"
}
}
when I run the command in command line.
npx nx run employee:make
It shows below error
TypeError: Cannot read properties of undefined (reading 'options')

Not sure you want to run in libs or apps. I assume you try to run command in libs. Your project.json look like that:
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/assets/src",
"projectType": "library",
"tags": [],
"targets": {
"lint": {
"executor": "#nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/assets/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "#nrwl/jest:jest",
"outputs": ["coverage/libs/assets"],
"options": {
"jestConfig": "libs/assets/jest.config.ts",
"passWithNoTests": true
}
}
}
}
and add your command:
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/assets/src",
"projectType": "library",
"tags": [],
"targets": {
"customCommand": {
"executor": "nx:run-commands",
"options": {
"command": "react-native run-android"
}
},
"lint": {
"executor": "#nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/assets/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "#nrwl/jest:jest",
"outputs": ["coverage/libs/assets"],
"options": {
"jestConfig": "libs/assets/jest.config.ts",
"passWithNoTests": true
}
}
}
}
run your command with:
nx run assets:customCommand
in case cmd not found run code below and try again:
nx reset

Related

Is there a way to extract rendered preset information from CMake?

I have a CMakePresets.json file which makes use of inheritance and macro expansion.
Here is an excerpt, in reality I use multiple versions of "Foo":
{
"configurePresets": [
{
"name": "default",
"hidden": true,
"generator": "Unix Makefiles",
"binaryDir": "cmake-build-${presetName}",
"environment": {
"PATH": "/opt/foo/$env{FOO_VERSION}/bin:$penv{PATH}",
"LD_LIBRARY_PATH": "/opt/foo/$env{FOO_VERSION}.0/lib"
},
"cacheVariables": {
"FOO_VERSION": "$env{FOO_VERSION}",
}
},
{
"name": "debug-foo1",
"inherits": "default",
"environment": { "FOO_VERSION": "1" }
},
{
"name": "release-foo1",
"inherits": "debug-foo1",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
],
"buildPresets": [
{
"name": "debug-foo1",
"configurePreset": "debug-foo1"
},
{
"name": "release-foo1",
"configurePreset": "release-foo1"
}
]
}
Now assume I select the preset release-foo1. This would render the following variables, among others:
binaryDir = "cmake-build-release-foo1"
FOO_VERSION = "1"
LD_LIBRARY_PATH = "/opt/foo/1.0/lib"
Is there a way to query these results for a given preset? For example, given release-foo1, I want to know the resulting binaryDir.
Of course I could parse the JSON myself, but that seems tedious, especially because of the cross references and substitutions which are being made by CMake.
You can use the -N flag to print the computed presets info without running the configure or generate steps. After modifying the presets file in your question to work, I created an empty CMakeLists.txt next to it and ran this test (*** stands in for my PATH):
$ cmake --preset=release-foo1 -N
Preset CMake variables:
CMAKE_BUILD_TYPE="Release"
FOO_VERSION="1"
Preset environment variables:
FOO_VERSION="1"
LD_LIBRARY_PATH="/opt/foo/1.0/lib"
PATH="/opt/foo/1/bin:***"
This is good enough for debugging your presets. If you need to go further, you could process the output using standard unix command line tools, like awk, grep, cut, etc.
I think this is the best you can do for now (CMake <=3.21) since there's nothing else in the command line documentation or the file API for IDEs that I could find.
Building on Alex Reinkings answer, you can get the binaryDir (and other parts) with the -N option if you tweek the preset a little bit.
You need to add a environment variable and reference it for binaryDir:.
See this tweeked example from CMake documentation:
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "$env{BUILD_DIR}",
"cacheVariables": {
"FIRST_CACHE_VARIABLE": {
"type": "BOOL",
"value": "OFF"
},
"SECOND_CACHE_VARIABLE": "ON"
},
"environment": {
"BUILD_DIR": "${sourceDir}/build/default",
"MY_ENVIRONMENT_VARIABLE": "Test",
"PATH": "$env{HOME}/ninja/bin:$penv{PATH}"
},
"vendor": {
"example.com/ExampleIDE/1.0": {
"autoFormat": true
}
}
},
{
"name": "ninja-multi",
"inherits": "default",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
],
"vendor": {
"example.com/ExampleIDE/1.0": {
"autoFormat": false
}
}
}
This will give you:
$ cmake --preset default -N
Preset CMake variables:
FIRST_CACHE_VARIABLE:BOOL="OFF"
SECOND_CACHE_VARIABLE="ON"
Preset environment variables:
=>BUILD_DIR="D:/tmp/presets/build/default"<=
MY_ENVIRONMENT_VARIABLE="Test"
PATH="..."

Debugging Vue in VScode and Chrome, unbound breakpoint

I'm trying to debug a Vue website I'm writing in VSCode and Chrome.
When I put a breakpoint in the data() { return {...} } function it stops on it, but if I try to put it in a method in a Vue file or a JS service, once I launch Chrome through the debug config the breakpoints become unbound. Does anyone have any ideas about how to keep the breakpoints bound?
This is my config file:
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/client/meet-for-lunch/src",
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
},
{
"type": "node",
"request": "launch",
"name": "Debug server",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/server/bin/www",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
}
]
}
I'm including the debug config for the server because in works.
Here is an example of a method I'm trying to debug (from the Vue file), I put a break point at this.error = null . The method runs normally so I expect it to stop at the breakpoint :
methods: {
async login() {
try {
this.error = null;
const response = await AuthenticationService.login({
email: this.email,
password: this.password
})
this.$store.dispatch('setToken', response.data.token)
this.$store.dispatch('setUser', response.data.user)
}
catch (err) {
console.log(`An error has occured: ${JSON.stringify(err.response)}`)
this.error = err.response.data.error
}
}
}
I'm also trying to debug my service:
login(credentials) {
return Api().post('/login', credentials)
}
The Api object just creates the Axios request
Thanks,
Ben
https://www.codegrepper.com/code-examples/javascript/vuejs+vscode+unbound+breakpoint
After a whole day of searching this solved my problem
{
"version": "0.2.0",
"configurations": [
{
"name": "WSL Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
When I had Unbound Breakpoints in VSCode I ended up needing to start the process with the --inspect or --debug-brk=5858 flag. Beyond that, launch.json gave me lots of trouble, and these resources helped
https://code.visualstudio.com/docs/nodejs/nodejs-debugging
https://code.visualstudio.com/docs/nodejs/debugging-recipes
https://github.com/microsoft/vscode-recipes/tree/master/nodemon
https://code.visualstudio.com/docs/typescript/typescript-debugging
launch.json examples:
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
},
{
"name": "Launch tests via NPM",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script", "testDebug"
],
"port": 5858
}
package.json
"scripts": {
"start": "NODE_PATH=./src DEBUG=express:* NODE_ENV=dev nodemon -w src --ext ts --exec node --inspect -r tsconfig-paths/register -r ts-node/register src/index.ts",
"testDebug": "NODE_ENV=test ts-mocha --debug-brk=5858 --paths -p tsconfig.json",
}
},
Well, it's not really an answer but I've restarted my Node server a couple of (more) times and now it stops at the breakpiont. I hope that the problem doesn't return. Now he doesn't show the value of the variables for some reason but I guess that's another problem.
Thanks for the help :)
Ben
I had the same issue in my vueJS project. Something to try before making any changes to files etc which solved it for me:
In the ClientApp/App folder: 1.Delete the node_modules folder 2.Delete the package-lock.json file 3.Open a cmd prompt for your ClientApp/App folder 4.Use the cmd "npm i"
This final step will reinstall all your node-modules. The issue I had must've been a conflicting node-module.
As of May 2022...
A note if you're using vscodium and firefox you need to install firefox-devtools directly from the marketplace: https://marketplace.visualstudio.com/items?itemName=firefox-devtools.vscode-firefox-debug
Beyond that the launch.json config is standard:
{
"name": "Vue:Client",
"type": "firefox",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"pathMappings": [
{
"url": "file://",
"path": ""
}
]
},
The extension suggested I insert those pathMappings.
See https://github.com/firefox-devtools/vscode-firefox-debug/issues/267

ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current character

started a new react-native project, followed link react native cli quickstart approach. even though I have not done any code change , getting the below error when i run npx react-native run-android
Version info:
"react": "16.9.0",
"react-native": "0.61.5"
Error info:
:ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is 'I' with an int value of 73
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
FAILURE: Build failed with an exception.
* Where:
Script 'D:\xp\feb2020xp\AwesomeProject\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' line: 200
* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx.cmd --quiet --no-install react-native config' command from 'D:\xp\feb2020xp\AwesomeProject' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again
What I Tried :
npm uninstall -g react-native react-native-cli
and
npx.cmd --quiet --no-install react-native config
console ouput from 2nd command:
{
"root": "D:\\xp\\feb2020xp\\AwesomeProject",
"reactNativePath": "D:\\xp\\feb2020xp\\AwesomeProject\\node_modules\\react-native",
"dependencies": {},
"commands": [
{
"name": "log-ios",
"description": "starts iOS device syslog tail"
},
{
"name": "run-ios",
"description": "builds your app and starts it on iOS simulator",
"examples": [
{
"desc": "Run on a different simulator, e.g. iPhone 5",
"cmd": "react-native run-ios --simulator \"iPhone 5\""
},
{
"desc": "Pass a non-standard location of iOS directory",
"cmd": "react-native run-ios --project-path \"./app/ios\""
},
{
"desc": "Run on a connected device, e.g. Max's iPhone",
"cmd": "react-native run-ios --device \"Max's iPhone\""
},
{
"desc": "Run on the AppleTV simulator",
"cmd": "react-native run-ios --simulator \"Apple TV\" --scheme \"helloworld-tvOS\""
}
],
"options": [
{
"name": "--simulator [string]",
"description": "Explicitly set simulator to use. Optionally include iOS version betweenparenthesis at the end to match an exact version: \"iPhone 6 (10.0)\"",
"default": "iPhone 11"
},
{
"name": "--configuration [string]",
"description": "Explicitly set the scheme configuration to use",
"default": "Debug"
},
{
"name": "--scheme [string]",
"description": "Explicitly set Xcode scheme to use"
},
{
"name": "--project-path [string]",
"description": "Path relative to project root where the Xcode project (.xcodeproj) lives.",
"default": "ios"
},
{
"name": "--device [string]",
"description": "Explicitly set device to use by name. The value is not required if you have a single device connected."
},
{
"name": "--udid [string]",
"description": "Explicitly set device to use by udid"
},
{
"name": "--no-packager",
"description": "Do not launch packager while building"
},
{
"name": "--verbose",
"description": "Do not use xcpretty even if installed"
},
{
"name": "--port [number]",
"default": 8081
},
{
"name": "--terminal [string]",
"description": "Launches the Metro Bundler in a new window using the specified terminal path."
}
]
},
{
"name": "log-android",
"description": "starts logkitty"
},
{
"name": "run-android",
"description": "builds your app and starts it on a connected Android emulator or device",
"options": [
{
"name": "--root [string]",
"description": "Override the root directory for the android build (which contains the android directory)",
"default": ""
},
{
"name": "--variant [string]",
"description": "Specify your app's build variant",
"default": "debug"
},
{
"name": "--appFolder [string]",
"description": "Specify a different application folder name for the android source. If not, we assume is \"app\"",
"default": "app"
},
{
"name": "--appId [string]",
"description": "Specify an applicationId to launch after build.",
"default": ""
},
{
"name": "--appIdSuffix [string]",
"description": "Specify an applicationIdSuffix to launch after build.",
"default": ""
},
{
"name": "--main-activity [string]",
"description": "Name of the activity to start",
"default": "MainActivity"
},
{
"name": "--deviceId [string]",
"description": "builds your app and starts it on a specific device/simulator with the given device id (listed by running \"adb devices\" on the command line)."
},
{
"name": "--no-packager",
"description": "Do not launch packager while building"
},
{
"name": "--port [number]",
"default": 8081
},
{
"name": "--terminal [string]",
"description": "Launches the Metro Bundler in a new window using the specified terminal path."
},
{
"name": "--tasks [list]",
"description": "Run custom Gradle tasks. By default it's \"installDebug\""
},
{
"name": "--no-jetifier",
"description": "Do not run \"jetifier\" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.",
"default": false
}
]
}
],
"assets": [],
"platforms": {
"ios": {},
"android": {}
},
"haste": {
"providesModuleNodeModules": [
"react-native"
],
"platforms": [
"ios",
"android"
]
},
"project": {
"ios": {
"sourceDir": "D:\\xp\\feb2020xp\\AwesomeProject\\ios",
"folder": "D:\\xp\\feb2020xp\\AwesomeProject",
"pbxprojPath": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\AwesomeProject.xcodeproj\\project.pbxproj",
"podfile": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\Podfile",
"podspecPath": null,
"projectPath": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\AwesomeProject.xcodeproj",
"projectName": "AwesomeProject.xcodeproj",
"libraryFolder": "Libraries",
"sharedLibraries": [],
"plist": [],
"scriptPhases": []
},
"android": {
"sourceDir": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app",
"isFlat": false,
"folder": "D:\\xp\\feb2020xp\\AwesomeProject",
"stringsPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\res\\values\\strings.xml",
"manifestPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\AndroidManifest.xml",
"buildGradlePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\build.gradle",
"settingsGradlePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\settings.gradle",
"assetsPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\assets",
"mainFilePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\java\\com\\awesomeproject\\MainApplication.java",
"packageName": "com.awesomeproject"
}
}
}
I am unable to figure out what is going wrong. please help me in resolving the error . thank you.
I experienced a similar issue. The problem for me turned out to be a syntax error in the file android/app/src/main/AndroidManifest.xml.
Specifically, I had a wrong part like android:screenOrientation=portrait rather than the correct android:screenOrientation="portrait" (note the quotation marks).
Although the specific reason for the problem likely does not match yours, it may hopefully give you a hint for a potential solution.

Npm Publish Issue - Artifactory

I am publishing an npm library to an npm repo on artifactory. The library is built using angular and the dist folder and package.json looks correct. When publishing, the request it's self is published but not the actual artifact.
All i see on artifactory is a single file and not a folder containing my package
Running
npm publish
Package.json
{
"name": "#abce/embedded-auth",
"version": "1.0.0-dev.0",
"main": "bundles/abce-auth.umd.js",
"module": "fesm5/abce-auth.js",
"es2015": "fesm2015/abce-auth.js",
"esm5": "esm5/abce-auth.js",
"esm2015": "esm2015/abce-auth.js",
"fesm5": "fesm5/abce.js",
"fesm2015": "fesm2015/abce-auth.js",
"typings": "abce-auth.d.ts",
"metadata": "abce-auth.metadata.json",
"sideEffects": false,
"dependencies": {
"tslib": "^1.9.0"
}
}
What actually gets published to artifactory in a single file.
{
"_id": "#abce/embedded-auth",
"name": "#abce/embedded-auth",
"dist-tags": {
"latest": "1.0.0-dev.1"
},
"versions": {
"1.0.0-dev.1": {
"name": "#abce/embedded-auth",
"version": "1.0.0-dev.1",
"main": "bundles/abce-auth.umd.js",
"module": "fesm5/abce-auth.js",
"es2015": "fesm2015/abce-auth.js",
"esm5": "esm5/abce-auth.js",
"esm2015": "esm2015/abce-auth.js",
"fesm5": "fesm5/abce-auth.js",
"fesm2015": "fesm2015/abce-auth.js",
"typings": "abce-auth.d.ts",
"metadata": "abce-auth.metadata.json",
"sideEffects": false,
"dependencies": {
"tslib": "^1.9.0"
},
"readme": "ERROR: No README data found!",
"_id": "#abce/embedded-auth#1.0.0-dev.1",
"_npmVersion": "6.4.1",
"_nodeVersion": "10.15.3",
"_npmUser": {
"name": "deployment",
"email": "bob#bob.ie"
},
"maintainers": [
{
"name": "deployment",
"email": "bob#bob.ie"
}
],
"dist": {
"integrity": "sha512-rpTN1sMpwnMwehzWUqbV+zElzaOlF5ekQRCQMncy6c+i4TAp5jbBobvzrhgl0ORqHgJn3Eo+EcrRgYLSjV7MdQ==",
"shasum": "71f654dd5fddb20a9d5063171d5293424a4271c7",
"tarball": "http://abce.jfrog.io/abce/internal-npm-dev/#abce/embedded-auth/-/#abce/embedded-auth-1.0.0-dev.1.tgz"
}
}
},
"readme": "ERROR: No README data found!",
"maintainers": [
{
"name": "deployment",
"email": "bob#bob.ie"
}
],
"_attachments": {
"#abce/embedded-auth-1.0.0-dev.1.tgz": {
"content_type": "application/octet-stream",
"data": "correctly populated tarball base64 data here. I checked it and it is correct",
"length": 12092
}
}
}
Expect:
I would expect the package to be parsed from the request and the package published correctly
Actual:
The put request data from the npm publish command is published as a file
npm version: 6.9.0
node version: v12.3.1(has also been run with 10.15.3)
Any ideas?
Please check the registry URL that you are using from npm, if it doesn't include /api/npm - it is invalid.
Wrong URL: https://domain/artifactory/some-directory/.
Valid URL: https://domain/artifactory/api/npm/some-directory/.

Create env fails when using a daemonset to create processes in Kubernetes

I want to deploy a software in to nodes with daemonset, but it is not a docker app. I created a daemonset json like this :
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "uniagent"
},
"annotations": {
"scheduler.alpha.kubernetes.io/tolerations": "[{\"key\":\"beta.k8s.io/accepted-app\",\"operator\":\"Exists\", \"effect\":\"NoSchedule\"}]"
},
"enable": true
},
"spec": {
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"processes": [
{
"name": "foundation",
"package": "xxxxx",
"resources": {
"limits": {
"cpu": "100m",
"memory": "1Gi"
}
},
"lifecyclePlan": {
"kind": "ProcessLifecycle",
"namespace": "engb",
"name": "app-plc"
},
"env": [
{
"name": "SECRET_USERNAME",
"valueFrom": {
"secretKeyRef": {
"name": "key-secret",
"key": "uniagentuser"
}
}
},
{
"name": "SECRET_PASSWORD",
"valueFrom": {
"secretKeyRef": {
"name": "key-secret",
"key": "uniagenthash"
}
}
}
]
},
when the app deploy succeeds, the env variables do not exist at all.
What should I do to solve this problem?
Thanks
Daemon Sets have to be docker containers. You can't have non-containerized programs run as Daemon Sets. https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ Kubernetes only launches containers.
Also in your YAML manifest file, I see a "processes" key and I have reason to believe it's not a valid manifest file, so I doubt you deployed it successfully.
You have not pasted the "full" YAML file, but I'm guessing the "template" key at the beginning is the spec.template key of the file.
Run kubectl explain daemonset.spec.template.spec and you'll see that there is no "processes" field.