feat: initial version
This commit is contained in:
parent
441e2688ad
commit
65f3dcca6f
|
@ -0,0 +1,13 @@
|
||||||
|
name: Build/Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
- develop-*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
main:
|
||||||
|
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
|
||||||
|
secrets: inherit
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"preset": [
|
||||||
|
"@lumeweb/node-library-preset"
|
||||||
|
]
|
||||||
|
}
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) <year> <copyright holders>
|
Copyright (c) 2023 Hammer Technologies LLC
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"name": "@lumeweb/publish-kernel-module",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "gitea@git.lumeweb.com:LumeWeb/publish-kernel-module.git"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
|
||||||
|
"@types/prompts": "^2.4.4",
|
||||||
|
"presetter": "*"
|
||||||
|
},
|
||||||
|
"readme": "ERROR: No README data found!",
|
||||||
|
"_id": "@lumeweb/publish-kernel-module@0.1.0",
|
||||||
|
"scripts": {
|
||||||
|
"prepare": "presetter bootstrap",
|
||||||
|
"build": "run build",
|
||||||
|
"semantic-release": "semantic-release"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib/**"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@lumeweb/community-portals": "^0.1.0-develop.4",
|
||||||
|
"@lumeweb/libportal": "^0.2.0-develop.9",
|
||||||
|
"@lumeweb/libweb": "^0.2.0-develop.19",
|
||||||
|
"chalk": "^5.2.0",
|
||||||
|
"prompts": "^2.4.2"
|
||||||
|
},
|
||||||
|
"bin": "./lib/index.js"
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
#! /usr/bin/env node
|
||||||
|
|
||||||
|
import prompts from "prompts";
|
||||||
|
import * as process from "process";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import {
|
||||||
|
hexToBytes,
|
||||||
|
maybeInitDefaultPortals,
|
||||||
|
setActivePortalMasterKey,
|
||||||
|
uploadObject,
|
||||||
|
} from "@lumeweb/libweb";
|
||||||
|
import chalk from "chalk";
|
||||||
|
import * as util from "util";
|
||||||
|
import { fileExists } from "#util.js";
|
||||||
|
|
||||||
|
let key = process.env.PORTAL_PRIVATE_KEY;
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
// @ts-ignore
|
||||||
|
key = await prompts.prompts.password({
|
||||||
|
name: "private_key",
|
||||||
|
message: "Enter your private key",
|
||||||
|
validate: (prev) => prev && prev.length === 64,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let file = process.env.KERNEL_FILE;
|
||||||
|
|
||||||
|
if (!file || !(await fileExists(file))) {
|
||||||
|
const cwd = process.cwd();
|
||||||
|
|
||||||
|
const locations = [
|
||||||
|
"dist/module.js",
|
||||||
|
"dist/index.js",
|
||||||
|
"lib/module.js",
|
||||||
|
"lib/index.js",
|
||||||
|
];
|
||||||
|
|
||||||
|
const promises = locations.map((item) => {
|
||||||
|
item = path.join(cwd, item);
|
||||||
|
return [item, fileExists(item)];
|
||||||
|
});
|
||||||
|
|
||||||
|
const pResults: boolean[] = await Promise.all(
|
||||||
|
promises.map((item) => item[1] as Promise<boolean>),
|
||||||
|
);
|
||||||
|
const results = pResults.reduce((prev, cur, index) => {
|
||||||
|
if (cur) {
|
||||||
|
prev.push(locations[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return prev;
|
||||||
|
}, [] as any);
|
||||||
|
|
||||||
|
if (!results.length) {
|
||||||
|
console.error("Kernel module could not be found");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
file = results[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
setActivePortalMasterKey(hexToBytes(key as string));
|
||||||
|
maybeInitDefaultPortals();
|
||||||
|
|
||||||
|
const fd = await fs.open(file as string);
|
||||||
|
|
||||||
|
const [cid, err] = await uploadObject(
|
||||||
|
fd.createReadStream(),
|
||||||
|
BigInt((await fd.stat()).size),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.error("Failed to publish: ", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
util.format(
|
||||||
|
"%s: %s",
|
||||||
|
chalk.green("Kernel module successfully published"),
|
||||||
|
cid,
|
||||||
|
),
|
||||||
|
);
|
|
@ -0,0 +1,11 @@
|
||||||
|
import fs from "fs/promises";
|
||||||
|
|
||||||
|
export async function fileExists(path: string) {
|
||||||
|
try {
|
||||||
|
await fs.stat(path);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Reference in New Issue