swagger-sdk-generator 0.0.0-stage → 3.0.0
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/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printType = printType;
|
|
4
|
+
exports.resolveType = resolveType;
|
|
5
|
+
exports.propertyType = propertyType;
|
|
6
|
+
const ts_type_1 = require("./ts-type");
|
|
7
|
+
function printType(node, ctx) {
|
|
8
|
+
return (0, ts_type_1.printTsType)(resolveType(node, ctx));
|
|
9
|
+
}
|
|
10
|
+
function resolveType(node, ctx, position = 'top') {
|
|
11
|
+
const shape = resolveShape(node, ctx, position === 'nested');
|
|
12
|
+
if (ctx.options.nullable === 'union' && node.nullable && !hasNull(node))
|
|
13
|
+
return { kind: 'union', members: [shape, (0, ts_type_1.keyword)('null')] };
|
|
14
|
+
return shape;
|
|
15
|
+
}
|
|
16
|
+
function propertyType(node, type, options) {
|
|
17
|
+
if (options.nullable === 'ignore' || !node.nullable || tsHasNull(type))
|
|
18
|
+
return type;
|
|
19
|
+
return { kind: 'union', members: [type, (0, ts_type_1.keyword)('null')] };
|
|
20
|
+
}
|
|
21
|
+
function tsHasNull(type) {
|
|
22
|
+
if (type.kind === 'keyword')
|
|
23
|
+
return type.name === 'null';
|
|
24
|
+
if (type.kind === 'literal')
|
|
25
|
+
return type.value === null;
|
|
26
|
+
if (type.kind === 'union')
|
|
27
|
+
return type.members.some(tsHasNull);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function hasNull(node) {
|
|
31
|
+
if (node.kind === 'primitive')
|
|
32
|
+
return node.type === 'null';
|
|
33
|
+
if (node.kind === 'enum')
|
|
34
|
+
return node.values.includes(null);
|
|
35
|
+
if (node.kind === 'literal')
|
|
36
|
+
return node.value === null;
|
|
37
|
+
if (node.kind === 'union')
|
|
38
|
+
return node.variants.some(hasNull);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const nestedOf = (node, ctx) => resolveType(node, ctx, 'nested');
|
|
42
|
+
function resolveShape(node, ctx, nested) {
|
|
43
|
+
const { options } = ctx;
|
|
44
|
+
switch (node.kind) {
|
|
45
|
+
case 'primitive':
|
|
46
|
+
return (0, ts_type_1.keyword)(node.type === 'integer' ? 'number' : node.type, node);
|
|
47
|
+
case 'any':
|
|
48
|
+
return untyped(ctx, nested);
|
|
49
|
+
case 'ref':
|
|
50
|
+
if (node.unresolved)
|
|
51
|
+
return untyped(ctx, nested);
|
|
52
|
+
return { kind: 'ref', id: node.id, name: ctx.imports.model(node.id, { selfId: ctx.selfId, typeOnly: options.typeImports }) };
|
|
53
|
+
case 'array': {
|
|
54
|
+
const items = node.items.kind === 'array' && options.nestedArrays === 'any' ? (0, ts_type_1.keyword)('any') : nestedOf(node.items, ctx);
|
|
55
|
+
return { kind: 'array', items, generic: options.arrayStyle === 'generic' };
|
|
56
|
+
}
|
|
57
|
+
case 'map':
|
|
58
|
+
return (0, ts_type_1.record)(nestedOf(node.values, ctx));
|
|
59
|
+
case 'object':
|
|
60
|
+
return resolveObject(node, ctx);
|
|
61
|
+
case 'enum':
|
|
62
|
+
return resolveEnum(node, ctx);
|
|
63
|
+
case 'literal':
|
|
64
|
+
if (options.enums === 'base') {
|
|
65
|
+
if (node.value === null)
|
|
66
|
+
return (0, ts_type_1.keyword)('null');
|
|
67
|
+
return { kind: 'widened', as: (0, ts_type_1.keyword)(typeof node.value), values: [node.value] };
|
|
68
|
+
}
|
|
69
|
+
return (0, ts_type_1.literalType)(node.value);
|
|
70
|
+
case 'union':
|
|
71
|
+
if (node.variants.length === 0)
|
|
72
|
+
return untyped(ctx, nested);
|
|
73
|
+
return (0, ts_type_1.union)(node.variants.map((v) => nestedOf(v, ctx)));
|
|
74
|
+
case 'intersection':
|
|
75
|
+
if (node.members.length === 0)
|
|
76
|
+
return untyped(ctx, nested);
|
|
77
|
+
return (0, ts_type_1.intersection)(node.members.map((m) => nestedOf(m, ctx)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function untyped(ctx, nested) {
|
|
81
|
+
const { untyped } = ctx.options;
|
|
82
|
+
if (untyped === 'object')
|
|
83
|
+
return (0, ts_type_1.keyword)(nested ? 'any' : 'object');
|
|
84
|
+
return (0, ts_type_1.keyword)(untyped);
|
|
85
|
+
}
|
|
86
|
+
function resolveEnum(node, ctx) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (ctx.options.enums === 'base') {
|
|
89
|
+
const title = (_a = node.raw) === null || _a === void 0 ? void 0 : _a.title;
|
|
90
|
+
const as = typeof title === 'string' && title ? { kind: 'named', name: title } : (0, ts_type_1.keyword)('string');
|
|
91
|
+
return { kind: 'widened', as, values: Array.from(new Set(node.values.map((v) => String(v)))) };
|
|
92
|
+
}
|
|
93
|
+
if (node.values.length === 1)
|
|
94
|
+
return (0, ts_type_1.literalType)(node.values[0]);
|
|
95
|
+
return { kind: 'union', members: node.values.map(ts_type_1.literalType) };
|
|
96
|
+
}
|
|
97
|
+
function resolveObject(node, ctx) {
|
|
98
|
+
var _a;
|
|
99
|
+
const additional = node.additionalProperties ? nestedOf(node.additionalProperties, ctx) : undefined;
|
|
100
|
+
if (ctx.options.objects === 'object') {
|
|
101
|
+
if (additional !== undefined)
|
|
102
|
+
return (0, ts_type_1.record)(additional);
|
|
103
|
+
const rawType = (_a = node.raw) === null || _a === void 0 ? void 0 : _a.type;
|
|
104
|
+
if (node.properties.length > 0 && rawType === undefined)
|
|
105
|
+
return (0, ts_type_1.record)((0, ts_type_1.keyword)('any'));
|
|
106
|
+
return (0, ts_type_1.keyword)('object');
|
|
107
|
+
}
|
|
108
|
+
if (node.properties.length === 0)
|
|
109
|
+
return (0, ts_type_1.record)(additional !== null && additional !== void 0 ? additional : untyped(ctx, true));
|
|
110
|
+
const object = {
|
|
111
|
+
kind: 'object',
|
|
112
|
+
properties: node.properties.map((p) => ({ name: p.name, optional: !p.required, type: propertyType(p.type, resolveType(p.type, ctx), ctx.options) })),
|
|
113
|
+
};
|
|
114
|
+
return additional === undefined ? object : { kind: 'intersection', members: [object, (0, ts_type_1.record)(additional)] };
|
|
115
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FilterImplOptions } from 'liquidjs';
|
|
2
|
+
import type { TemplateRenderer } from '../core/plugin';
|
|
3
|
+
export declare const TEMPLATE_EXT = ".liquid";
|
|
4
|
+
export declare const BUILTIN_PREFIX = "@builtin/";
|
|
5
|
+
export interface TemplateEngineOptions {
|
|
6
|
+
builtinDir: string;
|
|
7
|
+
overrideDirs?: string[];
|
|
8
|
+
filters?: Record<string, FilterImplOptions>;
|
|
9
|
+
fallbackDirs?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface ResolvedTemplate {
|
|
12
|
+
file: string;
|
|
13
|
+
layer: 'override' | 'builtin';
|
|
14
|
+
}
|
|
15
|
+
export interface TemplateEngine extends TemplateRenderer {
|
|
16
|
+
resolve(name: string): ResolvedTemplate | undefined;
|
|
17
|
+
readonly roots: string[];
|
|
18
|
+
readonly builtinDir: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function createTemplateEngine(options: TemplateEngineOptions): TemplateEngine;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.BUILTIN_PREFIX = exports.TEMPLATE_EXT = void 0;
|
|
46
|
+
exports.createTemplateEngine = createTemplateEngine;
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const liquidjs_1 = require("liquidjs");
|
|
50
|
+
exports.TEMPLATE_EXT = '.liquid';
|
|
51
|
+
exports.BUILTIN_PREFIX = '@builtin/';
|
|
52
|
+
function createTemplateEngine(options) {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
const builtinDir = path.resolve(options.builtinDir);
|
|
55
|
+
const overrideDirs = ((_a = options.overrideDirs) !== null && _a !== void 0 ? _a : []).map((d) => path.resolve(d)).filter((d) => fs.existsSync(d));
|
|
56
|
+
const builtinDirs = [builtinDir, ...((_b = options.fallbackDirs) !== null && _b !== void 0 ? _b : []).map((d) => path.resolve(d)).filter((d) => fs.existsSync(d))];
|
|
57
|
+
const roots = [...overrideDirs, ...builtinDirs];
|
|
58
|
+
const withExt = (file, ext) => (file.endsWith(ext) ? file : file + ext);
|
|
59
|
+
const builtinFile = (name, ext) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const rel = withExt(name, ext);
|
|
62
|
+
return (_a = builtinDirs.map((d) => path.join(d, rel)).find((f) => fs.existsSync(f))) !== null && _a !== void 0 ? _a : path.join(builtinDir, rel);
|
|
63
|
+
};
|
|
64
|
+
const liquidFs = {
|
|
65
|
+
exists: (file) => __awaiter(this, void 0, void 0, function* () { return fs.existsSync(file); }),
|
|
66
|
+
existsSync: (file) => fs.existsSync(file),
|
|
67
|
+
readFile: (file) => __awaiter(this, void 0, void 0, function* () { return stripFinalNewline(yield fs.promises.readFile(file, 'utf8')); }),
|
|
68
|
+
readFileSync: (file) => stripFinalNewline(fs.readFileSync(file, 'utf8')),
|
|
69
|
+
resolve: (root, file, ext) => assertLogicalName(file) ||
|
|
70
|
+
file.startsWith(exports.BUILTIN_PREFIX)
|
|
71
|
+
? builtinFile(file.slice(exports.BUILTIN_PREFIX.length), ext)
|
|
72
|
+
: path.join(root, withExt(file, ext)),
|
|
73
|
+
contains: () => __awaiter(this, void 0, void 0, function* () { return true; }),
|
|
74
|
+
containsSync: () => true,
|
|
75
|
+
sep: path.sep,
|
|
76
|
+
dirname: path.dirname,
|
|
77
|
+
};
|
|
78
|
+
const liquid = new liquidjs_1.Liquid({
|
|
79
|
+
root: roots,
|
|
80
|
+
partials: roots,
|
|
81
|
+
layouts: roots,
|
|
82
|
+
extname: exports.TEMPLATE_EXT,
|
|
83
|
+
fs: liquidFs,
|
|
84
|
+
relativeReference: false,
|
|
85
|
+
strictVariables: true,
|
|
86
|
+
strictFilters: true,
|
|
87
|
+
lenientIf: true,
|
|
88
|
+
greedy: false,
|
|
89
|
+
cache: true,
|
|
90
|
+
});
|
|
91
|
+
for (const [name, impl] of Object.entries(Object.assign(Object.assign({}, baseFilters), ((_c = options.filters) !== null && _c !== void 0 ? _c : {})))) {
|
|
92
|
+
liquid.registerFilter(name, impl);
|
|
93
|
+
}
|
|
94
|
+
const resolve = (name) => {
|
|
95
|
+
assertLogicalName(name);
|
|
96
|
+
if (name.startsWith(exports.BUILTIN_PREFIX)) {
|
|
97
|
+
const file = builtinFile(name.slice(exports.BUILTIN_PREFIX.length), exports.TEMPLATE_EXT);
|
|
98
|
+
return fs.existsSync(file) ? { file, layer: 'builtin' } : undefined;
|
|
99
|
+
}
|
|
100
|
+
for (const root of roots) {
|
|
101
|
+
const file = path.join(root, withExt(name, exports.TEMPLATE_EXT));
|
|
102
|
+
if (fs.existsSync(file))
|
|
103
|
+
return { file, layer: builtinDirs.includes(root) ? 'builtin' : 'override' };
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
roots,
|
|
109
|
+
builtinDir,
|
|
110
|
+
resolve,
|
|
111
|
+
has: (name) => resolve(name) !== undefined,
|
|
112
|
+
render(name, data) {
|
|
113
|
+
if (!resolve(name)) {
|
|
114
|
+
throw new Error(`Template not found: "${name}" (searched: ${roots.join(', ')})`);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return liquid.renderFileSync(name, data);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
121
|
+
throw new Error(`Failed to render template "${name}": ${message}`);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function assertLogicalName(name) {
|
|
127
|
+
const bare = name.startsWith(exports.BUILTIN_PREFIX) ? name.slice(exports.BUILTIN_PREFIX.length) : name;
|
|
128
|
+
if (path.isAbsolute(bare) || /^[A-Za-z]:/.test(bare) || bare.includes('\\') || bare.split('/').includes('..')) {
|
|
129
|
+
throw new Error(`Invalid template name "${name}": use a logical path inside the template root (e.g. "models/model")`);
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
function stripFinalNewline(content) {
|
|
134
|
+
if (content.endsWith('\r\n'))
|
|
135
|
+
return content.slice(0, -2);
|
|
136
|
+
if (content.endsWith('\n'))
|
|
137
|
+
return content.slice(0, -1);
|
|
138
|
+
return content;
|
|
139
|
+
}
|
|
140
|
+
const baseFilters = {
|
|
141
|
+
pascal: (value) => {
|
|
142
|
+
const s = camelize(String(value !== null && value !== void 0 ? value : ''));
|
|
143
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
144
|
+
},
|
|
145
|
+
camel: (value) => {
|
|
146
|
+
const s = camelize(String(value !== null && value !== void 0 ? value : ''));
|
|
147
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
148
|
+
},
|
|
149
|
+
upper_first: (value) => {
|
|
150
|
+
const s = String(value !== null && value !== void 0 ? value : '');
|
|
151
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
152
|
+
},
|
|
153
|
+
lower_first: (value) => {
|
|
154
|
+
const s = String(value !== null && value !== void 0 ? value : '');
|
|
155
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
156
|
+
},
|
|
157
|
+
quote: (value) => JSON.stringify(value),
|
|
158
|
+
};
|
|
159
|
+
function camelize(s) {
|
|
160
|
+
return s.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));
|
|
161
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface TemplateRef {
|
|
2
|
+
name: string;
|
|
3
|
+
kind: 'render' | 'include' | 'layout';
|
|
4
|
+
args: string[];
|
|
5
|
+
dynamic?: boolean;
|
|
6
|
+
line: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TemplateInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
file: string;
|
|
11
|
+
layer: 'override' | 'builtin';
|
|
12
|
+
shadowsBuiltin: boolean;
|
|
13
|
+
refs: TemplateRef[];
|
|
14
|
+
blocks: string[];
|
|
15
|
+
description?: string;
|
|
16
|
+
shadowed?: TemplateInfo;
|
|
17
|
+
}
|
|
18
|
+
export interface InspectOptions {
|
|
19
|
+
builtinDir: string;
|
|
20
|
+
overrideDirs?: string[];
|
|
21
|
+
fallbackDirs?: string[];
|
|
22
|
+
}
|
|
23
|
+
export declare function inspectTemplates(opts: InspectOptions): TemplateInfo[];
|
|
24
|
+
export declare function findEntryTemplates(infos: TemplateInfo[]): TemplateInfo[];
|
|
25
|
+
export declare function renderTemplateTree(infos: TemplateInfo[], opts?: {
|
|
26
|
+
root?: string;
|
|
27
|
+
}): string;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.inspectTemplates = inspectTemplates;
|
|
37
|
+
exports.findEntryTemplates = findEntryTemplates;
|
|
38
|
+
exports.renderTemplateTree = renderTemplateTree;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const liquidjs_1 = require("liquidjs");
|
|
42
|
+
const engine_1 = require("./engine");
|
|
43
|
+
function inspectTemplates(opts) {
|
|
44
|
+
const engine = (0, engine_1.createTemplateEngine)({ builtinDir: opts.builtinDir, overrideDirs: opts.overrideDirs, fallbackDirs: opts.fallbackDirs });
|
|
45
|
+
const liquid = new liquidjs_1.Liquid();
|
|
46
|
+
const names = new Set();
|
|
47
|
+
for (const root of engine.roots) {
|
|
48
|
+
for (const name of listLogicalNames(root))
|
|
49
|
+
names.add(name);
|
|
50
|
+
}
|
|
51
|
+
const cache = new Map();
|
|
52
|
+
const parse = (file) => {
|
|
53
|
+
let parsed = cache.get(file);
|
|
54
|
+
if (!parsed) {
|
|
55
|
+
parsed = parseTemplate(liquid, file);
|
|
56
|
+
cache.set(file, parsed);
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
};
|
|
60
|
+
const infos = [];
|
|
61
|
+
for (const name of [...names].sort(compareStrings)) {
|
|
62
|
+
const winner = engine.resolve(name);
|
|
63
|
+
if (!winner)
|
|
64
|
+
continue;
|
|
65
|
+
const builtin = engine.resolve(engine_1.BUILTIN_PREFIX + name);
|
|
66
|
+
const shadowsBuiltin = winner.layer === 'override' && builtin !== undefined;
|
|
67
|
+
const info = Object.assign({ name, file: winner.file, layer: winner.layer, shadowsBuiltin }, parse(winner.file));
|
|
68
|
+
if (shadowsBuiltin && builtin) {
|
|
69
|
+
info.shadowed = Object.assign({ name, file: builtin.file, layer: 'builtin', shadowsBuiltin: false }, parse(builtin.file));
|
|
70
|
+
}
|
|
71
|
+
infos.push(info);
|
|
72
|
+
}
|
|
73
|
+
return infos;
|
|
74
|
+
}
|
|
75
|
+
function findEntryTemplates(infos) {
|
|
76
|
+
const referenced = new Set();
|
|
77
|
+
const builtinReferenced = new Set();
|
|
78
|
+
const visitedShadowed = new Set();
|
|
79
|
+
const byName = new Map(infos.map((i) => [i.name, i]));
|
|
80
|
+
const visit = (info) => {
|
|
81
|
+
for (const ref of info.refs) {
|
|
82
|
+
if (ref.dynamic)
|
|
83
|
+
continue;
|
|
84
|
+
if (ref.name.startsWith(engine_1.BUILTIN_PREFIX)) {
|
|
85
|
+
const name = ref.name.slice(engine_1.BUILTIN_PREFIX.length);
|
|
86
|
+
builtinReferenced.add(name);
|
|
87
|
+
const target = byName.get(name);
|
|
88
|
+
if ((target === null || target === void 0 ? void 0 : target.shadowed) && !visitedShadowed.has(target.shadowed)) {
|
|
89
|
+
visitedShadowed.add(target.shadowed);
|
|
90
|
+
visit(target.shadowed);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (ref.name !== info.name) {
|
|
94
|
+
referenced.add(ref.name);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
for (const info of infos)
|
|
99
|
+
visit(info);
|
|
100
|
+
return infos.filter((info) => !referenced.has(info.name) && !(info.layer === 'builtin' && builtinReferenced.has(info.name)));
|
|
101
|
+
}
|
|
102
|
+
function renderTemplateTree(infos, opts = {}) {
|
|
103
|
+
var _a;
|
|
104
|
+
const byName = new Map(infos.map((i) => [i.name, i]));
|
|
105
|
+
const lines = [];
|
|
106
|
+
const roots = opts.root
|
|
107
|
+
? [(_a = byName.get(opts.root)) !== null && _a !== void 0 ? _a : opts.root]
|
|
108
|
+
: findEntryTemplates(infos);
|
|
109
|
+
for (const root of roots) {
|
|
110
|
+
if (typeof root === 'string') {
|
|
111
|
+
lines.push(`${root} (missing)`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
lines.push(describe(root.name, root));
|
|
115
|
+
walk(root, '', new Set([root.file]));
|
|
116
|
+
}
|
|
117
|
+
return lines.join('\n');
|
|
118
|
+
function walk(info, prefix, ancestors) {
|
|
119
|
+
const entries = [];
|
|
120
|
+
const targets = [];
|
|
121
|
+
for (const block of info.blocks) {
|
|
122
|
+
entries.push(`block ${block}`);
|
|
123
|
+
targets.push(undefined);
|
|
124
|
+
}
|
|
125
|
+
for (const ref of info.refs) {
|
|
126
|
+
const target = ref.dynamic ? undefined : lookup(ref.name);
|
|
127
|
+
const label = ref.dynamic ? `${ref.kind} <dynamic: ${ref.name}>` : `${ref.kind} ${ref.name}`;
|
|
128
|
+
const args = ref.args.length > 0 ? ` (${ref.args.join(', ')})` : '';
|
|
129
|
+
if (ref.dynamic) {
|
|
130
|
+
entries.push(label + args);
|
|
131
|
+
targets.push(undefined);
|
|
132
|
+
}
|
|
133
|
+
else if (!target) {
|
|
134
|
+
entries.push(`${label}${args} (missing)`);
|
|
135
|
+
targets.push(undefined);
|
|
136
|
+
}
|
|
137
|
+
else if (ancestors.has(target.file)) {
|
|
138
|
+
entries.push(`${label}${args} (cycle)`);
|
|
139
|
+
targets.push(undefined);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
entries.push(describe(label + args, target));
|
|
143
|
+
targets.push(target);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
entries.forEach((entry, i) => {
|
|
147
|
+
const last = i === entries.length - 1;
|
|
148
|
+
lines.push(`${prefix}${last ? '└─ ' : '├─ '}${entry}`);
|
|
149
|
+
const target = targets[i];
|
|
150
|
+
if (target)
|
|
151
|
+
walk(target, prefix + (last ? ' ' : '│ '), new Set([...ancestors, target.file]));
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function lookup(name) {
|
|
155
|
+
if (name.startsWith(engine_1.BUILTIN_PREFIX)) {
|
|
156
|
+
const target = byName.get(name.slice(engine_1.BUILTIN_PREFIX.length));
|
|
157
|
+
if (!target)
|
|
158
|
+
return undefined;
|
|
159
|
+
return target.layer === 'builtin' ? target : target.shadowed;
|
|
160
|
+
}
|
|
161
|
+
return byName.get(name);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function describe(label, info) {
|
|
165
|
+
let out = label;
|
|
166
|
+
if (info.description)
|
|
167
|
+
out += ` — ${info.description}`;
|
|
168
|
+
if (info.shadowsBuiltin)
|
|
169
|
+
out += ' [shadows builtin]';
|
|
170
|
+
else if (info.layer === 'override')
|
|
171
|
+
out += ' [override]';
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
function parseTemplate(liquid, file) {
|
|
175
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
176
|
+
let tokens;
|
|
177
|
+
try {
|
|
178
|
+
tokens = new liquidjs_1.Tokenizer(source, liquid.options.operators, file).readTopLevelTokens(liquid.options);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
+
throw new Error(`Failed to tokenize template "${file}": ${message}`);
|
|
183
|
+
}
|
|
184
|
+
const refs = [];
|
|
185
|
+
const blocks = [];
|
|
186
|
+
let description;
|
|
187
|
+
let commentDepth = 0;
|
|
188
|
+
let commentStart;
|
|
189
|
+
let sawContent = false;
|
|
190
|
+
for (const token of tokens) {
|
|
191
|
+
if (!(token instanceof liquidjs_1.TagToken)) {
|
|
192
|
+
if (commentDepth === 0 && token.getText().trim() !== '')
|
|
193
|
+
sawContent = true;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const line = token.getPosition()[0];
|
|
197
|
+
if (token.name === 'comment') {
|
|
198
|
+
if (commentDepth === 0 && !sawContent)
|
|
199
|
+
commentStart = token;
|
|
200
|
+
commentDepth++;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (token.name === 'endcomment') {
|
|
204
|
+
commentDepth = Math.max(0, commentDepth - 1);
|
|
205
|
+
if (commentDepth === 0 && commentStart) {
|
|
206
|
+
description = firstLine(source.slice(commentStart.end, token.begin));
|
|
207
|
+
commentStart = undefined;
|
|
208
|
+
sawContent = true;
|
|
209
|
+
}
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (commentDepth > 0)
|
|
213
|
+
continue;
|
|
214
|
+
sawContent = true;
|
|
215
|
+
if (token.name === 'liquid') {
|
|
216
|
+
token.args.split(/\r?\n/).forEach((raw, i) => {
|
|
217
|
+
const match = /^\s*(\w+)\s*(.*)$/.exec(raw);
|
|
218
|
+
if (match)
|
|
219
|
+
collect(match[1], match[2], line + i);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
collect(token.name, token.args, line);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return Object.assign({ refs, blocks }, (description ? { description } : {}));
|
|
227
|
+
function collect(tag, args, line) {
|
|
228
|
+
if (tag === 'block') {
|
|
229
|
+
const name = args.trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
230
|
+
if (name)
|
|
231
|
+
blocks.push(name);
|
|
232
|
+
}
|
|
233
|
+
else if (tag === 'render' || tag === 'include' || tag === 'layout') {
|
|
234
|
+
const ref = parseRef(tag, args, line);
|
|
235
|
+
if (ref)
|
|
236
|
+
refs.push(ref);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function firstLine(text) {
|
|
241
|
+
for (const line of text.split(/\r?\n/)) {
|
|
242
|
+
const trimmed = line.trim();
|
|
243
|
+
if (trimmed)
|
|
244
|
+
return trimmed;
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
function parseRef(kind, rawArgs, line) {
|
|
249
|
+
const args = rawArgs.trim();
|
|
250
|
+
if (!args)
|
|
251
|
+
return undefined;
|
|
252
|
+
if (kind === 'layout' && args === 'none')
|
|
253
|
+
return undefined;
|
|
254
|
+
let name;
|
|
255
|
+
let rest;
|
|
256
|
+
let dynamic = false;
|
|
257
|
+
const quoted = /^(['"])(.*?)\1/.exec(args);
|
|
258
|
+
if (quoted) {
|
|
259
|
+
name = stripExt(quoted[2]);
|
|
260
|
+
rest = args.slice(quoted[0].length);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const expr = /^[^\s,]+/.exec(args);
|
|
264
|
+
name = expr ? expr[0] : args;
|
|
265
|
+
rest = expr ? args.slice(expr[0].length) : '';
|
|
266
|
+
dynamic = true;
|
|
267
|
+
}
|
|
268
|
+
const names = [];
|
|
269
|
+
const withFor = /^\s*(?:with|for)\s+(.+?)\s+as\s+([A-Za-z_][\w-]*)/.exec(rest);
|
|
270
|
+
if (withFor) {
|
|
271
|
+
names.push(withFor[2]);
|
|
272
|
+
rest = rest.slice(withFor[0].length);
|
|
273
|
+
}
|
|
274
|
+
for (const segment of splitTopLevel(rest)) {
|
|
275
|
+
const key = /^\s*([A-Za-z_][\w-]*)\s*:/.exec(segment);
|
|
276
|
+
if (key)
|
|
277
|
+
names.push(key[1]);
|
|
278
|
+
}
|
|
279
|
+
return Object.assign(Object.assign({ name, kind, args: names }, (dynamic ? { dynamic: true } : {})), { line });
|
|
280
|
+
}
|
|
281
|
+
function splitTopLevel(text) {
|
|
282
|
+
const parts = [];
|
|
283
|
+
let depth = 0;
|
|
284
|
+
let quote;
|
|
285
|
+
let current = '';
|
|
286
|
+
for (const ch of text) {
|
|
287
|
+
if (quote) {
|
|
288
|
+
if (ch === quote)
|
|
289
|
+
quote = undefined;
|
|
290
|
+
}
|
|
291
|
+
else if (ch === '"' || ch === "'") {
|
|
292
|
+
quote = ch;
|
|
293
|
+
}
|
|
294
|
+
else if (ch === '(' || ch === '[') {
|
|
295
|
+
depth++;
|
|
296
|
+
}
|
|
297
|
+
else if (ch === ')' || ch === ']') {
|
|
298
|
+
depth--;
|
|
299
|
+
}
|
|
300
|
+
else if (ch === ',' && depth === 0) {
|
|
301
|
+
parts.push(current);
|
|
302
|
+
current = '';
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
current += ch;
|
|
306
|
+
}
|
|
307
|
+
parts.push(current);
|
|
308
|
+
return parts;
|
|
309
|
+
}
|
|
310
|
+
function stripExt(name) {
|
|
311
|
+
return name.endsWith(engine_1.TEMPLATE_EXT) ? name.slice(0, -engine_1.TEMPLATE_EXT.length) : name;
|
|
312
|
+
}
|
|
313
|
+
function listLogicalNames(root) {
|
|
314
|
+
const out = [];
|
|
315
|
+
const walkDir = (dir) => {
|
|
316
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
317
|
+
const full = path.join(dir, entry.name);
|
|
318
|
+
if (entry.isDirectory())
|
|
319
|
+
walkDir(full);
|
|
320
|
+
else if (entry.isFile() && entry.name.endsWith(engine_1.TEMPLATE_EXT)) {
|
|
321
|
+
out.push(path.relative(root, full).split(path.sep).join('/').slice(0, -engine_1.TEMPLATE_EXT.length));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
if (fs.existsSync(root))
|
|
326
|
+
walkDir(root);
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
function compareStrings(a, b) {
|
|
330
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
331
|
+
}
|