icore 0.1.38 → 1.0.0-alpha
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/dist/argv.d.ts +14 -0
- package/dist/argv.d.ts.map +1 -0
- package/dist/argv.js +62 -0
- package/dist/argv.js.map +1 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +36 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +81 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +132 -0
- package/dist/commands.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +119 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +132 -0
- package/dist/options.js.map +1 -0
- package/package.json +30 -25
- package/readme.md +587 -0
- package/README.md +0 -267
- package/index.js +0 -18
- package/src/application.js +0 -219
- package/src/async-function.js +0 -3
- package/src/inquiry.js +0 -141
- package/src/route.js +0 -109
package/dist/options.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeOptionsSchema = mergeOptionsSchema;
|
|
4
|
+
exports.parseOptions = parseOptions;
|
|
5
|
+
exports.parseOptionsDetailed = parseOptionsDetailed;
|
|
6
|
+
/**
|
|
7
|
+
* Merges option schemas while preserving literal option definition types.
|
|
8
|
+
*
|
|
9
|
+
* Later schemas override earlier schemas with the same option name.
|
|
10
|
+
*/
|
|
11
|
+
function mergeOptionsSchema(schema, ...schemas) {
|
|
12
|
+
return Object.assign({}, schema, ...schemas);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates raw option values against a declarative option schema.
|
|
16
|
+
*/
|
|
17
|
+
function parseOptions(schema, values) {
|
|
18
|
+
return parseOptionsDetailed(schema, values).options;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validates raw option values and returns parsed values with user-provided
|
|
22
|
+
* metadata.
|
|
23
|
+
*/
|
|
24
|
+
function parseOptionsDetailed(schema, values) {
|
|
25
|
+
const parsed = {};
|
|
26
|
+
const provided = {};
|
|
27
|
+
for (const name of Object.keys(values)) {
|
|
28
|
+
if (!Object.hasOwn(schema, name)) {
|
|
29
|
+
throw new Error(`Unexpected argument '--${name}'`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const name of Object.keys(schema)) {
|
|
33
|
+
const definition = schema[name];
|
|
34
|
+
const value = values[String(name)];
|
|
35
|
+
if (definition === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
provided[name] = value !== undefined;
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
if ('default' in definition) {
|
|
41
|
+
parsed[name] = parseDefaultOptionValue(String(name), definition);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (definition.required === true) {
|
|
45
|
+
throw new Error(`Expected required argument '--${String(name)}'`);
|
|
46
|
+
}
|
|
47
|
+
parsed[name] = undefined;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
parsed[name] = parseOptionValue(String(name), definition, value);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
options: parsed,
|
|
54
|
+
provided: provided
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function parseOptionValue(name, definition, value) {
|
|
58
|
+
if (definition.type === 'string') {
|
|
59
|
+
return parseStringOption(name, definition, value);
|
|
60
|
+
}
|
|
61
|
+
if (definition.type === 'boolean') {
|
|
62
|
+
return parseBooleanOption(name, value);
|
|
63
|
+
}
|
|
64
|
+
return parseNumberOption(name, definition, value);
|
|
65
|
+
}
|
|
66
|
+
function parseDefaultOptionValue(name, definition) {
|
|
67
|
+
const value = definition.default;
|
|
68
|
+
if (definition.type === 'string') {
|
|
69
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
70
|
+
throw new Error(`Expected default for '--${name}' as string`);
|
|
71
|
+
}
|
|
72
|
+
assertChoice(name, definition.choices, value);
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (definition.type === 'boolean') {
|
|
76
|
+
if (typeof value !== 'boolean') {
|
|
77
|
+
throw new Error(`Expected default for '--${name}' as boolean`);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
82
|
+
throw new Error(`Expected default for '--${name}' as number`);
|
|
83
|
+
}
|
|
84
|
+
validateNumberConstraints(name, definition, value);
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function parseStringOption(name, definition, value) {
|
|
88
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
89
|
+
throw new Error(`Expected '--${name}' as string`);
|
|
90
|
+
}
|
|
91
|
+
assertChoice(name, definition.choices, value);
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
function parseBooleanOption(name, value) {
|
|
95
|
+
if (value !== true) {
|
|
96
|
+
throw new Error(`Expected '--${name}' as boolean flag`);
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
function parseNumberOption(name, definition, value) {
|
|
101
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
102
|
+
throw new Error(`Expected '--${name}' as number`);
|
|
103
|
+
}
|
|
104
|
+
if (!/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(value)) {
|
|
105
|
+
throw new Error(`Expected '--${name}' as number`);
|
|
106
|
+
}
|
|
107
|
+
const parsed = Number(value);
|
|
108
|
+
if (!Number.isFinite(parsed)) {
|
|
109
|
+
throw new Error(`Expected '--${name}' as number`);
|
|
110
|
+
}
|
|
111
|
+
validateNumberConstraints(name, definition, parsed);
|
|
112
|
+
return parsed;
|
|
113
|
+
}
|
|
114
|
+
function validateNumberConstraints(name, definition, parsed) {
|
|
115
|
+
if (definition.integer === true && !Number.isInteger(parsed)) {
|
|
116
|
+
throw new Error(`Expected '--${name}' as integer`);
|
|
117
|
+
}
|
|
118
|
+
if (definition.min !== undefined && parsed < definition.min) {
|
|
119
|
+
throw new Error(`Expected '--${name}' to be greater than or equal to ${String(definition.min)}`);
|
|
120
|
+
}
|
|
121
|
+
if (definition.max !== undefined && parsed > definition.max) {
|
|
122
|
+
throw new Error(`Expected '--${name}' to be less than or equal to ${String(definition.max)}`);
|
|
123
|
+
}
|
|
124
|
+
assertChoice(name, definition.choices, parsed);
|
|
125
|
+
}
|
|
126
|
+
function assertChoice(name, choices, value) {
|
|
127
|
+
if (choices === undefined || choices.includes(value)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`Expected '--${name}' as one of: ${choices.join(', ')}`);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;AAiJA,gDAYC;AAKD,oCAKC;AAMD,oDA4CC;AA7ED;;;;GAIG;AACH,SAAgB,kBAAkB,CAIhC,MAAe,EACf,GAAG,OAAiB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,MAAM,EACN,GAAG,OAAO,CAC6C,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAC1B,MAAe,EACf,MAAsC;IAEtC,OAAO,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,MAAe,EACf,MAAsC;IAEtC,MAAM,MAAM,GAA4C,EAAE,CAAC;IAC3D,MAAM,QAAQ,GAA4C,EAAE,CAAC;IAE7D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,IAAI,CAA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AAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,cAAc,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,oCAAoC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,iCAAiC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,YAAY,CACnB,IAAY,EACZ,OAAsC,EACtC,KAAa;IAEb,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,gBAAgB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icore",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "mocha"
|
|
7
|
-
},
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/woodger/icore"
|
|
11
|
-
},
|
|
3
|
+
"version": "1.0.0-alpha",
|
|
4
|
+
"description": "Build command line interface",
|
|
12
5
|
"keywords": [
|
|
13
|
-
"
|
|
14
|
-
"router",
|
|
15
|
-
"nebbia"
|
|
6
|
+
"cli"
|
|
16
7
|
],
|
|
8
|
+
"license": "MIT",
|
|
17
9
|
"author": {
|
|
18
10
|
"name": "Stanislav Woodger",
|
|
19
11
|
"email": "woodger@ya.ru"
|
|
20
12
|
},
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/woodger/icore"
|
|
24
16
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"test": "node --test dist/**/*.test.js",
|
|
29
|
+
"lint": "eslint src eslint.config.mjs"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20.19.0"
|
|
29
33
|
},
|
|
34
|
+
"dependencies": {},
|
|
30
35
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
36
|
+
"@eslint/js": "^9.39.4",
|
|
37
|
+
"@types/node": "^26.0.1",
|
|
38
|
+
"eslint": "^9.39.4",
|
|
39
|
+
"globals": "^17.7.0",
|
|
40
|
+
"typescript": "^6.0.3",
|
|
41
|
+
"typescript-eslint": "^8.62.0"
|
|
37
42
|
}
|
|
38
43
|
}
|