Skip to content

Commit

Permalink
WIP - setup tests, pull in jsonc-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hamlim committed May 14, 2024
1 parent 25eb897 commit 98972fe
Show file tree
Hide file tree
Showing 9 changed files with 812 additions and 9 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"devDependencies": {
"@turbo/gen": "1.13.3",
"dprint": "0.45.0",
"turbo": "1.13.3"
"turbo": "1.13.3",
"one-version": "workspace:*"
},
"scripts": {
"dev": "turbo run dev",
Expand All @@ -19,6 +20,7 @@
"format": "dprint fmt",
"format:check": "dprint check",
"test": "turbo run test",
"one-version:check": "one-version check",
"generator": "bun ./scripts/generator.ts"
}
}
15 changes: 15 additions & 0 deletions packages/one-version/__tests__/jsonc-parser.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert";
import { after, before, test } from "node:test";
import { parse } from "../utils/jsonc-parser.mjs";

test("parses plain old JSON fine", () => {
let sample = {
foo: {
bar: ["baz", 1, 2, false, true, null],
},
};

let result = parse(JSON.stringify(sample));

assert.deepEqual(result, sample);
});
13 changes: 11 additions & 2 deletions packages/one-version/__tests__/one-version.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import assert from "node:assert";
import { after, before, test } from "node:test";
import { start } from "../one-version.mjs";

test("stub", () => {
assert.ok(true);
test("supports help command", async () => {
let logs = [];
const logger = {
log: (...args) => {
logs.push(args.join(" "));
},
};
await start({ rootDirectory: process.cwd(), logger, args: ["help"] });

assert.match(logs[0], /one-version/);
});
2 changes: 1 addition & 1 deletion packages/one-version/bin/index.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { start } from "../one-version.mjs";

start({ rootDirectory: process.cwd(), logger: console }).catch((e) => {
start({ rootDirectory: process.cwd(), logger: console, args: process.argv.slice(2) }).catch((e) => {
console.error("Error running one-version:");
console.error(e);
process.exit(1);
Expand Down
6 changes: 5 additions & 1 deletion packages/one-version/biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"style": {
"useConst": "off",
"noUnusedTemplateLiteral": "off"
}
}
}
}
39 changes: 36 additions & 3 deletions packages/one-version/one-version.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
export async function start({ rootDirectory, logger }) {
logger.log(`Running one-version in ${rootDirectory}`);
return Promise.resolve();
import { parse } from "./utils/jsonc-parser.mjs";

async function _loadConfig({ rootDirectory }) {
}

export async function start({ rootDirectory, logger, args, loadConfig = _loadConfig }) {
let [firstArg] = args;

let usageLogs = [
"",
`Usage:`,
` one-version check - Check the repo to ensure all dependencies are match the expected versions`,
` one-version help - Display this help message!`,
"",
];

switch (firstArg) {
case "check": {
// @TODO
return;
}
case "help": {
logger.log(`one-version - a strict dependency conformance tool for (mono)repos!`);
for (let log of usageLogs) {
logger.log(log);
}
return;
}
default: {
logger.log(`Unknown command: ${firstArg}`);
for (let log of usageLogs) {
logger.log(log);
}
return;
}
}
}
Loading

0 comments on commit 98972fe

Please sign in to comment.