+98
| #!/usr/bin/env node | ||
| 'use strict' | ||
| const tool = require('command-line-tool') | ||
| const fs = require('fs') | ||
| const FileSet = require('file-set') | ||
| const cp = require('child_process') | ||
| const alert = require('../lib/alert') | ||
| const defs = [ | ||
| { name: 'do', type: String, multiple: true, typeLabel: '<commands>' }, | ||
| { name: 'when', type: String, multiple: true, defaultOption: true, typeLabel: '<files>'}, | ||
| { name: 'change', type: Boolean }, | ||
| { name: 'speak', alias: 's', type: Boolean }, | ||
| { name: 'poll-interval', alias: 'p', type: Number, defaultValue: 1000, typeLabel: '<ms>' }, | ||
| { name: 'help', alias: 'h', type: Boolean }, | ||
| { name: 'verbose', alias: 'v', type: Boolean } | ||
| ] | ||
| const usageSections = [ | ||
| { | ||
| header: 'baldrick', | ||
| content: 'A general-purpose filesystem watch-and-respond tool.' | ||
| }, | ||
| { | ||
| header: 'Synopsis', | ||
| content: [ | ||
| '$ baldrick --do <command> --when <files> [--change] [--speak] [--poll-interval <ms>]', | ||
| '$ baldrick --help' | ||
| ] | ||
| }, | ||
| { | ||
| header: 'Options', | ||
| optionList: defs | ||
| }, | ||
| { | ||
| content: 'Project page: [underline]{https://github.com/75lb/baldrick}' | ||
| } | ||
| ] | ||
| let cli | ||
| try { | ||
| cli = tool.getCli(defs, usageSections) | ||
| } catch(err) { | ||
| tool.halt(err) | ||
| } | ||
| const options = cli.options | ||
| if (options.help) { | ||
| tool.stop(cli.usage) | ||
| } | ||
| validate() | ||
| watchFiles(options.when) | ||
| function runCommand (file, command) { | ||
| if (file) { | ||
| command = command.replace(/{{file}}/g, file) | ||
| } | ||
| if (/{{file}}/.test(command)) return | ||
| cp.exec(command, function (err, stdout, stderr) { | ||
| if (err) { | ||
| alert.bell() | ||
| if (options.speak) alert.say('i fucked up!') | ||
| tool.printOutput('[red]{✖ fucked up}') | ||
| console.log(err.message) | ||
| } else { | ||
| if (options.speak) alert.say('my lord') | ||
| tool.printOutput('[green]{✔︎ work done}') | ||
| if (stdout || stderr) { | ||
| tool.printOutput('[bold]{\noutput}') | ||
| if (stdout) console.log(stdout) | ||
| if (stderr) console.log(stderr) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| function watchFiles (whenExpression) { | ||
| const fileSet = new FileSet(whenExpression) | ||
| fileSet.files.forEach(function (file) { | ||
| if (options.verbose) { | ||
| console.log(file) | ||
| } | ||
| fs.watchFile(file, { interval: options['poll-interval']}, function (currStat, prevStat) { | ||
| tool.printOutput(`[bold underline]{${file} touched}`) | ||
| if (options.change && (currStat.mtime.getTime() > prevStat.mtime.getTime())) { | ||
| options.do.forEach(runCommand.bind(null, file)) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| options.do.forEach(runCommand.bind(null, null)) | ||
| function validate () { | ||
| if (!(options.do.length && options.when)) halt('Must specify --do and --when') | ||
| } |
+8
-7
@@ -1,12 +0,13 @@ | ||
| var cp = require("child_process"); | ||
| 'use strict' | ||
| const cp = require('child_process') | ||
| exports.say = say; | ||
| exports.bell = bell; | ||
| exports.say = say | ||
| exports.bell = bell | ||
| function say(msg){ | ||
| cp.exec("say -v Ralph " + msg); | ||
| function say (msg) { | ||
| cp.exec('say ' + msg) | ||
| } | ||
| function bell(){ | ||
| console.log("\u0007") | ||
| function bell () { | ||
| console.log('\u0007') | ||
| } |
+1
-1
| The MIT License (MIT) | ||
| Copyright (c) 2015 Lloyd Brookes <75pound@gmail.com> | ||
| Copyright (c) 2014-16 Lloyd Brookes <75pound@gmail.com> | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
+4
-6
| { | ||
| "name": "baldrick", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "description": "A general-purpose filesystem-watch-and-respond tool.", | ||
| "repository": "https://github.com/75lb/baldrick", | ||
| "license": "MIT", | ||
| "bin": "bin/baldrick.js", | ||
| "bin": "bin/cli.js", | ||
| "scripts": { | ||
@@ -20,7 +20,5 @@ "test": "" | ||
| "dependencies": { | ||
| "console-dope": "~0.3.3", | ||
| "command-line-args": "^1.0.0", | ||
| "file-set": "~0.2.0", | ||
| "string-tools": "~0.1.8" | ||
| "command-line-tool": "^0.6.4", | ||
| "file-set": "^1.1.1" | ||
| } | ||
| } |
+4
-3
| [](https://www.npmjs.org/package/baldrick) | ||
|  | ||
| [](https://david-dm.org/75lb/baldrick) | ||
| [](https://github.com/feross/standard) | ||
| # baldrick | ||
| A general-purpose filesystem-watch-and-respond tool. | ||
| A general-purpose filesystem-watch-and-respond tool. | ||
@@ -34,4 +35,4 @@  | ||
| * * * | ||
| * * * | ||
| © 2015 Lloyd Brookes 75pound@gmail.com. | ||
| © 2014-16 Lloyd Brookes 75pound@gmail.com. |
| #!/usr/bin/env node | ||
| "use strict"; | ||
| var cliArgs = require("command-line-args"); | ||
| var fs = require("fs"); | ||
| var FileSet = require("file-set"); | ||
| var cp = require("child_process"); | ||
| var dope = require("console-dope"); | ||
| var s = require("string-tools"); | ||
| var alert = require("../lib/alert"); | ||
| var cli = cliArgs([ | ||
| { name: "do", type: String, multiple: true, typeLabel: "<commands>" }, | ||
| { name: "when", type: String, multiple: true, defaultOption: true, typeLabel: "<files>"}, | ||
| { name: "change", type: Boolean }, | ||
| { name: "speak", alias: "s", type: Boolean }, | ||
| { name: "poll-interval", alias: "p", type: Number, defaultValue: 1000, typeLabel: "<ms>" }, | ||
| { name: "help", alias: "h", type: Boolean }, | ||
| { name: "verbose", alias: "v", type: Boolean } | ||
| ]); | ||
| var usage = cli.getUsage({ | ||
| title: "baldrick", | ||
| description: "A general-purpose filesystem-watch-and-respond tool.", | ||
| usage: { | ||
| forms: [ | ||
| "$ baldrick --do <command> --when <files> [--change] [--speak] [--poll-interval <ms>]", | ||
| "$ baldrick --help" | ||
| ] | ||
| }, | ||
| footer: "Project page: [underline]{https://github.com/75lb/baldrick}" | ||
| }); | ||
| try { | ||
| var options = cli.parse(); | ||
| } catch(err){ | ||
| halt(err.message); | ||
| } | ||
| if (options.help){ | ||
| console.log(usage); | ||
| process.exit(0); | ||
| } | ||
| validate(); | ||
| watchFiles(options.when); | ||
| function runCommand(file, command){ | ||
| if (file){ | ||
| command = command.replace(/{{file}}/g, file); | ||
| } | ||
| if (/{{file}}/.test(command)) return; | ||
| cp.exec(command, function(err, stdout, stderr){ | ||
| if (err){ | ||
| alert.bell(); | ||
| if (options.speak) alert.say("i fucked up!"); | ||
| dope.red.bold.log("%s fucked up", s.symbol.cross); | ||
| dope.log(err.message); | ||
| } else { | ||
| if (options.speak) alert.say("my lord"); | ||
| dope.bold.green.log("%s work done", s.symbol.tick); | ||
| if (stdout || stderr){ | ||
| dope.bold.log("\noutput"); | ||
| if (stdout) dope.log(stdout); | ||
| if (stderr) dope.log(stderr); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| function watchFiles(whenExpression){ | ||
| var fileSet = new FileSet(whenExpression); | ||
| fileSet.files.forEach(function(file){ | ||
| if (options.verbose){ | ||
| console.log(file); | ||
| } | ||
| fs.watchFile(file, { interval: options["poll-interval"] }, function(currStat, prevStat){ | ||
| dope.bold.underline.log("%s touched", file); | ||
| if (options.change && (currStat.mtime.getTime() > prevStat.mtime.getTime())){ | ||
| options.do.forEach(runCommand.bind(null, file)); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| options.do.forEach(runCommand.bind(null, null)); | ||
| function halt(msg){ | ||
| dope.red.error("Error: " + msg); | ||
| dope.log(usage); | ||
| process.exit(1); | ||
| } | ||
| function validate(){ | ||
| if (!(options.do.length && options.when)) halt("Must specify --do and --when"); | ||
| } |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
-50%98
4.26%38
2.7%5458
-3.53%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated