buddy-cli
Advanced tools
Comparing version 0.9.0 to 0.10.0
108
index.js
var fs = require('fs') | ||
, path = require('path') | ||
, mkdirp = require('mkdirp') | ||
, spawn = require('child_process').spawn | ||
, existsSync = fs.existsSync || path.existsSync | ||
, existsSync = fs.existsSync | ||
, program = require('commander') | ||
, promptly = require('promptly') | ||
, prompt = promptly.prompt | ||
, confirm = promptly.confirm | ||
, useCli = require.main.filename.indexOf('buddy-cli') != -1 | ||
, Builder, builder, ver, npm; | ||
, Builder, builder, ver; | ||
@@ -37,47 +33,2 @@ // Register for uncaught errors and clean up | ||
program | ||
.command('init') | ||
.description('set up a basic buddy project') | ||
.action(function() { | ||
if (existsSync(path.resolve('package.json'))) { | ||
throw('package.json already exists'); | ||
} else { | ||
var pkg = { | ||
name: '', | ||
version: '0.1.0', | ||
devDependencies: {buddy: '*'}, | ||
buddy: {} | ||
} | ||
, dir = path.basename(process.cwd()); | ||
console.log('This utility will walk you through a basic \033[0;90mbuddy\033[0m \033[0;36mpackage.json\033[0m set-up.'); | ||
prompt('+ project name: (' + dir + ')', {default: dir}, function(err, name) { | ||
pkg.name = name; | ||
prompt('+ project version (0.1.0): ', {default: '0.1.0'}, function(err, version) { | ||
if (version) pkg.version = version; | ||
addBuild('js', pkg.buddy, function() { | ||
addBuild('css', pkg.buddy, function() { | ||
addBuild('html', pkg.buddy, function() { | ||
var filename = path.resolve(process.cwd(), 'package.json'); | ||
fs.writeFileSync(filename, JSON.stringify(pkg, null, 2), 'utf8'); | ||
console.log('Installing buddy...'); | ||
npm = spawn('npm', ['install']); | ||
npm.on('exit', function(code) { | ||
if (code == 0) { | ||
findBuddy(); | ||
// Replace buddy version with latest version number | ||
fs.writeFileSync(filename, JSON.stringify(pkg, null, 2).replace('*', ver), 'utf8'); | ||
console.log('See \033[0;90mhttps://github.com/popeindustries/buddy\033[0m for more.\n\033[0;32mHappy coding!\033[0m'); | ||
process.exit(0); | ||
} else { | ||
throw('OOPS! Having trouble installing Buddy. Try running "npm install" manually'); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
program | ||
.command('install [config]') | ||
@@ -159,3 +110,3 @@ .description('install dependencies [ADD-ON buddy-dependencies]') | ||
/** | ||
* Walk directory tree to find nearest node_modules/buddy | ||
* Walk directory tree from cwd to find nearest node_modules/buddy | ||
*/ | ||
@@ -177,3 +128,3 @@ function findBuddy () { | ||
if (typeof dir !== "undefined" && dir !== null) { | ||
prnt = path.resolve(dir, '../'); | ||
prnt = path.resolve(dir, '..'); | ||
// Exit if we can no longer go up a level | ||
@@ -213,53 +164,2 @@ if (prnt === dir) { | ||
} | ||
} | ||
/** | ||
* Add prompts for build 'type' | ||
* @param {String} type | ||
* @param {Object} obj | ||
* @param {Function} fn | ||
*/ | ||
function addBuild (type, obj, fn) { | ||
confirm('+ build ' + type + ' (y/n)?: ', function(err, ok) { | ||
if (ok) { | ||
if (!obj.build) obj.build = {}; | ||
var build = obj.build[type] = {}; | ||
prompt('+ source directories: ', {default: ''}, function(err, source) { | ||
if (source) { | ||
build.sources = source.split(' '); | ||
createDir(build.sources); | ||
} | ||
prompt('+ input file or directory: ', function(err, input) { | ||
var target = { | ||
input: input, | ||
output: '' | ||
}; | ||
build.targets = [target]; | ||
createDir(input); | ||
prompt('+ output file or directory: ', function(err, output) { | ||
target.output = output; | ||
createDir(output); | ||
fn(); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
fn(); | ||
} | ||
}); | ||
} | ||
/** | ||
* Create subdirectory 'str' in current directory | ||
* @param {String|Array} str | ||
*/ | ||
function createDir (str) { | ||
if (Array.isArray(str)) { | ||
str.forEach(createDir.bind(this)); | ||
} else { | ||
var filepath = path.resolve(str); | ||
// Resolve directory name if passed a file | ||
if (path.extname(filepath).length) filepath = path.dirname(filepath); | ||
if (!existsSync(filepath)) mkdirp.sync(filepath); | ||
} | ||
} |
{ | ||
"name": "buddy-cli", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "The command-line bootstrapper for buddy(1).", | ||
@@ -17,3 +17,3 @@ "author": "popeindustries <alex@pope-industries.com>", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.11.9" | ||
}, | ||
@@ -20,0 +20,0 @@ "repository": "https://github.com/popeindustries/buddy-cli.git", |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
0
10331
143