-
Notifications
You must be signed in to change notification settings - Fork 0
/
after_build.js
55 lines (42 loc) · 1.39 KB
/
after_build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { mkdir, copyFile } from "fs/promises";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import recursive_read_dir from "recursive-readdir";
import { getPackagesSync } from "@manypkg/get-packages";
const __dirname = dirname(fileURLToPath(import.meta.url));
const action_target = (pkg) => join(__dirname, "actions", pkg);
const action_src = (pkg) => join(__dirname, "packages", pkg);
async function copy_dist(pkg_name, pkg_dir) {
let files;
let pkg_src = action_src(pkg_name);
let pkg_dest = action_target(pkg_name);
try {
files = await recursive_read_dir(join(pkg_dir, "dist"), ["node_modules"]);
} catch (e) {
console.error(e);
}
await mkdir(join(pkg_dest, "dist"), {
recursive: true,
});
await copyFile(join(pkg_src, "action.yml"), join(pkg_dest, "action.yml"));
await Promise.all(
files.map((f) => {
const dest_file = f.replace(pkg_src, pkg_dest);
return copyFile(f, dest_file);
})
);
console.log(`"${pkg_name}" action folder created."`);
}
async function handle_packages() {
const { packages: pkgs } = getPackagesSync(process.cwd());
const action_packages = pkgs
.filter((p) => p.packageJson.name.startsWith("@gradio-action/"))
.map((p) => ({
name: p.packageJson.name.replace("@gradio-action/", ""),
path: p.dir,
}));
await Promise.all(
action_packages.map(({ name, path }) => copy_dist(name, path))
);
}
handle_packages();