add --json flag to strudel sampler

This commit is contained in:
Felix Roos 2025-08-21 20:30:02 +02:00
parent d81b1ab65c
commit 66aa3ac1da
No known key found for this signature in database
2 changed files with 28 additions and 8 deletions

View file

@ -20,3 +20,13 @@ samples('http://localhost:5432')
LOG=1 npx @strudel/sampler # adds logging
PORT=5555 npx @strudel/sampler # changes port
```
## static json
when running with `--json`, you will simply get the json logged back:
```sh
npx @strudel/sampler --json > strudel.json
```
this is useful if you want to create a sample pack from the current folder.

View file

@ -10,14 +10,6 @@ import os from 'os';
// eslint-disable-next-line
const LOG = !!process.env.LOG || false;
console.log(
cowsay.say({
text: 'welcome to @strudel/sampler',
e: 'oO',
T: 'U ',
}),
);
async function getFilesInDirectory(directory) {
let files = [];
const dirents = await readdir(directory, { withFileTypes: true });
@ -60,8 +52,26 @@ async function getBanks(directory) {
return { banks, files };
}
const args = process.argv.slice(2);
// eslint-disable-next-line
const directory = process.cwd();
if (args.includes('--json')) {
const { banks, files } = await getBanks(directory);
const json = JSON.stringify(banks);
console.log(json);
process.exit(0);
}
console.log(
cowsay.say({
text: 'welcome to @strudel/sampler',
e: 'oO',
T: 'U ',
}),
);
const server = http.createServer(async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
const { banks, files } = await getBanks(directory);