@runium/core 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +30 -0
- package/.prettierrc.json +10 -0
- package/README.md +1 -0
- package/package.json +23 -11
- package/src/error.ts +22 -0
- package/src/file.ts +53 -0
- package/src/index.ts +8 -0
- package/src/macros.ts +91 -0
- package/src/project-config.ts +483 -0
- package/src/project-schema.ts +767 -0
- package/src/project.ts +748 -0
- package/src/task.ts +381 -0
- package/src/trigger.ts +170 -0
- package/tsconfig.json +29 -0
- package/types/index.d.ts +510 -0
- package/types/package.json +22 -0
- package/vite.config.ts +123 -0
- package/index.js +0 -586
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true,
|
|
4
|
+
"es2022": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"plugin:prettier/recommended"
|
|
10
|
+
],
|
|
11
|
+
"parser": "@typescript-eslint/parser",
|
|
12
|
+
"parserOptions": {
|
|
13
|
+
"ecmaVersion": 2022,
|
|
14
|
+
"sourceType": "module"
|
|
15
|
+
},
|
|
16
|
+
"plugins": ["@typescript-eslint", "prettier"],
|
|
17
|
+
"rules": {
|
|
18
|
+
"prettier/prettier": "error",
|
|
19
|
+
"@typescript-eslint/no-unused-vars": [
|
|
20
|
+
"error",
|
|
21
|
+
{
|
|
22
|
+
"argsIgnorePattern": "^_",
|
|
23
|
+
"varsIgnorePattern": "^_"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
27
|
+
"no-console": "warn"
|
|
28
|
+
},
|
|
29
|
+
"ignorePatterns": ["dist/", "node_modules/"]
|
|
30
|
+
}
|
package/.prettierrc.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @runium/core
|
package/package.json
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runium/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Runium Core",
|
|
5
5
|
"author": "TheBeastApp",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"import": "./index.js"
|
|
16
|
-
}
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"lint": "eslint ./src --ext .ts",
|
|
11
|
+
"lint:fix": "eslint ./src --ext .ts --fix",
|
|
12
|
+
"format": "prettier --write \"src/**/*.ts\""
|
|
17
13
|
},
|
|
18
14
|
"dependencies": {
|
|
19
15
|
"ajv": "^8.17.1",
|
|
20
16
|
"ajv-keywords": "^5.1.0",
|
|
21
17
|
"bcx-expression-evaluator": "^1.2.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.18.0",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
22
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
23
|
+
"eslint": "^8.56.0",
|
|
24
|
+
"eslint-config-prettier": "^9.1.0",
|
|
25
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
26
|
+
"prettier": "^3.2.5",
|
|
27
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
28
|
+
"terser": "^5.44.0",
|
|
29
|
+
"ts-node": "^10.9.2",
|
|
30
|
+
"typescript": "^5.3.3",
|
|
31
|
+
"vite": "^7.1.12",
|
|
32
|
+
"vite-plugin-dts": "^4.5.4",
|
|
33
|
+
"vite-plugin-externalize-deps": "^0.10.0"
|
|
22
34
|
}
|
|
23
|
-
}
|
|
35
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runium error class
|
|
3
|
+
*/
|
|
4
|
+
export class RuniumError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
|
|
7
|
+
payload: unknown;
|
|
8
|
+
|
|
9
|
+
constructor(message: string, code: string, payload: unknown = null) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.payload = payload;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the given error is a RuniumError
|
|
18
|
+
* @param error
|
|
19
|
+
*/
|
|
20
|
+
export function isRuniumError(error: unknown): boolean {
|
|
21
|
+
return !!error && error instanceof RuniumError;
|
|
22
|
+
}
|
package/src/file.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { RuniumError } from './error';
|
|
3
|
+
|
|
4
|
+
export type JSONValue = string | number | boolean | JSONObject | JSONValue[];
|
|
5
|
+
|
|
6
|
+
export interface JSONObject {
|
|
7
|
+
[x: string]: JSONValue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* File error codes
|
|
12
|
+
*/
|
|
13
|
+
export enum FileErrorCode {
|
|
14
|
+
READ_JSON = 'file-read-json',
|
|
15
|
+
WRITE_JSON = 'file-write-json',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Reads a JSON file
|
|
20
|
+
* @param path
|
|
21
|
+
*/
|
|
22
|
+
export async function readJsonFile<T = JSONValue>(path: string): Promise<T> {
|
|
23
|
+
try {
|
|
24
|
+
const data = await readFile(path, { encoding: 'utf-8' });
|
|
25
|
+
return JSON.parse(data);
|
|
26
|
+
} catch (ex) {
|
|
27
|
+
throw new RuniumError(
|
|
28
|
+
`Can not read JSON file ${path}`,
|
|
29
|
+
FileErrorCode.READ_JSON,
|
|
30
|
+
{ path, original: ex }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Writes a JSON file
|
|
37
|
+
* @param path
|
|
38
|
+
* @param data
|
|
39
|
+
*/
|
|
40
|
+
export async function writeJsonFile<T = JSONValue>(
|
|
41
|
+
path: string,
|
|
42
|
+
data: T
|
|
43
|
+
): Promise<void> {
|
|
44
|
+
try {
|
|
45
|
+
await writeFile(path, JSON.stringify(data, null, 2), { encoding: 'utf-8' });
|
|
46
|
+
} catch (ex) {
|
|
47
|
+
throw new RuniumError(
|
|
48
|
+
`Can not write JSON file ${path}`,
|
|
49
|
+
FileErrorCode.WRITE_JSON,
|
|
50
|
+
{ path, data, original: ex }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/index.ts
ADDED
package/src/macros.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { RuniumError } from './error';
|
|
2
|
+
|
|
3
|
+
export type Macro = (...params: string[]) => string;
|
|
4
|
+
|
|
5
|
+
export type MacrosCollection = Record<string, Macro>;
|
|
6
|
+
|
|
7
|
+
const UNWRAP_MACROS_PATTERN = String.raw`"\$unwrap\((.*)\)"`;
|
|
8
|
+
|
|
9
|
+
export enum MacrosErrorCode {
|
|
10
|
+
MACRO_APPLY_ERROR = 'macro-apply-error',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Apply unwrap macro
|
|
15
|
+
* @param value
|
|
16
|
+
*/
|
|
17
|
+
function unwrap(value: string): string {
|
|
18
|
+
const unwrapRegex = new RegExp(UNWRAP_MACROS_PATTERN, 'g');
|
|
19
|
+
|
|
20
|
+
return value.replace(unwrapRegex, (match: string, value: string) => {
|
|
21
|
+
return value.trim();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Apply macros to a text
|
|
27
|
+
* @param text
|
|
28
|
+
* @param macros
|
|
29
|
+
*/
|
|
30
|
+
export function applyMacros(text: string, macros: MacrosCollection): string {
|
|
31
|
+
const macrosNames = Object.keys(macros);
|
|
32
|
+
|
|
33
|
+
const pattern = String.raw`\$(${macrosNames.join('|')})\(([^()]*(?:\([^()]*\)[^()]*)*)\)`;
|
|
34
|
+
|
|
35
|
+
const apply = (data: string): string => {
|
|
36
|
+
const macrosRegex = new RegExp(pattern, 'g');
|
|
37
|
+
|
|
38
|
+
let result = data;
|
|
39
|
+
|
|
40
|
+
let hasMacros = true;
|
|
41
|
+
while (hasMacros) {
|
|
42
|
+
hasMacros = false;
|
|
43
|
+
result = result.replace(
|
|
44
|
+
macrosRegex,
|
|
45
|
+
(match: string, type: string, args: string) => {
|
|
46
|
+
hasMacros = true;
|
|
47
|
+
|
|
48
|
+
const macroArgs: string[] = [];
|
|
49
|
+
let depth = 0;
|
|
50
|
+
let current = '';
|
|
51
|
+
|
|
52
|
+
for (const char of args) {
|
|
53
|
+
if (char === ',' && depth === 0) {
|
|
54
|
+
macroArgs.push(current.trim());
|
|
55
|
+
current = '';
|
|
56
|
+
} else {
|
|
57
|
+
if (char === '(') {
|
|
58
|
+
depth++;
|
|
59
|
+
}
|
|
60
|
+
if (char === ')') {
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
current += char;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
macroArgs.push(current.trim());
|
|
67
|
+
|
|
68
|
+
const values = macroArgs.map(arg => {
|
|
69
|
+
return arg ? apply(arg) : '';
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
return macros[type](...values);
|
|
73
|
+
} catch (ex) {
|
|
74
|
+
throw new RuniumError(
|
|
75
|
+
`Can not apply macro "${type}"`,
|
|
76
|
+
MacrosErrorCode.MACRO_APPLY_ERROR,
|
|
77
|
+
{ type, args: macroArgs, original: ex }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// process text
|
|
88
|
+
const processedText = macrosNames.length ? apply(text) : text;
|
|
89
|
+
// apply unwrap macros
|
|
90
|
+
return unwrap(processedText);
|
|
91
|
+
}
|