How to create a sails.js skeleton so I can quickly build new apps with common goals? - node.js

This is more for some fun and playing around with, but hopefully should produce something useful.
I would like to extend sails.js framework so that when I generate a new app using 'sails new project-name' it will already have a lot of previous configurations or modules added. For example, with every project I would probably intend to use SASS. If you have had to setup SASS with sails before you will know it has a few bits of configuration to do first. It would be advantageous to not have to repeat this with each new project.
In short some things I would like to achieve upon creating each new project:
Get SASS configured
Generate multiple SASS partial files, such as _buttons.scss, _forms.scss
Include SASS mixings within certain SASS files
Include configuration and set up to use multiple databases like mongoDB and MariaDB (Much more complex I imagine)
Thanks

At Balderdash we do this all the time to quickly spin up certain "types" of application.
You can fork https://github.com/balderdashy/sails-generate-new and customize it to call additional generators that you can create using ejs templates.
I created a module called sails-generate-entities which you can see in use here: https://github.com/tjwebb/sails-permissions/blob/master/index.js. For this sails extension, you'd call sails generate permissions-api and all those files would be added to the project. Your fork of sails-generate-new could include a call to a custom generator such as this.

Related

Is it possible to have MVC in sub folders when using node.js express framework?

Is it possible to have MVC in sub folders (modules) when using node.js express framework?
Today I have this structure of my project:
Controllers
Blog/*
Poll/*
And many more
Models
Blog/*
Poll/*
And many more
View
Blog/*
Poll/*
And many more
Routes
Blog
Poll
And many more
Should it be possible to have this structure in a module way instead?:
Blog
Controllers/*
Models/*
View/*
routes.js
Poll
Controllers/*
Models/*
View/*
routes.js
And more modules
When I develop I feel I mostly work with one part of the project at the time. When I the current structure its a lot of moving between folders. However most of the time I only focus on "module". It will also be easier to remove as module just to delete the sub folder and all it files are removed. If a project has more 30 modules it will be hard to find the file (Its possible to search but should be nice just have it in same folder). I been working with Drupal before that has this type of module system where you can easy add and remove modules (Might be that am used to to it and not yet familiar with this new this way of doing it). What are the main benefits of the first approach over the module way?
Is this possible to achieve in the express framework? If so any tutorials on how to set it up? Any other node.js framework support this?

How to efficiently update the API when Swagger spec file is updated? (express, nodejs)

I'm trying to setup a nodejs-express boilerplate for my new project, and this time I want to try doc-driven flow. I've checked couples of packages like swagger-node, swaggerize-express ...etc. They all provide great functionalities.
However, I don't see anything that could support incremental scaffolding when the Swagger file is updated. That means when the spec changes I have to manually check the diff and manually add/modify the new specs. That doesn't sound cool.
Does anyone could share something that is more reasonable? Thanks!!!
Edit:
After trying some frameworks, I decided to use swagger-express-middleware. This framework offers a convenient way to automatically check routes/parameters for your service.
You can use tools like swagger-maven-plugin to incrementally rebuild your server code, which means reading from your api definition and updating/building code as necessary. There are SAAS products like SwaggerHub which enable this as well, by merging code and pushing to git.

Run-time bundling of ES6 modules in ASP.NET MVC

Are there any existing solutions for run-time bundling of ES6 modules?
I'm looking to simplify JavaScript code development in a MVC5 web app. We're having issues with large, unwieldy JS files, so I'm hoping to get a module loader system in place. So far, I'm not finding any existing bundle transformers for ES6 or another module loader format. I'd be fine with using TypeScript or nodejs require style. I prefer not to use require.js style, though.
Perhaps there's a good reason this solution doesn't exist already. Maybe the dependency resolution processing is too much for a run-time bundling solution. But, I figure it's worth a shot to ask.
Solutions Considered
Prebuilt Web Client
Ultimately, this is where I want to be, but I need a stop-gap solution for now. I know how to put together a build system for an HTML client using grunt/gulp/webpack. But I don't want to have to tell developers to run webpack -w or something similar during development. Nor do I want to tell them to rebuild a solution for every JS change. They should be able to modify the file, refresh the browser, and see the change.
Directory Structure
This is the route I'll probably end up going with. Basically, this JS codebase consists of jQuery widgets and plain JS (helpers/common functions). So, if I structure the code in this directory structure and include the js dir, it should get me most of the way there:
js (DIR)
app-start.js
helpers (DIR)
widgets (DIR)
Widgets should be fine. Helpers, I can see issues where one function/class depends on another. Though, since a function call should never start with a helper (only a widget), this should work fine, assuming no globals are used (or maybe one global like 'App').

using requirejs without main file nor config()

I'm building an app that will contain many js (jquery) modules (files) using the following setup;
The build is run using Grunt task runner.
I use handlebars templates, then generate the html from *.hbs files.
During the build, I uglify all the js files into one minified file.
I call the minified file in my application <script src="assets/js/app.min.js"></script>
Now, I want to use requirejs to organize my code and adhere to the AMD specifications..
But I got 3 problems with this approach:
I need to have 1 single minified file for all the js; this keeps my code harder to "decode" thus to copy (since it is mixed with other dependencies; jquery, modernizer..) and also helps avoid extra http requests if scripts are called individually.. However, requirejs needs a main file to initialize the app and inside that main file It calls the other required files.. I don't have such configuration.
Many of the dependencies I'm using are in a bower package (that I don't include in the distribution); this makes it not possible to call those files using the suggested requirejs method.
I'm using jquery on this with some 3rd party plugins that don't call define(); to make them work I have to use shim config which again rises the problem #2!
So how am I supposed to take advantage of requirejs while keeping my code in modules and well organized?
Sorry for the long question and thanks for reading :)
ps: Feel free to change the title of the question as I couldn't find a better one!
I finally opted for AngularJS as it adheres to my setup above and allows me to split my app into manageable small modules.
I have also the possibility to use the ease of jQuery (even though it is not a best practice among angular community) and much more.

How to share common client-side javascript across NodeJS projects?

I'm a Node n00b starting a couple web app projects using Express, and I've got some common client-side libraries I'd like to share between the two projects. This seems like a very common problem, so there must be several solutions available already.
I come from a java background, and in java, I'd create a separate "common" project and "overlay" common WAR over my project during packaging. This would also allow for r.js optimization during the build process.
My best guess in Node is that I need to create a private NPM module, and map those common files into express via a use() middleware plugin. Is that right?
How, then, can I package both my common and project specific javascript into a minified file using r.js?
Or is source control the answer? Checking out my "common" repository inside each project?
Any help would be most appreciated. Thanks.
This seems like a very common problem, so there must be several solutions available already.
Good news: Yes, this is a common problem. Yes, there are several "solutions".
Bad News: All of the "solutions" are at least partially terrible.
Here's my advice:
1) Individual .js files should be coded as CommonJS modules
2) Groups of related .js files should be made into npm packages
3A) Use them in node via the regular node.js/CommonJS require function and use browserify to use them in the browser
3B) OR use a built tool like grunt to wrap commonjs into AMD format for use with requireJS in the browser
3C) OR consider something like component.io components

Resources