react-native init doesn't make src folder - react-native

I'm following this tutorial: https://docs.realm.io/sync/getting-started-1/react-native-quick-start/step-1-query-based-sync#step-4-create-a-constants-file-and-set-the-realm-instance-address
Many documents including this tutorial refers a src folder, but when I create a React Native project with a command like react-native init MyProject, it doesn't create src folder. Why is that?
Following is my folder structure:
├── App.js
├── android
├── app.json
├── index.js
├── ios
├── node_modules
├── package.json
└── yarn.lock

because react-native-cli do not provide src folder. its up to you, how you design or architect your app. directory structures are upto you and you need to write code accordingly. Generally project specific code always kept in src folder. In your case, there is just one component and App.js is the only file that holds the entire code. but as there will many screens/components you will find it unmanageable. for sake of modularity, src folder is made and used.
App
|
|--src
|
|--assets
|--components
|--screens
|
|--loginScreen.jsx
|--homeScreen.jsx

Just manually create your src folder. It's just used to better organize your project.

Related

Resolve image url imported from another package in Vue

I have a repo called core-components
The folder structure for the repo is
├── src
│ ├── assets
│ └── components
Assets contains all the images and components use images from assets.
I have used core-components as dependency in another repo called ui
ui also has same folder structure. Now whenever I am using components from core-components in ui I am not able see the image. I get the following error in ui.
[Vue Router warn]: No match found for location with path "/assets/images/abc.svg
It is trying to look the image in ui assets folder.
Image in core-componets is written in template like this
<v-img src="../assets/images/abc.svg" />
ui is using nuxt3 and core-components is using vue3.

What is the recommended way to point an npm package's imports to a specific directory?

I have an npm package structured as follows:
my-package
├── build
├── many.config.files
├── package.json
└── src
It made sense to put helper files such as config files and scripts into the root of my package. Then it made sense to have a src file so that my source files wouldn't mix with all my config files. Then it made sense to have a build directory where the built version of src would get populated (maybe some transpiling and minification happens, etc).
Now my src directory has various JS files and folders, all of which users of my library should be able to import.
src
├── file1.js
├── file2.js
└── utils
For example, import utils3 from "my-package/utils/file3.js" should work just fine for them. They should not need to type import utils3 from "my-package/build/utils/file3.js" to import the file.
What is the best practice for dealing with this situation?
I have tried/considered various approaches:
Setting "main": "./build" in my package.json. This did not resolve the import error for me.
Setting "directories": {"utils": "./build/utils"} in my package.json. This did not resolve the import error for me.
Copying package.json into my build directory during build. Then npm publishing the build directory instead of the entire project. This has the upside of only sharing the built code. This has the downside that the built package will have information in its package.json that doesn't make sense because files/directories are missing/mislocated.
Something along the lines of module.exports = require('./build') in an index.js file. This did not work either.

Use relative path in init function cannot be found in test

I'm running into an annoying problem when using relative path in the init function which cannot be found by the unit test.
Say I have a project structured like:
.
├── conf
│   └── blacklist
├── filter
│   ├── filter.go
│   └── filter_test.go
And in the init function of filter.go, I try to load the blacklist by using relative path conf/blacklist to avoid loading it multiple times.
Since the default working directory is exactly the project root directory, it works well with compiled binary. However filter_test.go will panic by
panic: open conf/blacklist: no such file or directory, becasue go test always uses the package directory as the working directory.
I also referred this solution, which could dynamically build the relative path to find the config file. It did work well until I add the covermode=set flag and try to do some coverage testing. It seems that the covermode would rewrite and generate some middle packages like _obj, which makes the dynamical relative path not working any more.
Has anyone run into the same problem before? I'm still new to golang for a couple of months. Any suggestions will be appreciated.
A simple solution is to run tests using something like SRC_ROOT=$PWD go test and then inside the test that want to access files use os.Getenv("SRC_ROOT").

GO in IntelliJ IDEA. Multiple File and Error Undefined: Data

I want use IntelliJ IDE Community Edition to write code in GO (GoLang). I instaled right plugin, and instaled all need tools to build application.
My application consists with two below file. Each is in direcytory ../EventServer.
Main.go
Data.go
If I want to run project from IntelliJ using function Run (Ctlr+Shift+F10) and I get below error
/usr/lib/go/bin/go build -o "/tmp/Build Main.go and run0go" -gcflags "-N -l" /my/home/blah/EventServer/Main.go
# command-line-arguments
./Main.go:11: undefined: Data
I can without any problem compiled code from terminal come in to direcytory with project and execution command
:~/Pulpit/EventServer$ go build
./EventServer
Hello
dane w strukturze someone
tree direcytory and files looks like
EventServer$ tree -a
.
├── Data.go
├── EventServer
├── EventServer.iml
├── .idea
│   ├── compiler.xml
│   ├── copyright
│   │   └── profiles_settings.xml
│   ├── libraries
│   │   └── GOPATH__EventServer_.xml
│   ├── misc.xml
│   ├── modules.xml
│   ├── .name
│   ├── vcs.xml
│   └── workspace.xml
└── Main.go
I suppose that command to run is bad, because compiler trying build program with only one file Main.go but not with all files. Right command should be
$ go run *.go
But I do not know where Can I set this.
I also set GOPATH to:
export GOPATH=$HOME/Pulpit/EventServer
This also hasn't help
CODE
Main.go
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
abcd := Data{"someone" , "1234567"}
fmt.Printf("dane w strukturze %s ", abcd.Name)
}
And Data.go
package main
type Data struct {
Name string
Phone string
}
SYSTEM: LINUX
----------------------SOLVED-------------------------------------------SOLVED---------------------
Steps
Project must be found in directory for/example/MyProject/src/HERE_DIRECTORY_WITH_YOUR_SOURCE_GO_FILE
sub direcytory src is important
Go to Run --> Edit Configurations
Find below position
Change Run Kind to Package
In Position Package write Your folder with Your code (Shold be Highlight it is correct)
Click On PLUS icon in left top corner, and Add Go Application
Apply changes
In the right top corner main window IDE You see small icon Play
Chose early defined Go Application my is Unamed
Click Play
An Joy :D
Let say you are having a project with src/ sub directory and two .go files inside: hello.go and typetest.go and both defines the same package "main". One of them (hello.go) also implements func main().
To make it compile as whole you need to make sure two things are configured properly: GOPATH and Run/Debug configuration.
Open the Project Libraries/GOPATH settings:
For Gogland
File -> Settings -> Go
For Intellij IDEA
File -> Settings -> Languages & Frameworks -> Go -> Go Libraries
Makes sure the GOPATH for the project looks something like that:
GOPATH settings
Next, open Run -> Edit Configurations and make sure your configuration looks similar to this:
Run/Debug configuration
You can add second file (in your case Data.go) as Go tool arguments field in Run/Debug Configurations. I read about this here: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/2013 near the end of discussion. Example below (I used 2 files HelGo.go and aaa.go) worked for me:
Go Run Configuration with 2 files
Intellij objected in these 2 files were in different folders, and so both of them has to be same package (main).
On the other side I couldn't make any advises on this page work at all.
I solved the same problem with a complete list of checking. Usually, there are multiple problems combined with each other.
First of all, check your GOPATH settings, there are two ways:
use the command line to check your go environment:
$ go env
you will get a global environment setting, make sure your GO folders are correct. If you are using some local packages, be aware of them too.
check your Build tool setting, whether you have added all your resources files into your dependencies. This is another way to set up your project GOPATH, and do not affects the global settings.
Secondly, check your Run/Debug configuration, and make sure your settings have located the main package or main file. No matter which kind of configuration you use, this is always the start.
Sarp Kaya, just follow Mbded steps. Additional step is, ensure that your additional GOPATH should be there.
For example, this is our ~/.profile GOPATH
export GOPATH=$HOME/lib/Go:$HOME/Development/Go
The first path used by go get processes etc, while your active go development directory goes to the next path.
According to our config, the RightApp exact path should be $HOME/Development/Go/src/RightApp.

How to use grunt-contrib-copy to copy to root AND change directory structure

I have an express app with my dev views in /assets/views. I figure I need to separate development and production views because in production I'll be editing the HTML when I used grunt-contrib-usemin to concat/uglify scripts.
So here's the problem. My current tree:
assets/views
├── 404.html
├── index.html
├── layout.html
├── question_ask.html
└── question_display.html
Ideally, I want my production-ready views to live on the same level as assets. Using grunt-contrib-copy, it seems to copy the whole tree. I currently am putting it into public since I'm not sure how to set my dest to the root of the project.
copy: {
views: {
src: ['assets/views/*.html'],
dest: 'public/'
}
So there are a few questions here:
Is it bad practice to have dev views and production views? If so, is there another way of producing a view that has references to concat/uglified scripts?
How the heck can I use grunt-contrib-copy to copy to the root of my project? I don't want assets/views obviously, I just want a views/* folder that has the contents of what's in assets/views/*.
Thanks!
You need to specify the flatten option which will remove the directory structure from the destination path. See my answer here: Copy all files from directory to another with Grunt.js copy