feat: initial version

This commit is contained in:
Derrick Hammer 2023-06-26 02:18:37 -04:00
parent 441e2688ad
commit 65f3dcca6f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
7 changed files with 13504 additions and 1 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -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

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

View File

@ -1,6 +1,6 @@
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:

13355
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

35
package.json Normal file
View File

@ -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"
}

84
src/index.ts Normal file
View File

@ -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,
),
);

11
src/util.ts Normal file
View File

@ -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;
}