Here is my package.json looks like:
{
"name": "Myproject",
"version": "0.4.13",
Note:Here 4 is not the minor version.0013 is minor
"dependencies": {
"lodash": "^4.0.0",
"vinyl-fs": "2.2.1"
},
"repository": {},
"devDependencies": {
.........
......
How can I automate versioning of package.json using Jenkins build.
Required format should be:
0.4.13-$BUILD_NUMBER
So far I try to do it using sed command:
sed -i "s/version: .*/version: 0.4.13-$BUILD_NUMBER/" package.json
But it's not updating version number in package.json file.
Also used
npm version 0.4.13-$BUILD_NUMBER
FYI:The generated build artifact should look like 0.0013-1.war
If you're using grunt, you could use the recommendation here.
Alternatively, there's a built in function in npm that does this for you. Run npm version, docs here.
Related
I just updated the polymer cli, on my linux pc to the freshly released version 1.0.0 (as confirmed by the polymer --version command).
However when I use the cli to set up a new polymer-2-application project, the bower.json file is still pointing to the 2.0.0-rc.3 version of polymer and other pre 2.0 release candidate dependencies.
{
"name": "temp",
"main": "index.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0-rc.3"
},
"devDependencies": {
"web-component-tester": "^6.0.0-prerelease.5",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0-rc.7"
}
}
How can I get polymer-cli to use the newly released stable 2.0.0 version?
I don't believe you are actually looking for the polymer-cli update. The polymer-cli is ran from a terminal and has commands for building, linting, serving, etc. The current version of the CLI is 1.0.0 as of today.
To update the CLI use, npm i -g polymer-cli
I believe what you are really asking about is the Polymer library which was tagged the other day as stable 2.0.0. you can update the line in your bower.json to point to ^2.0.0 instead of ^2.0.0-rc.3. Take a look at the Polymer Starter Kit for other dependency updates you should probably make. https://github.com/PolymerElements/polymer-starter-kit/blob/2.0-preview/bower.json
If you don't feel like taking a look...
{
"name": "temp",
"main": "index.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
},
"devDependencies": {
"web-component-tester": "^6.0.0"
}
}
https://www.polymer-project.org/2.0/docs/upgrade
You'll need to run npm install -g polymer-cli#next instead of the regular polymer-cli.
More information can be found here: https://www.polymer-project.org/2.0/docs/upgrade
I used nodejs on my vserver to make a tiny script to manage users in a db.
In package.json I added the "bin" and set it to my script. My attempt was to make a command available on the whole server so I dont need to go to the directory where the script lies and write "node usermanager.js".
I used npm link and it seemed to work fine:
/home/sl4yer/bin/cl9wnhook -> /home/sl4yer/lib/node_modules/cl9wnhook_usermanager/usermanager.js
/home/sl4yer/lib/node_modules/cl9wnhook_usermanager -> /home/sl4yer/cl9wnHook/usermanager
package.json btw is:
{
"name": "cl9wnhook_usermanager",
"version": "1.0.0",
"description": "User manager for cl9wnHook",
"main": "usermanager.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"cl9wnhook": "./usermanager.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"js-sha512": "^0.2.2",
"readline-sync": "^1.4.5"
}
}
so using the command "cl9wnhook" should work.
But when I call it, I get:
[sl4yer#lynx usermanager]$ cl9wnhook
: No such file or directory
Any idea?
sudo npm link
I did it, and successfully.
Try adding
#!/usr/bin/env node
on the top of your usermanager.js file. It should work.
Pack the package
npm pack
Then install it globally to run it from any folder.
npm install --global <package_file>.tgz
your bin in your package.json like this:
{
"bin": {
"app": "bin/app"
},
}
but first in your app file you should add at the top this #!/usr/bin/env node
Note
This will help you
Really things can mess up from time to time when working with NPM or Yarn. In these cases first do a complete clean install.
rm -rf ./node_modules
yarn install
npm install
If that doesn't solve your problem then check the bin property in package.json, if it is mapping to the cli file correctly?
You can check what is packed by running yarn pack.
In Mac Terminal:
package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.
Please include the following file with any support request:
npm ERR! /Users/stickupartist/portfolio/npm-debug.log
stickup-artists-macbook-pro:portfolio stickupartist$ npm init
This utility will walk you through creating a package.json file.
What utility is being referred to?
And next:
Use `npm install <pkg> --save` afterwards to install a package
and
save it as a dependency in the package.json file.
Name: (portfolio)
I type:
npm install <portfolio> --save
And the terminal prints out:
Sorry, name can only contain URL-friendly characters.
What am I doing wrong with my naming? I'm working on my local machine with Meteor, on Mac OS X.
To create the package.json file, you can run npm init (and go through its options) or manually create the file based on these rules.
Here's a simple package.json file:
{
"name": "my-cool-app",
"version": "1.0.0",
"description": "This is my cool app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
},
"author": "Me",
"license": "MIT",
"dependencies": {
"jquery": "1.1.1",
}
}
Now, as far as the error:
Sorry, name can only contain URL-friendly characters.
It means that the package name doesn't meet one of the naming rules, mainly:
package name must not contain any non-url-safe characters (since name ends up being part of a URL)
This is most likely happening because you wrapped your package name in <>.
<> means it is a placeholder for a value. When actually typing it in, you should overwrite it (and anything it wraps) with some appropriate value, in this case a valid package name.
It is how you would define an npm install command, not use it:
Definition:
npm install <package_name_goes_here>
Usage
npm install portfolio
Use: npm init -y
Then install your packages.
That worked for me when I had the same problem.
See nem035's answer to create package.json (just npm init).
For your other problem: in npm install <pkg> --save refers to the name of a package. You can install the package with its name, without brackets. For example, npm install portfolio --save
Log out of the session. Then re-login and try npm install -y. This has worked for me.
In a project I inherited, the packages.json looks roughly like this:
{
"name": "...",
"version": "...",
"description": "",
"author": "...",
"license": "ISC",
"dependencies": {
"lodash": "^3.10.1",
"assemble": "^0.4.37",
"cheerio": "^0.16.0",
"grunt": "^0.4.4",
"grunt-build-control": "^0.1.3",
},
"keywords": [
"handlebars-helper-md",
"handlebars-helper-rel"
]
}
When I first got it, lodash was ~2.4.1 and I'm trying to update it to 3.10.1 (as shown above). However, npm continues to install 2.4.1 at the top-level (Despite the package.json requesting the newer version) and it does not install the requested versions 2.4.1 or 2.4.2 in some of the dependencies (like assemble and cheerio). Thus when I npm install lodash#3.10.1 it complains about unmet dependencies.
I've tried removing node_modules and npm clear cache and rm -rf $HOME/.npm in different orders and combinations with no change.
How do I get lodash#3.10.1 to install at the top-level and the requested version of lodash in all the dependencies (and not have the dependencies use the top-level copy of lodash -- which I thought was the normal way for npm to work)?
Preferably a solution would not require updating all the dependencies to new versions (assuming that is even possible). That could be a solution, but that would require a lot more validation to make sure nothing broke.
Using the $ bower init command, I have created a bower.json for my package and registered it with Bower, no problem.
After looking at the Github homepages for some popular Bower packages, e.g. RequireJS and Modernizr, I've noticed their repo's don't contain a bower.json or a component.json. How is this possible?
I've also noticed that when I download any Bower package, the package contains a .bower.json file (note the dot in the beginning) and that file contains quite a bit more information than what I was asked during $ bower init for my package. For example, below is the .bower.json from Modernizr:
{
"name": "modernizr",
"homepage": "https://github.com/Modernizr/Modernizr",
"version": "2.6.2",
"_release": "2.6.2",
"_resolution": {
"type": "version",
"tag": "v2.6.2",
"commit": "ca45d02757b83367d8455d477e3cbc42dfdee035"
},
"_source": "git://github.com/Modernizr/Modernizr.git",
"_target": "~2.6.2",
"_direct": true
}
When I download my newly created package, it just contains the same info that I originally checked in to git.
Is there a new format for bower.json that I should be using? Or did I simply miss something in the setup process?
Bower doesn't need a bower.json or a component.json to install packages. The manifest file provide some useful info, like dependencies, ignored files, version and etc, but in the end it just downloads Git commits and place them somewhere.
In the case of Modernizr/Require.js, someone just registered their repos and Bower is retrieving a tag.
About the .bower.json file: this is generated by Bower itself after installing a package. It contains some more verbose info about a package, like the commit from which the package was retrieved, for example.
TL;DR: Keep using bower init, it'll do the right thing for you!
I am using Yeoman and the following is the content of my bower.json file. I thought it might help you. (I have installed all the latest versions of bower and grunt)
{
"name": "yowebapp",
"version": "0.0.0",
"dependencies": {
"sass-bootstrap": "~3.0",
"requirejs": "~2.1.4",
"modernizr": "~2.6.2",
"jquery": "~1.9.1",
"d3":"~3.3.2",
"angular":"1.0.7"
},
"devDependencies": {}
}
and I download my dependencies with bower install.