Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autodev

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autodev - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

180

autodev.js

@@ -1,104 +0,124 @@

(function() {
var chokidar, http, path, uncache;
var chokidar, http, path, uncache;
http = require("http");
http = require("http");
chokidar = require("chokidar");
chokidar = require("chokidar");
uncache = require("recursive-uncache");
uncache = require("recursive-uncache");
path = require("path");
path = require("path");
module.exports = (program) => {
var busy, close, connections, entry, k, ref, ref1, restart, server, startup, unwatchedModules, v, watcher;
if (((ref = program.args) != null ? ref[0] : void 0) == null) {
return;
module.exports = (program) => {
var busy, close, connections, entry, ref, restart, server, startup, unwatchedModules, watcher;
if (((ref = program.args) != null ? ref[0] : void 0) == null) {
return;
}
if (path.extname(program.args[0]) === ".coffee") {
try {
require("coffeescript/register");
} catch (error) {
try {
require("coffee-script/register");
} catch (error) {}
}
if (path.extname(program.args[0]) === ".coffee") {
try {
require("coffeescript/register");
} catch (error) {
try {
require("coffee-script/register");
} catch (error) {}
}
entry = path.resolve(program.args[0]);
server = null;
close = null;
watcher = null;
busy = false;
unwatchedModules = [];
connections = [];
startup = async(isRestart) => {
var e, filesToWatch, k, ref1, ref2, start, v;
console.log("\x1b[36mautodev: " + (isRestart ? "starting up again" : "starting up") + "\x1b[0m");
server = http.createServer();
server.on("connection", (con) => {
return connections.push(con);
});
try {
start = (await require(entry));
} catch (error) {
e = error;
console.error(e);
}
filesToWatch = [];
if (!isRestart) {
ref1 = require.cache;
for (k in ref1) {
v = ref1[k];
unwatchedModules.push(k);
}
filesToWatch.push(entry);
}
entry = path.resolve(program.args[0]);
server = null;
close = null;
watcher = null;
busy = false;
unwatchedModules = [];
ref1 = require.cache;
for (k in ref1) {
v = ref1[k];
unwatchedModules.push(k);
}
connections = [];
startup = (isRestart) => {
var e, filesToWatch, ref2;
console.log("autodev: " + (isRestart ? "restart" : "startup"));
server = http.createServer();
server.on("connection", function(con) {
return connections.push(con);
});
if (typeof start === "function") {
try {
close = require(entry)(server, isRestart);
close = (await start(server, isRestart));
} catch (error) {
e = error;
return console.log(e);
console.error(e);
}
filesToWatch = [];
ref2 = require.cache;
for (k in ref2) {
v = ref2[k];
if (unwatchedModules.indexOf(k) < 0) {
if (!~unwatchedModules.indexOf(k)) {
filesToWatch.push(k);
}
}
if (watcher == null) {
watcher = chokidar.watch(filesToWatch, {
ignoreInitial: true
}).on("all", (e, filepath) => {
if (busy) {
return;
}
uncache(filepath, __filename);
return restart();
});
} else {
watcher.add(filesToWatch);
}
if (watcher == null) {
watcher = chokidar.watch(filesToWatch, {
ignoreInitial: true
}).on("all", (e, filepath) => {
if (busy) {
return;
}
uncache(filepath, __filename);
return restart();
});
} else {
watcher.add(filesToWatch);
}
return busy = false;
};
startup(false);
return restart = async() => {
var con, i, len, promise;
if (busy) {
return;
}
busy = true;
console.log("autodev: tearing down\n");
promise = new Promise(async(resolve) => {
var e;
try {
await (typeof close === "function" ? close() : void 0);
} catch (error) {
e = error;
console.error(e);
}
return busy = false;
};
startup(false);
return restart = () => {
var con, i, len;
if (busy) {
return;
}
busy = true;
if (typeof close === "function") {
close();
}
close = null;
if (server) {
server.once("close", startup.bind(null, true));
server.close();
server = null;
for (i = 0, len = connections.length; i < len; i++) {
con = connections[i];
if (con != null) {
if (typeof con.destroy === "function") {
con.destroy();
}
return resolve();
});
if (server) {
server.once("close", async() => {
await promise;
return startup(true);
});
server.close();
server = null;
for (i = 0, len = connections.length; i < len; i++) {
con = connections[i];
if (con != null) {
if (typeof con.destroy === "function") {
con.destroy();
}
}
return connections = [];
} else {
return startup(true);
}
};
return connections = [];
} else {
await promise;
return startup(true);
}
};
}).call(this);
};
{
"name": "autodev",
"description": "quick auto restart script for dev servers",
"version": "0.0.2",
"version": "0.1.0",
"homepage": "https://github.com/paulpflug/",

@@ -26,5 +26,5 @@ "author": {

"dependencies": {
"chokidar": "^1.6.1",
"commander": "^2.9.0",
"recursive-uncache": "^0.0.1"
"chokidar": "^1.7.0",
"commander": "^2.11.0",
"recursive-uncache": "^0.1.0"
},

@@ -41,3 +41,3 @@ "devDependencies": {

"scripts": {
"build": "coffee --no-header --compile --output ./ src/*.coffee",
"build": "coffee --bare --no-header --compile --output ./ src/*.coffee",
"dev": "npm run build && node ./cli.js dev/server.coffee",

@@ -44,0 +44,0 @@ "test": "",

@@ -16,7 +16,9 @@ # autodev

```js
//devserver.js
// devserver.js
// requires outside won't get watched
Koa = require("koa") // koa
express = require("express") // express
module.exports = (server, isRestart) =>
// requires inside will get watched
yourapp = require("./yourapp")
// your startup code

@@ -23,0 +25,0 @@ // koa

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc