Is it possible to run an script when installing a cordova plugin? - node.js

I know when I install a cordova plugin the native files are copied into the platform folder and will be compiled when I build that platform. But is it possible to execute an script to for example download additional binary files, or build custom frameworks?
What I am looking for is a way to specify in plugin.xml to execute a particular shell script or install an npm module when the plugin is first installed into a Cordova project. Is this possible?

That is not possible using the 'cordova plugin add' command (not what they were designed to do) but definitely possible if you use task manager tools like Grunt to automate your process.
You can combine tasks to run in order, such as running your own shell scripts before/after you make a call to install plugins.
Check out npm grunt for more info.

Yes, you can
check this:
https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html
You only have to make a folder, called "after_plugin_add", inside the hooks folder of the project, and add there your script.

Related

How to make a Nodejs distributable command line application

I'm making a command line application with commander, inquirer and nightwatch as top dependencies. The main purpose of the app is for automation and testing.. Is there any way i can make this distributable instead of publishing it as npm package. I want the same functionality as those cli made with python, where it can be setup, and run on a target machine. is this possible? Thank you
Here are two open source projects (PKG and Nexe) that enable you to package your Node.js project into an executable:
https://github.com/zeit/pkg/blob/master/README.md
Or
https://github.com/nexe/nexe/blob/dev/README.md
You can use either one to make an executable of your project.

NodeJs Plugin Installation not found in Jenkins/configure

I am trying to configure Jenkins to build my code using NodeJS Plugin. I have installed NodeJS plugin but NodeJS Installation are not available in System Configuration.
ManageJenkins -> Configure System -> NodeJS installation (not
available)
I am running Jenkins on localhost.
What can I do to resolve this issue?
Have you installed and followed the instruction mentioned in node.js plugin? It is quite straight forward:
After installing the plugin, go to the global jenkins configuration
panel (JENKINS_HOME/configure or JENKINS_HOME/configureTools if
using jenkins 2), and add new NodeJS installations For every Nodejs
installation, you can choose to install some global npm packages.
Now, go to a job configuration screen, you will have 2 new items :
On the "Build environnment" section, you will be able to pick one of
the NodeJS installations to provide its bin/ folder to the PATH.
This way, during shell build scripts, you will have some npm
executables available to the command line (like bower or grunt)
Go to a job configuration screen, you will have 2 new items : On the
"Build environnment" section, you will be able to pick one of the
NodeJS installations to provide its bin/ folder to the PATH. This
way, during shell build scripts, you will have some npm executables
available to the command line (like bower or grunt)
You have to goto "/pluginManager/advanced" and run "check now" so that it will check the nodejs site and do the global install.
This will solve your problem

What is the proper workflow of starting a new project with grunt

So i started using grunt, ran through some tutorials but somehow i haven't found an easy way of initialising a new project with all the predefined plugins in your default gruntfile.js?
So, yeah, i got that everytime you have to reinstall grunt locally with cd your-working-dir and then npm install grunt --save-dev?
Then i have my gruntfile.js which, i guess, i can copy and use just like my default grunt file? I guess the main question of mine is this: do i have to install each of grunt plugins manually whenever i start a new project?
for example if i have sass task in my gruntfile.js and when i start this new project i have to npm install grunt-contrib-sass --save-dev every single time?
You have at least several options, ordered by complexity ascending:
Create your default projects on disk, and a shell script to automate the bootstrapping.
Use Github, and create a default project that you can bootstrap with GIT on your box.
Use Yeoman scaffolding, and create a custom yeoman generator as a NPM package.
Shell automation can apply to the second and third approach as well.
Yeoman, is def. the cool option, but also takes the most time, and requires more maintenance than the other options.

Cordova CLI, using Git, and saving plugins/platforms

I'm trying to figure out how to reconcile some Cordova + git "best practices" with what I think is reality, and I'm hoping someone can shed some light on this for me.
If I understand correctly, the current "best practice" is to add these directories to my .gitignore (from the book "Developing with Cordova CLI", the current version):
platforms/
plugins/
node_modules/
This removes the easily downloadable plugins and mostly boilerplate platform code from version control because it can be easily generated with a simple Cordova CLI command.
But, this seems counter-intuitive because - and I'm thinking like NPM or Bower - with the Cordova CLI I can't save which platforms and plugins I'm using in a config file. With NPM, I can add a --save switch to save the package in the package.json file. This allows me to not version control my node_modules folder and instead use 'npm install'. With the Cordova CLI I can't seem to use the --save switch (is there an equivalent) to 'remember' the plugins or platforms I intend to use.
It seems that the config.xml file in the www/ directory doesn't save which platforms or plugins have been added.
Is there some other file in the project that keeps a memory of which platforms and plugins I want to use? How does it work?
Cordova 4.3.0 + allows you to save and restore platforms and plugins. Saved information is stored in config.xml file. See v5.0.0 release notes and the official Cordova docs.
You can save platforms and plugins using the --save option when you add them:
cordova platforms add PLATFORM --save
cordova plugins add PLUGIN --save
Or you can save platforms and plugins that are currently added:
cordova platforms save
cordova plugins save
By doing this there is no need to check in platforms or plugins into your code repository. They will be automatically restored based on your config.xml file when cordova prepare command is run.
I typically write a hook to capture the plugins I want to use in my project. You can see this in an article I wrote here: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/
With the new modular architecture of Cordova 3.x, every app needs plugins, even to use basic functionality such as logging or geolocation. Rather than document which plugins/features your project needs and ask each new developer to install them, download and install them automatically with a hook in the after_platform_add step. Using this plugin, every time a developer checks out the project and adds a platform, they automatically have the required plugins.
You also may be interested in following along with this bug, which suggests npm style --save functionality: https://issues.apache.org/jira/browse/CB-5775
Platforms are a little more difficult because they don't fit into the hook architecture, but you could write a shell script which you could execute to add your platforms.
#!/bin/sh
for plat in ios android; do
cordova platform add $plat
done
You could do something similar with the version of cordova you have installed in node_modules (at least that is what I think you are installing in node_modules)--have shell script to get the correct version of cordova:
#!/bin/sh
VERSION=3.3.1-0.4.2
npm install cordova#$VERSION
PS Glad you liked the book!

Run a post-build script from brunch

I need to run a system script after a brunch build (either manually built or with brunch watch). Is there a good way to do that?
An alternative solution is to install the after-brunch NPM package that exposes a config point where you can insert command line scripts.
Create a plugin that will have onCompile method.
See example plugin https://github.com/steffenmllr/imageoptmizer-brunch/blob/master/src/index.coffee

Resources