mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
init
This commit is contained in:
3
packages/mini-loader/.gitignore
vendored
Normal file
3
packages/mini-loader/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/dist/
|
||||
/node_modules/
|
||||
/coverage/
|
||||
23
packages/mini-loader/package.json
Normal file
23
packages/mini-loader/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@morten-olsen/mini-loader",
|
||||
"version": "1.0.0",
|
||||
"main": "./dist/esm/index.js",
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc --build"
|
||||
},
|
||||
"type": "module",
|
||||
"files": [
|
||||
"./dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.js"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@morten-olsen/mini-loader-configs": "workspace:^",
|
||||
"@types/node": "^20.10.8",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
26
packages/mini-loader/src/artifacts/artifacts.ts
Normal file
26
packages/mini-loader/src/artifacts/artifacts.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { send } from '../utils.js';
|
||||
|
||||
type ArtifactCreateEvent = {
|
||||
type: 'artifact:create';
|
||||
payload: {
|
||||
name: string;
|
||||
data: string;
|
||||
};
|
||||
};
|
||||
|
||||
const create = (name: string, data: Buffer | string) => {
|
||||
send({
|
||||
type: 'artifact:create',
|
||||
payload: {
|
||||
name,
|
||||
data: data.toString('base64'),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const artifacts = {
|
||||
create,
|
||||
};
|
||||
|
||||
export type { ArtifactCreateEvent };
|
||||
export { artifacts };
|
||||
10
packages/mini-loader/src/index.ts
Normal file
10
packages/mini-loader/src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { LoggerEvent } from './logger/logger.js';
|
||||
import type { ArtifactCreateEvent } from './artifacts/artifacts.js';
|
||||
|
||||
type Event = LoggerEvent | ArtifactCreateEvent;
|
||||
|
||||
export type { Event, LoggerEvent, ArtifactCreateEvent };
|
||||
export { logger } from './logger/logger.js';
|
||||
export { artifacts } from './artifacts/artifacts.js';
|
||||
export { input } from './input/input.js';
|
||||
export { secrets } from './secrets/secrets.js';
|
||||
11
packages/mini-loader/src/input/input.ts
Normal file
11
packages/mini-loader/src/input/input.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { workerData } from 'worker_threads';
|
||||
|
||||
const get = <T>() => {
|
||||
return workerData as T;
|
||||
};
|
||||
|
||||
const input = {
|
||||
get,
|
||||
};
|
||||
|
||||
export { input };
|
||||
50
packages/mini-loader/src/logger/logger.ts
Normal file
50
packages/mini-loader/src/logger/logger.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { send } from '../utils.js';
|
||||
|
||||
type LoggerEvent = {
|
||||
type: 'log';
|
||||
payload: {
|
||||
severity: 'info' | 'warning' | 'error';
|
||||
message: string;
|
||||
data?: unknown;
|
||||
};
|
||||
};
|
||||
|
||||
const sendLog = (event: LoggerEvent['payload']) => {
|
||||
send({
|
||||
type: 'log',
|
||||
payload: event,
|
||||
});
|
||||
};
|
||||
|
||||
const info = (message: string, data?: unknown) => {
|
||||
sendLog({
|
||||
severity: 'info',
|
||||
message,
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
const warn = (message: string, data?: unknown) => {
|
||||
sendLog({
|
||||
severity: 'warning',
|
||||
message,
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
const error = (message: string, data?: unknown) => {
|
||||
sendLog({
|
||||
severity: 'error',
|
||||
message,
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
const logger = {
|
||||
info,
|
||||
warn,
|
||||
error,
|
||||
};
|
||||
|
||||
export type { LoggerEvent };
|
||||
export { logger };
|
||||
12
packages/mini-loader/src/secrets/secrets.ts
Normal file
12
packages/mini-loader/src/secrets/secrets.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { workerData } from 'worker_threads';
|
||||
|
||||
const get = (id: string) => {
|
||||
const items = workerData?.secrets ?? {};
|
||||
return items[id];
|
||||
};
|
||||
|
||||
const secrets = {
|
||||
get,
|
||||
};
|
||||
|
||||
export { secrets };
|
||||
8
packages/mini-loader/src/utils.ts
Normal file
8
packages/mini-loader/src/utils.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { parentPort } from 'worker_threads';
|
||||
|
||||
const send = (data: any) => {
|
||||
const cleaned = JSON.parse(JSON.stringify(data));
|
||||
parentPort?.postMessage(cleaned);
|
||||
};
|
||||
|
||||
export { send };
|
||||
9
packages/mini-loader/tsconfig.json
Normal file
9
packages/mini-loader/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "@morten-olsen/mini-loader-configs/tsconfig.esm.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/esm",
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user