Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Jan 27, 2016
0 parents commit 4b42e5f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file added README.md
Empty file.
62 changes: 62 additions & 0 deletions bin/cnpm-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env node
var readPkgUp = require('read-pkg-up')
var npa = require('npm-package-arg')
var debug = require('debug')('cnpm:install')
var dirname = require('path').dirname
var join = require('path').join
var mkdirp = require('../lib/mkdirp')

const cli = require('meow')([
'Usage:',
' $ cnpm install',
' $ cnpm install <name>',
'',
'Options:',
' -D, --save-dev',
' -S, --save',
' -E, --save-exact',
' --dry-run'
].join('\n'), {
boolean: ['save-dev', 'save', 'save-exact', 'dry-run']
})
// console.log(cli.flags, cli.input)

/*
* Installs a package
*
* install(path, 'underscore@latest')
*/

function install (modPath, pkg, options) {
debug('installing ' + pkg)
return Promise.resolve(true)
}

/*
* Install multiple modules
*/

function installMultiple (modPath, pkgs, options) {
return Promise.all(pkgs.map(function (pkg) {
return install(modPath, pkg, options)
}))
}

/*
* Returns the path of package.json
*/

function getPath () {
return readPkgUp()
.then(function (pkg) {
debug('root: ' + dirname(pkg.path))
return dirname(pkg.path)
})
}

if (!module.parent) {
getPath()
.then(_ => mkdirp(join(_, 'node_modules')))
.then(_ => installMultiple(_, cli.input, cli.flags))
.catch(require('../lib/err'))
}
4 changes: 4 additions & 0 deletions lib/err.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function err (error) {
console.error(err.stack)
process.exit(1)
}
15 changes: 15 additions & 0 deletions lib/mkdirp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var debug = require('debug')('cnpm:mkdirp')

/*
* mkdir -p as a promise.
*/

module.exports = function mkdirp (path) {
return new Promise(function (resolve, reject) {
debug(path)
require('mkdirp')(path, function (err) {
if (err) reject(err)
else resolve(path)
})
})
}
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "cnpm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Rico Sta. Cruz <rico@ricostacruz.com>",
"license": "MIT",
"dependencies": {
"meow": "3.7.0",
"npm-package-arg": "4.1.0",
"read-pkg-up": "1.0.1"
},
"bin": {
"cnpm-install": "bin/cnpm-install"
},
"devDependencies": {
"debug": "2.2.0",
"mkdirp": "0.5.1",
"thenify": "3.1.1"
}
}

0 comments on commit 4b42e5f

Please sign in to comment.