-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
88 lines (77 loc) · 1.97 KB
/
app.js
File metadata and controls
88 lines (77 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
const $ = require('jquery');
const exec = require('child_process').exec;
const fs = require('fs');
const configFile = __dirname + '/dqlrunner.json';
const readConfig = (cb) => {
fs.access(configFile, fs.F_OK, (err) => {
if (err) {
// file does not exist
return cb(null, {});
}
fs.readFile(configFile, 'utf8', (err, buffer) => {
if (err) {
return cb(err);
}
let config = {};
try {
config = JSON.parse(buffer.toString());
} catch (e) {
err = e;
}
cb(err, config);
});
});
};
const logError = (error) => {
let $error = $('#error');
$error.html(error.toString());
};
const updateButton = ($el, value) => {
$el.val(value);
};
$(() => {
const $dql = $('[name="dql"]');
const $cwd = $('[name="cwd"]');
const $opt = $('[name="opt"]');
const $output = $('#output');
const $submit = $('#submit');
const $error = $('#error');
$('#query-form').on('submit', (e) => {
e.preventDefault();
$output.html('');
$error.html('');
updateButton($submit, 'Loading...');
const dql = $dql.val().trim();
const cwd = $cwd.val() || __dirname;
const opt = $opt.val() || '';
const cmdParts = ['php app/console doctrine:query:dql'];
if (opt) {
cmdParts.push(opt);
}
cmdParts.push('-- "' + dql + '"');
const cmd = cmdParts.join(' ');
console.log(cwd);
console.log(dql);
console.log(cmd);
exec(cmd, { cwd: cwd }, (err, stdout, stderr) => {
if (err) {
logError(err);
} else if (stderr) {
logError(stderr);
} else {
$output.html(stdout.toString());
window.Prism.highlightAll();
}
updateButton($submit, 'Query...');
});
});
readConfig((err, config) => {
if (err) {
return logError(err);
}
$dql.val(config.dql || '');
$cwd.val(config.cwd || '');
$opt.val(config.opt || '');
});
});