@coffeekraken/scripts-stack
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -8,29 +8,29 @@ "use strict"; | ||
const path = require('path'); | ||
const path = require("path"); | ||
const fs = require('fs'); | ||
const fs = require("fs"); | ||
const blessed = require('blessed'); | ||
const blessed = require("blessed"); | ||
const logSymbols = require('log-symbols'); | ||
const logSymbols = require("log-symbols"); | ||
const chalk = require('chalk'); | ||
const chalk = require("chalk"); | ||
const clipboardy = require('clipboardy'); | ||
const clipboardy = require("clipboardy"); | ||
const stripAnsi = require('strip-ansi'); | ||
const stripAnsi = require("strip-ansi"); | ||
const nodeNotifier = require('node-notifier'); | ||
const nodeNotifier = require("node-notifier"); | ||
const terminate = require('terminate'); | ||
const terminate = require("terminate"); | ||
const clear = require('clear'); | ||
const clear = require("clear"); | ||
const pad = require('pad'); | ||
const pad = require("pad"); | ||
const flatten = require('flat'); | ||
const flatten = require("flat"); | ||
const pkgUp = require('pkg-up'); | ||
const pkgUp = require("pkg-up"); | ||
const Script = require('./Script'); | ||
const Script = require("./Script"); | ||
@@ -40,3 +40,3 @@ class scriptsStack { | ||
this._config = Object.assign({}, { | ||
color: 'yellow' | ||
color: "yellow" | ||
}, config); | ||
@@ -75,5 +75,18 @@ this._scriptsIds = []; | ||
this._scriptsObj = {}; | ||
if (this._packageScripts && this._packageScripts.scripts) this._scriptsObj = this._packageScripts.scripts; | ||
if (this._packageJson && this._packageJson.scripts) this._scriptsObj = this._packageJson.scripts; | ||
if (this._packageUpJson && this._packageUpJson.scripts) this._scriptsObj = this._packageUpJson.scripts; | ||
if (this._packageUpJson && this._packageUpJson.scripts) { | ||
this._scriptsObj = this._packageUpJson.scripts; | ||
} | ||
if (this._packageScripts && this._packageScripts.scripts) { | ||
this._scriptsObj = { ...this._scriptsObj, | ||
...this._packageScripts.scripts | ||
}; | ||
} | ||
if (this._packageJson && this._packageJson.scripts) { | ||
this._scriptsObj = { ...this._scriptsObj, | ||
...this._packageJson.scripts | ||
}; | ||
} | ||
} | ||
@@ -148,3 +161,3 @@ | ||
stack[scriptId] = new Script(scriptId, this._scriptsObj[scriptId], watchObj, 'npm'); | ||
stack[scriptId] = new Script(scriptId, this._scriptsObj[scriptId], watchObj, "npm"); | ||
@@ -159,3 +172,3 @@ if (this._config.watch) { | ||
_loadPackageJson() { | ||
const packageJson = require(process.env.PWD + '/package.json'); | ||
const packageJson = require(process.env.PWD + "/package.json"); | ||
@@ -170,7 +183,7 @@ if (!packageJson) { | ||
_getScriptInstance(key) { | ||
if (typeof key === 'number') { | ||
if (typeof key === "number") { | ||
return this._scriptsStack[Object.keys(this._scriptsStack)[parseInt(key) - 1]]; | ||
} else if (key instanceof Script) { | ||
return key; | ||
} else if (typeof key === 'string') { | ||
} else if (typeof key === "string") { | ||
return this._scriptsStack[this._getScriptIdFromListLine(key)]; | ||
@@ -188,5 +201,5 @@ } | ||
autoPadding: true, | ||
ignoreLocked: ['C-c'], | ||
ignoreLocked: ["C-c"], | ||
style: { | ||
bg: 'black' | ||
bg: "black" | ||
} | ||
@@ -197,6 +210,6 @@ }); | ||
parent: screen, | ||
width: '100%', | ||
height: '100%', | ||
width: "100%", | ||
height: "100%", | ||
style: { | ||
bg: 'black' | ||
bg: "black" | ||
} | ||
@@ -210,7 +223,7 @@ }); | ||
headerContent.push("".concat(chalk.black.bold(this._packageJson.name), " ").concat(chalk.bgWhite.black(' ' + this._packageJson.version + ' '))); | ||
headerContent.push("".concat(chalk.black.bold(this._packageJson.name), " ").concat(chalk.bgWhite.black(" " + this._packageJson.version + " "))); | ||
screen.$headerBox = blessed.box({ | ||
parent: screen.$container, | ||
width: '100%', | ||
content: "\n ".concat(headerContent.join(' ')), | ||
width: "100%", | ||
content: "\n ".concat(headerContent.join(" ")), | ||
height: 3, | ||
@@ -223,3 +236,3 @@ style: { | ||
parent: screen.$container, | ||
width: '25%', | ||
width: "25%", | ||
top: 4, | ||
@@ -236,10 +249,10 @@ bottom: 2, | ||
fg: this._config.color, | ||
bg: 'black' | ||
bg: "black" | ||
}, | ||
fg: 'white', | ||
bg: 'black' | ||
fg: "white", | ||
bg: "black" | ||
} | ||
}); | ||
screen.$scriptsList.focus(); | ||
screen.$scriptsList.on('select', (item, index) => { | ||
screen.$scriptsList.on("select", (item, index) => { | ||
// get the script instance of the selected script and run it | ||
@@ -254,5 +267,5 @@ const script = this._getScriptInstance(item.getContent()); | ||
parent: screen.$container, | ||
orientation: 'vertical', | ||
orientation: "vertical", | ||
top: 4, | ||
left: '26%', | ||
left: "26%", | ||
width: 1, | ||
@@ -262,3 +275,3 @@ bottom: 3, | ||
fg: this._config.color, | ||
bg: 'black' | ||
bg: "black" | ||
} | ||
@@ -270,3 +283,3 @@ }); | ||
bottom: 3, | ||
left: '28%', | ||
left: "28%", | ||
keys: true, | ||
@@ -279,4 +292,4 @@ mouse: true, | ||
style: { | ||
bg: 'black', | ||
fg: 'white' | ||
bg: "black", | ||
fg: "white" | ||
}, | ||
@@ -289,3 +302,3 @@ scrollbar: { | ||
parent: screen.$container, | ||
width: '100%', | ||
width: "100%", | ||
content: "", | ||
@@ -304,3 +317,3 @@ height: 2, | ||
// Quit on Escape, q, or Control-C. | ||
this.screen.key(['escape', 'q', 'C-c'], (ch, key) => { | ||
this.screen.key(["escape", "q", "C-c"], (ch, key) => { | ||
// unwatch files | ||
@@ -321,3 +334,3 @@ Object.keys(this._watchers).forEach(watchKey => { | ||
}); | ||
this.screen.key(['r'], (ch, key) => { | ||
this.screen.key(["r"], (ch, key) => { | ||
// run the selected script | ||
@@ -330,3 +343,3 @@ const script = this._getCurrentScriptInstance(); | ||
}); | ||
this.screen.key(['s'], (ch, key) => { | ||
this.screen.key(["s"], (ch, key) => { | ||
// run the selected script | ||
@@ -337,3 +350,3 @@ this._config.switch = !this._config.switch; // update the footer content | ||
}); | ||
this.screen.key(['w'], (ch, key) => { | ||
this.screen.key(["w"], (ch, key) => { | ||
// run the selected script | ||
@@ -358,3 +371,3 @@ const script = this._getCurrentScriptInstance(); | ||
}); | ||
this.screen.key(['c'], (ch, key) => { | ||
this.screen.key(["c"], (ch, key) => { | ||
// run the selected script | ||
@@ -364,5 +377,5 @@ const script = this._getCurrentScriptInstance(); | ||
if (!script) return; | ||
clipboardy.writeSync(stripAnsi(script.stack.join(''))); | ||
clipboardy.writeSync(stripAnsi(script.stack.join(""))); | ||
}); | ||
this.screen.key(['e'], (ch, key) => { | ||
this.screen.key(["e"], (ch, key) => { | ||
// run the selected script | ||
@@ -375,4 +388,4 @@ const script = this._getCurrentScriptInstance(); | ||
let keyTimeout = null; | ||
let keys = ''; | ||
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].forEach(key => { | ||
let keys = ""; | ||
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].forEach(key => { | ||
this.screen.key(["".concat(key)], (ch, key) => { | ||
@@ -383,3 +396,3 @@ keys += key.full; | ||
if (parseInt(keys) > Object.keys(this._scriptsStack).length) { | ||
keys = ''; | ||
keys = ""; | ||
return; | ||
@@ -398,3 +411,3 @@ } // select the script | ||
keys = ''; | ||
keys = ""; | ||
}, 150); | ||
@@ -412,11 +425,11 @@ }); | ||
const watchColorFn = currentScript.isWatched() ? chalk.bgBlue.black : chalk.bgWhite.black; | ||
footerContent.push("".concat(chalk.bgWhite.black(' Run (r) '))); | ||
footerContent.push("".concat(chalk.bgWhite.black(' Exit (e) '))); | ||
footerContent.push("".concat(chalk.bgWhite.black(' Copy (c) '))); | ||
footerContent.push("".concat(chalk.bgWhite.black(" Run (r) "))); | ||
footerContent.push("".concat(chalk.bgWhite.black(" Exit (e) "))); | ||
footerContent.push("".concat(chalk.bgWhite.black(" Copy (c) "))); | ||
if (currentScript.isWatchable()) { | ||
footerContent.push("".concat(watchColorFn(' Watch (w) '))); | ||
footerContent.push("".concat(watchColorFn(" Watch (w) "))); | ||
} | ||
footerContent.push("".concat(switchColorFn(' Switch (s) '))); // footerContent.push(`${chalk.bgWhite.black(' Exit ')} ${chalk.bold.black('ctrl-c')} `) | ||
footerContent.push("".concat(switchColorFn(" Switch (s) "))); // footerContent.push(`${chalk.bgWhite.black(' Exit ')} ${chalk.bold.black('ctrl-c')} `) | ||
@@ -426,10 +439,10 @@ footerContent.push("\n"); | ||
if (this._packageJson.homepage) { | ||
footerContent.push("".concat(chalk.bgBlack.white(' Homepage '), " ").concat(chalk.bold.black(this._packageJson.homepage), " ")); | ||
footerContent.push("".concat(chalk.bgBlack.white(" Homepage "), " ").concat(chalk.bold.black(this._packageJson.homepage), " ")); | ||
} | ||
if (this._packageJson.author) { | ||
footerContent.push("".concat(chalk.bgBlack.white(' Author '), " ").concat(chalk.bold.black(this._packageJson.author))); | ||
footerContent.push("".concat(chalk.bgBlack.white(" Author "), " ").concat(chalk.bold.black(this._packageJson.author))); | ||
} | ||
this.screen.$footerBox.setContent(footerContent.join('')); | ||
this.screen.$footerBox.setContent(footerContent.join("")); | ||
} | ||
@@ -446,3 +459,3 @@ | ||
_getScriptIdFromListLine(line) { | ||
const splits = line.split(' '); | ||
const splits = line.split(" "); | ||
return splits[splits.length - 1]; | ||
@@ -454,6 +467,6 @@ } | ||
let watched = script.isWatchable() ? chalk.blue('-') + ' ' : ''; | ||
let watched = script.isWatchable() ? chalk.blue("-") + " " : ""; | ||
if (script.isWatched()) { | ||
watched = chalk.blue('w') + ' '; | ||
watched = chalk.blue("w") + " "; | ||
} | ||
@@ -467,9 +480,9 @@ | ||
let readedIcon = ''; | ||
let readedIcon = ""; | ||
if (!script.isReaded()) { | ||
readedIcon = logSymbols.info + ' '; | ||
readedIcon = logSymbols.info + " "; | ||
} | ||
let idx = pad(2, Object.keys(this._scriptsStack).indexOf(scriptId) + 1, '0'); | ||
let idx = pad(2, Object.keys(this._scriptsStack).indexOf(scriptId) + 1, "0"); | ||
return " ".concat(idx, ". ").concat(iconToDisplay).concat(readedIcon).concat(scriptId); | ||
@@ -512,3 +525,3 @@ } | ||
this.screen.$consoleBox.setContent(script.stack.join('')); | ||
this.screen.$consoleBox.setContent(script.stack.join("")); | ||
this.screen.$consoleBox.scroll(99999999999); // mark the script as read | ||
@@ -534,4 +547,4 @@ // script.markAsRead() | ||
(script => { | ||
script.on('start', data => { | ||
const chars = ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷']; | ||
script.on("start", data => { | ||
const chars = ["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"]; | ||
let current = 0; | ||
@@ -550,3 +563,3 @@ | ||
}); | ||
script.on('exit', data => { | ||
script.on("exit", data => { | ||
clearInterval(script._updateInterval); | ||
@@ -566,4 +579,4 @@ | ||
const icons = ['css', 'fonts', 'icons', 'img', 'js']; | ||
const splitedScript = script.id.split(':'); | ||
const icons = ["css", "fonts", "icons", "img", "js"]; | ||
const splitedScript = script.id.split(":"); | ||
const lastSplit = splitedScript[splitedScript.length - 1]; | ||
@@ -576,3 +589,3 @@ const icon = icons.indexOf(lastSplit) !== -1 ? "icon-".concat(lastSplit) : null; | ||
subtitle: script.id, | ||
message: 'Completed successfuly', | ||
message: "Completed successfuly", | ||
icon: icon ? path.join(__dirname, "../.resources/".concat(icon, ".png")) : null, | ||
@@ -584,5 +597,5 @@ sound: true, | ||
}); | ||
script.on('data', data => { | ||
script.on("data", data => { | ||
if (this._currentScriptId === scriptId) { | ||
this.screen.$consoleBox.setContent(script.stack.join('')); | ||
this.screen.$consoleBox.setContent(script.stack.join("")); | ||
} | ||
@@ -594,3 +607,3 @@ | ||
}); | ||
script.on('error', data => { | ||
script.on("error", data => { | ||
// set the error icon on the item | ||
@@ -597,0 +610,0 @@ clearInterval(script._updateInterval); |
@@ -8,18 +8,18 @@ "use strict"; | ||
const spawn = require('child_process').spawn; | ||
const spawn = require("child_process").spawn; | ||
const chalk = require('chalk'); | ||
const chalk = require("chalk"); | ||
const chokidar = require('chokidar'); | ||
const chokidar = require("chokidar"); | ||
const logSymbols = require('log-symbols'); | ||
const logSymbols = require("log-symbols"); | ||
const removeBlankLines = require('remove-blank-lines'); | ||
const removeBlankLines = require("remove-blank-lines"); | ||
const terminate = require('terminate'); | ||
const terminate = require("terminate"); | ||
const commandExistsSync = require('command-exists').sync; | ||
const commandExistsSync = require("command-exists").sync; | ||
class Script { | ||
constructor(id, script, watchOpts = null, runner = 'npm') { | ||
constructor(id, script, watchOpts = null, runner = "npm") { | ||
this._id = id; | ||
@@ -41,3 +41,3 @@ this._script = script; | ||
// reset the stack | ||
this._stack = ["press ".concat(chalk.yellow.bold('r'), " to run or ").concat(chalk.red.bold('e'), " to exit the ").concat(chalk.bold(this.id), " script")]; | ||
this._stack = ["press ".concat(chalk.yellow.bold("r"), " to run or ").concat(chalk.red.bold("e"), " to exit the ").concat(chalk.bold(this.id), " script")]; | ||
} | ||
@@ -70,6 +70,6 @@ | ||
if (commandExistsSync('ck')) this._runner = 'ck'; // build command stack | ||
if (commandExistsSync("ck")) this._runner = "ck"; // build command stack | ||
const commandArgs = []; | ||
if (this._runner === 'npm' || this._runner === 'ck') commandArgs.push('run'); | ||
if (this._runner === "npm" || this._runner === "ck") commandArgs.push("run"); | ||
commandArgs.push(this.id); // spawn a new process with the runner and commandArgs | ||
@@ -82,3 +82,3 @@ | ||
this._childScript.stdout.on('data', data => { | ||
this._childScript.stdout.on("data", data => { | ||
// new data | ||
@@ -93,3 +93,3 @@ this._readed = false; // push new data to the stack | ||
this._childScript.stderr.on('data', data => { | ||
this._childScript.stderr.on("data", data => { | ||
// new data | ||
@@ -107,3 +107,3 @@ this._readed = false; // push new data to the stack | ||
this._childScript.on('exit', (code, signal) => { | ||
this._childScript.on("exit", (code, signal) => { | ||
this._isRunning = false; // end time | ||
@@ -143,7 +143,7 @@ | ||
this._watcher.on('add', path => { | ||
this._watcher.on("add", path => { | ||
this.run(); | ||
}).on('change', path => { | ||
}).on("change", path => { | ||
this.run(); | ||
}).on('unlink', path => { | ||
}).on("unlink", path => { | ||
this.run(); | ||
@@ -161,4 +161,4 @@ }); | ||
_dispatchStart() { | ||
if (this._on['start']) { | ||
this._on['start'].forEach(cb => { | ||
if (this._on["start"]) { | ||
this._on["start"].forEach(cb => { | ||
cb(); | ||
@@ -170,4 +170,4 @@ }); | ||
_dispatchWarning(data) { | ||
if (this._on['warning']) { | ||
this._on['warning'].forEach(cb => { | ||
if (this._on["warning"]) { | ||
this._on["warning"].forEach(cb => { | ||
cb(data); | ||
@@ -179,4 +179,4 @@ }); | ||
_dispatchExit() { | ||
if (this._on['exit']) { | ||
this._on['exit'].forEach(cb => { | ||
if (this._on["exit"]) { | ||
this._on["exit"].forEach(cb => { | ||
cb(); | ||
@@ -188,4 +188,4 @@ }); | ||
_dispatchData(data) { | ||
if (this._on['data']) { | ||
this._on['data'].forEach(cb => { | ||
if (this._on["data"]) { | ||
this._on["data"].forEach(cb => { | ||
cb(data); | ||
@@ -197,4 +197,4 @@ }); | ||
_dispatchError(data) { | ||
if (this._on['error']) { | ||
this._on['error'].forEach(cb => { | ||
if (this._on["error"]) { | ||
this._on["error"].forEach(cb => { | ||
cb(data); | ||
@@ -201,0 +201,0 @@ }); |
{ | ||
"name": "@coffeekraken/scripts-stack", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Nice terminal interface to handle npm/yarn scripts execution as well as watch and run automatically the wanted ones", | ||
@@ -5,0 +5,0 @@ "homepage": "https://coffeekraken.io", |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
38228
648