Skip to content

First prototype version implementation #1

@konard

Description

@konard

Proof of concept in the code

#!/usr/bin/env node

import { execSync } from "child_process";
import fs from "fs";
import path from "path";

// ---------------------------
//  Input validation
// ---------------------------
if (process.argv.length < 3) {
  console.error("Usage: upload-log.mjs <path-to-log-file>");
  process.exit(1);
}

const inputPath = process.argv[2];

// Check file exists
if (!fs.existsSync(inputPath)) {
  console.error(`ERROR: File does not exist: ${inputPath}`);
  process.exit(1);
}

// ---------------------------
//  Generate names
// ---------------------------
const normalized = inputPath.replace(/^\/*/, "").replace(/\//g, "-");  
// Example: home-hive-solve-2025-11-13T04-00-57-948Z.log

const baseName = path.basename(normalized, ".log");
// Example: home-hive-solve-2025-11-13T04-00-57-948Z

const repoName = baseName;
const workDir = `/tmp/${repoName}`;

// ---------------------------
//  Prepare directory
// ---------------------------
console.log(`→ Creating work directory: ${workDir}`);
fs.rmSync(workDir, { recursive: true, force: true });
fs.mkdirSync(workDir);

console.log("→ Copying file...");
execSync(`cp "${inputPath}" "${workDir}/"`);

// ---------------------------
//  Split file into 100MB chunks
// ---------------------------
console.log("→ Splitting file into 100MB chunks...");
execSync(
  `cd "${workDir}" && split -b 100m -d -a 2 "${normalized}" "${baseName}.part-"`
);

// Delete original large file
console.log("→ Removing original large file...");
fs.rmSync(`${workDir}/${normalized}`);

// ---------------------------
//  Initialize git repository
// ---------------------------
console.log("→ Initializing git repository...");
execSync(`rm -rf "${workDir}/.git"`);
execSync(`cd "${workDir}" && git init`);
execSync(`cd "${workDir}" && git branch -m main`);

// ---------------------------
//  Git add + commit
// ---------------------------
console.log("→ Adding and committing split parts...");
execSync(`cd "${workDir}" && git add .`);
execSync(`cd "${workDir}" && git commit -m "Add split log files"`);

// ---------------------------
//  Create GitHub repo + push
// ---------------------------
console.log(`→ Creating public GitHub repo: ${repoName}`);
execSync(
  `cd "${workDir}" && gh repo create "${repoName}" --public --source=. --push`,
  { stdio: "inherit" }
);

console.log("\n✓ ALL DONE!");
console.log(`Github repo: https://github.com/<your-user>/${repoName}`);

I want to make globally installable CLI npm tool, that should be also be available as JavaScript function (library), that will use our best tech:

If you cannot do it in one step, just do first steps you can and plan for next steps we will go through it until everything is done perfectly.

If you find any bugs in external projects and they are in JavaScript - you can copy them as separate folder and reimplement with fix of the issue.

So we can iterate quickly and improve all above projects on a later stage.

I also want you to know exact limits of gh gist create limit (is it also 100 mb as with GitHub repository or less or more?).

So the logic of the program is like this options: --private / --public (user can select only one of them) by default - private.

If file fits in gist or can be split in parts that will fit in gist as multiple files in a single gist - than we upload it as gist.

If it does not fully (or all parts) fits in gist.github.com - we upload the file (or its parts) as separate github repository.

By default first argument should be a path to log file.

We replace all / with - in log file name, keeping its full or relative path, and we should add log- as prefix for GitHub repository name. And use the file name of log for file names (and base for parts) in gist/repository.

So the end result will be high quality project, that works on all platforms (macOS, Linux, Windows) if gh and git tools are installed on the system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions