1612 changed files with 89498 additions and 105555 deletions
@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */ |
||||
/* @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. */ |
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
||||
../in-publish/in-install.js |
||||
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node |
||||
'use strict' |
||||
var inInstall = require('./index.js').inInstall |
||||
process.exit(inInstall() ? 0 : 1) |
||||
@ -1 +0,0 @@
|
||||
../in-publish/in-publish.js |
||||
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node |
||||
'use strict' |
||||
var inPublish = require('./index.js').inPublish |
||||
process.exit(inPublish() ? 0 : 1) |
||||
@ -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(); |
||||
} |
||||
})(); |
||||
@ -1 +0,0 @@
|
||||
../node-gyp/bin/node-gyp.js |
||||
@ -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() |
||||
@ -1 +0,0 @@
|
||||
../node-sass/bin/node-sass |
||||
@ -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); |
||||
}); |
||||
} |
||||
@ -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) |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../in-publish/not-in-install.js |
||||
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node |
||||
'use strict' |
||||
var inInstall = require('./index.js').inInstall |
||||
process.exit(inInstall() ? 1 : 0) |
||||
@ -1 +0,0 @@
|
||||
../in-publish/not-in-publish.js |
||||
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node |
||||
'use strict' |
||||
var inPublish = require('./index.js').inPublish |
||||
process.exit(inPublish() ? 1 : 0) |
||||
@ -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) |
||||
}) |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../sass-graph/bin/sassgraph |
||||
@ -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); |
||||
} |
||||
@ -0,0 +1,160 @@
|
||||
#!/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) |
||||
|
||||
var versions = [] |
||||
|
||||
var range = [] |
||||
|
||||
var inc = null |
||||
|
||||
var version = require('../package.json').version |
||||
|
||||
var loose = false |
||||
|
||||
var includePrerelease = false |
||||
|
||||
var coerce = false |
||||
|
||||
var identifier |
||||
|
||||
var semver = require('../semver') |
||||
|
||||
var reverse = false |
||||
|
||||
var options = {} |
||||
|
||||
main() |
||||
|
||||
function main () { |
||||
if (!argv.length) return help() |
||||
while (argv.length) { |
||||
var a = argv.shift() |
||||
var indexOfEqualSign = a.indexOf('=') |
||||
if (indexOfEqualSign !== -1) { |
||||
a = a.slice(0, indexOfEqualSign) |
||||
argv.unshift(a.slice(indexOfEqualSign + 1)) |
||||
} |
||||
switch (a) { |
||||
case '-rv': case '-rev': case '--rev': case '--reverse': |
||||
reverse = true |
||||
break |
||||
case '-l': case '--loose': |
||||
loose = true |
||||
break |
||||
case '-p': case '--include-prerelease': |
||||
includePrerelease = 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 '-c': case '--coerce': |
||||
coerce = true |
||||
break |
||||
case '-h': case '--help': case '-?': |
||||
return help() |
||||
default: |
||||
versions.push(a) |
||||
break |
||||
} |
||||
} |
||||
|
||||
var options = { loose: loose, includePrerelease: includePrerelease } |
||||
|
||||
versions = versions.map(function (v) { |
||||
return coerce ? (semver.coerce(v) || { version: v }).version : v |
||||
}).filter(function (v) { |
||||
return semver.valid(v) |
||||
}) |
||||
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], options) |
||||
}) |
||||
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, options) |
||||
}).map(function (v) { |
||||
return semver.clean(v, options) |
||||
}).map(function (v) { |
||||
return inc ? semver.inc(v, inc, options, identifier) : v |
||||
}).forEach(function (v, i, _) { console.log(v) }) |
||||
} |
||||
|
||||
function help () { |
||||
console.log(['SemVer ' + version, |
||||
'', |
||||
'A JavaScript implementation of the https://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', |
||||
'', |
||||
'-p --include-prerelease', |
||||
' Always include prerelease versions in range matching', |
||||
'', |
||||
'-c --coerce', |
||||
' Coerce a string into SemVer if possible', |
||||
' (does not imply --loose)', |
||||
'', |
||||
'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')) |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../sshpk/bin/sshpk-conv |
||||
@ -0,0 +1,243 @@
|
||||
#!/usr/bin/env node |
||||
// -*- mode: js -*- |
||||
// vim: set filetype=javascript : |
||||
// Copyright 2018 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: ['fingerprint', 'F'], |
||||
type: 'bool', |
||||
help: 'Output key fingerprint' |
||||
}, |
||||
{ |
||||
names: ['hash', 'H'], |
||||
type: 'string', |
||||
help: 'Hash function to use for key fingeprint with -F' |
||||
}, |
||||
{ |
||||
names: ['spki', 's'], |
||||
type: 'bool', |
||||
help: 'With -F, generates an SPKI fingerprint instead of SSH' |
||||
}, |
||||
{ |
||||
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 key 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'); |
||||
console.error(' - putty PuTTY ppk format'); |
||||
console.error('\navailable fingerprint formats:'); |
||||
console.error(' - hex colon-separated hex for SSH'); |
||||
console.error(' straight hex for SPKI'); |
||||
console.error(' - base64 SHA256:* format from OpenSSH'); |
||||
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) { |
||||
ifError(e, 'error opening input file'); |
||||
} |
||||
|
||||
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) { |
||||
ifError(e, 'error opening output file'); |
||||
} |
||||
|
||||
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) |
||||
ifError(err); |
||||
parseOpts.passphrase = pw; |
||||
processKey(); |
||||
}); |
||||
return; |
||||
} |
||||
ifError(e); |
||||
} |
||||
|
||||
if (opts.derive) |
||||
key = key.derive(opts.derive); |
||||
|
||||
if (opts.comment) |
||||
key.comment = opts.comment; |
||||
|
||||
if (opts.identify) { |
||||
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('SHA256 fingerprint: ' + |
||||
key.fingerprint('sha256').toString()); |
||||
console.log('MD5 fingerprint: ' + |
||||
key.fingerprint('md5').toString()); |
||||
console.log('SPKI-SHA256 fingerprint: ' + |
||||
key.fingerprint('sha256', 'spki').toString()); |
||||
process.exit(0); |
||||
return; |
||||
} |
||||
|
||||
if (opts.fingerprint) { |
||||
var hash = opts.hash; |
||||
var type = opts.spki ? 'spki' : 'ssh'; |
||||
var format = opts.outformat; |
||||
var fp = key.fingerprint(hash, type).toString(format); |
||||
outFile.write(fp); |
||||
outFile.write('\n'); |
||||
outFile.once('drain', function () { |
||||
process.exit(0); |
||||
}); |
||||
return; |
||||
} |
||||
|
||||
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); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
function ifError(e, txt) { |
||||
if (txt) |
||||
txt = txt + ': '; |
||||
else |
||||
txt = ''; |
||||
console.error('sshpk-conv: ' + txt + e.name + ': ' + e.message); |
||||
if (process.env['DEBUG'] || process.env['V']) { |
||||
console.error(e.stack); |
||||
if (e.innerErr) |
||||
console.error(e.innerErr.stack); |
||||
} |
||||
process.exit(1); |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../sshpk/bin/sshpk-sign |
||||
@ -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); |
||||
}); |
||||
}); |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../sshpk/bin/sshpk-verify |
||||
@ -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); |
||||
}); |
||||
} |
||||
@ -1 +0,0 @@
|
||||
../strip-indent/cli.js |
||||
@ -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); |
||||
} |
||||
@ -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); |
||||
} |
||||
@ -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)) |
||||
@ -1 +0,0 @@
|
||||
../semver/bin/semver |
||||
@ -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")) |
||||
} |
||||
|
After Width: | Height: | Size: 94 KiB |
@ -0,0 +1,165 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* Iterates individual characters (Unicode codepoints) of DOM text and CDATA nodes |
||||
* while keeping track of their position in the document. |
||||
* |
||||
* Example: |
||||
* |
||||
* $doc = new DOMDocument(); |
||||
* $doc->load('example.xml'); |
||||
* foreach(new DOMLettersIterator($doc) as $letter) echo $letter; |
||||
* |
||||
* NB: If you only need characters without their position |
||||
* in the document, use DOMNode->textContent instead. |
||||
* |
||||
* @author porneL http://pornel.net |
||||
* @license Public Domain |
||||
* @url https://github.com/antoligy/dom-string-iterators |
||||
* |
||||
* @implements Iterator<int,string> |
||||
*/ |
||||
final class DOMLettersIterator implements Iterator |
||||
{ |
||||
/** @var DOMElement */ |
||||
private $start; |
||||
/** @var DOMElement|null */ |
||||
private $current; |
||||
/** @var int */ |
||||
private $offset = -1; |
||||
/** @var int|null */ |
||||
private $key; |
||||
/** @var array<int,string>|null */ |
||||
private $letters; |
||||
|
||||
/** |
||||
* expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML) |
||||
* |
||||
* @param DOMNode $el |
||||
*/ |
||||
public function __construct(DOMNode $el) |
||||
{ |
||||
if ($el instanceof DOMDocument) { |
||||
$el = $el->documentElement; |
||||
} |
||||
|
||||
if (!$el instanceof DOMElement) { |
||||
throw new InvalidArgumentException('Invalid arguments, expected DOMElement or DOMDocument'); |
||||
} |
||||
|
||||
$this->start = $el; |
||||
} |
||||
|
||||
/** |
||||
* Returns position in text as DOMText node and character offset. |
||||
* (it's NOT a byte offset, you must use mb_substr() or similar to use this offset properly). |
||||
* node may be NULL if iterator has finished. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function currentTextPosition(): array |
||||
{ |
||||
return [$this->current, $this->offset]; |
||||
} |
||||
|
||||
/** |
||||
* Returns DOMElement that is currently being iterated or NULL if iterator has finished. |
||||
* |
||||
* @return DOMElement|null |
||||
*/ |
||||
public function currentElement(): ?DOMElement |
||||
{ |
||||
return $this->current ? $this->current->parentNode : null; |
||||
} |
||||
|
||||
// Implementation of Iterator interface |
||||
|
||||
/** |
||||
* @return int|null |
||||
*/ |
||||
public function key(): ?int |
||||
{ |
||||
return $this->key; |
||||
} |
||||
|
||||
/** |
||||
* @return void |
||||
*/ |
||||
public function next(): void |
||||
{ |
||||
if (null === $this->current) { |
||||
return; |
||||
} |
||||
|
||||
if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) { |
||||
if ($this->offset === -1) { |
||||
preg_match_all('/./us', $this->current->textContent, $m); |
||||
$this->letters = $m[0]; |
||||
} |
||||
|
||||
$this->offset++; |
||||
$this->key++; |
||||
if ($this->letters && $this->offset < count($this->letters)) { |
||||
return; |
||||
} |
||||
|
||||
$this->offset = -1; |
||||
} |
||||
|
||||
while ($this->current->nodeType === XML_ELEMENT_NODE && $this->current->firstChild) { |
||||
$this->current = $this->current->firstChild; |
||||
if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) { |
||||
$this->next(); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
while (!$this->current->nextSibling && $this->current->parentNode) { |
||||
$this->current = $this->current->parentNode; |
||||
if ($this->current === $this->start) { |
||||
$this->current = null; |
||||
return; |
||||
} |
||||
} |
||||
|
||||
$this->current = $this->current->nextSibling; |
||||
|
||||
$this->next(); |
||||
} |
||||
|
||||
/** |
||||
* Return the current element |
||||
* @link https://php.net/manual/en/iterator.current.php |
||||
* |
||||
* @return string|null |
||||
*/ |
||||
public function current(): ?string |
||||
{ |
||||
return $this->letters ? $this->letters[$this->offset] : null; |
||||
} |
||||
|
||||
/** |
||||
* Checks if current position is valid |
||||
* @link https://php.net/manual/en/iterator.valid.php |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function valid(): bool |
||||
{ |
||||
return (bool)$this->current; |
||||
} |
||||
|
||||
/** |
||||
* @return void |
||||
*/ |
||||
public function rewind(): void |
||||
{ |
||||
$this->current = $this->start; |
||||
$this->offset = -1; |
||||
$this->key = 0; |
||||
$this->letters = []; |
||||
|
||||
$this->next(); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,158 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* Iterates individual words of DOM text and CDATA nodes |
||||
* while keeping track of their position in the document. |
||||
* |
||||
* Example: |
||||
* |
||||
* $doc = new DOMDocument(); |
||||
* $doc->load('example.xml'); |
||||
* foreach(new DOMWordsIterator($doc) as $word) echo $word; |
||||
* |
||||
* @author pjgalbraith http://www.pjgalbraith.com |
||||
* @author porneL http://pornel.net (based on DOMLettersIterator available at http://pornel.net/source/domlettersiterator.php) |
||||
* @license Public Domain |
||||
* @url https://github.com/antoligy/dom-string-iterators |
||||
* |
||||
* @implements Iterator<int,string> |
||||
*/ |
||||
|
||||
final class DOMWordsIterator implements Iterator |
||||
{ |
||||
/** @var DOMElement */ |
||||
private $start; |
||||
/** @var DOMElement|null */ |
||||
private $current; |
||||
/** @var int */ |
||||
private $offset = -1; |
||||
/** @var int|null */ |
||||
private $key; |
||||
/** @var array<int,array<int,int|string>>|null */ |
||||
private $words; |
||||
|
||||
/** |
||||
* expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML) |
||||
* |
||||
* @param DOMNode $el |
||||
*/ |
||||
public function __construct(DOMNode $el) |
||||
{ |
||||
if ($el instanceof DOMDocument) { |
||||
$el = $el->documentElement; |
||||
} |
||||
|
||||
if (!$el instanceof DOMElement) { |
||||
throw new InvalidArgumentException('Invalid arguments, expected DOMElement or DOMDocument'); |
||||
} |
||||
|
||||
$this->start = $el; |
||||
} |
||||
|
||||
/** |
||||
* Returns position in text as DOMText node and character offset. |
||||
* (it's NOT a byte offset, you must use mb_substr() or similar to use this offset properly). |
||||
* node may be NULL if iterator has finished. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function currentWordPosition(): array |
||||
{ |
||||
return [$this->current, $this->offset, $this->words]; |
||||
} |
||||
|
||||
/** |
||||
* Returns DOMElement that is currently being iterated or NULL if iterator has finished. |
||||
* |
||||
* @return DOMElement|null |
||||
*/ |
||||
public function currentElement(): ?DOMElement |
||||
{ |
||||
return $this->current ? $this->current->parentNode : null; |
||||
} |
||||
|
||||
// Implementation of Iterator interface |
||||
|
||||
/** |
||||
* Return the key of the current element |
||||
* @link https://php.net/manual/en/iterator.key.php |
||||
* @return int|null |
||||
*/ |
||||
public function key(): ?int |
||||
{ |
||||
return $this->key; |
||||
} |
||||
|
||||
/** |
||||
* @return void |
||||
*/ |
||||
public function next(): void |
||||
{ |
||||
if (null === $this->current) { |
||||
return; |
||||
} |
||||
|
||||
if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) { |
||||
if ($this->offset === -1) { |
||||
$this->words = preg_split("/[\n\r\t ]+/", $this->current->textContent, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_OFFSET_CAPTURE) ?: []; |
||||
} |
||||
$this->offset++; |
||||
|
||||
if ($this->words && $this->offset < count($this->words)) { |
||||
$this->key++; |
||||
return; |
||||
} |
||||
$this->offset = -1; |
||||
} |
||||
|
||||
while ($this->current->nodeType === XML_ELEMENT_NODE && $this->current->firstChild) { |
||||
$this->current = $this->current->firstChild; |
||||
if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) { |
||||
$this->next(); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
while (!$this->current->nextSibling && $this->current->parentNode) { |
||||
$this->current = $this->current->parentNode; |
||||
if ($this->current === $this->start) { |
||||
$this->current = null; |
||||
return; |
||||
} |
||||
} |
||||
|
||||
$this->current = $this->current->nextSibling; |
||||
|
||||
$this->next(); |
||||
} |
||||
|
||||
/** |
||||
* Return the current element |
||||
* @link https://php.net/manual/en/iterator.current.php |
||||
* @return string|null |
||||
*/ |
||||
public function current(): ?string |
||||
{ |
||||
return $this->words ? (string)$this->words[$this->offset][0] : null; |
||||
} |
||||
|
||||
/** |
||||
* Checks if current position is valid |
||||
* @link https://php.net/manual/en/iterator.valid.php |
||||
* @return bool |
||||
*/ |
||||
public function valid(): bool |
||||
{ |
||||
return (bool)$this->current; |
||||
} |
||||
|
||||
public function rewind(): void |
||||
{ |
||||
$this->current = $this->start; |
||||
$this->offset = -1; |
||||
$this->key = 0; |
||||
$this->words = []; |
||||
|
||||
$this->next(); |
||||
} |
||||
} |
||||
@ -0,0 +1,207 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @package Grav\Common\Assets |
||||
* |
||||
* @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. |
||||
* @license MIT License; see LICENSE file for details. |
||||
*/ |
||||
|
||||
namespace Grav\Common\Assets; |
||||
|
||||
use Grav\Common\Assets; |
||||
use Grav\Common\Config\Config; |
||||
use Grav\Common\Grav; |
||||
use Grav\Framework\ContentBlock\HtmlBlock; |
||||
use function strlen; |
||||
|
||||
/** |
||||
* Register block assets into Grav. |
||||
*/ |
||||
class BlockAssets |
||||
{ |
||||
/** |
||||
* @param HtmlBlock $block |
||||
* @return void |
||||
*/ |
||||
public static function registerAssets(HtmlBlock $block): void |
||||
{ |
||||
$grav = Grav::instance(); |
||||
|
||||
/** @var Assets $assets */ |
||||
$assets = $grav['assets']; |
||||
|
||||
$types = $block->getAssets(); |
||||
foreach ($types as $type => $groups) { |
||||
switch ($type) { |
||||
case 'frameworks': |
||||
static::registerFrameworks($assets, $groups); |
||||
break; |
||||
case 'styles': |
||||
static::registerStyles($assets, $groups); |
||||
break; |
||||
case 'scripts': |
||||
static::registerScripts($assets, $groups); |
||||
break; |
||||
case 'links': |
||||
static::registerLinks($assets, $groups); |
||||
break; |
||||
case 'html': |
||||
static::registerHtml($assets, $groups); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param Assets $assets |
||||
* @param array $list |
||||
* @return void |
||||
*/ |
||||
protected static function registerFrameworks(Assets $assets, array $list): void |
||||
{ |
||||
if ($list) { |
||||
throw new \RuntimeException('Not Implemented'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param Assets $assets |
||||
* @param array $groups |
||||
* @return void |
||||
*/ |
||||
protected static function registerStyles(Assets $assets, array $groups): void |
||||
{ |
||||
$grav = Grav::instance(); |
||||
|
||||
/** @var Config $config */ |
||||
$config = $grav['config']; |
||||
|
||||
foreach ($groups as $group => $styles) { |
||||
foreach ($styles as $style) { |
||||
switch ($style[':type']) { |
||||
case 'file': |
||||
$options = [ |
||||
'priority' => $style[':priority'], |
||||
'group' => $group, |
||||
'type' => $style['type'], |
||||
'media' => $style['media'] |
||||
] + $style['element']; |
||||
|
||||
$assets->addCss(static::getRelativeUrl($style['href'], $config->get('system.assets.css_pipeline')), $options); |
||||
break; |
||||
case 'inline': |
||||
$options = [ |
||||
'priority' => $style[':priority'], |
||||
'group' => $group, |
||||
'type' => $style['type'], |
||||
] + $style['element']; |
||||
|
||||
$assets->addInlineCss($style['content'], $options); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param Assets $assets |
||||
* @param array $groups |
||||
* @return void |
||||
*/ |
||||
protected static function registerScripts(Assets $assets, array $groups): void |
||||
{ |
||||
$grav = Grav::instance(); |
||||
|
||||
/** @var Config $config */ |
||||
$config = $grav['config']; |
||||
|
||||
foreach ($groups as $group => $scripts) { |
||||
$group = $group === 'footer' ? 'bottom' : $group; |
||||
|
||||
foreach ($scripts as $script) { |
||||
switch ($script[':type']) { |
||||
case 'file': |
||||
$options = [ |
||||
'group' => $group, |
||||
'priority' => $script[':priority'], |
||||
'src' => $script['src'], |
||||
'type' => $script['type'], |
||||
'loading' => $script['loading'], |
||||
'defer' => $script['defer'], |
||||
'async' => $script['async'], |
||||
'handle' => $script['handle'] |
||||
] + $script['element']; |
||||
|
||||
$assets->addJs(static::getRelativeUrl($script['src'], $config->get('system.assets.js_pipeline')), $options); |
||||
break; |
||||
case 'inline': |
||||
$options = [ |
||||
'priority' => $script[':priority'], |
||||
'group' => $group, |
||||
'type' => $script['type'], |
||||
'loading' => $script['loading'] |
||||
] + $script['element']; |
||||
|
||||
$assets->addInlineJs($script['content'], $options); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param Assets $assets |
||||
* @param array $groups |
||||
* @return void |
||||
*/ |
||||
protected static function registerLinks(Assets $assets, array $groups): void |
||||
{ |
||||
foreach ($groups as $group => $links) { |
||||
foreach ($links as $link) { |
||||
$href = $link['href']; |
||||
$options = [ |
||||
'group' => $group, |
||||
'priority' => $link[':priority'], |
||||
'rel' => $link['rel'], |
||||
] + $link['element']; |
||||
|
||||
$assets->addLink($href, $options); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param Assets $assets |
||||
* @param array $groups |
||||
* @return void |
||||
*/ |
||||
protected static function registerHtml(Assets $assets, array $groups): void |
||||
{ |
||||
if ($groups) { |
||||
throw new \RuntimeException('Not Implemented'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param string $url |
||||
* @param bool $pipeline |
||||
* @return string |
||||
*/ |
||||
protected static function getRelativeUrl($url, $pipeline) |
||||
{ |
||||
$grav = Grav::instance(); |
||||
|
||||
$base = rtrim($grav['base_url'], '/') ?: '/'; |
||||
|
||||
if (strpos($url, $base) === 0) { |
||||
if ($pipeline) { |
||||
// Remove file timestamp if CSS pipeline has been enabled. |
||||
$url = preg_replace('|[?#].*|', '', $url); |
||||
} |
||||
|
||||
return substr($url, strlen($base) - 1); |
||||
} |
||||
return $url; |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @package Grav\Common\Assets |
||||
* |
||||
* @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. |
||||
* @license MIT License; see LICENSE file for details. |
||||
*/ |
||||
|
||||
namespace Grav\Common\Assets; |
||||
|
||||
use Grav\Common\Utils; |
||||
|
||||
/** |
||||
* Class InlineJs |
||||
* @package Grav\Common\Assets |
||||
*/ |
||||
class InlineJsModule extends BaseAsset |
||||
{ |
||||
/** |
||||
* InlineJs constructor. |
||||
* @param array $elements |
||||
* @param string|null $key |
||||
*/ |
||||
public function __construct(array $elements = [], ?string $key = null) |
||||
{ |
||||
$base_options = [ |
||||
'asset_type' => 'js_module', |
||||
'attributes' => ['type' => 'module'], |
||||
'position' => 'after' |
||||
]; |
||||
|
||||
$merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements); |
||||
|
||||
parent::__construct($merged_attributes, $key); |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function render() |
||||
{ |
||||
return '<script' . $this->renderAttributes(). ">\n" . trim($this->asset) . "\n</script>\n"; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,49 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @package Grav\Common\Assets |
||||
* |
||||
* @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. |
||||
* @license MIT License; see LICENSE file for details. |
||||
*/ |
||||
|
||||
namespace Grav\Common\Assets; |
||||
|
||||
use Grav\Common\Utils; |
||||
|
||||
/** |
||||
* Class Js |
||||
* @package Grav\Common\Assets |
||||
*/ |
||||
class JsModule extends BaseAsset |
||||
{ |
||||
/** |
||||
* Js constructor. |
||||
* @param array $elements |
||||
* @param string|null $key |
||||
*/ |
||||
public function __construct(array $elements = [], ?string $key = null) |
||||
{ |
||||
$base_options = [ |
||||
'asset_type' => 'js_module', |
||||
'attributes' => ['type' => 'module'] |
||||
]; |
||||
|
||||
$merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements); |
||||
|
||||
parent::__construct($merged_attributes, $key); |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function render() |
||||
{ |
||||
if (isset($this->attributes['loading']) && $this->attributes['loading'] === 'inline') { |
||||
$buffer = $this->gatherLinks([$this], self::JS_MODULE_ASSET); |
||||
return '<script' . $this->renderAttributes() . ">\n" . trim($buffer) . "\n</script>\n"; |
||||
} |
||||
|
||||
return '<script src="' . trim($this->asset) . $this->renderQueryString() . '"' . $this->renderAttributes() . $this->integrityHash($this->asset) . "></script>\n"; |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @package Grav\Common\Assets |
||||
* |
||||
* @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. |
||||
* @license MIT License; see LICENSE file for details. |
||||
*/ |
||||
|
||||
namespace Grav\Common\Assets; |
||||
|
||||
use Grav\Common\Utils; |
||||
|
||||
/** |
||||
* Class Link |
||||
* @package Grav\Common\Assets |
||||
*/ |
||||
class Link extends BaseAsset |
||||
{ |
||||
/** |
||||
* Css constructor. |
||||
* @param array $elements |
||||
* @param string|null $key |
||||
*/ |
||||
public function __construct(array $elements = [], ?string $key = null) |
||||
{ |
||||
$base_options = [ |
||||
'asset_type' => 'link', |
||||
]; |
||||
|
||||
$merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements); |
||||
|
||||
parent::__construct($merged_attributes, $key); |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function render() |
||||
{ |
||||
return '<link href="' . trim($this->asset) . $this->renderQueryString() . '"' . $this->renderAttributes() . $this->integrityHash($this->asset) . ">\n"; |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue