first commit
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
require('./_acorn.js');
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var atob = require('../node-atob');
|
||||
var str = process.argv[2];
|
||||
console.log(atob(str));
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
let mode = process.argv[2]
|
||||
if (mode === '--info') {
|
||||
process.stdout.write(
|
||||
require('../')().info() + '\n')
|
||||
} else if (mode === '--version') {
|
||||
process.stdout.write(
|
||||
'autoprefixer ' + require('../package.json').version + '\n')
|
||||
} else {
|
||||
process.stdout.write(
|
||||
'autoprefix\n' +
|
||||
'\n' +
|
||||
'Options:\n' +
|
||||
' --info Show target browsers and used prefixes\n' +
|
||||
' --version Show version number\n' +
|
||||
' --help Show help\n' +
|
||||
'\n' +
|
||||
'Usage:\n' +
|
||||
' autoprefixer --info\n'
|
||||
)
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs')
|
||||
|
||||
var browserslist = require('./')
|
||||
var pkg = require('./package.json')
|
||||
var args = process.argv.slice(2)
|
||||
|
||||
var USAGE = 'Usage:\n' +
|
||||
' ' + pkg.name + '\n' +
|
||||
' ' + pkg.name + ' "QUERIES"\n' +
|
||||
' ' + pkg.name + ' --json "QUERIES"\n' +
|
||||
' ' + pkg.name + ' --config="path/to/browserlist/file"\n' +
|
||||
' ' + pkg.name + ' --coverage "QUERIES"\n' +
|
||||
' ' + pkg.name + ' --coverage=US "QUERIES"\n' +
|
||||
' ' + pkg.name + ' --coverage=US,RU,world "QUERIES"\n' +
|
||||
' ' + pkg.name + ' --env="environment name defined in config"\n' +
|
||||
' ' + pkg.name + ' --stats="path/to/browserlist/stats/file"'
|
||||
|
||||
function isArg (arg) {
|
||||
return args.some(function (str) {
|
||||
return str === arg || str.indexOf(arg + '=') === 0
|
||||
})
|
||||
}
|
||||
|
||||
function error (msg) {
|
||||
process.stderr.write(pkg.name + ': ' + msg + '\n')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (isArg('--help') || isArg('-h')) {
|
||||
process.stdout.write(pkg.description + '.\n\n' + USAGE + '\n')
|
||||
} else if (isArg('--version') || isArg('-v')) {
|
||||
process.stdout.write(pkg.name + ' ' + pkg.version + '\n')
|
||||
} else {
|
||||
var mode = 'browsers'
|
||||
var opts = { }
|
||||
var queries
|
||||
var areas
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i][0] !== '-') {
|
||||
queries = args[i].replace(/^["']|["']$/g, '')
|
||||
continue
|
||||
}
|
||||
|
||||
var arg = args[i].split('=')
|
||||
var name = arg[0]
|
||||
var value = arg[1]
|
||||
|
||||
if (value) value = value.replace(/^["']|["']$/g, '')
|
||||
|
||||
if (name === '--config' || name === '-b') {
|
||||
opts.config = value
|
||||
} else if (name === '--env' || name === '-e') {
|
||||
opts.env = value
|
||||
} else if (name === '--stats' || name === '-s') {
|
||||
opts.stats = value
|
||||
} else if (name === '--coverage' || name === '-c') {
|
||||
if (mode !== 'json') mode = 'coverage'
|
||||
if (value) {
|
||||
areas = value.split(',')
|
||||
} else {
|
||||
areas = ['global']
|
||||
}
|
||||
} else if (name === '--json') {
|
||||
mode = 'json'
|
||||
} else {
|
||||
error('Unknown arguments ' + args[i] + '.\n\n' + USAGE)
|
||||
}
|
||||
}
|
||||
|
||||
var browsers
|
||||
try {
|
||||
if (!queries && !opts.config) {
|
||||
if (browserslist.findConfig(process.cwd())) {
|
||||
opts.path = process.cwd()
|
||||
} else {
|
||||
error(
|
||||
'Browserslist config was not found. ' +
|
||||
'Define queries or config path.' +
|
||||
'\n\n' + USAGE
|
||||
)
|
||||
}
|
||||
}
|
||||
browsers = browserslist(queries, opts)
|
||||
} catch (e) {
|
||||
if (e.name === 'BrowserslistError') {
|
||||
error(e.message)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
var coverage
|
||||
if (mode === 'browsers') {
|
||||
browsers.forEach(function (browser) {
|
||||
process.stdout.write(browser + '\n')
|
||||
})
|
||||
} else if (areas) {
|
||||
coverage = areas.map(function (area) {
|
||||
var stats
|
||||
if (area !== 'global') {
|
||||
stats = area
|
||||
} else if (opts.stats) {
|
||||
stats = JSON.parse(fs.readFileSync(opts.stats))
|
||||
}
|
||||
var result = browserslist.coverage(browsers, stats)
|
||||
var round = Math.round(result * 100) / 100.0
|
||||
|
||||
return [area, round]
|
||||
})
|
||||
|
||||
if (mode === 'coverage') {
|
||||
var prefix = 'These browsers account for '
|
||||
process.stdout.write(prefix)
|
||||
coverage.forEach(function (data, index) {
|
||||
var area = data[0]
|
||||
var round = data[1]
|
||||
var end = 'globally'
|
||||
if (area && area !== 'global') {
|
||||
end = 'in the ' + area.toUpperCase()
|
||||
} else if (opts.stats) {
|
||||
end = 'in custom statistics'
|
||||
}
|
||||
|
||||
if (index !== 0) {
|
||||
process.stdout.write(prefix.replace(/./g, ' '))
|
||||
}
|
||||
|
||||
process.stdout.write(round + '% of all users ' + end + '\n')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (mode === 'json') {
|
||||
var data = { browsers: browsers }
|
||||
if (coverage) {
|
||||
data.coverage = coverage.reduce(function (object, j) {
|
||||
object[j[0]] = j[1]
|
||||
return object
|
||||
}, { })
|
||||
}
|
||||
process.stdout.write(JSON.stringify(data, null, ' ') + '\n')
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
var colorSupport = require('./')({alwaysReturn: true })
|
||||
console.log(JSON.stringify(colorSupport, null, 2))
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('../lib/cli');
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* ./bin/gonzales.js filename
|
||||
* ./bin/gonzales.js filename -s
|
||||
*/
|
||||
var gonzales = require('..'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
filename = process.argv[2],
|
||||
silent = process.argv[3] === '-s';
|
||||
|
||||
if (!filename) {
|
||||
console.log('Please supply a filename. Usage "gonzales file"');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
var syntax = path.extname(filename).substring(1);
|
||||
var css = fs.readFileSync(filename, 'utf-8');
|
||||
|
||||
try {
|
||||
var ast = gonzales.parse(css, {syntax: syntax});
|
||||
if (!silent) console.log(ast.toString());
|
||||
} catch (e) {
|
||||
if (!silent) throw e;
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
var gutil = require('gulp-util');
|
||||
var prettyTime = require('pretty-hrtime');
|
||||
var chalk = require('chalk');
|
||||
var semver = require('semver');
|
||||
var archy = require('archy');
|
||||
var Liftoff = require('liftoff');
|
||||
var tildify = require('tildify');
|
||||
var interpret = require('interpret');
|
||||
var v8flags = require('v8flags');
|
||||
var completion = require('../lib/completion');
|
||||
var argv = require('minimist')(process.argv.slice(2));
|
||||
var taskTree = require('../lib/taskTree');
|
||||
|
||||
// Set env var for ORIGINAL cwd
|
||||
// before anything touches it
|
||||
process.env.INIT_CWD = process.cwd();
|
||||
|
||||
var cli = new Liftoff({
|
||||
name: 'gulp',
|
||||
completions: completion,
|
||||
extensions: interpret.jsVariants,
|
||||
v8flags: v8flags,
|
||||
});
|
||||
|
||||
// Exit with 0 or 1
|
||||
var failed = false;
|
||||
process.once('exit', function(code) {
|
||||
if (code === 0 && failed) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Parse those args m8
|
||||
var cliPackage = require('../package');
|
||||
var versionFlag = argv.v || argv.version;
|
||||
var tasksFlag = argv.T || argv.tasks;
|
||||
var tasks = argv._;
|
||||
var toRun = tasks.length ? tasks : ['default'];
|
||||
|
||||
// This is a hold-over until we have a better logging system
|
||||
// with log levels
|
||||
var simpleTasksFlag = argv['tasks-simple'];
|
||||
var shouldLog = !argv.silent && !simpleTasksFlag;
|
||||
|
||||
if (!shouldLog) {
|
||||
gutil.log = function() {};
|
||||
}
|
||||
|
||||
cli.on('require', function(name) {
|
||||
gutil.log('Requiring external module', chalk.magenta(name));
|
||||
});
|
||||
|
||||
cli.on('requireFail', function(name) {
|
||||
gutil.log(chalk.red('Failed to load external module'), chalk.magenta(name));
|
||||
});
|
||||
|
||||
cli.on('respawn', function(flags, child) {
|
||||
var nodeFlags = chalk.magenta(flags.join(', '));
|
||||
var pid = chalk.magenta(child.pid);
|
||||
gutil.log('Node flags detected:', nodeFlags);
|
||||
gutil.log('Respawned to PID:', pid);
|
||||
});
|
||||
|
||||
cli.launch({
|
||||
cwd: argv.cwd,
|
||||
configPath: argv.gulpfile,
|
||||
require: argv.require,
|
||||
completion: argv.completion,
|
||||
}, handleArguments);
|
||||
|
||||
// The actual logic
|
||||
function handleArguments(env) {
|
||||
if (versionFlag && tasks.length === 0) {
|
||||
gutil.log('CLI version', cliPackage.version);
|
||||
if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') {
|
||||
gutil.log('Local version', env.modulePackage.version);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!env.modulePath) {
|
||||
gutil.log(
|
||||
chalk.red('Local gulp not found in'),
|
||||
chalk.magenta(tildify(env.cwd))
|
||||
);
|
||||
gutil.log(chalk.red('Try running: npm install gulp'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!env.configPath) {
|
||||
gutil.log(chalk.red('No gulpfile found'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check for semver difference between cli and local installation
|
||||
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
|
||||
gutil.log(chalk.red('Warning: gulp version mismatch:'));
|
||||
gutil.log(chalk.red('Global gulp is', cliPackage.version));
|
||||
gutil.log(chalk.red('Local gulp is', env.modulePackage.version));
|
||||
}
|
||||
|
||||
// Chdir before requiring gulpfile to make sure
|
||||
// we let them chdir as needed
|
||||
if (process.cwd() !== env.cwd) {
|
||||
process.chdir(env.cwd);
|
||||
gutil.log(
|
||||
'Working directory changed to',
|
||||
chalk.magenta(tildify(env.cwd))
|
||||
);
|
||||
}
|
||||
|
||||
// This is what actually loads up the gulpfile
|
||||
require(env.configPath);
|
||||
gutil.log('Using gulpfile', chalk.magenta(tildify(env.configPath)));
|
||||
|
||||
var gulpInst = require(env.modulePath);
|
||||
logEvents(gulpInst);
|
||||
|
||||
process.nextTick(function() {
|
||||
if (simpleTasksFlag) {
|
||||
return logTasksSimple(env, gulpInst);
|
||||
}
|
||||
if (tasksFlag) {
|
||||
return logTasks(env, gulpInst);
|
||||
}
|
||||
gulpInst.start.apply(gulpInst, toRun);
|
||||
});
|
||||
}
|
||||
|
||||
function logTasks(env, localGulp) {
|
||||
var tree = taskTree(localGulp.tasks);
|
||||
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
|
||||
archy(tree)
|
||||
.split('\n')
|
||||
.forEach(function(v) {
|
||||
if (v.trim().length === 0) {
|
||||
return;
|
||||
}
|
||||
gutil.log(v);
|
||||
});
|
||||
}
|
||||
|
||||
function logTasksSimple(env, localGulp) {
|
||||
console.log(Object.keys(localGulp.tasks)
|
||||
.join('\n')
|
||||
.trim());
|
||||
}
|
||||
|
||||
// Format orchestrator errors
|
||||
function formatError(e) {
|
||||
if (!e.err) {
|
||||
return e.message;
|
||||
}
|
||||
|
||||
// PluginError
|
||||
if (typeof e.err.showStack === 'boolean') {
|
||||
return e.err.toString();
|
||||
}
|
||||
|
||||
// Normal error
|
||||
if (e.err.stack) {
|
||||
return e.err.stack;
|
||||
}
|
||||
|
||||
// Unknown (string, number, etc.)
|
||||
return new Error(String(e.err)).stack;
|
||||
}
|
||||
|
||||
// Wire up logging events
|
||||
function logEvents(gulpInst) {
|
||||
|
||||
// Total hack due to poor error management in orchestrator
|
||||
gulpInst.on('err', function() {
|
||||
failed = true;
|
||||
});
|
||||
|
||||
gulpInst.on('task_start', function(e) {
|
||||
// TODO: batch these
|
||||
// so when 5 tasks start at once it only logs one time with all 5
|
||||
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
|
||||
});
|
||||
|
||||
gulpInst.on('task_stop', function(e) {
|
||||
var time = prettyTime(e.hrDuration);
|
||||
gutil.log(
|
||||
'Finished', '\'' + chalk.cyan(e.task) + '\'',
|
||||
'after', chalk.magenta(time)
|
||||
);
|
||||
});
|
||||
|
||||
gulpInst.on('task_err', function(e) {
|
||||
var msg = formatError(e);
|
||||
var time = prettyTime(e.hrDuration);
|
||||
gutil.log(
|
||||
'\'' + chalk.cyan(e.task) + '\'',
|
||||
chalk.red('errored after'),
|
||||
chalk.magenta(time)
|
||||
);
|
||||
gutil.log(msg);
|
||||
});
|
||||
|
||||
gulpInst.on('task_not_found', function(err) {
|
||||
gutil.log(
|
||||
chalk.red('Task \'' + err.task + '\' is not in your gulpfile')
|
||||
);
|
||||
gutil.log('Please check the documentation for proper gulpfile formatting');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
var inInstall = require('./index.js').inInstall
|
||||
process.exit(inInstall() ? 0 : 1)
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
var inPublish = require('./index.js').inPublish
|
||||
process.exit(inPublish() ? 0 : 1)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var mkdirp = require('../');
|
||||
var minimist = require('minimist');
|
||||
var fs = require('fs');
|
||||
|
||||
var argv = minimist(process.argv.slice(2), {
|
||||
alias: { m: 'mode', h: 'help' },
|
||||
string: [ 'mode' ]
|
||||
});
|
||||
if (argv.help) {
|
||||
fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
var paths = argv._.slice();
|
||||
var mode = argv.mode ? parseInt(argv.mode, 8) : undefined;
|
||||
|
||||
(function next () {
|
||||
if (paths.length === 0) return;
|
||||
var p = paths.shift();
|
||||
|
||||
if (mode === undefined) mkdirp(p, cb)
|
||||
else mkdirp(p, mode, cb)
|
||||
|
||||
function cb (err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
else next();
|
||||
}
|
||||
})();
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Set the title.
|
||||
*/
|
||||
|
||||
process.title = 'node-gyp'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var gyp = require('../')
|
||||
var log = require('npmlog')
|
||||
var osenv = require('osenv')
|
||||
var path = require('path')
|
||||
|
||||
/**
|
||||
* Process and execute the selected commands.
|
||||
*/
|
||||
|
||||
var prog = gyp()
|
||||
var completed = false
|
||||
prog.parseArgv(process.argv)
|
||||
prog.devDir = prog.opts.devdir
|
||||
|
||||
var homeDir = osenv.home()
|
||||
if (prog.devDir) {
|
||||
prog.devDir = prog.devDir.replace(/^~/, homeDir)
|
||||
} else if (homeDir) {
|
||||
prog.devDir = path.resolve(homeDir, '.node-gyp')
|
||||
} else {
|
||||
throw new Error(
|
||||
"node-gyp requires that the user's home directory is specified " +
|
||||
"in either of the environmental variables HOME or USERPROFILE. " +
|
||||
"Overide with: --devdir /path/to/.node-gyp")
|
||||
}
|
||||
|
||||
if (prog.todo.length === 0) {
|
||||
if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {
|
||||
console.log('v%s', prog.version)
|
||||
} else {
|
||||
console.log('%s', prog.usage())
|
||||
}
|
||||
return process.exit(0)
|
||||
}
|
||||
|
||||
log.info('it worked if it ends with', 'ok')
|
||||
log.verbose('cli', process.argv)
|
||||
log.info('using', 'node-gyp@%s', prog.version)
|
||||
log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch)
|
||||
|
||||
|
||||
/**
|
||||
* Change dir if -C/--directory was passed.
|
||||
*/
|
||||
|
||||
var dir = prog.opts.directory
|
||||
if (dir) {
|
||||
var fs = require('fs')
|
||||
try {
|
||||
var stat = fs.statSync(dir)
|
||||
if (stat.isDirectory()) {
|
||||
log.info('chdir', dir)
|
||||
process.chdir(dir)
|
||||
} else {
|
||||
log.warn('chdir', dir + ' is not a directory')
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
log.warn('chdir', dir + ' is not a directory')
|
||||
} else {
|
||||
log.warn('chdir', 'error during chdir() "%s"', e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function run () {
|
||||
var command = prog.todo.shift()
|
||||
if (!command) {
|
||||
// done!
|
||||
completed = true
|
||||
log.info('ok')
|
||||
return
|
||||
}
|
||||
|
||||
prog.commands[command.name](command.args, function (err) {
|
||||
if (err) {
|
||||
log.error(command.name + ' error')
|
||||
log.error('stack', err.stack)
|
||||
errorMessage()
|
||||
log.error('not ok')
|
||||
return process.exit(1)
|
||||
}
|
||||
if (command.name == 'list') {
|
||||
var versions = arguments[1]
|
||||
if (versions.length > 0) {
|
||||
versions.forEach(function (version) {
|
||||
console.log(version)
|
||||
})
|
||||
} else {
|
||||
console.log('No node development files installed. Use `node-gyp install` to install a version.')
|
||||
}
|
||||
} else if (arguments.length >= 2) {
|
||||
console.log.apply(console, [].slice.call(arguments, 1))
|
||||
}
|
||||
|
||||
// now run the next command in the queue
|
||||
process.nextTick(run)
|
||||
})
|
||||
}
|
||||
|
||||
process.on('exit', function (code) {
|
||||
if (!completed && !code) {
|
||||
log.error('Completion callback never invoked!')
|
||||
issueMessage()
|
||||
process.exit(6)
|
||||
}
|
||||
})
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
log.error('UNCAUGHT EXCEPTION')
|
||||
log.error('stack', err.stack)
|
||||
issueMessage()
|
||||
process.exit(7)
|
||||
})
|
||||
|
||||
function errorMessage () {
|
||||
// copied from npm's lib/util/error-handler.js
|
||||
var os = require('os')
|
||||
log.error('System', os.type() + ' ' + os.release())
|
||||
log.error('command', process.argv
|
||||
.map(JSON.stringify).join(' '))
|
||||
log.error('cwd', process.cwd())
|
||||
log.error('node -v', process.version)
|
||||
log.error('node-gyp -v', 'v' + prog.package.version)
|
||||
}
|
||||
|
||||
function issueMessage () {
|
||||
errorMessage()
|
||||
log.error('', [ 'This is a bug in `node-gyp`.'
|
||||
, 'Try to update node-gyp and file an Issue if it does not help:'
|
||||
, ' <https://github.com/nodejs/node-gyp/issues>'
|
||||
].join('\n'))
|
||||
}
|
||||
|
||||
// start running the given commands!
|
||||
run()
|
||||
+412
@@ -0,0 +1,412 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var Emitter = require('events').EventEmitter,
|
||||
forEach = require('async-foreach').forEach,
|
||||
Gaze = require('gaze'),
|
||||
meow = require('meow'),
|
||||
util = require('util'),
|
||||
path = require('path'),
|
||||
glob = require('glob'),
|
||||
sass = require('../lib'),
|
||||
render = require('../lib/render'),
|
||||
watcher = require('../lib/watcher'),
|
||||
stdout = require('stdout-stream'),
|
||||
stdin = require('get-stdin'),
|
||||
fs = require('fs');
|
||||
|
||||
/**
|
||||
* Initialize CLI
|
||||
*/
|
||||
|
||||
var cli = meow({
|
||||
pkg: '../package.json',
|
||||
version: sass.info,
|
||||
help: [
|
||||
'Usage:',
|
||||
' node-sass [options] <input.scss>',
|
||||
' cat <input.scss> | node-sass [options] > output.css',
|
||||
'',
|
||||
'Example: Compile foobar.scss to foobar.css',
|
||||
' node-sass --output-style compressed foobar.scss > foobar.css',
|
||||
' cat foobar.scss | node-sass --output-style compressed > foobar.css',
|
||||
'',
|
||||
'Example: Watch the sass directory for changes, compile with sourcemaps to the css directory',
|
||||
' node-sass --watch --recursive --output css',
|
||||
' --source-map true --source-map-contents sass',
|
||||
'',
|
||||
'Options',
|
||||
' -w, --watch Watch a directory or file',
|
||||
' -r, --recursive Recursively watch directories or files',
|
||||
' -o, --output Output directory',
|
||||
' -x, --omit-source-map-url Omit source map URL comment from output',
|
||||
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
|
||||
' -q, --quiet Suppress log output except on error',
|
||||
' -v, --version Prints version info',
|
||||
' --output-style CSS output style (nested | expanded | compact | compressed)',
|
||||
' --indent-type Indent type for output CSS (space | tab)',
|
||||
' --indent-width Indent width; number of spaces or tabs (maximum value: 10)',
|
||||
' --linefeed Linefeed style (cr | crlf | lf | lfcr)',
|
||||
' --source-comments Include debug info in output',
|
||||
' --source-map Emit source map (boolean, or path to output .map file)',
|
||||
' --source-map-contents Embed include contents in map',
|
||||
' --source-map-embed Embed sourceMappingUrl as data URI',
|
||||
' --source-map-root Base path, will be emitted in source-map as is',
|
||||
' --include-path Path to look for imported files',
|
||||
' --follow Follow symlinked directories',
|
||||
' --precision The amount of precision allowed in decimal numbers',
|
||||
' --error-bell Output a bell character on errors',
|
||||
' --importer Path to .js file containing custom importer',
|
||||
' --functions Path to .js file containing custom functions',
|
||||
' --help Print usage info'
|
||||
].join('\n')
|
||||
}, {
|
||||
boolean: [
|
||||
'error-bell',
|
||||
'follow',
|
||||
'indented-syntax',
|
||||
'omit-source-map-url',
|
||||
'quiet',
|
||||
'recursive',
|
||||
'source-map-embed',
|
||||
'source-map-contents',
|
||||
'source-comments',
|
||||
'watch'
|
||||
],
|
||||
string: [
|
||||
'functions',
|
||||
'importer',
|
||||
'include-path',
|
||||
'indent-type',
|
||||
'linefeed',
|
||||
'output',
|
||||
'output-style',
|
||||
'precision',
|
||||
'source-map-root'
|
||||
],
|
||||
alias: {
|
||||
c: 'source-comments',
|
||||
i: 'indented-syntax',
|
||||
q: 'quiet',
|
||||
o: 'output',
|
||||
r: 'recursive',
|
||||
x: 'omit-source-map-url',
|
||||
v: 'version',
|
||||
w: 'watch'
|
||||
},
|
||||
default: {
|
||||
'include-path': process.cwd(),
|
||||
'indent-type': 'space',
|
||||
'indent-width': 2,
|
||||
linefeed: 'lf',
|
||||
'output-style': 'nested',
|
||||
precision: 5,
|
||||
quiet: false,
|
||||
recursive: true
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Is a Directory
|
||||
*
|
||||
* @param {String} filePath
|
||||
* @returns {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isDirectory(filePath) {
|
||||
var isDir = false;
|
||||
try {
|
||||
var absolutePath = path.resolve(filePath);
|
||||
isDir = fs.statSync(absolutePath).isDirectory();
|
||||
} catch (e) {
|
||||
isDir = e.code === 'ENOENT';
|
||||
}
|
||||
return isDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct glob pattern
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function globPattern(options) {
|
||||
return options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create emitter
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getEmitter() {
|
||||
var emitter = new Emitter();
|
||||
|
||||
emitter.on('error', function(err) {
|
||||
if (options.errorBell) {
|
||||
err += '\x07';
|
||||
}
|
||||
console.error(err);
|
||||
if (!options.watch) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
emitter.on('warn', function(data) {
|
||||
if (!options.quiet) {
|
||||
console.warn(data);
|
||||
}
|
||||
});
|
||||
|
||||
emitter.on('info', function(data) {
|
||||
if (!options.quiet) {
|
||||
console.info(data);
|
||||
}
|
||||
});
|
||||
|
||||
emitter.on('log', stdout.write.bind(stdout));
|
||||
|
||||
return emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct options
|
||||
*
|
||||
* @param {Array} arguments
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getOptions(args, options) {
|
||||
var cssDir, sassDir, file, mapDir;
|
||||
options.src = args[0];
|
||||
|
||||
if (args[1]) {
|
||||
options.dest = path.resolve(args[1]);
|
||||
} else if (options.output) {
|
||||
options.dest = path.join(
|
||||
path.resolve(options.output),
|
||||
[path.basename(options.src, path.extname(options.src)), '.css'].join('')); // replace ext.
|
||||
}
|
||||
|
||||
if (options.directory) {
|
||||
sassDir = path.resolve(options.directory);
|
||||
file = path.relative(sassDir, args[0]);
|
||||
cssDir = path.resolve(options.output);
|
||||
options.dest = path.join(cssDir, file).replace(path.extname(file), '.css');
|
||||
}
|
||||
|
||||
if (options.sourceMap) {
|
||||
if(!options.sourceMapOriginal) {
|
||||
options.sourceMapOriginal = options.sourceMap;
|
||||
}
|
||||
|
||||
// check if sourceMap path ends with .map to avoid isDirectory false-positive
|
||||
var sourceMapIsDirectory = options.sourceMapOriginal.indexOf('.map', options.sourceMapOriginal.length - 4) === -1 && isDirectory(options.sourceMapOriginal);
|
||||
|
||||
if (options.sourceMapOriginal === 'true') {
|
||||
options.sourceMap = options.dest + '.map';
|
||||
} else if (!sourceMapIsDirectory) {
|
||||
options.sourceMap = path.resolve(options.sourceMapOriginal);
|
||||
} else if (sourceMapIsDirectory) {
|
||||
if (!options.directory) {
|
||||
options.sourceMap = path.resolve(options.sourceMapOriginal, path.basename(options.dest) + '.map');
|
||||
} else {
|
||||
sassDir = path.resolve(options.directory);
|
||||
file = path.relative(sassDir, args[0]);
|
||||
mapDir = path.resolve(options.sourceMapOriginal);
|
||||
options.sourceMap = path.join(mapDir, file).replace(path.extname(file), '.css.map');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function watch(options, emitter) {
|
||||
var handler = function(files) {
|
||||
files.added.forEach(function(file) {
|
||||
var watch = gaze.watched();
|
||||
Object.keys(watch).forEach(function (dir) {
|
||||
if (watch[dir].indexOf(file) !== -1) {
|
||||
gaze.add(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
files.changed.forEach(function(file) {
|
||||
if (path.basename(file)[0] !== '_') {
|
||||
renderFile(file, options, emitter);
|
||||
}
|
||||
});
|
||||
|
||||
files.removed.forEach(function(file) {
|
||||
gaze.remove(file);
|
||||
});
|
||||
};
|
||||
|
||||
var gaze = new Gaze();
|
||||
gaze.add(watcher.reset(options));
|
||||
gaze.on('error', emitter.emit.bind(emitter, 'error'));
|
||||
|
||||
gaze.on('changed', function(file) {
|
||||
handler(watcher.changed(file));
|
||||
});
|
||||
|
||||
gaze.on('added', function(file) {
|
||||
handler(watcher.added(file));
|
||||
});
|
||||
|
||||
gaze.on('deleted', function(file) {
|
||||
handler(watcher.removed(file));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function run(options, emitter) {
|
||||
if (!Array.isArray(options.includePath)) {
|
||||
options.includePath = [options.includePath];
|
||||
}
|
||||
|
||||
if (options.directory) {
|
||||
if (!options.output) {
|
||||
emitter.emit('error', 'An output directory must be specified when compiling a directory');
|
||||
}
|
||||
if (!isDirectory(options.output)) {
|
||||
emitter.emit('error', 'An output directory must be specified when compiling a directory');
|
||||
}
|
||||
}
|
||||
|
||||
if (options.sourceMapOriginal && options.directory && !isDirectory(options.sourceMapOriginal) && options.sourceMapOriginal !== 'true') {
|
||||
emitter.emit('error', 'The --source-map option must be either a boolean or directory when compiling a directory');
|
||||
}
|
||||
|
||||
if (options.importer) {
|
||||
if ((path.resolve(options.importer) === path.normalize(options.importer).replace(/(.+)([\/|\\])$/, '$1'))) {
|
||||
options.importer = require(options.importer);
|
||||
} else {
|
||||
options.importer = require(path.resolve(options.importer));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.functions) {
|
||||
if ((path.resolve(options.functions) === path.normalize(options.functions).replace(/(.+)([\/|\\])$/, '$1'))) {
|
||||
options.functions = require(options.functions);
|
||||
} else {
|
||||
options.functions = require(path.resolve(options.functions));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.watch) {
|
||||
watch(options, emitter);
|
||||
} else if (options.directory) {
|
||||
renderDir(options, emitter);
|
||||
} else {
|
||||
render(options, emitter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a file
|
||||
*
|
||||
* @param {String} file
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
function renderFile(file, options, emitter) {
|
||||
options = getOptions([path.resolve(file)], options);
|
||||
if (options.watch && !options.quiet) {
|
||||
emitter.emit('info', util.format('=> changed: %s', file));
|
||||
}
|
||||
render(options, emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render all sass files in a directory
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
function renderDir(options, emitter) {
|
||||
var globPath = path.resolve(options.directory, globPattern(options));
|
||||
glob(globPath, { ignore: '**/_*', follow: options.follow }, function(err, files) {
|
||||
if (err) {
|
||||
return emitter.emit('error', util.format('You do not have permission to access this path: %s.', err.path));
|
||||
} else if (!files.length) {
|
||||
return emitter.emit('error', 'No input file was found.');
|
||||
}
|
||||
|
||||
forEach(files, function(subject) {
|
||||
emitter.once('done', this.async());
|
||||
renderFile(subject, options, emitter);
|
||||
}, function(successful, arr) {
|
||||
var outputDir = path.join(process.cwd(), options.output);
|
||||
if (!options.quiet) {
|
||||
emitter.emit('info', util.format('Wrote %s CSS files to %s', arr.length, outputDir));
|
||||
}
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments and options
|
||||
*/
|
||||
|
||||
var options = getOptions(cli.input, cli.flags);
|
||||
var emitter = getEmitter();
|
||||
|
||||
/**
|
||||
* Show usage if no arguments are supplied
|
||||
*/
|
||||
|
||||
if (!options.src && process.stdin.isTTY) {
|
||||
emitter.emit('error', [
|
||||
'Provide a Sass file to render',
|
||||
'',
|
||||
'Example: Compile foobar.scss to foobar.css',
|
||||
' node-sass --output-style compressed foobar.scss > foobar.css',
|
||||
' cat foobar.scss | node-sass --output-style compressed > foobar.css',
|
||||
'',
|
||||
'Example: Watch the sass directory for changes, compile with sourcemaps to the css directory',
|
||||
' node-sass --watch --recursive --output css',
|
||||
' --source-map true --source-map-contents sass',
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply arguments
|
||||
*/
|
||||
|
||||
if (options.src) {
|
||||
if (isDirectory(options.src)) {
|
||||
options.directory = options.src;
|
||||
}
|
||||
run(options, emitter);
|
||||
} else if (!process.stdin.isTTY) {
|
||||
stdin(function(data) {
|
||||
options.data = data;
|
||||
options.stdin = true;
|
||||
run(options, emitter);
|
||||
});
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
var nopt = require("../lib/nopt")
|
||||
, path = require("path")
|
||||
, types = { num: Number
|
||||
, bool: Boolean
|
||||
, help: Boolean
|
||||
, list: Array
|
||||
, "num-list": [Number, Array]
|
||||
, "str-list": [String, Array]
|
||||
, "bool-list": [Boolean, Array]
|
||||
, str: String
|
||||
, clear: Boolean
|
||||
, config: Boolean
|
||||
, length: Number
|
||||
, file: path
|
||||
}
|
||||
, shorthands = { s: [ "--str", "astring" ]
|
||||
, b: [ "--bool" ]
|
||||
, nb: [ "--no-bool" ]
|
||||
, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]
|
||||
, "?": ["--help"]
|
||||
, h: ["--help"]
|
||||
, H: ["--help"]
|
||||
, n: [ "--num", "125" ]
|
||||
, c: ["--config"]
|
||||
, l: ["--length"]
|
||||
, f: ["--file"]
|
||||
}
|
||||
, parsed = nopt( types
|
||||
, shorthands
|
||||
, process.argv
|
||||
, 2 )
|
||||
|
||||
console.log("parsed", parsed)
|
||||
|
||||
if (parsed.help) {
|
||||
console.log("")
|
||||
console.log("nopt cli tester")
|
||||
console.log("")
|
||||
console.log("types")
|
||||
console.log(Object.keys(types).map(function M (t) {
|
||||
var type = types[t]
|
||||
if (Array.isArray(type)) {
|
||||
return [t, type.map(function (type) { return type.name })]
|
||||
}
|
||||
return [t, type && type.name]
|
||||
}).reduce(function (s, i) {
|
||||
s[i[0]] = i[1]
|
||||
return s
|
||||
}, {}))
|
||||
console.log("")
|
||||
console.log("shorthands")
|
||||
console.log(shorthands)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
var inInstall = require('./index.js').inInstall
|
||||
process.exit(inInstall() ? 1 : 0)
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
var inPublish = require('./index.js').inPublish
|
||||
process.exit(inPublish() ? 1 : 0)
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rimraf = require('./')
|
||||
|
||||
var help = false
|
||||
var dashdash = false
|
||||
var noglob = false
|
||||
var args = process.argv.slice(2).filter(function(arg) {
|
||||
if (dashdash)
|
||||
return !!arg
|
||||
else if (arg === '--')
|
||||
dashdash = true
|
||||
else if (arg === '--no-glob' || arg === '-G')
|
||||
noglob = true
|
||||
else if (arg === '--glob' || arg === '-g')
|
||||
noglob = false
|
||||
else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/))
|
||||
help = true
|
||||
else
|
||||
return !!arg
|
||||
})
|
||||
|
||||
if (help || args.length === 0) {
|
||||
// If they didn't ask for help, then this is not a "success"
|
||||
var log = help ? console.log : console.error
|
||||
log('Usage: rimraf <path> [<path> ...]')
|
||||
log('')
|
||||
log(' Deletes all files and folders at "path" recursively.')
|
||||
log('')
|
||||
log('Options:')
|
||||
log('')
|
||||
log(' -h, --help Display this usage info')
|
||||
log(' -G, --no-glob Do not expand glob patterns in arguments')
|
||||
log(' -g, --glob Expand glob patterns in arguments (default)')
|
||||
process.exit(help ? 0 : 1)
|
||||
} else
|
||||
go(0)
|
||||
|
||||
function go (n) {
|
||||
if (n >= args.length)
|
||||
return
|
||||
var options = {}
|
||||
if (noglob)
|
||||
options = { glob: false }
|
||||
rimraf(args[n], options, function (er) {
|
||||
if (er)
|
||||
throw er
|
||||
go(n+1)
|
||||
})
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env node
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var command, directory, file;
|
||||
|
||||
var yargs = require('yargs')
|
||||
.usage('Usage: $0 <command> [options] <dir> [file]')
|
||||
// .demand(1)
|
||||
|
||||
.command('ancestors', 'Output the ancestors')
|
||||
.command('descendents', 'Output the descendents')
|
||||
|
||||
.example('$0 ancestors -I src src/ src/_footer.scss', 'outputs the ancestors of src/_footer.scss')
|
||||
|
||||
.option('I', {
|
||||
alias: 'load-path',
|
||||
default: [process.cwd()],
|
||||
describe: 'Add directories to the sass load path',
|
||||
type: 'array',
|
||||
})
|
||||
|
||||
.option('e', {
|
||||
alias: 'extensions',
|
||||
default: ['scss', 'css', 'sass'],
|
||||
describe: 'File extensions to include in the graph',
|
||||
type: 'array',
|
||||
})
|
||||
|
||||
.option('f', {
|
||||
alias: 'follow',
|
||||
default: false,
|
||||
describe: 'Follow symbolic links',
|
||||
type: 'bool',
|
||||
})
|
||||
|
||||
.option('j', {
|
||||
alias: 'json',
|
||||
default: false,
|
||||
describe: 'Output the index in json',
|
||||
type: 'bool',
|
||||
})
|
||||
|
||||
.version(function() {
|
||||
return require('../package').version;
|
||||
})
|
||||
.alias('v', 'version')
|
||||
|
||||
.help('h')
|
||||
.alias('h', 'help');
|
||||
|
||||
var argv = yargs.argv;
|
||||
|
||||
if (argv._.length === 0) {
|
||||
yargs.showHelp();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (['ancestors', 'descendents'].indexOf(argv._[0]) !== -1) {
|
||||
command = argv._.shift();
|
||||
}
|
||||
|
||||
if (argv._ && path.extname(argv._[0]) === '') {
|
||||
directory = argv._.shift();
|
||||
}
|
||||
|
||||
if (argv._ && path.extname(argv._[0])) {
|
||||
file = argv._.shift();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (!directory) {
|
||||
throw new Error('Missing directory');
|
||||
}
|
||||
|
||||
if (!command && !argv.json) {
|
||||
throw new Error('Missing command');
|
||||
}
|
||||
|
||||
if (!file && (command === 'ancestors' || command === 'descendents')) {
|
||||
throw new Error(command + ' command requires a file');
|
||||
}
|
||||
|
||||
var loadPaths = argv.loadPath;
|
||||
if(process.env.SASS_PATH) {
|
||||
loadPaths = loadPaths.concat(process.env.SASS_PATH.split(/:/).map(function(f) {
|
||||
return path.resolve(f);
|
||||
}));
|
||||
}
|
||||
|
||||
var graph = require('../').parseDir(directory, {
|
||||
extensions: argv.extensions,
|
||||
loadPaths: loadPaths,
|
||||
follow: argv.follow,
|
||||
});
|
||||
|
||||
if(argv.json) {
|
||||
console.log(JSON.stringify(graph.index, null, 4));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (command === 'ancestors') {
|
||||
graph.visitAncestors(path.resolve(file), function(f) {
|
||||
console.log(f);
|
||||
});
|
||||
}
|
||||
|
||||
if (command === 'descendents') {
|
||||
graph.visitDescendents(path.resolve(file), function(f) {
|
||||
console.log(f);
|
||||
});
|
||||
}
|
||||
} catch(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
console.error('Error: no such file or directory "' + e.path + '"');
|
||||
}
|
||||
else {
|
||||
console.log('Error: ' + e.message);
|
||||
}
|
||||
|
||||
// console.log(e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env node
|
||||
// Standalone semver comparison program.
|
||||
// Exits successfully and prints matching version(s) if
|
||||
// any supplied version is valid and passes all tests.
|
||||
|
||||
var argv = process.argv.slice(2)
|
||||
, versions = []
|
||||
, range = []
|
||||
, gt = []
|
||||
, lt = []
|
||||
, eq = []
|
||||
, inc = null
|
||||
, version = require("../package.json").version
|
||||
, loose = false
|
||||
, identifier = undefined
|
||||
, semver = require("../semver")
|
||||
, reverse = false
|
||||
|
||||
main()
|
||||
|
||||
function main () {
|
||||
if (!argv.length) return help()
|
||||
while (argv.length) {
|
||||
var a = argv.shift()
|
||||
var i = a.indexOf('=')
|
||||
if (i !== -1) {
|
||||
a = a.slice(0, i)
|
||||
argv.unshift(a.slice(i + 1))
|
||||
}
|
||||
switch (a) {
|
||||
case "-rv": case "-rev": case "--rev": case "--reverse":
|
||||
reverse = true
|
||||
break
|
||||
case "-l": case "--loose":
|
||||
loose = true
|
||||
break
|
||||
case "-v": case "--version":
|
||||
versions.push(argv.shift())
|
||||
break
|
||||
case "-i": case "--inc": case "--increment":
|
||||
switch (argv[0]) {
|
||||
case "major": case "minor": case "patch": case "prerelease":
|
||||
case "premajor": case "preminor": case "prepatch":
|
||||
inc = argv.shift()
|
||||
break
|
||||
default:
|
||||
inc = "patch"
|
||||
break
|
||||
}
|
||||
break
|
||||
case "--preid":
|
||||
identifier = argv.shift()
|
||||
break
|
||||
case "-r": case "--range":
|
||||
range.push(argv.shift())
|
||||
break
|
||||
case "-h": case "--help": case "-?":
|
||||
return help()
|
||||
default:
|
||||
versions.push(a)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
versions = versions.filter(function (v) {
|
||||
return semver.valid(v, loose)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
if (inc && (versions.length !== 1 || range.length))
|
||||
return failInc()
|
||||
|
||||
for (var i = 0, l = range.length; i < l ; i ++) {
|
||||
versions = versions.filter(function (v) {
|
||||
return semver.satisfies(v, range[i], loose)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
}
|
||||
return success(versions)
|
||||
}
|
||||
|
||||
function failInc () {
|
||||
console.error("--inc can only be used on a single version with no range")
|
||||
fail()
|
||||
}
|
||||
|
||||
function fail () { process.exit(1) }
|
||||
|
||||
function success () {
|
||||
var compare = reverse ? "rcompare" : "compare"
|
||||
versions.sort(function (a, b) {
|
||||
return semver[compare](a, b, loose)
|
||||
}).map(function (v) {
|
||||
return semver.clean(v, loose)
|
||||
}).map(function (v) {
|
||||
return inc ? semver.inc(v, inc, loose, identifier) : v
|
||||
}).forEach(function (v,i,_) { console.log(v) })
|
||||
}
|
||||
|
||||
function help () {
|
||||
console.log(["SemVer " + version
|
||||
,""
|
||||
,"A JavaScript implementation of the http://semver.org/ specification"
|
||||
,"Copyright Isaac Z. Schlueter"
|
||||
,""
|
||||
,"Usage: semver [options] <version> [<version> [...]]"
|
||||
,"Prints valid versions sorted by SemVer precedence"
|
||||
,""
|
||||
,"Options:"
|
||||
,"-r --range <range>"
|
||||
," Print versions that match the specified range."
|
||||
,""
|
||||
,"-i --increment [<level>]"
|
||||
," Increment a version by the specified level. Level can"
|
||||
," be one of: major, minor, patch, premajor, preminor,"
|
||||
," prepatch, or prerelease. Default level is 'patch'."
|
||||
," Only one version may be specified."
|
||||
,""
|
||||
,"--preid <identifier>"
|
||||
," Identifier to be used to prefix premajor, preminor,"
|
||||
," prepatch or prerelease version increments."
|
||||
,""
|
||||
,"-l --loose"
|
||||
," Interpret versions and ranges loosely"
|
||||
,""
|
||||
,"Program exits successfully if any valid version satisfies"
|
||||
,"all supplied ranges, and prints all satisfying versions."
|
||||
,""
|
||||
,"If no satisfying versions are found, then exits failure."
|
||||
,""
|
||||
,"Versions are printed in ascending order, so supplying"
|
||||
,"multiple versions to the utility will just sort them."
|
||||
].join("\n"))
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
#!/usr/bin/env node
|
||||
// -*- mode: js -*-
|
||||
// vim: set filetype=javascript :
|
||||
// Copyright 2015 Joyent, Inc. All rights reserved.
|
||||
|
||||
var dashdash = require('dashdash');
|
||||
var sshpk = require('../lib/index');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var tty = require('tty');
|
||||
var readline = require('readline');
|
||||
var getPassword = require('getpass').getPass;
|
||||
|
||||
var options = [
|
||||
{
|
||||
names: ['outformat', 't'],
|
||||
type: 'string',
|
||||
help: 'Output format'
|
||||
},
|
||||
{
|
||||
names: ['informat', 'T'],
|
||||
type: 'string',
|
||||
help: 'Input format'
|
||||
},
|
||||
{
|
||||
names: ['file', 'f'],
|
||||
type: 'string',
|
||||
help: 'Input file name (default stdin)'
|
||||
},
|
||||
{
|
||||
names: ['out', 'o'],
|
||||
type: 'string',
|
||||
help: 'Output file name (default stdout)'
|
||||
},
|
||||
{
|
||||
names: ['private', 'p'],
|
||||
type: 'bool',
|
||||
help: 'Produce a private key as output'
|
||||
},
|
||||
{
|
||||
names: ['derive', 'd'],
|
||||
type: 'string',
|
||||
help: 'Output a new key derived from this one, with given algo'
|
||||
},
|
||||
{
|
||||
names: ['identify', 'i'],
|
||||
type: 'bool',
|
||||
help: 'Print key metadata instead of converting'
|
||||
},
|
||||
{
|
||||
names: ['comment', 'c'],
|
||||
type: 'string',
|
||||
help: 'Set key comment, if output format supports'
|
||||
},
|
||||
{
|
||||
names: ['help', 'h'],
|
||||
type: 'bool',
|
||||
help: 'Shows this help text'
|
||||
}
|
||||
];
|
||||
|
||||
if (require.main === module) {
|
||||
var parser = dashdash.createParser({
|
||||
options: options
|
||||
});
|
||||
|
||||
try {
|
||||
var opts = parser.parse(process.argv);
|
||||
} catch (e) {
|
||||
console.error('sshpk-conv: error: %s', e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (opts.help || opts._args.length > 1) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-conv: converts between SSH key formats\n');
|
||||
console.error(help);
|
||||
console.error('\navailable formats:');
|
||||
console.error(' - pem, pkcs1 eg id_rsa');
|
||||
console.error(' - ssh eg id_rsa.pub');
|
||||
console.error(' - pkcs8 format you want for openssl');
|
||||
console.error(' - openssh like output of ssh-keygen -o');
|
||||
console.error(' - rfc4253 raw OpenSSH wire format');
|
||||
console.error(' - dnssec dnssec-keygen format');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Key derivation can only be done on private keys, so use of the -d
|
||||
* option necessarily implies -p.
|
||||
*/
|
||||
if (opts.derive)
|
||||
opts.private = true;
|
||||
|
||||
var inFile = process.stdin;
|
||||
var inFileName = 'stdin';
|
||||
|
||||
var inFilePath;
|
||||
if (opts.file) {
|
||||
inFilePath = opts.file;
|
||||
} else if (opts._args.length === 1) {
|
||||
inFilePath = opts._args[0];
|
||||
}
|
||||
|
||||
if (inFilePath)
|
||||
inFileName = path.basename(inFilePath);
|
||||
|
||||
try {
|
||||
if (inFilePath) {
|
||||
fs.accessSync(inFilePath, fs.R_OK);
|
||||
inFile = fs.createReadStream(inFilePath);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sshpk-conv: error opening input file' +
|
||||
': ' + e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var outFile = process.stdout;
|
||||
|
||||
try {
|
||||
if (opts.out && !opts.identify) {
|
||||
fs.accessSync(path.dirname(opts.out), fs.W_OK);
|
||||
outFile = fs.createWriteStream(opts.out);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sshpk-conv: error opening output file' +
|
||||
': ' + e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var bufs = [];
|
||||
inFile.on('readable', function () {
|
||||
var data;
|
||||
while ((data = inFile.read()))
|
||||
bufs.push(data);
|
||||
});
|
||||
var parseOpts = {};
|
||||
parseOpts.filename = inFileName;
|
||||
inFile.on('end', function processKey() {
|
||||
var buf = Buffer.concat(bufs);
|
||||
var fmt = 'auto';
|
||||
if (opts.informat)
|
||||
fmt = opts.informat;
|
||||
var f = sshpk.parseKey;
|
||||
if (opts.private)
|
||||
f = sshpk.parsePrivateKey;
|
||||
try {
|
||||
var key = f(buf, fmt, parseOpts);
|
||||
} catch (e) {
|
||||
if (e.name === 'KeyEncryptedError') {
|
||||
getPassword(function (err, pw) {
|
||||
if (err) {
|
||||
console.log('sshpk-conv: ' +
|
||||
err.name + ': ' +
|
||||
err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
parseOpts.passphrase = pw;
|
||||
processKey();
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.error('sshpk-conv: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (opts.derive)
|
||||
key = key.derive(opts.derive);
|
||||
|
||||
if (opts.comment)
|
||||
key.comment = opts.comment;
|
||||
|
||||
if (!opts.identify) {
|
||||
fmt = undefined;
|
||||
if (opts.outformat)
|
||||
fmt = opts.outformat;
|
||||
outFile.write(key.toBuffer(fmt));
|
||||
if (fmt === 'ssh' ||
|
||||
(!opts.private && fmt === undefined))
|
||||
outFile.write('\n');
|
||||
outFile.once('drain', function () {
|
||||
process.exit(0);
|
||||
});
|
||||
} else {
|
||||
var kind = 'public';
|
||||
if (sshpk.PrivateKey.isPrivateKey(key))
|
||||
kind = 'private';
|
||||
console.log('%s: a %d bit %s %s key', inFileName,
|
||||
key.size, key.type.toUpperCase(), kind);
|
||||
if (key.type === 'ecdsa')
|
||||
console.log('ECDSA curve: %s', key.curve);
|
||||
if (key.comment)
|
||||
console.log('Comment: %s', key.comment);
|
||||
console.log('Fingerprint:');
|
||||
console.log(' ' + key.fingerprint().toString());
|
||||
console.log(' ' + key.fingerprint('md5').toString());
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env node
|
||||
// -*- mode: js -*-
|
||||
// vim: set filetype=javascript :
|
||||
// Copyright 2015 Joyent, Inc. All rights reserved.
|
||||
|
||||
var dashdash = require('dashdash');
|
||||
var sshpk = require('../lib/index');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var getPassword = require('getpass').getPass;
|
||||
|
||||
var options = [
|
||||
{
|
||||
names: ['hash', 'H'],
|
||||
type: 'string',
|
||||
help: 'Hash algorithm (sha1, sha256, sha384, sha512)'
|
||||
},
|
||||
{
|
||||
names: ['verbose', 'v'],
|
||||
type: 'bool',
|
||||
help: 'Display verbose info about key and hash used'
|
||||
},
|
||||
{
|
||||
names: ['identity', 'i'],
|
||||
type: 'string',
|
||||
help: 'Path to key to use'
|
||||
},
|
||||
{
|
||||
names: ['file', 'f'],
|
||||
type: 'string',
|
||||
help: 'Input filename'
|
||||
},
|
||||
{
|
||||
names: ['out', 'o'],
|
||||
type: 'string',
|
||||
help: 'Output filename'
|
||||
},
|
||||
{
|
||||
names: ['format', 't'],
|
||||
type: 'string',
|
||||
help: 'Signature format (asn1, ssh, raw)'
|
||||
},
|
||||
{
|
||||
names: ['binary', 'b'],
|
||||
type: 'bool',
|
||||
help: 'Output raw binary instead of base64'
|
||||
},
|
||||
{
|
||||
names: ['help', 'h'],
|
||||
type: 'bool',
|
||||
help: 'Shows this help text'
|
||||
}
|
||||
];
|
||||
|
||||
var parseOpts = {};
|
||||
|
||||
if (require.main === module) {
|
||||
var parser = dashdash.createParser({
|
||||
options: options
|
||||
});
|
||||
|
||||
try {
|
||||
var opts = parser.parse(process.argv);
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error: %s', e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (opts.help || opts._args.length > 1) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-sign: sign data using an SSH key\n');
|
||||
console.error(help);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!opts.identity) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-sign: the -i or --identity option ' +
|
||||
'is required\n');
|
||||
console.error(help);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var keyData = fs.readFileSync(opts.identity);
|
||||
parseOpts.filename = opts.identity;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
function run() {
|
||||
var key;
|
||||
try {
|
||||
key = sshpk.parsePrivateKey(keyData, 'auto', parseOpts);
|
||||
} catch (e) {
|
||||
if (e.name === 'KeyEncryptedError') {
|
||||
getPassword(function (err, pw) {
|
||||
parseOpts.passphrase = pw;
|
||||
run();
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.error('sshpk-sign: error loading private key "' +
|
||||
opts.identity + '": ' + e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var hash = opts.hash || key.defaultHashAlgorithm();
|
||||
|
||||
var signer;
|
||||
try {
|
||||
signer = key.createSign(hash);
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error creating signer: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (opts.verbose) {
|
||||
console.error('sshpk-sign: using %s-%s with a %d bit key',
|
||||
key.type, hash, key.size);
|
||||
}
|
||||
|
||||
var inFile = process.stdin;
|
||||
var inFileName = 'stdin';
|
||||
|
||||
var inFilePath;
|
||||
if (opts.file) {
|
||||
inFilePath = opts.file;
|
||||
} else if (opts._args.length === 1) {
|
||||
inFilePath = opts._args[0];
|
||||
}
|
||||
|
||||
if (inFilePath)
|
||||
inFileName = path.basename(inFilePath);
|
||||
|
||||
try {
|
||||
if (inFilePath) {
|
||||
fs.accessSync(inFilePath, fs.R_OK);
|
||||
inFile = fs.createReadStream(inFilePath);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error opening input file' +
|
||||
': ' + e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var outFile = process.stdout;
|
||||
|
||||
try {
|
||||
if (opts.out && !opts.identify) {
|
||||
fs.accessSync(path.dirname(opts.out), fs.W_OK);
|
||||
outFile = fs.createWriteStream(opts.out);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error opening output file' +
|
||||
': ' + e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
inFile.pipe(signer);
|
||||
inFile.on('end', function () {
|
||||
var sig;
|
||||
try {
|
||||
sig = signer.sign();
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error signing data: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var fmt = opts.format || 'asn1';
|
||||
var output;
|
||||
try {
|
||||
output = sig.toBuffer(fmt);
|
||||
if (!opts.binary)
|
||||
output = output.toString('base64');
|
||||
} catch (e) {
|
||||
console.error('sshpk-sign: error converting signature' +
|
||||
' to ' + fmt + ' format: ' + e.name + ': ' +
|
||||
e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
outFile.write(output);
|
||||
if (!opts.binary)
|
||||
outFile.write('\n');
|
||||
outFile.once('drain', function () {
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env node
|
||||
// -*- mode: js -*-
|
||||
// vim: set filetype=javascript :
|
||||
// Copyright 2015 Joyent, Inc. All rights reserved.
|
||||
|
||||
var dashdash = require('dashdash');
|
||||
var sshpk = require('../lib/index');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Buffer = require('safer-buffer').Buffer;
|
||||
|
||||
var options = [
|
||||
{
|
||||
names: ['hash', 'H'],
|
||||
type: 'string',
|
||||
help: 'Hash algorithm (sha1, sha256, sha384, sha512)'
|
||||
},
|
||||
{
|
||||
names: ['verbose', 'v'],
|
||||
type: 'bool',
|
||||
help: 'Display verbose info about key and hash used'
|
||||
},
|
||||
{
|
||||
names: ['identity', 'i'],
|
||||
type: 'string',
|
||||
help: 'Path to (public) key to use'
|
||||
},
|
||||
{
|
||||
names: ['file', 'f'],
|
||||
type: 'string',
|
||||
help: 'Input filename'
|
||||
},
|
||||
{
|
||||
names: ['format', 't'],
|
||||
type: 'string',
|
||||
help: 'Signature format (asn1, ssh, raw)'
|
||||
},
|
||||
{
|
||||
names: ['signature', 's'],
|
||||
type: 'string',
|
||||
help: 'base64-encoded signature data'
|
||||
},
|
||||
{
|
||||
names: ['help', 'h'],
|
||||
type: 'bool',
|
||||
help: 'Shows this help text'
|
||||
}
|
||||
];
|
||||
|
||||
if (require.main === module) {
|
||||
var parser = dashdash.createParser({
|
||||
options: options
|
||||
});
|
||||
|
||||
try {
|
||||
var opts = parser.parse(process.argv);
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error: %s', e.message);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
if (opts.help || opts._args.length > 1) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-verify: sign data using an SSH key\n');
|
||||
console.error(help);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
if (!opts.identity) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-verify: the -i or --identity option ' +
|
||||
'is required\n');
|
||||
console.error(help);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
if (!opts.signature) {
|
||||
var help = parser.help({}).trimRight();
|
||||
console.error('sshpk-verify: the -s or --signature option ' +
|
||||
'is required\n');
|
||||
console.error(help);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
var keyData = fs.readFileSync(opts.identity);
|
||||
|
||||
var key;
|
||||
try {
|
||||
key = sshpk.parseKey(keyData);
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error loading key "' +
|
||||
opts.identity + '": ' + e.name + ': ' + e.message);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
var fmt = opts.format || 'asn1';
|
||||
var sigData = Buffer.from(opts.signature, 'base64');
|
||||
|
||||
var sig;
|
||||
try {
|
||||
sig = sshpk.parseSignature(sigData, key.type, fmt);
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error parsing signature: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
var hash = opts.hash || key.defaultHashAlgorithm();
|
||||
|
||||
var verifier;
|
||||
try {
|
||||
verifier = key.createVerify(hash);
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error creating verifier: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
if (opts.verbose) {
|
||||
console.error('sshpk-verify: using %s-%s with a %d bit key',
|
||||
key.type, hash, key.size);
|
||||
}
|
||||
|
||||
var inFile = process.stdin;
|
||||
var inFileName = 'stdin';
|
||||
|
||||
var inFilePath;
|
||||
if (opts.file) {
|
||||
inFilePath = opts.file;
|
||||
} else if (opts._args.length === 1) {
|
||||
inFilePath = opts._args[0];
|
||||
}
|
||||
|
||||
if (inFilePath)
|
||||
inFileName = path.basename(inFilePath);
|
||||
|
||||
try {
|
||||
if (inFilePath) {
|
||||
fs.accessSync(inFilePath, fs.R_OK);
|
||||
inFile = fs.createReadStream(inFilePath);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error opening input file' +
|
||||
': ' + e.name + ': ' + e.message);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
inFile.pipe(verifier);
|
||||
inFile.on('end', function () {
|
||||
var ret;
|
||||
try {
|
||||
ret = verifier.verify(sig);
|
||||
} catch (e) {
|
||||
console.error('sshpk-verify: error verifying data: ' +
|
||||
e.name + ': ' + e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
console.error('OK');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
console.error('NOT OK');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var pkg = require('./package.json');
|
||||
var stripBom = require('./');
|
||||
var argv = process.argv.slice(2);
|
||||
var input = argv[0];
|
||||
|
||||
function help() {
|
||||
console.log([
|
||||
'',
|
||||
' ' + pkg.description,
|
||||
'',
|
||||
' Usage',
|
||||
' strip-bom <file> > <new-file>',
|
||||
' cat <file> | strip-bom > <new-file>',
|
||||
'',
|
||||
' Example',
|
||||
' strip-bom unicorn.txt > unicorn-without-bom.txt'
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
if (argv.indexOf('--help') !== -1) {
|
||||
help();
|
||||
return;
|
||||
}
|
||||
|
||||
if (argv.indexOf('--version') !== -1) {
|
||||
console.log(pkg.version);
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.stdin.isTTY) {
|
||||
if (!input) {
|
||||
help();
|
||||
return;
|
||||
}
|
||||
|
||||
fs.createReadStream(input).pipe(stripBom.stream()).pipe(process.stdout);
|
||||
} else {
|
||||
process.stdin.pipe(stripBom.stream()).pipe(process.stdout);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var stdin = require('get-stdin');
|
||||
var pkg = require('./package.json');
|
||||
var stripIndent = require('./');
|
||||
var argv = process.argv.slice(2);
|
||||
var input = argv[0];
|
||||
|
||||
function help() {
|
||||
console.log([
|
||||
'',
|
||||
' ' + pkg.description,
|
||||
'',
|
||||
' Usage',
|
||||
' strip-indent <file>',
|
||||
' echo <string> | strip-indent',
|
||||
'',
|
||||
' Example',
|
||||
' echo \'\\tunicorn\\n\\t\\tcake\' | strip-indent',
|
||||
' unicorn',
|
||||
' \tcake'
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
function init(data) {
|
||||
console.log(stripIndent(data));
|
||||
}
|
||||
|
||||
if (argv.indexOf('--help') !== -1) {
|
||||
help();
|
||||
return;
|
||||
}
|
||||
|
||||
if (argv.indexOf('--version') !== -1) {
|
||||
console.log(pkg.version);
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.stdin.isTTY) {
|
||||
if (!input) {
|
||||
help();
|
||||
return;
|
||||
}
|
||||
|
||||
init(fs.readFileSync(input, 'utf8'));
|
||||
} else {
|
||||
stdin(init);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
var pkg = require('./package.json');
|
||||
var userHome = require('./');
|
||||
|
||||
function help() {
|
||||
console.log([
|
||||
pkg.description,
|
||||
'',
|
||||
'Example',
|
||||
' $ user-home',
|
||||
' /Users/sindresorhus'
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
if (process.argv.indexOf('--help') !== -1) {
|
||||
help();
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.argv.indexOf('--version') !== -1) {
|
||||
console.log(pkg.version);
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(userHome);
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env node
|
||||
var assert = require('assert');
|
||||
|
||||
function usage() {
|
||||
console.log('Usage:');
|
||||
console.log(' uuid');
|
||||
console.log(' uuid v1');
|
||||
console.log(' uuid v3 <name> <namespace uuid>');
|
||||
console.log(' uuid v4');
|
||||
console.log(' uuid v5 <name> <namespace uuid>');
|
||||
console.log(' uuid --help');
|
||||
console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122');
|
||||
}
|
||||
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
if (args.indexOf('--help') >= 0) {
|
||||
usage();
|
||||
process.exit(0);
|
||||
}
|
||||
var version = args.shift() || 'v4';
|
||||
|
||||
switch (version) {
|
||||
case 'v1':
|
||||
var uuidV1 = require('../v1');
|
||||
console.log(uuidV1());
|
||||
break;
|
||||
|
||||
case 'v3':
|
||||
var uuidV3 = require('../v3');
|
||||
|
||||
var name = args.shift();
|
||||
var namespace = args.shift();
|
||||
assert(name != null, 'v3 name not specified');
|
||||
assert(namespace != null, 'v3 namespace not specified');
|
||||
|
||||
if (namespace == 'URL') namespace = uuidV3.URL;
|
||||
if (namespace == 'DNS') namespace = uuidV3.DNS;
|
||||
|
||||
console.log(uuidV3(name, namespace));
|
||||
break;
|
||||
|
||||
case 'v4':
|
||||
var uuidV4 = require('../v4');
|
||||
console.log(uuidV4());
|
||||
break;
|
||||
|
||||
case 'v5':
|
||||
var uuidV5 = require('../v5');
|
||||
|
||||
var name = args.shift();
|
||||
var namespace = args.shift();
|
||||
assert(name != null, 'v5 name not specified');
|
||||
assert(namespace != null, 'v5 namespace not specified');
|
||||
|
||||
if (namespace == 'URL') namespace = uuidV5.URL;
|
||||
if (namespace == 'DNS') namespace = uuidV5.DNS;
|
||||
|
||||
console.log(uuidV5(name, namespace));
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
process.exit(1);
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
var which = require("../")
|
||||
if (process.argv.length < 3)
|
||||
usage()
|
||||
|
||||
function usage () {
|
||||
console.error('usage: which [-as] program ...')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var all = false
|
||||
var silent = false
|
||||
var dashdash = false
|
||||
var args = process.argv.slice(2).filter(function (arg) {
|
||||
if (dashdash || !/^-/.test(arg))
|
||||
return true
|
||||
|
||||
if (arg === '--') {
|
||||
dashdash = true
|
||||
return false
|
||||
}
|
||||
|
||||
var flags = arg.substr(1).split('')
|
||||
for (var f = 0; f < flags.length; f++) {
|
||||
var flag = flags[f]
|
||||
switch (flag) {
|
||||
case 's':
|
||||
silent = true
|
||||
break
|
||||
case 'a':
|
||||
all = true
|
||||
break
|
||||
default:
|
||||
console.error('which: illegal option -- ' + flag)
|
||||
usage()
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
process.exit(args.reduce(function (pv, current) {
|
||||
try {
|
||||
var f = which.sync(current, { all: all })
|
||||
if (all)
|
||||
f = f.join('\n')
|
||||
if (!silent)
|
||||
console.log(f)
|
||||
return pv;
|
||||
} catch (e) {
|
||||
return 1;
|
||||
}
|
||||
}, 0))
|
||||
Reference in New Issue
Block a user