I am using bower packaging system to fetch files to local project however breaking conventions these files are useless on their own. They need to be injected in the proper location in the MVC framework I'm using so whatever bower fetches I need to essentially do a post action and copy the directory structure / files from components/myexample/ to application/
remote bower package:
controllers
mycontroller.php
models
mymodel.php
view
layout
myview.php
composer.json
local project:
composer.json
components
myexample
controllers
mycontroller.php
models
mymodel.php
view
layout
myview.php
application
controllers
models
view
I was thinking of upon retrieving the directory structure and files to zip it all and then do an extract to the right directory. I need the solution to be cross platform compatible. How would you do it and better yet how else would you implement this?
Related
I have a VueJS project that uses Vuetify. I've created a web component that requires ShadowDOM and I've had to make a change to a single file in node_modules to make the Vuetify dialog work in ShadowDOM.
I got the fix from here.
I'm aware that changing files in node_modules is not recommended but what is the best practice when a change/fix needs to be implemented such as my one?
Can a function within a file contained in node_modules be overridden?
so far i've learned a bit about NodeJS. But now i want to write a huge enterprise app with it and i'm wondering how to setup the structure correctly? Coming from other languages like PHP and Java, i imagine, i would split my project in different NPM modules. For example #mybigproject/customer, #mybigproject/cart and #mybigproject/checkout and so on.
But those submodules would be installed in the node_modules folder of the application skeleton. How would i tell for example Express, that the template files are in the different module directories? Or for example i use TypeORM for data access. So each module would have it's own set of models. How do those models know the database configuration data, as it's only in the main application skeleton, or the other way around, how does the application skeleton should know where to find the models?
Don't use npm modules for different parts of your project.
This components is integral part of your project and usually depend on your global config / schema / routing / etc
Just put it in different files and require it where you need it.
You can get an idea for folders structure from projects like Sail.JS
Use npm modules if you writing some utility that going to serve you for different apps and you want an easy way to upgrade the utility code once for all your apps (or in case you want to share that utility as open source for all of us)
NPM can install your local folder as a dependency. (ref)
npm install <folder>:
Install the package in the directory as a symlink in the current
project. Its dependencies will be installed before it's linked. If
sits inside the root of your project, its dependencies may be
hoisted to the toplevel node_modules as they would for other types of
dependencies.
Your module keeps its original location after installed and a symlink is created as the same name of your module folder in the top level node_modules folder.
In these custom sub-modules, you can use __dirname and relative paths to locate you configuration files to feed to database or other data consumers.
But remember that, sub-modules often serve as utility functions for the main module. They should be independent from the project context.
Node/NPM newbie with a front-end dev question. I understand one of the strengths of an NPM-type module is that its dependencies get installed within itself, in node_modules. Modules always have the code that they need, and outside libs don't conflict.
That said, seems like this would result in the client downloading the same lib+ver (say, jquery v.X) multiple times. What's the technique for specifying that a module needs a dependency but that it shouldn't package that code if the dependency is already available on the site/page? Does said technique involve parent modules that make the shared lib+ver available?
Or, should various front-end modules just re-download the same lib+ver that other modules on the page might have already downloaded?
The client will only grab files from that folder that are needed, so if it's linked in HTML once the client will only grab it once. NPM handles dependency duplicates automatically.
Having said that, normally you will want to only serve a static folder to the client without revealing your entire server structure. This can be achieved using:
app.use(express.static('server/public')
where 'server/public' is the directory relative to the server.js file that you want to serve. In this case, 'public' contains all my linked view files, stylesheets, JS files, etc. that are linked from the HTML pages. You don't need to move that module's dependencies there as well.
The downside to this is that you'd have to manually move dependencies into the public folder (I make a 'vendor' directory usually) and link from there. It's more work but it's much more efficient and safer in the long run.
NOTE: when using a static folder to serve files, your HTML links will be served from a relative path to that folder.
I am starting a new project in which the idea is to organize the project file/folder structure in to different modules (.csproj) and finally once deployed these modules would be loaded to one AppHost of MainModule (these sub modules would act as plugins).
However, for better physical file management (SVN/VCS) and effective organization of my project files these modules would be maintained as separate projects in SVN too. Thought is to have views, assets etc. specific to each module in its own module directory scope. (Refer screenshot).
Main Module
SubModuleOne
Views
ModuleOneDefault.cshtml
SubModuleTwo
Views
ModuleTwoDefault.cshtml
Views
Shared
_Layout.cshtml
Hello.cshtml
Module specific files would be copied as post build action into root project path rather than /Views directly (if copied then it messes up with Main module's Views folder).
Problem is with how ServiceStack loads and handles Razor views from /Views folder and anything outside is considered to be content pages. More about this, explained here...!
With VirtualFileSystem in place I was thinking aloud to maintain module specific views in respective "/ModuleOne/Views/" folder but outside the root "/Views". Somehow, this doesn't seem to work, trying to seek help on how this could be achieved or handled appropriately.
PS: Am aware that anything outside Views folder is content pages, however the idea is still to maintain as Views folder but in different hierarchy - Hoping that ServiceStack Razor feature anyway handles nested (DEEP) structure well but within root /Views folder and not from the entire Project Root folder i.e. "/".
Question is, can this be achieved as is by default without any heavy lifting? or Should I be having custom VirtualPathProvider implementation etc.?
Opinion and thoughts are greatly appreciated!
Thanks!
All Razor Views must be in the /Views folder but otherwise they can be any hierarchy as any levels of nesting doesn't affect how they're resolved, they just need to be uniquely named, e.g:
/Views
/SubModuleOne
ModuleOneDefault.cshtml
/SubModuleTwo
ModuleTwoDefault.cshtml
/Shared
_Layout.cshtml
In a large web application, I'm using requirejs amd modules so that the scripts themselves are modular and maintainable. I have the following directory structure
web
|-src
|-main
|-java
|-resources
|-webapp
|-static
|-scripts
|-styles
|-images
|-static-built //output from r.js. not checked into git
|-WEB-INF
During build js and css are optimized using r.js into static-built folder. Gradle is the build tool.
Now the problem: The jsps refer to the scripts in static/scripts folder and this is how i want when working locally. However when building war, I want the static files to be served from static-built folder. The important thing is the source jsp should not have to change to serve the optimized files from static-built folder.
Two options that I have are: a) the gradle build while making war should include static-built instead of static. b)include static-built in addition to static and using tuckey urlrewrite pick the resouce from static-built rather than static.
What best practices are the community following in similar scenarios?
We've setup the server to have a runtime profile (dev, qa, prod, etc) read from a system property which determines some settings based on it. When running in production profile we serve the optimized files from the WAR. In development we serve the non-minified and non-concatenated files directly from the filesystem outside the application context.
Files are structured according to the official multipage example.
Configuring serving files depends on your chosen backend solution. Here's an example for spring.
Alternatively, r.js can generate source maps and those will help with development as well.
Not sure if this question is outdated already, but I had a kind of similar problem.
I had similar project structure, but with the only difference - I've split the project into 2 modules:
one of them (let's call it service) was java-module for back-end
the second one contained only js and other stuff related to front-end (let's call it ui).
Then in Gradle build 'assemble' task of the service depends on 'assemble' task of ui AND another custom task called 'pre-assemble'. This 'pre-assemble' task was copying the optimized js files to place where I wanted them to be.
So, basically, I've just added another task that was responsible for placing all the optimized js files in the proper place.