@@ -0,0 +1,57 @@
|
||||
import { execSync } from "child_process";
|
||||
import { readFileSync, mkdirSync, writeFileSync, readdirSync } from "fs";
|
||||
|
||||
const libName = process.env.PWD;
|
||||
const version = readFileSync("version", { encoding: "utf8" });
|
||||
const repoBaseUrl = `${process.env.INPUT_REPO_URL}/${libName}/${version}`;
|
||||
const packageJsonUrls = [];
|
||||
|
||||
const sendFile = async (path, data) => {
|
||||
await fetch(`${repoBaseUrl}/${path}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Basic ${process.env.INPUT_REPO_USER}:${process.env.INPUT_REPO_PASS}`,
|
||||
},
|
||||
body: data,
|
||||
});
|
||||
};
|
||||
|
||||
// Get system utils
|
||||
execSync("apt update", { encoding: "utf8" });
|
||||
execSync("apt install -y pipx", { encoding: "utf8" });
|
||||
execSync("pipx install mpy-cross", { encoding: "utf8" });
|
||||
|
||||
// Add base lib file to repo
|
||||
await sendFile(`__init__.mpy`, new ArrayBuffer(0));
|
||||
|
||||
// Update urls
|
||||
packageJsonUrls.push([`${libName}/__init__.mpy`, "__init__.mpy"]);
|
||||
|
||||
// Generate module folders/files
|
||||
readdirSync(".")
|
||||
.filter((f) => f.slice(-2) == "py")
|
||||
.forEach(async (moduleFile) => {
|
||||
const modName = moduleFile.slice(0, -3);
|
||||
const modInitPath = `${modName}/__init__.mpy`;
|
||||
const modPyPath = `${modName}/${modName}.mpy`;
|
||||
|
||||
// compile mpy file
|
||||
execSync(`pipx run mpy-cross ${moduleFile}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
|
||||
// Add module files to repo
|
||||
await sendFile(modInitPath, new ArrayBuffer(0));
|
||||
await sendFile(modPyPath, readFileSync(modPyPath).buffer);
|
||||
|
||||
// Update urls
|
||||
packageJsonUrls.push([`${libName}/${modInitPath}`, modInitPath]);
|
||||
packageJsonUrls.push([`${libName}/${modPyPath}`, modPyPath]);
|
||||
});
|
||||
|
||||
// Add package.json to repo
|
||||
await sendFile(`package.json`, {
|
||||
urls: packageJsonUrls,
|
||||
deps: [],
|
||||
version: version,
|
||||
});
|
||||
Reference in New Issue
Block a user