summaryrefslogtreecommitdiff
path: root/app/relay/runner.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/relay/runner.js')
-rw-r--r--app/relay/runner.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/relay/runner.js b/app/relay/runner.js
index 2713a2e..6620bca 100644
--- a/app/relay/runner.js
+++ b/app/relay/runner.js
@@ -5,6 +5,8 @@ import kill from 'tree-kill'
import { remote } from './remote'
import { set_connected } from './rpc'
import uuidv1 from 'uuid/v1'
+import * as fs from 'fs'
+import * as path from 'path'
const idle_state = { status: 'IDLE', task: {} }
@@ -108,6 +110,33 @@ export function run_system_command(cmd, cb) {
}
}
+export function list_directory(opt, cb) {
+ if (!opt.module || ! modules[opt.module]) {
+ cb([])
+ }
+ const module = modules[opt.module]
+ const dir = path.join(module.cwd, opt.dir.replace(/\.\.?\//g, ''))
+ fs.readdir(dir, (err, files) => {
+ const statPromises = files.filter(f => f[0] !== '.').map(f => {
+ return new Promise((resolve, reject) => {
+ const full_path = path.join(dir, f)
+ fs.stat(full_path, (err, stat={}) => {
+ resolve({
+ name: f,
+ path: full_path,
+ date: stat.ctime,
+ size: stat.size,
+ dir: stat.isDirectory(),
+ })
+ })
+ })
+ })
+ Promise.all(statPromises).then(stats => {
+ cb(stats)
+ })
+ })
+}
+
export function run_task(task, preempt, watch){
const module = modules[task.module]
if (! module) return { type: 'error', error: "No such module: " + task.module }
@@ -136,6 +165,7 @@ export function run_task(task, preempt, watch){
console.log(module.cwd)
console.log(interpreter.cmd, params)
+ task.started = new Date().toString()
const subprocess = spawn(interpreter.cmd, params, {
cwd: module.cwd,
})