repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

starfx / scripts
Jacob Bolda · 30 Jan 24

sync.ts

 1import { call, main, type Operation } from "./deps.ts";
 2
 3await main(function* (): Operation<void> {
 4  const [syncMethod, folderFromArgs] = Deno.args;
 5  const folder = folderFromArgs ?? "starfx-examples/vite-react";
 6  const dir = `../${folder}/node_modules/starfx`;
 7  const npmAssets = yield* call(Deno.realPath("./npm"));
 8
 9  if (syncMethod === "install") {
10    // parcel doesn't handle symlinks well, do a `file:` install instead
11    const command = new Deno.Command("npm", {
12      args: ["add", "starfx@file:../../starfx/npm", "--install-links"],
13      cwd: `../${folder}`,
14      stderr: "piped",
15      stdout: "piped",
16    });
17    yield* call(command.output());
18  } else if (syncMethod === "symlink") {
19    // this option is primarily for local usage
20    try {
21      yield* call(Deno.remove(dir, { recursive: true }));
22    } catch (_error) {
23      // assume that the folder does not exist
24    }
25
26    // create a symlink to the `dir` which should allow
27    // this example to run with the build assets
28    yield* call(Deno.symlink(npmAssets, dir));
29  }
30});