midi-shell-commands 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +54 -0
- package/.github/workflows/verify-pr.yml +37 -0
- package/.nvmrc +1 -1
- package/.releaserc.json +20 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +343 -0
- package/coverage/coverage-final.json +16 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/midi-shell-commands/index.html +116 -0
- package/coverage/midi-shell-commands/lib/check-inputs.js.html +112 -0
- package/coverage/midi-shell-commands/lib/clean-up-inputs.js.html +112 -0
- package/coverage/midi-shell-commands/lib/clean-up-watcher.js.html +115 -0
- package/coverage/midi-shell-commands/lib/escape-path.js.html +106 -0
- package/coverage/midi-shell-commands/lib/index.html +311 -0
- package/coverage/midi-shell-commands/lib/initialize-midi.js.html +112 -0
- package/coverage/midi-shell-commands/lib/initialize-scripts-directory.js.html +196 -0
- package/coverage/midi-shell-commands/lib/invoke-scripts.js.html +139 -0
- package/coverage/midi-shell-commands/lib/listen-to-input.js.html +118 -0
- package/coverage/midi-shell-commands/lib/log.js.html +94 -0
- package/coverage/midi-shell-commands/lib/map-message-to-file-names.js.html +106 -0
- package/coverage/midi-shell-commands/lib/post-install.js.html +490 -0
- package/coverage/midi-shell-commands/lib/refresh-scripts.js.html +124 -0
- package/coverage/midi-shell-commands/lib/report-errors.js.html +100 -0
- package/coverage/midi-shell-commands/lib/state.js.html +106 -0
- package/coverage/midi-shell-commands/midi-shell-commands.js.html +106 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/eslint.config.js +12 -0
- package/lib/check-inputs.js +9 -0
- package/lib/clean-up-inputs.js +9 -0
- package/lib/clean-up-watcher.js +10 -0
- package/lib/escape-path.js +7 -0
- package/lib/initialize-midi.js +9 -0
- package/lib/initialize-scripts-directory.js +37 -0
- package/lib/invoke-scripts.js +18 -0
- package/lib/listen-to-input.js +11 -0
- package/lib/log.js +3 -0
- package/lib/map-message-to-file-names.js +7 -0
- package/lib/{postinstall.js → post-install.js} +16 -23
- package/lib/refresh-scripts.js +13 -0
- package/lib/report-errors.js +5 -0
- package/lib/state.js +7 -0
- package/midi-shell-commands.js +6 -102
- package/package.json +28 -9
- package/renovate.json +26 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
+
|
|
31
|
+
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
|
32
|
+
// it will be treated as a plain text search
|
|
33
|
+
let searchRegex;
|
|
34
|
+
try {
|
|
35
|
+
searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
|
|
36
|
+
} catch (error) {
|
|
37
|
+
searchRegex = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < rows.length; i++) {
|
|
41
|
+
const row = rows[i];
|
|
42
|
+
let isMatch = false;
|
|
43
|
+
|
|
44
|
+
if (searchRegex) {
|
|
45
|
+
// If a valid regex was created, use it for matching
|
|
46
|
+
isMatch = searchRegex.test(row.textContent);
|
|
47
|
+
} else {
|
|
48
|
+
// Otherwise, fall back to the original plain text search
|
|
49
|
+
isMatch = row.textContent
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.includes(searchValue.toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
row.style.display = isMatch ? '' : 'none';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// loads the search box
|
|
59
|
+
function addSearchBox() {
|
|
60
|
+
var template = document.getElementById('filterTemplate');
|
|
61
|
+
var templateClone = template.content.cloneNode(true);
|
|
62
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
63
|
+
template.parentElement.appendChild(templateClone);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// loads all columns
|
|
67
|
+
function loadColumns() {
|
|
68
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
69
|
+
colNode,
|
|
70
|
+
cols = [],
|
|
71
|
+
col,
|
|
72
|
+
i;
|
|
73
|
+
|
|
74
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
75
|
+
colNode = colNodes[i];
|
|
76
|
+
col = {
|
|
77
|
+
key: colNode.getAttribute('data-col'),
|
|
78
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
79
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
80
|
+
};
|
|
81
|
+
cols.push(col);
|
|
82
|
+
if (col.sortable) {
|
|
83
|
+
col.defaultDescSort = col.type === 'number';
|
|
84
|
+
colNode.innerHTML =
|
|
85
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return cols;
|
|
89
|
+
}
|
|
90
|
+
// attaches a data attribute to every tr element with an object
|
|
91
|
+
// of data values keyed by column name
|
|
92
|
+
function loadRowData(tableRow) {
|
|
93
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
94
|
+
colNode,
|
|
95
|
+
col,
|
|
96
|
+
data = {},
|
|
97
|
+
i,
|
|
98
|
+
val;
|
|
99
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
100
|
+
colNode = tableCols[i];
|
|
101
|
+
col = cols[i];
|
|
102
|
+
val = colNode.getAttribute('data-value');
|
|
103
|
+
if (col.type === 'number') {
|
|
104
|
+
val = Number(val);
|
|
105
|
+
}
|
|
106
|
+
data[col.key] = val;
|
|
107
|
+
}
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
// loads all row data
|
|
111
|
+
function loadData() {
|
|
112
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
113
|
+
i;
|
|
114
|
+
|
|
115
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
116
|
+
rows[i].data = loadRowData(rows[i]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// sorts the table using the data for the ith column
|
|
120
|
+
function sortByIndex(index, desc) {
|
|
121
|
+
var key = cols[index].key,
|
|
122
|
+
sorter = function(a, b) {
|
|
123
|
+
a = a.data[key];
|
|
124
|
+
b = b.data[key];
|
|
125
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
126
|
+
},
|
|
127
|
+
finalSorter = sorter,
|
|
128
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
129
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
130
|
+
rows = [],
|
|
131
|
+
i;
|
|
132
|
+
|
|
133
|
+
if (desc) {
|
|
134
|
+
finalSorter = function(a, b) {
|
|
135
|
+
return -1 * sorter(a, b);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
140
|
+
rows.push(rowNodes[i]);
|
|
141
|
+
tableBody.removeChild(rowNodes[i]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
rows.sort(finalSorter);
|
|
145
|
+
|
|
146
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
147
|
+
tableBody.appendChild(rows[i]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// removes sort indicators for current column being sorted
|
|
151
|
+
function removeSortIndicators() {
|
|
152
|
+
var col = getNthColumn(currentSort.index),
|
|
153
|
+
cls = col.className;
|
|
154
|
+
|
|
155
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
156
|
+
col.className = cls;
|
|
157
|
+
}
|
|
158
|
+
// adds sort indicators for current column being sorted
|
|
159
|
+
function addSortIndicators() {
|
|
160
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
161
|
+
? ' sorted-desc'
|
|
162
|
+
: ' sorted';
|
|
163
|
+
}
|
|
164
|
+
// adds event listeners for all sorter widgets
|
|
165
|
+
function enableUI() {
|
|
166
|
+
var i,
|
|
167
|
+
el,
|
|
168
|
+
ithSorter = function ithSorter(i) {
|
|
169
|
+
var col = cols[i];
|
|
170
|
+
|
|
171
|
+
return function() {
|
|
172
|
+
var desc = col.defaultDescSort;
|
|
173
|
+
|
|
174
|
+
if (currentSort.index === i) {
|
|
175
|
+
desc = !currentSort.desc;
|
|
176
|
+
}
|
|
177
|
+
sortByIndex(i, desc);
|
|
178
|
+
removeSortIndicators();
|
|
179
|
+
currentSort.index = i;
|
|
180
|
+
currentSort.desc = desc;
|
|
181
|
+
addSortIndicators();
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
185
|
+
if (cols[i].sortable) {
|
|
186
|
+
// add the click event handler on the th so users
|
|
187
|
+
// dont have to click on those tiny arrows
|
|
188
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
189
|
+
if (el.addEventListener) {
|
|
190
|
+
el.addEventListener('click', ithSorter(i));
|
|
191
|
+
} else {
|
|
192
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// adds sorting functionality to the UI
|
|
198
|
+
return function() {
|
|
199
|
+
if (!getTable()) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
cols = loadColumns();
|
|
203
|
+
loadData();
|
|
204
|
+
addSearchBox();
|
|
205
|
+
addSortIndicators();
|
|
206
|
+
enableUI();
|
|
207
|
+
};
|
|
208
|
+
})();
|
|
209
|
+
|
|
210
|
+
window.addEventListener('load', addSorting);
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
|
|
5
|
+
export default defineConfig([
|
|
6
|
+
{
|
|
7
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
8
|
+
plugins: { js },
|
|
9
|
+
extends: ['js/recommended'],
|
|
10
|
+
languageOptions: { globals: globals.node },
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { checkInputs } from './check-inputs.js';
|
|
2
|
+
import { cleanUpInputs } from './clean-up-inputs.js';
|
|
3
|
+
|
|
4
|
+
export function initializeMidi() {
|
|
5
|
+
const checkDelay = 60 * 1000 + (Math.random() * 3000) | 0;
|
|
6
|
+
checkInputs();
|
|
7
|
+
setInterval(checkInputs, checkDelay);
|
|
8
|
+
process.on('exit', cleanUpInputs);
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { cleanUpWatcher } from './clean-up-watcher.js';
|
|
5
|
+
import { log } from './log.js';
|
|
6
|
+
import { refreshScripts } from './refresh-scripts.js';
|
|
7
|
+
import { state } from './state.js';
|
|
8
|
+
|
|
9
|
+
export function initializeScriptsDirectory() {
|
|
10
|
+
// Default to ~/Documents/MidiShellCommands if no directory is provided
|
|
11
|
+
let targetDirArg = process.argv[process.argv.length - 1];
|
|
12
|
+
if (process.argv.length === 2 || targetDirArg === '--daemon') {
|
|
13
|
+
targetDirArg = path.join(os.homedir(), 'Documents', 'MidiShellCommands');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Ensure the directory exists
|
|
17
|
+
state.watchDir = path.resolve(targetDirArg);
|
|
18
|
+
try {
|
|
19
|
+
fs.mkdirSync(state.watchDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error('Failed to create or access scripts directory:', state.watchDir);
|
|
23
|
+
console.error(e);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
refreshScripts();
|
|
28
|
+
try {
|
|
29
|
+
state.watcher = fs.watch(state.watchDir, { persistent: true }, refreshScripts);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Non-fatal on some platforms
|
|
33
|
+
}
|
|
34
|
+
process.on('exit', cleanUpWatcher);
|
|
35
|
+
|
|
36
|
+
log(`Watching ${targetDirArg}`);
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import childProcess from 'node:child_process';
|
|
2
|
+
import { log } from './log.js';
|
|
3
|
+
import { mapMessageToFileNames } from './map-message-to-file-names.js';
|
|
4
|
+
import { reportErrors } from './report-errors.js';
|
|
5
|
+
import { state } from './state.js';
|
|
6
|
+
|
|
7
|
+
export function invokeScripts(msg) {
|
|
8
|
+
const possibleFileNames = mapMessageToFileNames(msg);
|
|
9
|
+
log(possibleFileNames[0]);
|
|
10
|
+
for (const possibleFileName of possibleFileNames) {
|
|
11
|
+
for (let i = 0; i < state.scriptsWithoutExtension.length; i++) {
|
|
12
|
+
if (state.scriptsWithoutExtension[i] === possibleFileName) {
|
|
13
|
+
log('Executing ' + state.scripts[i]);
|
|
14
|
+
childProcess.exec(`./${state.scripts[i]}`, { cwd: state.watchDir }, reportErrors);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import easyMIDI from 'easymidi';
|
|
2
|
+
import { invokeScripts } from './invoke-scripts.js';
|
|
3
|
+
import { state } from './state.js';
|
|
4
|
+
|
|
5
|
+
export function listenToInput(inputName) {
|
|
6
|
+
if (!state.watchedInputs[inputName]) {
|
|
7
|
+
const input = state.watchedInputs[inputName] = new easyMIDI.Input(inputName);
|
|
8
|
+
input.on('noteon', invokeScripts);
|
|
9
|
+
input.on('noteoff', invokeScripts);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/lib/log.js
ADDED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
#!/usr/local/bin/node
|
|
2
|
+
import childProcess from 'node:child_process';
|
|
2
3
|
/**
|
|
3
4
|
* Postinstall script to set up a macOS LaunchAgent which runs midi-shell-commands
|
|
4
5
|
* pointing at ~/Documents/MidiShellCommands.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function log(msg) {
|
|
12
|
-
try {
|
|
13
|
-
// Best-effort: npm may suppress some outputs; still try.
|
|
14
|
-
console.log(`[midi-shell-commands] ${msg}`);
|
|
15
|
-
}
|
|
16
|
-
catch {}
|
|
17
|
-
}
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { escapePath } from './escape-path.js';
|
|
11
|
+
import { log } from './log.js';
|
|
18
12
|
|
|
19
13
|
(function main() {
|
|
20
14
|
const platform = process.platform;
|
|
@@ -85,8 +79,10 @@ function log(msg) {
|
|
|
85
79
|
<key>StandardErrorPath</key>
|
|
86
80
|
<string>${stderrPath}</string>
|
|
87
81
|
<key>EnvironmentVariables</key>
|
|
88
|
-
<
|
|
89
|
-
|
|
82
|
+
<dict>
|
|
83
|
+
<key>PATH</key>
|
|
84
|
+
<string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
85
|
+
</dict>
|
|
90
86
|
</dict>
|
|
91
87
|
</plist>`;
|
|
92
88
|
|
|
@@ -111,7 +107,9 @@ function log(msg) {
|
|
|
111
107
|
try {
|
|
112
108
|
childProcess.execSync(`launchctl unload ${escapePath(plistPath)}`, { stdio: 'ignore' });
|
|
113
109
|
}
|
|
114
|
-
catch {
|
|
110
|
+
catch {
|
|
111
|
+
// Unload failed, proceed forward.
|
|
112
|
+
}
|
|
115
113
|
|
|
116
114
|
// Preferred modern approach: bootstrap into the current user session
|
|
117
115
|
const uid = process.getuid && process.getuid();
|
|
@@ -121,7 +119,9 @@ function log(msg) {
|
|
|
121
119
|
log('LaunchAgent bootstrapped.');
|
|
122
120
|
return;
|
|
123
121
|
}
|
|
124
|
-
catch {
|
|
122
|
+
catch {
|
|
123
|
+
console.log('Current user session bootstrap failed, falling back to legacy load.');
|
|
124
|
+
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// Fallback to legacy load
|
|
@@ -133,10 +133,3 @@ function log(msg) {
|
|
|
133
133
|
}
|
|
134
134
|
})();
|
|
135
135
|
|
|
136
|
-
function escapePath(p) {
|
|
137
|
-
// Simple shell escaping for spaces
|
|
138
|
-
if (p.includes(' ')) {
|
|
139
|
-
return `'${p.replace(/'/g, '\'\\\'\'')}'`;
|
|
140
|
-
}
|
|
141
|
-
return p;
|
|
142
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { state } from './state.js';
|
|
3
|
+
|
|
4
|
+
export function refreshScripts() {
|
|
5
|
+
try {
|
|
6
|
+
state.scripts = fs.readdirSync(state.watchDir).filter(f => f[0] !== '.');
|
|
7
|
+
state.scriptsWithoutExtension = state.scripts.map(script => script.split('.').slice(0, -1).join('.'));
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
console.error('Failed to read scripts directory:', state.watchDir);
|
|
11
|
+
console.error(e);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/lib/state.js
ADDED
package/midi-shell-commands.js
CHANGED
|
@@ -1,104 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
2
|
+
import { initializeMidi } from './lib/initialize-midi.js';
|
|
3
|
+
import { initializeScriptsDirectory } from './lib/initialize-scripts-directory.js';
|
|
4
|
+
import { log } from './lib/log.js';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let targetDirArg = process.argv[process.argv.length - 1];
|
|
12
|
-
if (process.argv.length === 2 || targetDirArg === '--daemon') {
|
|
13
|
-
targetDirArg = path.join(os.homedir(), 'Documents', 'MidiShellCommands');
|
|
14
|
-
}
|
|
15
|
-
console.log(`Watching ${targetDirArg}`);
|
|
16
|
-
|
|
17
|
-
const watchDir = path.resolve(targetDirArg);
|
|
18
|
-
|
|
19
|
-
// Ensure the directory exists
|
|
20
|
-
try {
|
|
21
|
-
fs.mkdirSync(watchDir, { recursive: true });
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
console.error('Failed to create or access scripts directory:', watchDir);
|
|
25
|
-
console.error(e);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let scripts = [];
|
|
30
|
-
let scriptsWithoutExtension = [];
|
|
31
|
-
|
|
32
|
-
process.on('exit', cleanUpInputs);
|
|
33
|
-
refreshScripts();
|
|
34
|
-
try {
|
|
35
|
-
fs.watch(watchDir, { persistent: true }, refreshScripts);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
// Non-fatal on some platforms
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const checkDelay = 60 * 1000 + (Math.random() * 3000) | 0;
|
|
42
|
-
const watchedInputs = {};
|
|
43
|
-
checkInputs();
|
|
44
|
-
setInterval(checkInputs, checkDelay);
|
|
45
|
-
|
|
46
|
-
function refreshScripts() {
|
|
47
|
-
try {
|
|
48
|
-
scripts = fs.readdirSync(watchDir).filter(f => f[0] !== '.');
|
|
49
|
-
scriptsWithoutExtension = scripts.map(script => script.split('.').slice(0, -1).join('.'));
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
console.error('Failed to read scripts directory:', watchDir);
|
|
53
|
-
console.error(e);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function checkInputs() {
|
|
58
|
-
const inputNames = easyMIDI.getInputs();
|
|
59
|
-
for (const inputName of inputNames) {
|
|
60
|
-
listenToInput(inputName);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function listenToInput(inputName) {
|
|
65
|
-
if (watchedInputs[inputName]) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const input = watchedInputs[inputName] = new easyMIDI.Input(inputName);
|
|
69
|
-
input.on('noteon', invokeScripts);
|
|
70
|
-
input.on('noteoff', invokeScripts);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function invokeScripts(msg) {
|
|
74
|
-
const possibleFileNames = mapMessageToFileNames(msg);
|
|
75
|
-
console.log(possibleFileNames[0]);
|
|
76
|
-
for (const possibleFileName of possibleFileNames) {
|
|
77
|
-
for (let i = 0; i < scriptsWithoutExtension.length; i++) {
|
|
78
|
-
if (scriptsWithoutExtension[i] === possibleFileName) {
|
|
79
|
-
console.log('Executing ' + scripts[i]);
|
|
80
|
-
childProcess.exec(`./${scripts[i]}`, { cwd: watchDir }, reportErrors);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function mapMessageToFileNames(msg) {
|
|
87
|
-
return [
|
|
88
|
-
`${msg._type}.${msg.note}.${msg.channel}.${msg.velocity}`,
|
|
89
|
-
`${msg._type}.${msg.note}.${msg.channel}`,
|
|
90
|
-
`${msg._type}.${msg.note}`,
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function reportErrors(err) {
|
|
95
|
-
if (err) {
|
|
96
|
-
console.error(err);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function cleanUpInputs() {
|
|
101
|
-
for (const input of Object.values(watchedInputs)) {
|
|
102
|
-
input.close();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
6
|
+
log('Starting up!');
|
|
7
|
+
initializeScriptsDirectory();
|
|
8
|
+
initializeMidi();
|
package/package.json
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "midi-shell-commands",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"midi-shell-commands": "midi-shell-commands.js"
|
|
7
|
-
},
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"author": "Dawson Toth",
|
|
5
|
+
"repository": "https://github.com/dawsontoth/midi-shell-commands.git",
|
|
8
6
|
"scripts": {
|
|
9
7
|
"start": "node midi-shell-commands.js ./scripts",
|
|
10
|
-
"postinstall": "node lib/
|
|
11
|
-
"test": "
|
|
8
|
+
"postinstall": "node lib/post-install.js",
|
|
9
|
+
"test": "vitest",
|
|
10
|
+
"test:ci": "vitest run",
|
|
11
|
+
"test:coverage": "vitest run --coverage",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix"
|
|
12
14
|
},
|
|
15
|
+
"description": "Execute shell scripts on MIDI note events; supports macOS daemon mode via LaunchAgent.",
|
|
16
|
+
"type": "module",
|
|
13
17
|
"keywords": [],
|
|
14
|
-
"
|
|
18
|
+
"main": "midi-shell-commands.js",
|
|
19
|
+
"bin": {
|
|
20
|
+
"midi-shell-commands": "midi-shell-commands.js"
|
|
21
|
+
},
|
|
15
22
|
"license": "ISC",
|
|
16
|
-
"description": "Execute shell scripts on MIDI note events; supports macOS daemon mode via LaunchAgent.",
|
|
17
23
|
"dependencies": {
|
|
18
24
|
"easymidi": "^3.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@eslint/js": "^9.36.0",
|
|
28
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
29
|
+
"@semantic-release/git": "^10.0.1",
|
|
30
|
+
"@semantic-release/github": "^11.0.6",
|
|
31
|
+
"@semantic-release/npm": "^12.0.2",
|
|
32
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
33
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
34
|
+
"eslint": "^9.36.0",
|
|
35
|
+
"globals": "^16.4.0",
|
|
36
|
+
"semantic-release": "^24.2.9",
|
|
37
|
+
"vitest": "^3.0.0"
|
|
19
38
|
}
|
|
20
39
|
}
|
package/renovate.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"extends": [
|
|
4
|
+
"config:recommended"
|
|
5
|
+
],
|
|
6
|
+
"lockFileMaintenance": {
|
|
7
|
+
"enabled": true,
|
|
8
|
+
"automerge": true
|
|
9
|
+
},
|
|
10
|
+
"packageRules": [
|
|
11
|
+
{
|
|
12
|
+
"matchDepTypes": [
|
|
13
|
+
"action"
|
|
14
|
+
],
|
|
15
|
+
"pinDigests": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"matchUpdateTypes": [
|
|
19
|
+
"minor",
|
|
20
|
+
"patch"
|
|
21
|
+
],
|
|
22
|
+
"matchCurrentVersion": "!/^0/",
|
|
23
|
+
"automerge": true
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|