add --json flag to strudel sampler
This commit is contained in:
parent
d81b1ab65c
commit
66aa3ac1da
2 changed files with 28 additions and 8 deletions
|
|
@ -20,3 +20,13 @@ samples('http://localhost:5432')
|
||||||
LOG=1 npx @strudel/sampler # adds logging
|
LOG=1 npx @strudel/sampler # adds logging
|
||||||
PORT=5555 npx @strudel/sampler # changes port
|
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.
|
||||||
|
|
@ -10,14 +10,6 @@ import os from 'os';
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const LOG = !!process.env.LOG || false;
|
const LOG = !!process.env.LOG || false;
|
||||||
|
|
||||||
console.log(
|
|
||||||
cowsay.say({
|
|
||||||
text: 'welcome to @strudel/sampler',
|
|
||||||
e: 'oO',
|
|
||||||
T: 'U ',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
async function getFilesInDirectory(directory) {
|
async function getFilesInDirectory(directory) {
|
||||||
let files = [];
|
let files = [];
|
||||||
const dirents = await readdir(directory, { withFileTypes: true });
|
const dirents = await readdir(directory, { withFileTypes: true });
|
||||||
|
|
@ -60,8 +52,26 @@ async function getBanks(directory) {
|
||||||
return { banks, files };
|
return { banks, files };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const directory = process.cwd();
|
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) => {
|
const server = http.createServer(async (req, res) => {
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
const { banks, files } = await getBanks(directory);
|
const { banks, files } = await getBanks(directory);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue