MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / copyAssetsPlugin

Function copyAssetsPlugin

packages/vite/src/copyAssetsPlugin.ts:10–120  ·  view source on GitHub ↗
(options: AlphaTabVitePluginOptions)

Source from the content-addressed store, hash-verified

8 * @public
9 */
10export function copyAssetsPlugin(options: AlphaTabVitePluginOptions): Plugin {
11 let resolvedConfig: ResolvedConfig;
12 let output = false;
13
14 return {
15 name: 'vite-plugin-alphatab-copy',
16 enforce: 'pre',
17 configResolved(config) {
18 resolvedConfig = config as ResolvedConfig;
19 },
20 buildEnd() {
21 // reset for watch mode
22 output = false;
23 },
24 async buildStart() {
25 // run copy only once even if multiple bundles are generated
26 if (output) {
27 return;
28 }
29 output = true;
30
31 let alphaTabSourceDir = options.alphaTabSourceDir;
32 if (!alphaTabSourceDir) {
33 try {
34 const isEsm = typeof import.meta.url === 'string';
35 if (isEsm) {
36 alphaTabSourceDir = url.fileURLToPath(import.meta.resolve('@coderline/alphatab'));
37 } else {
38 alphaTabSourceDir = require.resolve('@coderline/alphatab');
39 }
40
41 alphaTabSourceDir = path.resolve(alphaTabSourceDir, '..');
42
43 // walk up to package.json
44 while (alphaTabSourceDir) {
45 if (
46 await fs.promises
47 .access(path.join(alphaTabSourceDir, 'package.json'), fs.constants.F_OK)
48 .then(() => true)
49 .catch(() => false)
50 ) {
51 // found package directory
52 alphaTabSourceDir = path.resolve(alphaTabSourceDir, 'dist');
53 break;
54 } else {
55 // reached root
56 const parent = path.resolve(alphaTabSourceDir, '..');
57 if (parent === alphaTabSourceDir) {
58 alphaTabSourceDir = undefined;
59 } else {
60 alphaTabSourceDir = parent;
61 }
62 }
63 }
64 } catch {
65 alphaTabSourceDir = path.join(resolvedConfig.root, 'node_modules/@coderline/alphatab/dist/');
66 }
67 }

Callers 1

alphaTabFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected