Why grunt appears under `dependencies` instead of `devDependencies`? - gruntjs

After running sails new myProject a new sails project is created under myProject directory. Why grunt libraries appear under the dependencies section instead of devDependencies in package.json?

Related

Specify jar structure in sbt assembly

When sbt-assembly builds a fat jar, it places all the dependencies in the main folder. I need to construct a jar that looks like this
--domain
domain classes
-- lib
dependency classes
is it possible to do this with sbt assembly, or any other plugin?
If you want to seperate your app jar file and your dependecy jar files, here is the most practical method i found with sbt;
Create project/plugins.sbt file if not exists and add following line:
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.0")
After adding this line refresh your project.
Note: Plugin version might change in time.
When sbt refresh finishes update your build.sbt file like this:
lazy val MyApp = project.in(file("."))
.settings(artifactName := {(
sv: ScalaVersion,
module: ModuleID,
artifact: Artifact) => "MyApp.jar"
})
.settings(packSettings)
Then run:
sbt pack
Or if you're doing this for child project, run this:
sbt "project childproject" clean pack
This will nicely seperate your main jar file and your dependency jars.
Your app jar will be in target scala folder.
Your dependencies will be in target/pack/lib.
In this way you can deploy your dependencies once.
And whenever you change your app, you can just deploy your app jar file.
So in every change you don't have to deploy an uber jar file.
Also in production, you can run your app like:
java -cp "MyApp.jar:dependency_jars_folder/*" com.myapp.App

How to share a gruntfile.js file or grunt tasks between multiple projects?

My team currently works on multiple projects which all have their own gruntfile.js file. But they're all about the same, copied-pasted on every new project... Which is not good at all !
I'm searching for a way to maintain only one gruntfile.js and share an up-to-date version between all the projects. I see two ways of doing this : deploy the shared gruntfile.js to some path accessible through our internal network and ...
... use grunt --gruntfile = /path/to/share/gruntfile.js taskName on every call to a grunt task inside any project directory. A Jenkins build could keep the shared file up-to-date, re-deploying it on commit. In this way, a project wouldn't have its own gruntfile.js file anymore.
... inside the proper gruntfile.js of every project, find a way to tell grunt to import everything (tasks, configInit, etc.) declared in the shared gruntfile.js. Like it would be done with Maven pom.xml files having a parent pom.
Does anyone see a reason why one or both solutions wouldn't work ?
Does anyone know a simple way of doing this, maybe using an existing tool or plugin ?
Edit: We're on SVN, not GIT.
Finally, I found a way to share tasks declaration over multiple projects : I created a custom grunt plugin. This plugin contains :
custom-grunt-plugin
|_ config
|_ config.js : contains all the tasks configurations
|_ tasks
|_ custom-grunt.js : contains all the tasks declarations
|_ package.json : package info
|_ README.md : package documentation
I published my plugin and added it as a devDependency of all my projects.
Finally, the grunfile.js of all my projects :
module.exports = function (grunt) {
// Load custom tasks
grunt.loadNpmTasks('custom-grunt-plugin');
// Load grunt tasks automatically
require('load-grunt-tasks')( grunt );
// Load configuration from the custom grunt plugin
var config = require('custom-grunt-plugin/config/config');
// Add project specific variables to the config
config.pkg = grunt.file.readJSON('package.json');
config.paths = {
app: 'app',
dist: 'dist/<%= pkg.name %>/<%= pkg.version %>'
};
grunt.initConfig( config );
};
That's all ! Probably not the best solution. But this one works.
The next step would be to transfer the list of dependencies from the package.json of the projects to the package.json of the custom plugin, and install all dependencies recursively with 'npm install'. But it seems npm can't load and install the dependencies of the dependencies...

Using bower with Visual Studio Tools for Apache Cordova

When I create a blank Apache Cordova app, I got a directory structure like:
root
www
bower.json
...
From the project root directory, if I run "bower install ionic --save", the bower dependencies were all created in the project root while I expect them to go to www.
What is the best way use bower with VSTAC projects?
You can create a .bowerrc file at the root that has the key directory:'www/bower_components' set, indicating that the files are placed inside www instead of the root.
Visual Studio should be able to now download the dependencies inside the www folder.
Note that VS2015 also has intellisense when editing bower.json and automatically installs the dependencies too !!
Use the following command:
npm install -g "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\ApacheCordovaTools\Packages\vs-tac"
It worked perfect for me.

Is there an injector like grunt-wiredep that works for NPM dependencies?

Most packages nowadays are available in both NPM and Bower. I have to have NPM around, but I'd like cut Bower out of the loop on my project.
I'm currently relying on grunt-wiredep to create <script> includes in my index.html. This tool looks at all of the Bower configs to pull all the necessary js and css files into my index.html for me.
Is there a tool that will do the same for NPM dependencies?
You would be able to do that using a module bundler like Browserify or Webpack.
For getting started with Browserify , you will need to first install it via NPM globally
npm install -g browserify
Then in your project , get the frontend library you want to include , like for example the angular library
npm install --save angular
Now you will need to use require() to make Browserify aware of the dependencies that it needs to fetch for the project to work (In case of Angular app, where you define the main module , add this first line)
var angular = require('angular');
angular
.module('autocompleteDemo', [])
.controller('DemoCtrl', DemoCtrl);
For setting up the grunt-browserify task , first install it in the project
npm install grunt-browserify --save-dev
and configure the task as follows
browserify: {
main: {
src: 'entry.js',
dest: 'bundle.js'
}
}
Lastly in your index.html , you will need to add markup for the bundle.js script
<script src="bundle.js"></script>
Example code can be found at https://github.com/pra85/grunt-browserify-example

Setting Up Multiple Grunt files

I want to run grunt on several projects simultaneously. However i'm not sure how to setup so it works. Here's what my setup looks like:
- Project 1 folder
-[project files]
-Gruntfile
- Project 2 folder
-[project files]
-Gruntfile
- Grunt Folder
-[nodeModules]
-package.json
So the idea is that have all grunt dependencies (node modules) in a single centralised folder. Then each project folder has its own Gruntfile.
The problem I have is that I don't know how to setup the gruntFile so that it can use the node modules and package.json from the grunt dependancy folder.
Can anyone help me with how I can get this to work? Specifically with code examples.

Resources