Angular folder structure for CMS - angularjs

i’ve juz started with angular, i saw this post on folder structuring http://www.johnpapa.net/angular-growth-structure/
This is what my folder looks like which i'm building for an eCommerce site frontend:
.
├── index.html
├── css
├── images
├── fonts
├── scripts
│ ├── app.js
│ ├── directives
│ │ ├── search
│ │ ├── image-slider
│ │ ├── faq
│ │ └── form
│ └── api
└── templates
├── nav.html
├── footer.html
└── page
├── full.html
└── sidebar-right.html
Is there any better way/practice that you would do for this?
My greatest worry would be moving on into integrations with a CMS(opencart/magento) folder structure.

Your dir structure looks fine, however you may run into issues while integrating with any CMS as they put their views on a different directory.
Workaround: Once you do integrate Magento or some random CMS, move your views to the CMS's view folder and make sure you serve index.html with your angular from the CMS.
Hope I could help.

Related

How do you create a route that starts with a dot in Remix?

I just started using Remix.run and I'm trying to add a ssl certificate to my site and it requires that I make this specific path available in my app that's similar to this
www.mypage.com/.well-known/pki-validation/blah.txt
Unfortunately, I find that when i create a route folder in Remix that starts with a dot, it returns a 404 response. Even when i try to escape it in the name like so [.]well-known
https://remix.run/docs/en/v1/guides/resource-routes#url-escaping
Example of what I've tried.
app/
├── routes/
│ ├── [.]well-known/
│ │ ├── pki-validation
│ │ ├────── blah[.]txt.tsx
│ └── about.tsx
│ └── index.tsx
└── root.tsx
Any ideas? Thanks.
I think you are supposed to wrap more between those brackets.
app/
├── routes/
│ ├── [.well-known]/
│ │ ├── pki-validation
│ │ ├────── [blah.txt].tsx
│ └── about.tsx
│ └── index.tsx
└── root.tsx
Think i got something working here: https://stackblitz.com/edit/node-wmuju8
Edit: seems like escaping the dot in the wellknown folder and file is enough, so not sure why it is not working for you.

Need help to setup/shape a new project

we are creating a new react project using create-react-apps and we are trying to figure out a way to organise our page components. After some discussion, we basically have come up with 2 solutions
the first solution is to use hierarchical structure as shown below
src/
├── copmonents/
│ ├── sharedComponent1
│ ├── sharedComponent2
│ ├── sharedComponent3
| └── sharedComponent4
├── pages/
│ ├── page1/
│ | ├── component1/
│ | | ├── component11/
│ | | | ├── component111
│ | | | └── component112
│ | | └── component12
│ | └── component12
│ ├── page2 (same as above)
│ └── page3 (same as above)
└── utils/
We create pages and put components inside them. Once we find a component is used in multiple places, we hoist it into the component folder.
Idea behind is to use file hierarchy to reflect component structure. We fell developers might find it easier to locate files using this solution, but drawback would be it can easily go too deep?
the second solution is to use a 'flat' structure
src/
├── copmonents/
│ ├── component1
│ ├── component2
│ ├── component3
│ ├── component4
│ ├── component5
│ ├── component6
│ ├── component7
│ ├── component8
│ ├── component9
| └── component10
├── pages/
│ ├── page1.tsx
│ ├── page2.tsx
| └── page3.tsx
└── utils/
this way we have a very lean page folder and keep all components into a components folder. While this structure seems to be cleaner than the first one, I do agree that some people may feel this solution "less organised" as all components are dumped into a centralised place.
I do recognise this is a highly opinionated topic and I was thinking of using json normaliser as an analogy, but people even have different opinions in normalizing json.
thoughts?
Move files around until it feels right ref
Dan Abramov’s site
But, you can aboard it strategically with features (layout, Button, basket)
src/
├── copmonents/
│ ├── Layout
│ ├── Basket
│ ├── Button
| └── Feature specific
├── pages/
│ ├── page1/
│ | ├── index.ts/js/
│ | ├── logic.tsx
│ | └── ui-specific-to-page
│ ├── page2 (same as above)
│
└ hooks
one point that I missed in my initial post(I only discovered it yesterday), with the hierarchical code structure, we will end up with long referrence paths like ../../../../utils inside your components (imagine you are referring to a utils function inside component111 or it's sub components). While with the flat structure we don't have this type of issues.
there are ways to get around with it, like a custom resolve for webpack, but it may involve some effort to set it up (especially when your project is bootstrapped by cra)
src/
├── copmonents/
│ ├── sharedComponent1
│ ├── sharedComponent2
│ ├── sharedComponent3
| └── sharedComponent4
├── pages/
│ ├── page1/
│ | ├── component1/
│ | | ├── component11/
│ | | | ├── component111
│ | | | └── component112
│ | | └── component12
│ | └── component12
│ ├── page2 (same as above)
│ └── page3 (same as above)
└── utils/

Getting: conflicts with same file imported from GOPATH with google app engine, but not purely locally

I am still trying to deploy to google app engine both the local test environment and on app engine itself, and I keep getting this error:
2017/10/03 17:50:40 go-app-builder: Failed parsing input: app file DbConfig.go conflicts with same file imported from GOPATH
I have used grep to see if I explicitly import DbConfig but I, this is the result of grep:
$ grep -r 'DbConfig' .
./config.go:func GetDatabaseConfiguration() model.DbConfig {
./config.go: return model.DbConfig{connectionName, user, password, dbType, dbName}
Binary file ./share-services matches
./queries/db-config.go: dbConfig model.DbConfig
./queries/db-config.go:func Config(newDbConfig model.DbConfig) {
./queries/db-config.go: dbConfig = newDbConfig
./model/DbConfig.go:type DbConfig struct {
./model/DbConfig.go:func (d DbConfig) ConnectionString() string {
So from what I can tell I should not get an error and since other structs from my model package works just fine this is very strange to me. Firstly because Google App Engine accepts the deploy and first fails later, secondly because the dev server fails immediately, and lastly because if I run outside the app engine, I don't get this error.
Can someone give me a pointer to how to fix this please. I have search for a fix, but most state to use absolute include paths for packages which I already am.
EDIT:
I forgot to include the build command used, maybe that will help
go-app-builder -app_base /home/tools/go/src/bitbucket.com/chocolate-cloud-dev/share-services -arch 6 -dynamic -goroot /home/tools/sdks/google-cloud-sdk/platform/google_appengine/goroot-1.6 -gopath /home/tools/go -nobuild_files ^^$ -incremental_rebuild -unsafe -print_extras_hash links/generator.go model/user.go model/service.go model/SharedWith.go handlers.go config.go model/connection.go jsonHelpers/decoders.go queries/share-with-queries.go authentication/autenticate.go queries/share-queries.go model/share.go download/download.go model/Download.go model/File.go queries/file-queries.go jsonHelpers/encoders.go queries/db-config.go model/DbConfig.go model/NewestFile.go share-services.go jsonHelpers/CreateShare.go queries/download-queries.go
And this is my project structure:
.
├── app.yaml
├── authentication
│   └── autenticate.go
├── build-and-run
├── config.go
├── deply_v1.sh
├── download
│   └── download.go
├── go-notes.md
├── handlers.go
├── jsonHelpers
│   ├── CreateShare.go
│   ├── decoders.go
│   └── encoders.go
├── LICENSE
├── links
│   └── generator.go
├── model
│   ├── connection.go
│   ├── DbConfig.go
│   ├── Download.go
│   ├── File.go
│   ├── NewestFile.go
│   ├── service.go
│   ├── SharedWith.go
│   ├── share.go
│   └── user.go
├── models
├── queries
│   ├── db-config.go
│   ├── download-queries.go
│   ├── file-queries.go
│   ├── queries.sql
│   ├── share-queries.go
│   └── share-with-queries.go
├── README.md
├── run-locally-mac.sh
├── run-localy.sh
├── scripts
│   └── Script.sql
└── share-services.go
the answer is to either use relative paths instead of absolute, which still does not totaly work Or make a 100% flat folder structure.

Component image file in React Static Boilerplate

Where is the ideal location to put image file (.jpg, .png) in react static boilerplate
How to use them inside component?
Usually static files, images etc are stored inside ./public/ folder. It would be better if you store the images inside that folder. You can use another separate folder inside ./public/ folder, like images.
It is pretty clear if you have gone through the documentation page. Here is the folder structure. Please see the portion that is in bold.
.
├── /components/ # Shared or generic UI components
│ ├── /Button/ # Button component
│ ├── /Layout/ # Website layout component
│ ├── /Link / # Link component to be used instead of <a>
│ └── /... # etc.
├── /core/ # Core framework
│ ├── /history.js # Handles client-side navigation
│ ├── /router.js # Handles routing and data fetching
│ └── /store.js # Application state manager (Redux)
├── /node_modules/ # 3rd-party libraries and utilities
├── /pages/ # React components for web pages
│ ├── /about/ # About page
│ ├── /error/ # Error page
│ ├── /home/ # Home page
│ └── /... # etc.
├── /public/ # Static files such as favicon.ico etc.*
│ ├── /dist/ # The folder for compiled output
│ ├── favicon.ico # Application icon to be displayed in bookmarks
│ ├── robots.txt # Instructions for search engine crawlers
│ └── /... # etc.
├── /test/ # Unit and integration tests
├── /utils/ # Utility and helper classes
│── main.js # React application entry point
│── package.json # The list of project dependencies and NPM scripts
│── routes.json # This list of application routes
│── run.js # Build automation script, e.g. `node run build`
└── webpack.config.js # Bundling and optimization settings for Webpack

Load custom library while using CDN

I have an app that uses a custom application-specific library (sap.ui.foo) which contains custom controls, views and controllers.
My deployment strategy is serving my custom library from the same server/port that is serving the index.html file.
I would also like to use SAP's CDN to load the OpenUI5 libraries (sap.m, etc).
I am using the Grunt/node tools that come with OpenUI5's GitHub repository.
When I load my application all locally (no CDN) it works perfectly, but is very slow (such a huge download payload I suppose) so I'm trying to use the CDN in hopes of improving startup performance.
My index.html looks like this: (edited after #codeworrior's answer):
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.ui.layout, sap.m, sap.ui.foo"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-resourceroots='{
"ns":"./",
"sap.ui.foo": "./sap/ui/foo/"
}'
>
Here is my directory structure (which to my knowledge is "standard"):
src
├── foo
│ └── src
│ └── main
│ └── webapp
│ ├── index.html # start point
│ ├── resources
│ ├── test-resources
│ └── WEB-INF
├── sap.m
├── sap.ui.commons
...other sap libs...
└── sap.ui.foo
└── src
└── sap
└── ui
└── foo
└── # my controls...
and after a grunt build:production my "target" directory looks like this:
target
├── openui5-sap.m
├── openui5-sap.ui.commons
├── openui5-sap.ui.core
├── openui5-sap.ui.demokit
├── ...other sap libs...
├── openui5-sap.ui.foo
└── resources
└── sap
└── ui
└── foo
├── Bootstrap.js
├── controllers
├── controls
├── data
├── font
├── img
├── js
├── library.js
├── library-preload.json
├── models
├── tasks
├── themes
├── util.js
├── views
└── wrappers
But, after I do a grunt serve:target and hit the url http://localhost:8989/foo/, in Chrome's dev-tools I get:
failed to preload 'sap.ui.foo.library-preload': Not Found - sap.ui.ModuleSystem
Uncaught Error: failed to load 'sap/ui/foo/library.js' from ./sap/ui/foo/library.js: 404 - Not Found
The network tab shows me that the CDN files are being served just fine, but the files that I'm trying to serve locally (such as my custom lib's library.js and library-preload.json) are 404's.
Any advice on how to get my library to load?
If your library is stored in the usual way (reflecting the full qualified names in the folder structure), then it should be sufficient to define a corresponding entry in your data-sap-ui-resourceroots attribute:
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.ui.layout, sap.m, my.uilib"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-resourceroots="{
ns:'./',
'my.uilib': './my/uilib/'
}">
</script>
If the structure is different, just adapt the path in the configuration. resourceRoots are configured early, so you could even specify your lib in the data-sap-ui-libs attribute.
But maybe you tried that already and it didn't work. Then the problem might have been with the spelling of the option. It's 'resourceroots', not 'resource-roots'.

Resources