mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 05:38:35 +00:00
add sampler script + samples folder with README
This commit is contained in:
parent
abe775c3fd
commit
8f355dcf96
@ -25,6 +25,7 @@
|
||||
"format-check": "prettier --check .",
|
||||
"report-undocumented": "npm run jsdoc-json && node jsdoc/undocumented.mjs > undocumented.json",
|
||||
"check": "npm run format-check && npm run lint && npm run test",
|
||||
"sampler": "cd packages/sampler && node sample-server.mjs",
|
||||
"iclc": "cd paper && pandoc --template=pandoc/iclc.html --citeproc --number-sections iclc2023.md -o iclc2023.html && pandoc --template=pandoc/iclc.latex --citeproc --number-sections iclc2023.md -o iclc2023.pdf"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
2
packages/sampler/.gitignore
vendored
Normal file
2
packages/sampler/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
samples/*
|
||||
!samples/README.md
|
||||
@ -42,7 +42,7 @@ async function getBanks(directory) {
|
||||
banks[bank].push(url);
|
||||
return url;
|
||||
});
|
||||
banks._base = `http:localhost:5432`;
|
||||
banks._base = `http://localhost:5432`;
|
||||
return { banks, files };
|
||||
}
|
||||
|
||||
|
||||
5
packages/sampler/samples/README.md
Normal file
5
packages/sampler/samples/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# samples folder
|
||||
|
||||
1. copy any samples to this folder
|
||||
2. run `npm run sampler`
|
||||
3. add `samples('local:')` to your code
|
||||
@ -195,7 +195,7 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '', option
|
||||
sampleMap = githubPath(sampleMap, 'strudel.json');
|
||||
}
|
||||
if (sampleMap.startsWith('local:')) {
|
||||
sampleMap = `/strudel.json`;
|
||||
sampleMap = `http://localhost:5432`;
|
||||
}
|
||||
if (sampleMap.startsWith('shabda:')) {
|
||||
let [_, path] = sampleMap.split('shabda:');
|
||||
|
||||
3
website/.gitignore
vendored
3
website/.gitignore
vendored
@ -17,6 +17,3 @@ pnpm-debug.log*
|
||||
|
||||
# macOS-specific files
|
||||
.DS_Store
|
||||
|
||||
public/samples/**
|
||||
public/samples/!README.md
|
||||
@ -1,45 +0,0 @@
|
||||
import { readdir } from 'fs/promises';
|
||||
import { dirname, join, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
async function getFilesInDirectory(directory) {
|
||||
let files = [];
|
||||
const dirents = await readdir(directory, { withFileTypes: true });
|
||||
for (const dirent of dirents) {
|
||||
const fullPath = join(directory, dirent.name);
|
||||
if (dirent.isDirectory()) {
|
||||
const subFiles = await getFilesInDirectory(fullPath);
|
||||
files = files.concat(subFiles);
|
||||
} else {
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
let dir;
|
||||
if (import.meta.env.MODE === 'production') {
|
||||
// in prod (pnpm build), the path is "/website/dist/chunks/pages"
|
||||
dir = '../../../public/samples';
|
||||
} else {
|
||||
// in dev (pnpm dev), the path is "/website/src/pages"
|
||||
dir = '../../public/samples';
|
||||
}
|
||||
const directory = resolve(__dirname, dir);
|
||||
const files = await getFilesInDirectory(directory);
|
||||
let banks = {};
|
||||
files
|
||||
.filter((f) => ['wav', 'mp3', 'ogg'].includes(f.split('.').slice(-1)[0].toLowerCase()))
|
||||
.forEach((url) => {
|
||||
const [bank] = url.split('/').slice(-2);
|
||||
banks[bank] = banks[bank] || [];
|
||||
const rel = url.split('/public/samples/')[1];
|
||||
banks[bank].push(rel);
|
||||
});
|
||||
banks._base = '/samples/';
|
||||
return new Response(JSON.stringify(banks));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user