Skip to content

Commit

Permalink
Added shebang to all scripts so that they can be called directly. (#4)
Browse files Browse the repository at this point in the history
Also reference the scripts via 'bin' in the package.json to allow use via npx.
  • Loading branch information
LTLA authored Feb 20, 2024
1 parent 05b740f commit f45cb57
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.470.0",
"better-sqlite3": "^9.2.2"
},
"bin": {
"configure": "./scripts/configure.js",
"fresh": "./scripts/fresh.js",
"update": "./scripts/update.js",
"manual": "./scripts/manual.js"
}
}
2 changes: 2 additions & 0 deletions scripts/configure.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { parseArgs } from "node:util";
import * as fs from "fs";
import * as path from "path";
Expand Down
2 changes: 2 additions & 0 deletions scripts/fresh.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { freshHandler } from "../src/handlers/freshHandler.js";
import { parseArgs } from "node:util";
import * as fs from "fs";
Expand Down
2 changes: 2 additions & 0 deletions scripts/manual.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { manualHandler } from "../src/handlers/manualHandler.js";
import { parseArgs } from "node:util";
import * as fs from "fs";
Expand Down
2 changes: 2 additions & 0 deletions scripts/update.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { updateHandler } from "../src/handlers/updateHandler.js";
import { parseArgs } from "node:util";
import * as fs from "fs";
Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/configure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test("configure script works correctly", () => {
}
}`);

let output = execSync(`node ./scripts/configure.js --schema ${schema_path} --file_name falin --db_name marcille`);
let output = execSync(`./scripts/configure.js --schema ${schema_path} --file_name falin --db_name marcille`);
const dec = new TextDecoder;
let parsed = JSON.parse(dec.decode(output));
expect(parsed.file_name).toBe("falin");
Expand All @@ -62,7 +62,7 @@ test("configure script works correctly", () => {
expect(parsed.tokenizable).toEqual(expected);

// Schema is actually optional.
output = execSync(`node ./scripts/configure.js --file_name falin --db_name marcille`);
output = execSync(`./scripts/configure.js --file_name falin --db_name marcille`);
parsed = JSON.parse(dec.decode(output));
expect(parsed.tokenizable).toEqual([]);
})
2 changes: 1 addition & 1 deletion tests/scripts/fresh.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as utils from "../utils.js";

test("fresh script works correctly", () => {
const args = sutils.mockEnvironment("fresh");
execSync(`node ./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);
execSync(`./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);

const db0 = path.join(args.indices, "stuff.sqlite3");
const con0 = new Database(db0);
Expand Down
10 changes: 5 additions & 5 deletions tests/scripts/manual.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ test("manual script works correctly", () => {

// Creating an empty registry so that we can initialize the DBs with nothing in them.
const tmp = utils.setupTestDirectory("manual-empty");
execSync(`node ./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${tmp}`);
execSync(`./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${tmp}`);
{
execSync(`node ./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo --asset bar --version v1`);
execSync(`./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo --asset bar --version v1`);
const db1 = path.join(args.indices, "other.sqlite3");
let con1 = new Database(db1);
let output = con1.prepare("SELECT * FROM versions").all();
expect(output.length).toBe(1);
expect(output[0].version).toBe("v1");
con1.close();

execSync(`node ./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo --asset bar`);
execSync(`./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo --asset bar`);
con1 = new Database(db1);
output = con1.prepare("SELECT * FROM versions").all();
expect(output.length).toBe(2);
con1.close();
}

execSync(`node ./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${tmp}`);
execSync(`./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${tmp}`);
{
execSync(`node ./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo`);
execSync(`./scripts/manual.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry} --project foo`);
const db1 = path.join(args.indices, "other.sqlite3");
const con1 = new Database(db1);
let output = con1.prepare("SELECT * FROM versions").all();
Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { execSync } from "child_process";

test("update script works correctly", () => {
const args = sutils.mockEnvironment("update");
execSync(`node ./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);
execSync(`./scripts/fresh.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);

// Adding some juicy logs.
const logdir = path.join(args.registry, "..logs");
Expand All @@ -18,7 +18,7 @@ test("update script works correctly", () => {
const newer = new Date(now.getTime() + 100000);
fs.writeFileSync(path.join(logdir, newer.toISOString() + "_000000"), '{ "type":"delete-version", "project":"foo", "asset":"bar", "version":"v1" }');

execSync(`node ./scripts/update.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`, {stdio: 'inherit'});
execSync(`./scripts/update.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`, {stdio: 'inherit'});

const db0 = path.join(args.indices, "stuff.sqlite3");
const con0 = new Database(db0);
Expand All @@ -30,6 +30,6 @@ test("update script works correctly", () => {
expect(Number(fs.readFileSync(mod, { encoding: "utf8" }))).toEqual(newer.getTime());

// Re-running works as expected.
execSync(`node ./scripts/update.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);
execSync(`./scripts/update.js --config ${args.configs[0]} --config ${args.configs[1]} --dir ${args.indices} --registry ${args.registry}`);
expect(Number(fs.readFileSync(mod, { encoding: "utf8" }))).toEqual(newer.getTime());
})

0 comments on commit f45cb57

Please sign in to comment.