ubuntuvimdeMacBook-Pro:randomNichname ubuntuvim$ npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file.
Press ^C at any time to quit. name: (randomNichname) Sorry, name can no longer contain capital letters. name: (randomNichname) randomNichname Sorry, name can no longer contain capital letters. name: (randomNichname) y version: (1.0.0) 0.1.0 description: Get the name of the three kingdoms. entry point: (index.js) y test command: git repository: https://github.com/ubuntuvim/randomNichname.git keywords: nickname,random author: ubuntuvim license: (ISC) ISC About to write to /Users/ubuntuvim/codes/my-npm-plugins/randomNichname/package.json:
{ "name": "y", "version": "0.1.0", "description": "Get the name of the three kingdoms.", "main": "y", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/ubuntuvim/randomNichname.git" }, "keywords": [ "nickname", "random" ], "author": "ubuntuvim", "license": "ISC", "bugs": { "url": "https://github.com/ubuntuvim/randomNichname/issues" }, "homepage": "https://github.com/ubuntuvim/randomNichname#readme" }
Is this ok? (yes) yes ubuntuvimdeMacBook-Pro:randomNichname ubuntuvim$
var names = require('randomNickname'); var s = names.getNickname(); console.log('得到的人物名字为: ' + s);
提交代码到github
步骤如下:
git init
git remote add origin <git远程URL>
git add *
git commit -am '描述信息'
git push origin master 如果出现类似如下错误
1 2 3 4 5 6
! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/ubuntuvim/randomNickname.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
先更新合并再提交到远程代码库。
git pull
git merge origin/master
git push origin/master
发布到npmjs官网
步骤如下:
npm adduser (输入你在npmjs官网注册的账号和密码)
npm publish .
如果出现错误: no_perms Private mode enable, only admin can publish this module 执行下列代码重置后再执行npm adduser、npm publish .。