@intelligentgraphics/ig.gfx.packager 3.1.4 → 3.2.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/build/bin.js +7 -0
- package/build/bin.js.map +1 -0
- package/build/build-CMbCj7x-.js +945 -0
- package/build/build-CMbCj7x-.js.map +1 -0
- package/build/build-kkMVBBJL.js +408 -0
- package/build/build-kkMVBBJL.js.map +1 -0
- package/build/cli-Co1DhAmx.js +405 -0
- package/build/cli-Co1DhAmx.js.map +1 -0
- package/build/docs-BkGeoYY2.js +30 -0
- package/build/docs-BkGeoYY2.js.map +1 -0
- package/build/generateIndex-C_DxQ2R4.js +209 -0
- package/build/generateIndex-C_DxQ2R4.js.map +1 -0
- package/build/generateParameterType-CdCi5BWM.js +46 -0
- package/build/generateParameterType-CdCi5BWM.js.map +1 -0
- package/build/package-DHx2bvVO.js +1 -0
- package/build/postinstall-DHTlEmNr.js +35 -0
- package/build/postinstall-DHTlEmNr.js.map +1 -0
- package/build/prompter-DONgUlzS.js +20 -0
- package/build/prompter-DONgUlzS.js.map +1 -0
- package/build/publish-E5zcQAo0.js +348 -0
- package/build/publish-E5zcQAo0.js.map +1 -0
- package/build/publishNpm-CBT1819u.js +115 -0
- package/build/publishNpm-CBT1819u.js.map +1 -0
- package/build/publishedPackage-D-KiU0FG.js +1 -0
- package/build/rollup-Csyght27.js +179 -0
- package/build/rollup-Csyght27.js.map +1 -0
- package/build/scripts-CBblHIL1.js +29 -0
- package/build/scripts-CBblHIL1.js.map +1 -0
- package/build/versionFile-DViDwgCa.js +123 -0
- package/build/versionFile-DViDwgCa.js.map +1 -0
- package/build/workspace-D0XY2EMu.js +1 -0
- package/lib/lib.js +1595 -0
- package/package.json +30 -30
- package/readme.md +5 -0
- package/build/bin.mjs +0 -5
- package/build/bin.mjs.map +0 -1
- package/build/cli-CTqQeYIu.mjs +0 -768
- package/build/cli-CTqQeYIu.mjs.map +0 -1
- package/build/dependencies-CCIr5dgH.mjs +0 -129
- package/build/dependencies-CCIr5dgH.mjs.map +0 -1
- package/build/docs-DvFV9WXA.mjs +0 -37
- package/build/docs-DvFV9WXA.mjs.map +0 -1
- package/build/generateIndex-COnAgsMM.mjs +0 -306
- package/build/generateIndex-COnAgsMM.mjs.map +0 -1
- package/build/generateParameterType-BFVUv72F.mjs +0 -71
- package/build/generateParameterType-BFVUv72F.mjs.map +0 -1
- package/build/index-Ck4_b8Wk.mjs +0 -1400
- package/build/index-Ck4_b8Wk.mjs.map +0 -1
- package/build/index-DHSUlJia.mjs +0 -477
- package/build/index-DHSUlJia.mjs.map +0 -1
- package/build/postinstall-BTuIhY_F.mjs +0 -61
- package/build/postinstall-BTuIhY_F.mjs.map +0 -1
- package/build/publishNpm-A02qW1UY.mjs +0 -167
- package/build/publishNpm-A02qW1UY.mjs.map +0 -1
- package/build/rollup-BeQ0dM8U.mjs +0 -221
- package/build/rollup-BeQ0dM8U.mjs.map +0 -1
- package/build/scripts-B3noxiX3.mjs +0 -45
- package/build/scripts-B3noxiX3.mjs.map +0 -1
- package/build/versionFile-B9z_qwQL.mjs +0 -206
- package/build/versionFile-B9z_qwQL.mjs.map +0 -1
- package/lib/lib.mjs +0 -2706
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { C as readPackageCreatorIndex, E as writePackageCreatorIndex, n as getPackageTypescriptFiles, w as readPackageCreatorManifest } from "./build-kkMVBBJL.js";
|
|
2
|
+
import "./package-DHx2bvVO.js";
|
|
3
|
+
import { n as readScriptPackageTSConfig, r as resolveScriptPackageEntryModule } from "./scripts-CBblHIL1.js";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { findNamespaceByMemberSourceFile, resolveNamespaceFullName, resolveNamespaces } from "@intelligentgraphics/declarationbundler";
|
|
6
|
+
//#region src/commands/generateIndex.ts
|
|
7
|
+
/**
|
|
8
|
+
* Extracts and returns script array for _Index.json from a src folder
|
|
9
|
+
*
|
|
10
|
+
* @param folderPath path to a src folder
|
|
11
|
+
*/
|
|
12
|
+
function generateIndex({ location, ignore = [], strictOptional }) {
|
|
13
|
+
const arr = [];
|
|
14
|
+
const existingIndex = readPackageCreatorIndex(location) ?? [];
|
|
15
|
+
const manifest = readPackageCreatorManifest(location);
|
|
16
|
+
const compilerOptions = readScriptPackageTSConfig(location).options;
|
|
17
|
+
const isModule = compilerOptions.module === ts.ModuleKind.ES2015 || compilerOptions.module === ts.ModuleKind.ESNext;
|
|
18
|
+
if (strictOptional === void 0) strictOptional = compilerOptions.strict === true || compilerOptions.strictNullChecks === true;
|
|
19
|
+
const files = getPackageTypescriptFiles(location).filter((path) => !ignore.some((suffix) => path.endsWith(suffix)));
|
|
20
|
+
let program;
|
|
21
|
+
let rootNamespace;
|
|
22
|
+
if (isModule) {
|
|
23
|
+
const entryFilePath = resolveScriptPackageEntryModule(location, manifest);
|
|
24
|
+
if (entryFilePath === void 0) throw new Error(`Could not resolve entry module`);
|
|
25
|
+
const host = ts.createCompilerHost({}, true);
|
|
26
|
+
program = ts.createProgram([entryFilePath], {
|
|
27
|
+
allowJs: true,
|
|
28
|
+
...compilerOptions
|
|
29
|
+
}, host);
|
|
30
|
+
const entryFile = program.getSourceFile(entryFilePath);
|
|
31
|
+
if (entryFile === void 0) throw new Error(`Failed to find entry module`);
|
|
32
|
+
rootNamespace = resolveNamespaces(entryFile, program, host, program.getTypeChecker(), manifest.Scope ?? manifest.Package);
|
|
33
|
+
} else program = ts.createProgram(files, { allowJs: true });
|
|
34
|
+
const typeChecker = program.getTypeChecker();
|
|
35
|
+
files.forEach((file) => {
|
|
36
|
+
const sourceFile = program.getSourceFile(file);
|
|
37
|
+
if (sourceFile === void 0) return;
|
|
38
|
+
const namespace = rootNamespace === void 0 ? void 0 : findNamespaceByMemberSourceFile(rootNamespace, sourceFile);
|
|
39
|
+
for (const scriptingClass of findScriptingClasses(sourceFile)) {
|
|
40
|
+
if (scriptingClass.node.name === void 0) throw new Error(`Expected ${scriptingClass.type} class to have a name`);
|
|
41
|
+
let name;
|
|
42
|
+
if (isModule && namespace !== void 0) name = `${resolveNamespaceFullName(namespace)}.${scriptingClass.node.name.text}`;
|
|
43
|
+
else name = typeChecker.getFullyQualifiedName(typeChecker.getSymbolAtLocation(scriptingClass.node.name));
|
|
44
|
+
const parameterDeclaration = getScriptingClassParameterdeclaration(scriptingClass);
|
|
45
|
+
const parametersType = parameterDeclaration === void 0 ? void 0 : typeChecker.getTypeAtLocation(parameterDeclaration);
|
|
46
|
+
if (parametersType === void 0) console.log(`Failed to find parameters type declaration for ${scriptingClass.type} ${name}. Skipping parameter list generation`);
|
|
47
|
+
const existingIndexEntry = existingIndex.find((entry) => entry.Name === name);
|
|
48
|
+
const obj = {
|
|
49
|
+
Name: name,
|
|
50
|
+
Description: existingIndexEntry?.Description ?? name,
|
|
51
|
+
Type: scriptingClass.type === "evaluator" ? "Evaluator" : "Interactor",
|
|
52
|
+
Parameters: []
|
|
53
|
+
};
|
|
54
|
+
const dict = getTagDict(ts.getJSDocTags(scriptingClass.node));
|
|
55
|
+
if (dict.summary) obj.Description = dict.summary;
|
|
56
|
+
else {
|
|
57
|
+
const comment = typeChecker.getTypeAtLocation(scriptingClass.node).symbol.getDocumentationComment(typeChecker).map((comment) => comment.text).join(" ");
|
|
58
|
+
if (comment) obj.Description = comment;
|
|
59
|
+
}
|
|
60
|
+
if (parametersType !== void 0) {
|
|
61
|
+
obj.Parameters = parseParametersList(typeChecker.getPropertiesOfType(parametersType), strictOptional);
|
|
62
|
+
if (obj.Parameters.length === 0 && parametersType.getStringIndexType() !== void 0) obj.Parameters = existingIndexEntry?.Parameters ?? [];
|
|
63
|
+
} else if (existingIndexEntry !== void 0) obj.Parameters = existingIndexEntry.Parameters;
|
|
64
|
+
arr.push(obj);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
arr.sort((a, b) => a.Name.localeCompare(b.Name));
|
|
68
|
+
writePackageCreatorIndex(location, arr);
|
|
69
|
+
}
|
|
70
|
+
function capitalizeFirstLetter(string) {
|
|
71
|
+
return string?.charAt(0).toUpperCase() + string?.slice(1);
|
|
72
|
+
}
|
|
73
|
+
const parseDefault = (value, type) => {
|
|
74
|
+
const uType = capitalizeFirstLetter(type);
|
|
75
|
+
if (value === "null") return null;
|
|
76
|
+
switch (uType) {
|
|
77
|
+
case "LengthM":
|
|
78
|
+
case "ArcDEG":
|
|
79
|
+
case "Float": return parseFloat(value);
|
|
80
|
+
case "Integer":
|
|
81
|
+
case "Int": return parseInt(value);
|
|
82
|
+
case "Boolean":
|
|
83
|
+
case "Bool": return value === "true";
|
|
84
|
+
default: return value.replace(/^"/, "").replace(/"$/, "");
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const parseTypeFromName = (name) => {
|
|
88
|
+
const parts = name.split(".");
|
|
89
|
+
const identifier = parts[parts.length - 1];
|
|
90
|
+
switch (identifier) {
|
|
91
|
+
case "LengthM":
|
|
92
|
+
case "ArcDEG":
|
|
93
|
+
case "Float":
|
|
94
|
+
case "Integer": return identifier;
|
|
95
|
+
case "GeometryReference": return "Geometry";
|
|
96
|
+
case "MaterialReference": return "Material";
|
|
97
|
+
case "AnimationReference": return "Animation";
|
|
98
|
+
case "InteractorReference": return "Interactor";
|
|
99
|
+
case "EvaluatorReference": return "Evaluator";
|
|
100
|
+
case "String":
|
|
101
|
+
case "string": return "String";
|
|
102
|
+
case "number":
|
|
103
|
+
case "Number": return "Float";
|
|
104
|
+
case "boolean":
|
|
105
|
+
case "Boolean": return "Boolean";
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const parseParametersList = (properties, strictOptional) => {
|
|
109
|
+
return properties.map((symbol, i) => {
|
|
110
|
+
const parameter = {
|
|
111
|
+
Name: symbol.name,
|
|
112
|
+
Description: void 0,
|
|
113
|
+
Type: "String",
|
|
114
|
+
Default: void 0,
|
|
115
|
+
DisplayIndex: i + 1
|
|
116
|
+
};
|
|
117
|
+
if (parameter.Name.length > 45) throw new Error(`Parameter name length >45 '${parameter.Name}'`);
|
|
118
|
+
let declaration = symbol.getDeclarations()?.[0];
|
|
119
|
+
let documentationComment = symbol.getDocumentationComment(void 0);
|
|
120
|
+
let checkLinksSymbol = symbol;
|
|
121
|
+
while (checkLinksSymbol !== void 0 && declaration === void 0) {
|
|
122
|
+
const links = checkLinksSymbol.links;
|
|
123
|
+
if (links?.syntheticOrigin) {
|
|
124
|
+
declaration = links.syntheticOrigin.getDeclarations()?.[0];
|
|
125
|
+
if (documentationComment.length === 0) documentationComment = links.syntheticOrigin.getDocumentationComment(void 0);
|
|
126
|
+
checkLinksSymbol = links.syntheticOrigin;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (declaration !== void 0) {
|
|
130
|
+
const dict = getTagDict(ts.getJSDocTags(declaration));
|
|
131
|
+
if (dict.summary) parameter.Description = dict.summary;
|
|
132
|
+
else {
|
|
133
|
+
const comment = documentationComment.map((comment) => comment.text).join(" ");
|
|
134
|
+
if (comment) parameter.Description = comment;
|
|
135
|
+
}
|
|
136
|
+
if (dict.creatorType) parameter.Type = dict.creatorType;
|
|
137
|
+
else {
|
|
138
|
+
const propertySignature = declaration;
|
|
139
|
+
if (propertySignature.type !== void 0) {
|
|
140
|
+
const parsedType = parseTypeFromName(propertySignature.type.getText());
|
|
141
|
+
if (parsedType !== void 0) parameter.Type = parsedType;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (dict.default) parameter.Default = parseDefault(dict.default, parameter.Type);
|
|
145
|
+
if (strictOptional && declaration.kind === ts.SyntaxKind.PropertySignature) {
|
|
146
|
+
if (declaration.questionToken === void 0) parameter.Required = true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return parameter;
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
function getTagDict(tags) {
|
|
153
|
+
const dict = {};
|
|
154
|
+
for (const tag of tags) dict[tag.tagName.text] = tag.comment;
|
|
155
|
+
return dict;
|
|
156
|
+
}
|
|
157
|
+
const getScriptingClassParameterdeclaration = (scriptingClass) => {
|
|
158
|
+
for (const member of scriptingClass.node.members) {
|
|
159
|
+
if (ts.isMethodDeclaration(member)) for (let index = 0; index < member.parameters.length; index++) {
|
|
160
|
+
const parameter = member.parameters[index];
|
|
161
|
+
if (isScriptingClassParameterDeclaration(scriptingClass, member, index)) return parameter;
|
|
162
|
+
}
|
|
163
|
+
if (ts.isConstructorDeclaration(member)) for (let index = 0; index < member.parameters.length; index++) {
|
|
164
|
+
const parameter = member.parameters[index];
|
|
165
|
+
if (isScriptingClassParameterDeclaration(scriptingClass, member, index)) return parameter;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const isScriptingClassParameterDeclaration = (scriptingClass, memberNode, parameterIndex) => {
|
|
170
|
+
if (scriptingClass.type === "evaluator") return memberNode?.name?.getText() == "Create" && parameterIndex === 2;
|
|
171
|
+
if (scriptingClass.type === "interactor") return memberNode.kind === ts.SyntaxKind.Constructor && parameterIndex === 0;
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Finds interactors and evaluators within a script file
|
|
176
|
+
*
|
|
177
|
+
* @param {ts.Node} node
|
|
178
|
+
* @return {*}
|
|
179
|
+
*/
|
|
180
|
+
function* findScriptingClasses(node) {
|
|
181
|
+
for (const child of node.getChildren()) {
|
|
182
|
+
if (!ts.isClassDeclaration(child)) {
|
|
183
|
+
yield* findScriptingClasses(child);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const scriptingClass = detectScriptingClass(child);
|
|
187
|
+
if (scriptingClass !== void 0) yield scriptingClass;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const detectScriptingClass = (node) => {
|
|
191
|
+
if (node.heritageClauses?.some((clause) => {
|
|
192
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword && clause.token !== ts.SyntaxKind.ImplementsKeyword) return false;
|
|
193
|
+
return clause.types.some((type) => type.getText().includes("Evaluator"));
|
|
194
|
+
})) return {
|
|
195
|
+
node,
|
|
196
|
+
type: "evaluator"
|
|
197
|
+
};
|
|
198
|
+
if (node.heritageClauses?.some((clause) => {
|
|
199
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword) return false;
|
|
200
|
+
return clause.types.some((type) => type.getText().includes("Interactor"));
|
|
201
|
+
})) return {
|
|
202
|
+
node,
|
|
203
|
+
type: "interactor"
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
export { generateIndex };
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=generateIndex-C_DxQ2R4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateIndex-C_DxQ2R4.js","names":[],"sources":["../src/commands/generateIndex.ts"],"sourcesContent":["import ts from \"typescript\";\n\nimport {\n\tresolveNamespaceFullName,\n\tresolveNamespaces,\n\ttype Namespace,\n\tfindNamespaceByMemberSourceFile,\n} from \"@intelligentgraphics/declarationbundler\";\n\nimport {\n\ttype PackageLocation,\n\twritePackageCreatorIndex,\n\treadPackageCreatorIndex,\n\treadPackageCreatorManifest,\n} from \"../lib/package\";\nimport {\n\tgetPackageTypescriptFiles,\n\treadScriptPackageTSConfig,\n\tresolveScriptPackageEntryModule,\n} from \"../lib/scripts\";\nimport type {\n\tCreatorIndexEntry,\n\tCreatorIndexParameter,\n\tCreatorIndexParameterType,\n} from \"../lib/package\";\n\nexport interface GenerateIndexOptions {\n\tignore?: string[];\n\tlocation: PackageLocation;\n\n\t/**\n\t * Marks non optional parameter object properties as required in the generated index\n\t *\n\t * @type {boolean}\n\t */\n\tstrictOptional?: boolean;\n}\n\n/**\n * Extracts and returns script array for _Index.json from a src folder\n *\n * @param folderPath path to a src folder\n */\nexport function generateIndex({\n\tlocation,\n\tignore = [],\n\tstrictOptional,\n}: GenerateIndexOptions) {\n\tconst arr: CreatorIndexEntry[] = [];\n\n\tconst existingIndex = readPackageCreatorIndex(location) ?? [];\n\tconst manifest = readPackageCreatorManifest(location);\n\n\tconst compilerOptions = readScriptPackageTSConfig(location).options;\n\n\tconst isModule =\n\t\tcompilerOptions.module === ts.ModuleKind.ES2015 ||\n\t\tcompilerOptions.module === ts.ModuleKind.ESNext;\n\n\tif (strictOptional === undefined) {\n\t\tstrictOptional =\n\t\t\tcompilerOptions.strict === true ||\n\t\t\tcompilerOptions.strictNullChecks === true;\n\t}\n\n\tconst files = getPackageTypescriptFiles(location).filter(\n\t\t(path) => !ignore.some((suffix) => path.endsWith(suffix)),\n\t);\n\n\tlet program: ts.Program;\n\tlet rootNamespace: Namespace | undefined;\n\n\tif (isModule) {\n\t\tconst entryFilePath = resolveScriptPackageEntryModule(\n\t\t\tlocation,\n\t\t\tmanifest,\n\t\t);\n\n\t\tif (entryFilePath === undefined) {\n\t\t\tthrow new Error(`Could not resolve entry module`);\n\t\t}\n\n\t\tconst host = ts.createCompilerHost({}, true);\n\t\tprogram = ts.createProgram(\n\t\t\t[entryFilePath],\n\t\t\t{ allowJs: true, ...compilerOptions },\n\t\t\thost,\n\t\t);\n\n\t\tconst entryFile = program.getSourceFile(entryFilePath);\n\n\t\tif (entryFile === undefined) {\n\t\t\tthrow new Error(`Failed to find entry module`);\n\t\t}\n\n\t\trootNamespace = resolveNamespaces(\n\t\t\tentryFile,\n\t\t\tprogram,\n\t\t\thost,\n\t\t\tprogram.getTypeChecker(),\n\t\t\tmanifest.Scope ?? manifest.Package,\n\t\t);\n\t} else {\n\t\tprogram = ts.createProgram(files, { allowJs: true });\n\t}\n\n\tconst typeChecker = program.getTypeChecker();\n\n\tfiles.forEach((file) => {\n\t\t// Create a Program to represent the project, then pull out the\n\t\t// source file to parse its AST.\n\t\tconst sourceFile = program.getSourceFile(file);\n\n\t\tif (sourceFile === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst namespace =\n\t\t\trootNamespace === undefined\n\t\t\t\t? undefined\n\t\t\t\t: findNamespaceByMemberSourceFile(rootNamespace, sourceFile);\n\t\t// Loop through the root AST nodes of the file\n\n\t\tfor (const scriptingClass of findScriptingClasses(sourceFile)) {\n\t\t\tif (scriptingClass.node.name === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Expected ${scriptingClass.type} class to have a name`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet name: string;\n\n\t\t\tif (isModule && namespace !== undefined) {\n\t\t\t\tconst moduleNamespace = resolveNamespaceFullName(namespace);\n\t\t\t\tname = `${moduleNamespace}.${scriptingClass.node.name.text}`;\n\t\t\t} else {\n\t\t\t\tname = typeChecker.getFullyQualifiedName(\n\t\t\t\t\ttypeChecker.getSymbolAtLocation(scriptingClass.node.name)!,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst parameterDeclaration =\n\t\t\t\tgetScriptingClassParameterdeclaration(scriptingClass);\n\n\t\t\tconst parametersType =\n\t\t\t\tparameterDeclaration === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: typeChecker.getTypeAtLocation(parameterDeclaration);\n\n\t\t\tif (parametersType === undefined) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Failed to find parameters type declaration for ${scriptingClass.type} ${name}. Skipping parameter list generation`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst existingIndexEntry = existingIndex.find(\n\t\t\t\t(entry) => entry.Name === name,\n\t\t\t);\n\n\t\t\tconst obj: CreatorIndexEntry = {\n\t\t\t\tName: name,\n\t\t\t\tDescription: existingIndexEntry?.Description ?? name,\n\t\t\t\tType:\n\t\t\t\t\tscriptingClass.type === \"evaluator\"\n\t\t\t\t\t\t? \"Evaluator\"\n\t\t\t\t\t\t: \"Interactor\",\n\t\t\t\tParameters: [],\n\t\t\t};\n\n\t\t\tconst rawDocTags = ts.getJSDocTags(scriptingClass.node);\n\n\t\t\tconst dict = getTagDict(rawDocTags);\n\t\t\tif (dict.summary) {\n\t\t\t\tobj.Description = dict.summary;\n\t\t\t} else {\n\t\t\t\tconst comment = typeChecker\n\t\t\t\t\t.getTypeAtLocation(scriptingClass.node)\n\t\t\t\t\t.symbol.getDocumentationComment(typeChecker)\n\t\t\t\t\t.map((comment) => comment.text)\n\t\t\t\t\t.join(\" \");\n\n\t\t\t\tif (comment) {\n\t\t\t\t\tobj.Description = comment;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (parametersType !== undefined) {\n\t\t\t\tobj.Parameters = parseParametersList(\n\t\t\t\t\ttypeChecker.getPropertiesOfType(parametersType),\n\t\t\t\t\tstrictOptional,\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\tobj.Parameters.length === 0 &&\n\t\t\t\t\tparametersType.getStringIndexType() !== undefined\n\t\t\t\t) {\n\t\t\t\t\tobj.Parameters = existingIndexEntry?.Parameters ?? [];\n\t\t\t\t}\n\t\t\t} else if (existingIndexEntry !== undefined) {\n\t\t\t\tobj.Parameters = existingIndexEntry.Parameters;\n\t\t\t}\n\n\t\t\tarr.push(obj);\n\t\t}\n\t});\n\n\tarr.sort((a, b) => a.Name.localeCompare(b.Name));\n\n\twritePackageCreatorIndex(location, arr);\n}\n\nfunction capitalizeFirstLetter(string: string) {\n\treturn string?.charAt(0).toUpperCase() + string?.slice(1);\n}\n\nconst parseDefault = (value: string, type: string) => {\n\tconst uType: CreatorIndexParameterType = capitalizeFirstLetter(\n\t\ttype,\n\t) as CreatorIndexParameterType;\n\tif (value === \"null\") return null;\n\tswitch (uType) {\n\t\tcase \"LengthM\":\n\t\tcase \"ArcDEG\":\n\t\tcase \"Float\":\n\t\t\treturn parseFloat(value);\n\t\tcase \"Integer\":\n\t\tcase \"Int\":\n\t\t\treturn parseInt(value);\n\t\tcase \"Boolean\":\n\t\tcase \"Bool\":\n\t\t\treturn value === \"true\";\n\t\tcase \"Material\":\n\t\tcase \"String\":\n\t\tcase \"Geometry\":\n\t\tdefault:\n\t\t\treturn value.replace(/^\"/, \"\").replace(/\"$/, \"\");\n\t}\n};\n\nconst parseTypeFromName = (\n\tname: string,\n): CreatorIndexParameterType | undefined => {\n\tconst parts = name.split(\".\");\n\tconst identifier = parts[parts.length - 1];\n\n\tswitch (identifier) {\n\t\tcase \"LengthM\":\n\t\tcase \"ArcDEG\":\n\t\tcase \"Float\":\n\t\tcase \"Integer\":\n\t\t\treturn identifier;\n\t\tcase \"GeometryReference\":\n\t\t\treturn \"Geometry\";\n\t\tcase \"MaterialReference\":\n\t\t\treturn \"Material\";\n\t\tcase \"AnimationReference\":\n\t\t\treturn \"Animation\";\n\t\tcase \"InteractorReference\":\n\t\t\treturn \"Interactor\";\n\t\tcase \"EvaluatorReference\":\n\t\t\treturn \"Evaluator\";\n\t\tcase \"String\":\n\t\tcase \"string\":\n\t\t\treturn \"String\";\n\t\tcase \"number\":\n\t\tcase \"Number\":\n\t\t\treturn \"Float\";\n\t\tcase \"boolean\":\n\t\tcase \"Boolean\":\n\t\t\treturn \"Boolean\";\n\t}\n};\n\nconst parseParametersList = (\n\tproperties: ts.Symbol[],\n\tstrictOptional: boolean,\n): CreatorIndexParameter[] => {\n\treturn properties.map((symbol, i) => {\n\t\tconst parameter: CreatorIndexParameter = {\n\t\t\tName: symbol.name,\n\t\t\tDescription: undefined,\n\t\t\tType: \"String\",\n\t\t\tDefault: undefined,\n\t\t\tDisplayIndex: i + 1,\n\t\t};\n\n\t\tif (parameter.Name.length > 45) {\n\t\t\tthrow new Error(`Parameter name length >45 '${parameter.Name}'`);\n\t\t}\n\n\t\tlet declaration: ts.Declaration | undefined =\n\t\t\tsymbol.getDeclarations()?.[0];\n\t\tlet documentationComment = symbol.getDocumentationComment(undefined);\n\n\t\tlet checkLinksSymbol: ts.Symbol | undefined = symbol;\n\n\t\twhile (checkLinksSymbol !== undefined && declaration === undefined) {\n\t\t\tconst links:\n\t\t\t\t| {\n\t\t\t\t\t\tmappedType?: ts.Type;\n\t\t\t\t\t\tsyntheticOrigin?: ts.Symbol;\n\t\t\t\t }\n\t\t\t\t| undefined = (\n\t\t\t\tcheckLinksSymbol as {\n\t\t\t\t\tlinks?: {\n\t\t\t\t\t\tmappedType?: ts.Type;\n\t\t\t\t\t\tsyntheticOrigin?: ts.Symbol;\n\t\t\t\t\t};\n\t\t\t\t} & ts.Symbol\n\t\t\t).links;\n\n\t\t\tif (links?.syntheticOrigin) {\n\t\t\t\tdeclaration = links.syntheticOrigin.getDeclarations()?.[0];\n\n\t\t\t\tif (documentationComment.length === 0) {\n\t\t\t\t\tdocumentationComment =\n\t\t\t\t\t\tlinks.syntheticOrigin.getDocumentationComment(\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcheckLinksSymbol = links.syntheticOrigin;\n\t\t\t}\n\t\t}\n\n\t\tif (declaration !== undefined) {\n\t\t\tconst rawDocTags = ts.getJSDocTags(declaration);\n\n\t\t\tconst dict = getTagDict(rawDocTags);\n\n\t\t\tif (dict.summary) {\n\t\t\t\tparameter.Description = dict.summary;\n\t\t\t} else {\n\t\t\t\tconst comment = documentationComment\n\t\t\t\t\t.map((comment) => comment.text)\n\t\t\t\t\t.join(\" \");\n\n\t\t\t\tif (comment) {\n\t\t\t\t\tparameter.Description = comment;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (dict.creatorType) {\n\t\t\t\tparameter.Type = dict.creatorType as CreatorIndexParameterType;\n\t\t\t} else {\n\t\t\t\tconst propertySignature = declaration as ts.PropertySignature;\n\t\t\t\tif (propertySignature.type !== undefined) {\n\t\t\t\t\tconst parsedType = parseTypeFromName(\n\t\t\t\t\t\tpropertySignature.type.getText(),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (parsedType !== undefined) {\n\t\t\t\t\t\tparameter.Type = parsedType;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (dict.default) {\n\t\t\t\tparameter.Default = parseDefault(dict.default, parameter.Type);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tstrictOptional &&\n\t\t\t\tdeclaration.kind === ts.SyntaxKind.PropertySignature\n\t\t\t) {\n\t\t\t\tconst propertySignature = declaration as ts.PropertySignature;\n\t\t\t\tif (propertySignature.questionToken === undefined) {\n\t\t\t\t\tparameter.Required = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn parameter;\n\t});\n};\n\ninterface IDocTags {\n\tdefault?: string;\n\tcreatorType?: string;\n\tsummary?: string;\n}\n\nfunction getTagDict(tags: readonly ts.JSDocTag[]): IDocTags {\n\tconst dict: IDocTags = {};\n\n\tfor (const tag of tags) {\n\t\tdict[tag.tagName.text as keyof IDocTags] = tag.comment as string;\n\t}\n\n\treturn dict;\n}\n\nconst getScriptingClassParameterdeclaration = (\n\tscriptingClass: ScriptingClass,\n) => {\n\tfor (const member of scriptingClass.node.members) {\n\t\tif (ts.isMethodDeclaration(member)) {\n\t\t\tfor (let index = 0; index < member.parameters.length; index++) {\n\t\t\t\tconst parameter = member.parameters[index];\n\t\t\t\tif (\n\t\t\t\t\tisScriptingClassParameterDeclaration(\n\t\t\t\t\t\tscriptingClass,\n\t\t\t\t\t\tmember,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn parameter;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (ts.isConstructorDeclaration(member)) {\n\t\t\tfor (let index = 0; index < member.parameters.length; index++) {\n\t\t\t\tconst parameter = member.parameters[index];\n\t\t\t\tif (\n\t\t\t\t\tisScriptingClassParameterDeclaration(\n\t\t\t\t\t\tscriptingClass,\n\t\t\t\t\t\tmember,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn parameter;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst isScriptingClassParameterDeclaration = (\n\tscriptingClass: ScriptingClass,\n\tmemberNode: ts.ClassElement,\n\tparameterIndex: number,\n) => {\n\tif (scriptingClass.type === \"evaluator\") {\n\t\treturn memberNode?.name?.getText() == \"Create\" && parameterIndex === 2;\n\t}\n\tif (scriptingClass.type === \"interactor\") {\n\t\treturn (\n\t\t\tmemberNode.kind === ts.SyntaxKind.Constructor &&\n\t\t\tparameterIndex === 0\n\t\t);\n\t}\n\treturn false;\n};\n\ninterface ScriptingClass {\n\tnode: ts.ClassDeclaration;\n\ttype: \"interactor\" | \"evaluator\";\n}\n\n/**\n * Finds interactors and evaluators within a script file\n *\n * @param {ts.Node} node\n * @return {*}\n */\nfunction* findScriptingClasses(\n\tnode: ts.Node,\n): Generator<ScriptingClass, void, void> {\n\tfor (const child of node.getChildren()) {\n\t\tif (!ts.isClassDeclaration(child)) {\n\t\t\tyield* findScriptingClasses(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst scriptingClass = detectScriptingClass(child);\n\n\t\tif (scriptingClass !== undefined) {\n\t\t\tyield scriptingClass;\n\t\t}\n\t}\n}\n\nconst detectScriptingClass = (\n\tnode: ts.ClassDeclaration,\n): ScriptingClass | undefined => {\n\tconst isEvaluator = node.heritageClauses?.some((clause) => {\n\t\tif (\n\t\t\tclause.token !== ts.SyntaxKind.ExtendsKeyword &&\n\t\t\tclause.token !== ts.SyntaxKind.ImplementsKeyword\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn clause.types.some((type) =>\n\t\t\ttype.getText().includes(\"Evaluator\"),\n\t\t);\n\t});\n\n\tif (isEvaluator) {\n\t\treturn {\n\t\t\tnode,\n\t\t\ttype: \"evaluator\",\n\t\t};\n\t}\n\n\tconst isInteractor = node.heritageClauses?.some((clause) => {\n\t\tif (clause.token !== ts.SyntaxKind.ExtendsKeyword) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn clause.types.some((type) =>\n\t\t\ttype.getText().includes(\"Interactor\"),\n\t\t);\n\t});\n\n\tif (isInteractor) {\n\t\treturn {\n\t\t\tnode,\n\t\t\ttype: \"interactor\",\n\t\t};\n\t}\n};\n"],"mappings":";;;;;;;;;;;AA2CA,SAAgB,cAAc,EAC7B,UACA,SAAS,EAAE,EACX,kBACwB;CACxB,MAAM,MAA2B,EAAE;CAE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ACA,MACA,CAED,QAAO;;;;AAOZ,MAAM,wCACL,gBACA,YACA,mBACI;AACJ,KAAI,eAAe,SAAS,YAC3B,QAAO,YAAY,MAAM,SAAS,IAAI,YAAY,mBAAmB;AAEtE,KAAI,eAAe,SAAS,aAC3B,QACC,WAAW,SAAS,GAAG,WAAW,eAClC,mBAAmB;AAGrB,QAAO;;;;;;;;AAcR,UAAU,qBACT,MACwC;AACxC,MAAK,MAAM,SAAS,KAAK,aAAa,EAAE;AACvC,MAAI,CAAC,GAAG,mBAAmB,MAAM,EAAE;AAClC,UAAO,qBAAqB,MAAM;AAClC;;EAGD,MAAM,iBAAiB,qBAAqB,MAAM;AAElD,MAAI,mBAAmB,KAAA,EACtB,OAAM;;;AAKT,MAAM,wBACL,SACgC;AAchC,KAboB,KAAK,iBAAiB,MAAM,WAAW;AAC1D,MACC,OAAO,UAAU,GAAG,WAAW,kBAC/B,OAAO,UAAU,GAAG,WAAW,kBAE/B,QAAO;AAGR,SAAO,OAAO,MAAM,MAAM,SACzB,KAAK,SAAS,CAAC,SAAS,YAAY,CACpC;GACA,CAGD,QAAO;EACN;EACA,MAAM;EACN;AAaF,KAVqB,KAAK,iBAAiB,MAAM,WAAW;AAC3D,MAAI,OAAO,UAAU,GAAG,WAAW,eAClC,QAAO;AAGR,SAAO,OAAO,MAAM,MAAM,SACzB,KAAK,SAAS,CAAC,SAAS,aAAa,CACrC;GACA,CAGD,QAAO;EACN;EACA,MAAM;EACN"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { C as readPackageCreatorIndex, w as readPackageCreatorManifest, y as getCreatorIndexParameterPrimaryJSType } from "./build-kkMVBBJL.js";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
//#region src/commands/generateParameterType.ts
|
|
7
|
+
const generateParameterType = ({ location, name }) => {
|
|
8
|
+
const index = readPackageCreatorIndex(location);
|
|
9
|
+
const manifest = readPackageCreatorManifest(location);
|
|
10
|
+
if (index === void 0) throw new Error(`Could not find the _Index.json file`);
|
|
11
|
+
let qualifiedName = name;
|
|
12
|
+
let className = name;
|
|
13
|
+
const scope = manifest.Scope ?? manifest.Package;
|
|
14
|
+
if (name.startsWith(scope)) className = name.slice(scope.length + 1);
|
|
15
|
+
else qualifiedName = `${scope}.${name}`;
|
|
16
|
+
const informations = index.find((item) => item.Name === qualifiedName);
|
|
17
|
+
if (informations === void 0) throw new Error(`Could not find an index entry for ${name}`);
|
|
18
|
+
const members = [];
|
|
19
|
+
if (informations.Parameters !== void 0) {
|
|
20
|
+
const sortedList = informations.Parameters.slice();
|
|
21
|
+
sortedList.sort((a, b) => a.DisplayIndex - b.DisplayIndex);
|
|
22
|
+
for (const parameter of sortedList) {
|
|
23
|
+
const jsType = getCreatorIndexParameterPrimaryJSType(parameter.Type);
|
|
24
|
+
const type = jsType === "string" ? ts.factory.createTypeReferenceNode("string") : ts.factory.createUnionTypeNode([ts.factory.createTypeReferenceNode(jsType), ts.factory.createTypeReferenceNode("string")]);
|
|
25
|
+
let propertySignature = ts.factory.createPropertySignature(void 0, parameter.Name, parameter.Required ? void 0 : ts.factory.createToken(ts.SyntaxKind.QuestionToken), type);
|
|
26
|
+
const jsdocParts = [];
|
|
27
|
+
if (parameter.Description !== void 0) jsdocParts.push(parameter.Description, "");
|
|
28
|
+
jsdocParts.push(`@creatorType ${parameter.Type}`);
|
|
29
|
+
if (jsType === "string") jsdocParts.push(`@default "${parameter.Default}"`);
|
|
30
|
+
else jsdocParts.push(`@default ${parameter.Default}`);
|
|
31
|
+
const jsdocContent = jsdocParts.map((part) => `* ${part}`).join(os.EOL + " ");
|
|
32
|
+
propertySignature = ts.addSyntheticLeadingComment(propertySignature, ts.SyntaxKind.MultiLineCommentTrivia, `*${os.EOL} ${jsdocContent}${os.EOL} `, true);
|
|
33
|
+
members.push(propertySignature);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const interfaceName = `${className}Params`;
|
|
37
|
+
let interfaceDeclaration = ts.factory.createInterfaceDeclaration(void 0, interfaceName, void 0, void 0, members);
|
|
38
|
+
interfaceDeclaration = ts.addSyntheticLeadingComment(interfaceDeclaration, ts.SyntaxKind.MultiLineCommentTrivia, `*${os.EOL} * Parameters for the ${className} class${os.EOL} `, true);
|
|
39
|
+
const content = ts.createPrinter({ newLine: os.EOL === "\n" ? ts.NewLineKind.LineFeed : ts.NewLineKind.CarriageReturnLineFeed }).printNode(ts.EmitHint.Unspecified, interfaceDeclaration, ts.createSourceFile("index.ts", "", ts.ScriptTarget.Latest)).replace(/ /g, " ");
|
|
40
|
+
const outFile = path.join(location.scriptsDir, `${interfaceName}.txt`);
|
|
41
|
+
fs.writeFileSync(outFile, `Generated parameters interface for ${className}. Insert the interface declaration next to the class and use it as the type for the parameters. Afterwards you can delete this file.` + os.EOL + os.EOL + content);
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { generateParameterType };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=generateParameterType-CdCi5BWM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateParameterType-CdCi5BWM.js","names":[],"sources":["../src/commands/generateParameterType.ts"],"sourcesContent":["import ts from \"typescript\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\n\nimport {\n\ttype PackageLocation,\n\tgetCreatorIndexParameterPrimaryJSType,\n\treadPackageCreatorIndex,\n\treadPackageCreatorManifest,\n} from \"@intelligentgraphics/ig.gfx.tools.core\";\n\nexport interface GenerateParameterTypeOptions {\n\tlocation: PackageLocation;\n\tname: string;\n}\n\nexport const generateParameterType = ({\n\tlocation,\n\tname,\n}: GenerateParameterTypeOptions) => {\n\tconst index = readPackageCreatorIndex(location);\n\tconst manifest = readPackageCreatorManifest(location);\n\n\tif (index === undefined) {\n\t\tthrow new Error(`Could not find the _Index.json file`);\n\t}\n\n\tlet qualifiedName = name;\n\tlet className = name;\n\n\tconst scope = manifest.Scope ?? manifest.Package;\n\n\tif (name.startsWith(scope)) {\n\t\tclassName = name.slice(scope.length + 1);\n\t} else {\n\t\tqualifiedName = `${scope}.${name}`;\n\t}\n\n\tconst informations = index.find((item) => item.Name === qualifiedName);\n\n\tif (informations === undefined) {\n\t\tthrow new Error(`Could not find an index entry for ${name}`);\n\t}\n\n\tconst members: ts.TypeElement[] = [];\n\n\tif (informations.Parameters !== undefined) {\n\t\tconst sortedList = informations.Parameters.slice();\n\t\tsortedList.sort((a, b) => a.DisplayIndex - b.DisplayIndex);\n\n\t\tfor (const parameter of sortedList) {\n\t\t\tconst jsType = getCreatorIndexParameterPrimaryJSType(\n\t\t\t\tparameter.Type,\n\t\t\t);\n\n\t\t\tconst type =\n\t\t\t\tjsType === \"string\"\n\t\t\t\t\t? ts.factory.createTypeReferenceNode(\"string\")\n\t\t\t\t\t: ts.factory.createUnionTypeNode([\n\t\t\t\t\t\t\tts.factory.createTypeReferenceNode(jsType),\n\t\t\t\t\t\t\tts.factory.createTypeReferenceNode(\"string\"),\n\t\t\t\t\t\t]);\n\n\t\t\tlet propertySignature = ts.factory.createPropertySignature(\n\t\t\t\tundefined,\n\t\t\t\tparameter.Name,\n\t\t\t\tparameter.Required\n\t\t\t\t\t? undefined\n\t\t\t\t\t: ts.factory.createToken(ts.SyntaxKind.QuestionToken),\n\t\t\t\ttype,\n\t\t\t);\n\n\t\t\tconst jsdocParts: string[] = [];\n\n\t\t\tif (parameter.Description !== undefined) {\n\t\t\t\tjsdocParts.push(parameter.Description, \"\");\n\t\t\t}\n\n\t\t\tjsdocParts.push(`@creatorType ${parameter.Type}`);\n\n\t\t\tif (jsType === \"string\") {\n\t\t\t\tjsdocParts.push(`@default \"${parameter.Default}\"`);\n\t\t\t} else {\n\t\t\t\tjsdocParts.push(`@default ${parameter.Default}`);\n\t\t\t}\n\n\t\t\tconst jsdocContent = jsdocParts\n\t\t\t\t.map((part) => `* ${part}`)\n\t\t\t\t.join(os.EOL + \" \");\n\t\t\tpropertySignature = ts.addSyntheticLeadingComment(\n\t\t\t\tpropertySignature,\n\t\t\t\tts.SyntaxKind.MultiLineCommentTrivia,\n\t\t\t\t`*${os.EOL} ${jsdocContent}${os.EOL} `,\n\t\t\t\ttrue,\n\t\t\t);\n\n\t\t\tmembers.push(propertySignature);\n\t\t}\n\t}\n\n\tconst interfaceName = `${className}Params`;\n\n\tlet interfaceDeclaration = ts.factory.createInterfaceDeclaration(\n\t\tundefined,\n\t\tinterfaceName,\n\t\tundefined,\n\t\tundefined,\n\t\tmembers,\n\t);\n\n\tinterfaceDeclaration = ts.addSyntheticLeadingComment(\n\t\tinterfaceDeclaration,\n\t\tts.SyntaxKind.MultiLineCommentTrivia,\n\t\t`*${os.EOL} * Parameters for the ${className} class${os.EOL} `,\n\t\ttrue,\n\t);\n\n\tconst printer = ts.createPrinter({\n\t\tnewLine:\n\t\t\tos.EOL === \"\\n\"\n\t\t\t\t? ts.NewLineKind.LineFeed\n\t\t\t\t: ts.NewLineKind.CarriageReturnLineFeed,\n\t});\n\tconst content = printer\n\t\t.printNode(\n\t\t\tts.EmitHint.Unspecified,\n\t\t\tinterfaceDeclaration,\n\t\t\tts.createSourceFile(\"index.ts\", \"\", ts.ScriptTarget.Latest),\n\t\t)\n\t\t.replace(/ /g, \"\\t\");\n\n\tconst outFile = path.join(location.scriptsDir, `${interfaceName}.txt`);\n\n\tfs.writeFileSync(\n\t\toutFile,\n\t\t`Generated parameters interface for ${className}. Insert the interface declaration next to the class and use it as the type for the parameters. Afterwards you can delete this file.` +\n\t\t\tos.EOL +\n\t\t\tos.EOL +\n\t\t\tcontent,\n\t);\n};\n"],"mappings":";;;;;;AAiBA,MAAa,yBAAyB,EACrC,UACA,WACmC;CACnC,MAAM,QAAQ,wBAAwB,SAAS;CAC/C,MAAM,WAAW,2BAA2B,SAAS;AAErD,KAAI,UAAU,KAAA,EACb,OAAM,IAAI,MAAM,sCAAsC;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IACpC,KACA;AAED,WAAQ,KAAK,kBAAkB;;;CAIjC,MAAM,gBAAgB,GAAG,UAAU;CAEnC,IAAI,uBAAuB,GAAG,QAAQ,2BACrC,KAAA,GACA,eACA,KAAA,GACA,KAAA,GACA,QACA;AAED,wBAAuB,GAAG,2BACzB,sBACA,GAAG,WAAW,wBACd,IAAI,GAAG,IAAI,wBAAwB,UAAU,QAAQ,GAAG,IAAI,IAC5D,KACA;CAQD,MAAM,UANU,GAAG,cAAc,EAChC,SACC,GAAG,QAAQ,OACR,GAAG,YAAY,WACf,GAAG,YAAY,wBACnB,CAAC,CAEA,UACA,GAAG,SAAS,aACZ,sBACA,GAAG,iBAAiB,YAAY,IAAI,GAAG,aAAa,OAAO,CAC3D,CACA,QAAQ,SAAS,IAAK;CAExB,MAAM,UAAU,KAAK,KAAK,SAAS,YAAY,GAAG,cAAc,MAAM;AAEtE,IAAG,cACF,SACA,sCAAsC,UAAU,wIAC/C,GAAG,MACH,GAAG,MACH,QACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { c as getWorkspaceLibPath, d as readWorkspaceNpmManifest, h as readPublishedPackageNpmManifest, o as determineWorkspaceIGLibraries } from "./build-kkMVBBJL.js";
|
|
2
|
+
import "./workspace-D0XY2EMu.js";
|
|
3
|
+
import "./publishedPackage-D-KiU0FG.js";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import * as glob from "glob";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
//#region src/commands/postinstall.ts
|
|
9
|
+
const DEFINITION_FILE_HINT = "// This file is automatically managed by the ig.gfx.packager.";
|
|
10
|
+
const executePostInstall = (workspace) => {
|
|
11
|
+
readWorkspaceNpmManifest(workspace);
|
|
12
|
+
const libPath = getWorkspaceLibPath(workspace);
|
|
13
|
+
fs.mkdirSync(libPath, { recursive: true });
|
|
14
|
+
const existingDefinitions = glob.sync("**/*.d.ts", {
|
|
15
|
+
cwd: libPath,
|
|
16
|
+
absolute: true
|
|
17
|
+
});
|
|
18
|
+
for (const existingDefinitionPath of existingDefinitions) if (fs.readFileSync(existingDefinitionPath, { encoding: "utf-8" }).startsWith(DEFINITION_FILE_HINT)) fs.rmSync(existingDefinitionPath);
|
|
19
|
+
const libraryLocations = determineWorkspaceIGLibraries(workspace);
|
|
20
|
+
for (const location of libraryLocations) {
|
|
21
|
+
const manifest = readPublishedPackageNpmManifest(location);
|
|
22
|
+
for (const existingDefinitionPath of existingDefinitions) if (path.basename(existingDefinitionPath) === manifest.types) fs.rmSync(existingDefinitionPath, { force: true });
|
|
23
|
+
const content = [
|
|
24
|
+
DEFINITION_FILE_HINT,
|
|
25
|
+
`// This is a reference to version ${manifest.version}.`,
|
|
26
|
+
`// Run "npm install" to install the types if they are missing or not up to date.`,
|
|
27
|
+
`/// <reference types="${manifest.name}" />`
|
|
28
|
+
].join(os.EOL);
|
|
29
|
+
fs.writeFileSync(path.join(getWorkspaceLibPath(workspace), manifest.types), content, { encoding: "utf8" });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { executePostInstall };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=postinstall-DHTlEmNr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall-DHTlEmNr.js","names":[],"sources":["../src/commands/postinstall.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport * as glob from \"glob\";\nimport * as os from \"node:os\";\n\nimport {\n\tgetWorkspaceLibPath,\n\treadWorkspaceNpmManifest,\n\ttype WorkspaceLocation,\n} from \"../lib/workspace\";\nimport { readPublishedPackageNpmManifest } from \"../lib/publishedPackage\";\nimport { determineWorkspaceIGLibraries } from \"../lib/dependencies\";\n\nconst DEFINITION_FILE_HINT =\n\t\"// This file is automatically managed by the ig.gfx.packager.\";\n\nexport const executePostInstall = (workspace: WorkspaceLocation) => {\n\tconst manifest = readWorkspaceNpmManifest(workspace);\n\n\tconst libPath = getWorkspaceLibPath(workspace);\n\n\tfs.mkdirSync(libPath, { recursive: true });\n\n\tconst existingDefinitions = glob.sync(\"**/*.d.ts\", {\n\t\tcwd: libPath,\n\t\tabsolute: true,\n\t});\n\n\t// delete all existing definition files that are managed by the packager.\n\t// we'll recreate all needed definitions in the next step.\n\tfor (const existingDefinitionPath of existingDefinitions) {\n\t\tconst content = fs.readFileSync(existingDefinitionPath, {\n\t\t\tencoding: \"utf-8\",\n\t\t});\n\n\t\tif (content.startsWith(DEFINITION_FILE_HINT)) {\n\t\t\tfs.rmSync(existingDefinitionPath);\n\t\t}\n\t}\n\n\tconst libraryLocations = determineWorkspaceIGLibraries(workspace);\n\n\tfor (const location of libraryLocations) {\n\t\tconst manifest = readPublishedPackageNpmManifest(location);\n\n\t\tfor (const existingDefinitionPath of existingDefinitions) {\n\t\t\tconst basename = path.basename(existingDefinitionPath);\n\n\t\t\tif (basename === manifest.types) {\n\t\t\t\tfs.rmSync(existingDefinitionPath, { force: true });\n\t\t\t}\n\t\t}\n\n\t\t// add a hint to the top of the file so we know it's managed by the packager.\n\n\t\tconst content = [\n\t\t\tDEFINITION_FILE_HINT,\n\t\t\t`// This is a reference to version ${manifest.version}.`,\n\t\t\t`// Run \"npm install\" to install the types if they are missing or not up to date.`,\n\t\t\t`/// <reference types=\"${manifest.name}\" />`,\n\t\t].join(os.EOL);\n\n\t\tfs.writeFileSync(\n\t\t\tpath.join(getWorkspaceLibPath(workspace), manifest.types),\n\t\t\tcontent,\n\t\t\t{\n\t\t\t\tencoding: \"utf8\",\n\t\t\t},\n\t\t);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,uBACL;AAED,MAAa,sBAAsB,cAAiC;AAClD,0BAAyB,UAAU;CAEpD,MAAM,UAAU,oBAAoB,UAAU;AAE9C,IAAG,UAAU,SAAS,EAAE,WAAW,MAAM,CAAC;CAE1C,MAAM,sBAAsB,KAAK,KAAK,aAAa;EAClD,KAAK;EACL,UAAU;EACV,CAAC;AAIF,MAAK,MAAM,0BAA0B,oBAKpC,KAJgB,GAAG,aAAa,wBAAwB,EACvD,UAAU,SACV,CAAC,CAEU,WAAW,qBAAqB,CAC3C,IAAG,OAAO,uBAAuB;CAInC,MAAM,mBAAmB,8BAA8B,UAAU;AAEjE,MAAK,MAAM,YAAY,kBAAkB;EACxC,MAAM,WAAW,gCAAgC,SAAS;AAE1D,OAAK,MAAM,0BAA0B,oBAGpC,KAFiB,KAAK,SAAS,uBAAuB,KAErC,SAAS,MACzB,IAAG,OAAO,wBAAwB,EAAE,OAAO,MAAM,CAAC;EAMpD,MAAM,UAAU;GACf;GACA,qCAAqC,SAAS,QAAQ;GACtD;GACA,yBAAyB,SAAS,KAAK;GACvC,CAAC,KAAK,GAAG,IAAI;AAEd,KAAG,cACF,KAAK,KAAK,oBAAoB,UAAU,EAAE,SAAS,MAAM,EACzD,SACA,EACC,UAAU,QACV,CACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { confirm, select } from "@inquirer/prompts";
|
|
2
|
+
//#region src/lib/prompter.ts
|
|
3
|
+
const createDefaultPrompter = () => {
|
|
4
|
+
return {
|
|
5
|
+
confirm: async (message) => {
|
|
6
|
+
return await confirm({ message });
|
|
7
|
+
},
|
|
8
|
+
ask: async (question) => {
|
|
9
|
+
return await select({
|
|
10
|
+
message: question.message,
|
|
11
|
+
choices: question.options,
|
|
12
|
+
default: question.default
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createDefaultPrompter as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=prompter-DONgUlzS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompter-DONgUlzS.js","names":[],"sources":["../src/lib/prompter.ts"],"sourcesContent":["import { confirm, select } from \"@inquirer/prompts\";\n\nexport interface PrompterOption {\n\tname: string;\n\tvalue: string;\n}\n\nexport interface PrompterQuestion {\n\tmessage: string;\n\toptions: PrompterOption[];\n\tdefault?: string;\n}\n\nexport interface Prompter {\n\tconfirm(message: string): Promise<boolean>;\n\n\task(question: PrompterQuestion): Promise<string>;\n}\n\nexport const createDefaultPrompter = (): Prompter => {\n\treturn {\n\t\tconfirm: async (message) => {\n\t\t\tconst result = await confirm({\n\t\t\t\tmessage,\n\t\t\t});\n\t\t\treturn result;\n\t\t},\n\n\t\task: async (question) => {\n\t\t\tconst answer = await select({\n\t\t\t\tmessage: question.message,\n\t\t\t\tchoices: question.options,\n\t\t\t\tdefault: question.default,\n\t\t\t});\n\t\t\treturn answer;\n\t\t},\n\t};\n};\n"],"mappings":";;AAmBA,MAAa,8BAAwC;AACpD,QAAO;EACN,SAAS,OAAO,YAAY;AAI3B,UAHe,MAAM,QAAQ,EAC5B,SACA,CAAC;;EAIH,KAAK,OAAO,aAAa;AAMxB,UALe,MAAM,OAAO;IAC3B,SAAS,SAAS;IAClB,SAAS,SAAS;IAClB,SAAS,SAAS;IAClB,CAAC;;EAGH"}
|