Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aoctimer

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aoctimer - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

build/actions/recalibrate.js

10

build/actions/calibrate.js

@@ -5,8 +5,12 @@ "use strict";

const config_1 = require("../config");
const calibrate = () => {
const recalibrate = () => {
if (!(0, config_1.check)() || !config_1.default.benchmark) {
console.log("Please run 'aoctimer init' first.");
return;
}
console.log("Calibrating (it may take a while)...");
const bench = (0, benchmark_1.default)();
(0, config_1.save)({ benchmark: bench });
console.log("Calibrated!");
console.log("Done!");
};
exports.default = calibrate;
exports.default = recalibrate;

@@ -5,7 +5,6 @@ "use strict";

console.log(`
AoC TIMER v.2.0.0
AoC TIMER v.3.0.0
Commands:
init [language] [year] Calibrate and create local config
calibrate Recalibrate the timer
summary Display the summary

@@ -12,0 +11,0 @@ [-d, --day <day>] <command> Run the timer for your command

@@ -5,3 +5,4 @@ "use strict";

const config_1 = require("../config");
const calibrate_1 = require("./calibrate");
const get_system_1 = require("../helpers/get-system");
const benchmark_1 = require("../benchmark");
const ask = (rl, question) => new Promise((resolve) => rl.question(question, resolve));

@@ -15,9 +16,11 @@ const init = async ({ language, year }) => {

});
if (language === undefined) {
language = await ask(rl, "Language: ");
}
if (year === undefined) {
year = await ask(rl, `Year${yearData ? ` (default ${yearData[0]})` : ""}: `);
}
if (language === undefined) {
language = await ask(rl, "Language: ");
}
rl.close();
console.log("Calibrating (it may take a while)...");
const bench = (0, benchmark_1.default)();
(0, config_1.save)({

@@ -27,7 +30,8 @@ version: "2.0.0",

language: (language || "unknown"),
system: (0, get_system_1.default)().toString(),
benchmark: bench,
days: [],
});
(0, calibrate_1.default)();
console.log("Done!");
};
exports.default = init;

@@ -27,3 +27,3 @@ "use strict";

`;
const runStats = (time, day) => {
const runStats = (time, day, command) => {
if (time !== null) {

@@ -45,3 +45,3 @@ const data = stats_1.default.day(time);

}
console.log(views_1.default.day(day, data));
return data;
}

@@ -52,3 +52,3 @@ else {

};
const run = ({ day, exec, time }) => {
const run = ({ day, command, time }) => {
if (!(0, config_1.check)() || !config_1.default.benchmark) {

@@ -58,20 +58,18 @@ console.log("Please run 'aoctimer init' first.");

}
day = day ?? (0, get_day_1.default)();
day = day ?? (0, get_day_1.default)(command);
if (time !== null) {
runStats(time, day);
runStats(time, day, null);
process.exit();
}
let output = "";
const [command, ...args] = exec;
const ps = (0, child_process_1.spawn)(command, args, {
stdio: ["pipe", "pipe", process.stderr],
});
ps.stdout.on("data", (data) => {
output += data.toString();
});
ps.once("close", () => {
try {
const output = (0, child_process_1.execSync)(command).toString();
const time = (0, extract_time_1.default)(output);
runStats(time, day);
});
console.log("Running");
const data = runStats(time, day, command);
console.log(views_1.default.day(day, data));
}
catch (e) {
console.log(`Failed to execute the command: ${command}`);
}
};
exports.default = run;

@@ -6,3 +6,3 @@ "use strict";

const path = require("path");
const fileName = `aoctimer.json`;
const fileName = `.aoctimer.json`;
const configDir = process.cwd();

@@ -9,0 +9,0 @@ const configFile = path.join(configDir, fileName);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getDay = () => {
const dayData = `${process.cwd()} ${process.argv.slice(3).join(" ")}`
.replace(/20\d{2}/, "")
.match(/\d?\d/);
return dayData ? dayData[0].padStart(2, "0") : "??";
const getDay = (command) => {
if (command === null) {
return "??";
}
const dayData = command.replace(/20\d{2}/, "").match(/\d?\d/g);
if (dayData === null) {
return "??";
}
const day = Number(dayData[dayData.length - 1]);
if (day < 1 || day > 25) {
return "??";
}
return String(day).padStart(2, "0");
};
exports.default = getDay;

@@ -12,8 +12,8 @@ "use strict";

}
if (rawArgs.includes("-v") || rawArgs.includes("--version")) {
return { command: "version", args: null };
}
if (rawArgs[0] === "init") {
return { command: "init", args: { language: rawArgs[1], year: rawArgs[2] } };
}
if (rawArgs[0] === "calibrate") {
return { command: "calibrate", args: null };
}
if (rawArgs[0] === "summary") {

@@ -28,3 +28,3 @@ return { command: "summary", args: null };

day: rawArgs[1].padStart(2, "0"),
exec: time === null ? rawArgs.slice(2) : null,
command: time === null ? rawArgs.slice(2).join(" ") : null,
time,

@@ -37,5 +37,9 @@ },

command: "run",
args: { day: null, exec: time === null ? rawArgs : null, time },
args: {
day: null,
command: time === null ? rawArgs.join(" ") : null,
time,
},
};
};
exports.default = parseArgs;

@@ -6,3 +6,2 @@ #!/usr/bin/env node

const init_1 = require("./actions/init");
const calibrate_1 = require("./actions/calibrate");
const info_1 = require("./actions/info");

@@ -22,2 +21,6 @@ const summary_1 = require("./actions/summary");

}
case "version": {
console.log("v3.0.0");
break;
}
case "init": {

@@ -27,6 +30,2 @@ (0, init_1.default)(args);

}
case "calibrate": {
(0, calibrate_1.default)();
break;
}
case "summary": {

@@ -33,0 +32,0 @@ (0, summary_1.default)();

@@ -25,10 +25,13 @@ "use strict";

const completedView = `Completed: ${days.length} / 25`;
const totalTimeView = `Total time: ${days
.map((v) => v.time)
.reduce((a, b) => a + b)}ms`;
const relativeAvgView = `Benchmark (average): ${(days.map((v) => v.rel).reduce((a, b) => a + b) / days.length).toFixed(3)}%`;
const totalScoreView = `Total score: ${days
.map((v) => v.score)
.reduce((a, b) => a + b)}`;
const levelAvg = Math.round(days.map((v) => v.level).reduce((a, b) => a + b) / days.length);
const totalTime = days.map((v) => v.time).reduce((a, b) => a + b, 0);
const relativeAvg = days.length > 0
? (days.map((v) => v.rel).reduce((a, b) => a + b) / days.length).toFixed(3)
: 0;
const totalScore = days.map((v) => v.score).reduce((a, b) => a + b, 0);
const levelAvg = days.length > 0
? Math.round(days.map((v) => v.level).reduce((a, b) => a + b) / days.length)
: 0;
const totalTimeView = `Total time: ${totalTime}ms`;
const relativeAvgView = `Benchmark (average): ${relativeAvg}%`;
const totalScoreView = `Total score: ${totalScore}`;
const levelAvgView = `Level (average): ${"★"

@@ -35,0 +38,0 @@ .repeat(levelAvg)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const config_1 = require("../config");
const OS = {
aix: "AIX",
darwin: "MacOS",
freebsd: "FreeBSD",
linux: "Linux",
openbsd: "OpenBSD",
sunos: "SunOS",
win32: "Windows",
};
const cpu = os.cpus()[0].model;
const mem = Math.round(os.totalmem() / 10 ** 9);
const get_system_1 = require("../helpers/get-system");
const renderSystem = () => {
const osView = `${OS[os.platform()]} (${os.arch()}) ${mem}GB RAM`.padEnd(50, " ");
const { platform, arch, cpu, mem } = (0, get_system_1.default)();
const osView = `${platform} (${arch}) ${mem}GB RAM`.padEnd(50, " ");
const cpuView = cpu.padEnd(50, " ");

@@ -19,0 +9,0 @@ const langView = config_1.default.language.padEnd(40, " ");

{
"name": "aoctimer",
"version": "2.0.0",
"version": "3.0.0",
"description": "AoC TIMER - compare your AoC solutions with others",

@@ -5,0 +5,0 @@ "repository": "https://github.com/caderek/aoctimer",

@@ -52,5 +52,5 @@ # AoC TIMER

- [aoctimer-linux64-v2.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v2.0.0/aoctimer-linux64-v2.0.0.zip)
- [aoctimer-macos-v2.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v2.0.0/aoctimer-macos-v2.0.0.zip)
- [aoctimer-windows64-v2.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v2.0.0/aoctimer-windows64-v2.0.0.zip)
- [aoctimer-linux64-v3.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v3.0.0/aoctimer-linux64-v3.0.0.zip)
- [aoctimer-macos-v3.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v3.0.0/aoctimer-macos-v3.0.0.zip)
- [aoctimer-windows64-v3.0.0.zip](https://github.com/caderek/aoctimer/releases/download/v3.0.0/aoctimer-windows64-v3.0.0.zip)

@@ -57,0 +57,0 @@ ## Preparing your code

const help = () => {
console.log(`
AoC TIMER v.2.0.0
AoC TIMER v.3.0.0
Commands:
init [language] [year] Calibrate and create local config
calibrate Recalibrate the timer
summary Display the summary

@@ -9,0 +8,0 @@ [-d, --day <day>] <command> Run the timer for your command

import * as readline from "readline"
import { save } from "../config"
import calibrate from "./calibrate"
import getSystem from "../helpers/get-system"
import benchmark from "../benchmark"

@@ -18,2 +19,6 @@ const ask = (rl, question): Promise<string> =>

if (language === undefined) {
language = await ask(rl, "Language: ")
}
if (year === undefined) {

@@ -23,8 +28,7 @@ year = await ask(rl, `Year${yearData ? ` (default ${yearData[0]})` : ""}: `)

if (language === undefined) {
language = await ask(rl, "Language: ")
}
rl.close()
console.log("Calibrating (it may take a while)...")
const bench = benchmark()
save({

@@ -34,7 +38,7 @@ version: "2.0.0",

language: (language || "unknown") as string,
system: getSystem().toString(),
benchmark: bench,
days: [],
})
calibrate()
console.log("Done!")

@@ -41,0 +45,0 @@ }

@@ -1,2 +0,2 @@

import { spawn } from "child_process"
import { spawn, execSync } from "child_process"
import config, { check, save } from "../config"

@@ -27,3 +27,3 @@ import views from "../views"

const runStats = (time: bigint, day: string) => {
const runStats = (time: bigint, day: string, command: string | null) => {
if (time !== null) {

@@ -47,3 +47,3 @@ const data = stats.day(time)

console.log(views.day(day, data))
return data
} else {

@@ -54,3 +54,3 @@ console.log(NO_TIME_MESSAGE)

const run = ({ day, exec, time }) => {
const run = ({ day, command, time }) => {
if (!check() || !config.benchmark) {

@@ -61,27 +61,20 @@ console.log("Please run 'aoctimer init' first.")

day = day ?? getDay()
day = day ?? getDay(command)
if (time !== null) {
runStats(time, day)
runStats(time, day, null)
process.exit()
}
let output = ""
const [command, ...args] = exec
const ps = spawn(command, args, {
stdio: ["pipe", "pipe", process.stderr],
})
ps.stdout.on("data", (data) => {
output += data.toString()
})
ps.once("close", () => {
try {
const output = execSync(command).toString()
const time = extractTime(output)
runStats(time, day)
})
console.log("Running")
const data = runStats(time, day, command)
console.log(views.day(day, data))
} catch (e) {
console.log(`Failed to execute the command: ${command}`)
}
}
export default run

@@ -9,2 +9,3 @@ import views from "../views"

}
console.log(views.summary(config.year, config.days))

@@ -11,0 +12,0 @@ }

@@ -17,6 +17,7 @@ const fs = require("fs")

language?: string
system?: string
days?: Day[]
}
const fileName = `aoctimer.json`
const fileName = `.aoctimer.json`

@@ -23,0 +24,0 @@ const configDir = process.cwd()

@@ -1,9 +0,21 @@

const getDay = () => {
const dayData = `${process.cwd()} ${process.argv.slice(3).join(" ")}`
.replace(/20\d{2}/, "")
.match(/\d?\d/)
const getDay = (command: string | null) => {
if (command === null) {
return "??"
}
return dayData ? dayData[0].padStart(2, "0") : "??"
const dayData = command.replace(/20\d{2}/, "").match(/\d?\d/g)
if (dayData === null) {
return "??"
}
const day = Number(dayData[dayData.length - 1])
if (day < 1 || day > 25) {
return "??"
}
return String(day).padStart(2, "0")
}
export default getDay

@@ -14,2 +14,6 @@ import extractTime from "./extract-time"

if (rawArgs.includes("-v") || rawArgs.includes("--version")) {
return { command: "version", args: null }
}
if (rawArgs[0] === "init") {

@@ -19,6 +23,2 @@ return { command: "init", args: { language: rawArgs[1], year: rawArgs[2] } }

if (rawArgs[0] === "calibrate") {
return { command: "calibrate", args: null }
}
if (rawArgs[0] === "summary") {

@@ -34,3 +34,3 @@ return { command: "summary", args: null }

day: rawArgs[1].padStart(2, "0"),
exec: time === null ? rawArgs.slice(2) : null,
command: time === null ? rawArgs.slice(2).join(" ") : null,
time,

@@ -44,3 +44,7 @@ },

command: "run",
args: { day: null, exec: time === null ? rawArgs : null, time },
args: {
day: null,
command: time === null ? rawArgs.join(" ") : null,
time,
},
}

@@ -47,0 +51,0 @@ }

#!/usr/bin/env node
import help from "./actions/help"
import init from "./actions/init"
import calibrate from "./actions/calibrate"
import info from "./actions/info"

@@ -21,2 +20,6 @@ import summary from "./actions/summary"

}
case "version": {
console.log("v3.0.0")
break
}
case "init": {

@@ -26,6 +29,2 @@ init(args as { language: string; year: string })

}
case "calibrate": {
calibrate()
break
}
case "summary": {

@@ -36,3 +35,3 @@ summary()

case "run": {
run(args as { day: string | null; exec: string[]; time: string | null })
run(args as { day: string | null; command: string; time: string | null })
break

@@ -39,0 +38,0 @@ }

@@ -31,18 +31,23 @@ import config, { Day } from "../config"

const totalTimeView = `Total time: ${days
.map((v) => v.time)
.reduce((a, b) => a + b)}ms`
const totalTime = days.map((v) => v.time).reduce((a, b) => a + b, 0)
const relativeAvgView = `Benchmark (average): ${(
days.map((v) => v.rel).reduce((a, b) => a + b) / days.length
).toFixed(3)}%`
const relativeAvg =
days.length > 0
? (days.map((v) => v.rel).reduce((a, b) => a + b) / days.length).toFixed(
3,
)
: 0
const totalScoreView = `Total score: ${days
.map((v) => v.score)
.reduce((a, b) => a + b)}`
const totalScore = days.map((v) => v.score).reduce((a, b) => a + b, 0)
const levelAvg = Math.round(
days.map((v) => v.level).reduce((a, b) => a + b) / days.length,
)
const levelAvg =
days.length > 0
? Math.round(
days.map((v) => v.level).reduce((a, b) => a + b) / days.length,
)
: 0
const totalTimeView = `Total time: ${totalTime}ms`
const relativeAvgView = `Benchmark (average): ${relativeAvg}%`
const totalScoreView = `Total score: ${totalScore}`
const levelAvgView = `Level (average): ${"★"

@@ -49,0 +54,0 @@ .repeat(levelAvg)

@@ -1,23 +0,9 @@

import * as os from "os"
import config from "../config"
import getSystem from "../helpers/get-system"
const OS = {
aix: "AIX",
darwin: "MacOS",
freebsd: "FreeBSD",
linux: "Linux",
openbsd: "OpenBSD",
sunos: "SunOS",
win32: "Windows",
}
const renderSystem = () => {
const { platform, arch, cpu, mem } = getSystem()
const cpu = os.cpus()[0].model
const mem = Math.round(os.totalmem() / 10 ** 9)
const osView = `${platform} (${arch}) ${mem}GB RAM`.padEnd(50, " ")
const renderSystem = () => {
const osView = `${OS[os.platform()]} (${os.arch()}) ${mem}GB RAM`.padEnd(
50,
" ",
)
const cpuView = cpu.padEnd(50, " ")

@@ -24,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc