@intelligentgraphics/ig.gfx.packager 3.0.21 → 3.1.0-alpha.1
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.mjs +1 -1
- package/build/{cli-91fabb36.mjs → cli-fec9c069.mjs} +89 -115
- package/build/cli-fec9c069.mjs.map +1 -0
- package/build/{dependencies-7711a9db.mjs → dependencies-d870016d.mjs} +2 -2
- package/build/{dependencies-7711a9db.mjs.map → dependencies-d870016d.mjs.map} +1 -1
- package/build/{generateIndex-47c082d0.mjs → generateIndex-dd0b4563.mjs} +3 -3
- package/build/{generateIndex-47c082d0.mjs.map → generateIndex-dd0b4563.mjs.map} +1 -1
- package/build/{generateParameterType-10d124a6.mjs → generateParameterType-9a671e36.mjs} +4 -4
- package/build/{generateParameterType-10d124a6.mjs.map → generateParameterType-9a671e36.mjs.map} +1 -1
- package/build/{index-e6ead55c.mjs → index-0caf1a6e.mjs} +16 -11
- package/build/index-0caf1a6e.mjs.map +1 -0
- package/build/{index-ca04836f.mjs → index-7fa42d48.mjs} +19 -18
- package/build/index-7fa42d48.mjs.map +1 -0
- package/build/{postinstall-0ea76778.mjs → postinstall-81b6f0b0.mjs} +3 -3
- package/build/{postinstall-0ea76778.mjs.map → postinstall-81b6f0b0.mjs.map} +1 -1
- package/build/{publishNpm-aadd7dc2.mjs → publishNpm-c985bd6e.mjs} +9 -5
- package/build/publishNpm-c985bd6e.mjs.map +1 -0
- package/build/scripts-7ed8dff6.mjs.map +1 -1
- package/build/swc-9ed0f3ce.mjs +60 -0
- package/build/swc-9ed0f3ce.mjs.map +1 -0
- package/build/{versionFile-ad981e93.mjs → versionFile-cbfd3f4a.mjs} +6 -10
- package/build/{versionFile-ad981e93.mjs.map → versionFile-cbfd3f4a.mjs.map} +1 -1
- package/lib/lib.mjs +18 -2520
- package/package.json +8 -8
- package/readme.md +10 -0
- package/build/cli-91fabb36.mjs.map +0 -1
- package/build/index-ca04836f.mjs.map +0 -1
- package/build/index-e6ead55c.mjs.map +0 -1
- package/build/publishNpm-aadd7dc2.mjs.map +0 -1
package/lib/lib.mjs
CHANGED
|
@@ -1,2523 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
export { b as buildFolders, a as buildFoldersWatch, c as generateIndex, r as releaseFolder } from './lib-5a3a2112.mjs';
|
|
2
|
+
import 'path';
|
|
3
|
+
import 'fs/promises';
|
|
4
|
+
import 'terser';
|
|
5
|
+
import 'fs';
|
|
6
|
+
import 'resolve';
|
|
7
7
|
import 'write-pkg';
|
|
8
|
-
import
|
|
8
|
+
import 'glob';
|
|
9
9
|
import 'write-json-file';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
const stripUtf8Bom = (text)=>{
|
|
23
|
-
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
|
|
24
|
-
// conversion translates it to FEFF (UTF-16 BOM).
|
|
25
|
-
if (text.charCodeAt(0) === 0xfeff) {
|
|
26
|
-
return text.slice(1);
|
|
27
|
-
}
|
|
28
|
-
return text;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const readNpmManifest = (directory)=>{
|
|
32
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
33
|
-
const packageJson = stripUtf8Bom(fs.readFileSync(packageJsonPath, {
|
|
34
|
-
encoding: "utf8"
|
|
35
|
-
}));
|
|
36
|
-
return JSON.parse(packageJson);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getNodeErrorCode = (error)=>{
|
|
40
|
-
if (error !== null && typeof error === "object" && error.code !== undefined) {
|
|
41
|
-
return error.code;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Permission denied: An attempt was made to access a file in a way forbidden by its file access permissions.
|
|
46
|
-
*
|
|
47
|
-
* @param {unknown} error
|
|
48
|
-
*/ const isErrorEACCES = (error)=>getNodeErrorCode(error) === "EACCES";
|
|
49
|
-
/**
|
|
50
|
-
* No such file or directory: Commonly raised by fs operations to indicate that a component of the specified pathname does not exist. No entity (file or directory) could be found by the given path.
|
|
51
|
-
*
|
|
52
|
-
* @param {unknown} error
|
|
53
|
-
*/ const isErrorENOENT = (error)=>getNodeErrorCode(error) === "ENOENT";
|
|
54
|
-
const isErrorEPERM = (error)=>getNodeErrorCode(error) === "EPERM";
|
|
55
|
-
|
|
56
|
-
// Functionality related to working with a single package.
|
|
57
|
-
const PACKAGE_FILE = "_Package.json";
|
|
58
|
-
const INDEX_FILE = "_Index.json";
|
|
59
|
-
const ANIMATION_FILE_SUFFIX = ".animation.json";
|
|
60
|
-
const parseCreatorPackageName = (manifest)=>{
|
|
61
|
-
const [domain, subdomain] = manifest.Package.split(".");
|
|
62
|
-
return {
|
|
63
|
-
domain,
|
|
64
|
-
subdomain
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
const readPackageCreatorManifest = (location)=>{
|
|
68
|
-
const packageJsonPath = path.join(location.manifestDir, PACKAGE_FILE);
|
|
69
|
-
const packageJson = stripUtf8Bom(fs.readFileSync(packageJsonPath, {
|
|
70
|
-
encoding: "utf8"
|
|
71
|
-
}));
|
|
72
|
-
return JSON.parse(packageJson);
|
|
73
|
-
};
|
|
74
|
-
const writePackageCreatorManifest = (location, creatorPackage)=>{
|
|
75
|
-
const packageJsonPath = path.join(location.manifestDir, PACKAGE_FILE);
|
|
76
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(creatorPackage, null, "\t") + "\n");
|
|
77
|
-
};
|
|
78
|
-
const getPackageCreatorIndexPath = (location)=>path.join(location.manifestDir, INDEX_FILE);
|
|
79
|
-
const readPackageCreatorIndex = (location)=>{
|
|
80
|
-
try {
|
|
81
|
-
const indexPath = getPackageCreatorIndexPath(location);
|
|
82
|
-
const index = stripUtf8Bom(fs.readFileSync(indexPath, {
|
|
83
|
-
encoding: "utf8"
|
|
84
|
-
}));
|
|
85
|
-
return JSON.parse(index);
|
|
86
|
-
} catch (err) {
|
|
87
|
-
if (isErrorENOENT(err)) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
throw err;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const writePackageCreatorIndex = (location, index)=>{
|
|
94
|
-
const indexPath = getPackageCreatorIndexPath(location);
|
|
95
|
-
fs.writeFileSync(indexPath, JSON.stringify(index, null, "\t") + "\n");
|
|
96
|
-
};
|
|
97
|
-
const readPackageNpmManifest = (location)=>{
|
|
98
|
-
try {
|
|
99
|
-
return readNpmManifest(location.manifestDir);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
if (isErrorENOENT(err)) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const readPackageAnimationList = (location)=>{
|
|
108
|
-
const directoryContent = fs.readdirSync(location.manifestDir);
|
|
109
|
-
const animationPathList = [];
|
|
110
|
-
for (const entry of directoryContent){
|
|
111
|
-
if (entry.endsWith(ANIMATION_FILE_SUFFIX)) {
|
|
112
|
-
const animationPath = path.join(location.manifestDir, entry);
|
|
113
|
-
animationPathList.push(animationPath);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return animationPathList;
|
|
117
|
-
};
|
|
118
|
-
const getPackageReleasesDirectory = (location)=>path.join(location.path, "Releases");
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Detects a published package from a path.
|
|
122
|
-
*
|
|
123
|
-
* Can return undefined if the package is not installed.
|
|
124
|
-
*
|
|
125
|
-
* @param {string} resolveBasePath
|
|
126
|
-
* @param {string} name
|
|
127
|
-
* @return {*} {(PublishedPackageLocation | undefined)}
|
|
128
|
-
*/ const detectPublishedPackageFromPath = (resolveBasePath, name)=>{
|
|
129
|
-
try {
|
|
130
|
-
const manifestPath = resolve.sync(name + "/package.json", {
|
|
131
|
-
basedir: resolveBasePath
|
|
132
|
-
});
|
|
133
|
-
const dir = path.dirname(manifestPath);
|
|
134
|
-
return {
|
|
135
|
-
_kind: "PublishedPackageLocation",
|
|
136
|
-
path: dir
|
|
137
|
-
};
|
|
138
|
-
} catch (err) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const readPublishedPackageNpmManifest = (location)=>{
|
|
143
|
-
return readNpmManifest(location.path);
|
|
144
|
-
};
|
|
145
|
-
const readPublishedPackageCreatorManifest = (location)=>{
|
|
146
|
-
try {
|
|
147
|
-
const packageJsonPath = path.join(location.path, PACKAGE_FILE);
|
|
148
|
-
const packageJson = stripUtf8Bom(fs.readFileSync(packageJsonPath, {
|
|
149
|
-
encoding: "utf8"
|
|
150
|
-
}));
|
|
151
|
-
return JSON.parse(packageJson);
|
|
152
|
-
} catch (err) {
|
|
153
|
-
if (isErrorENOENT(err)) {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
throw err;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const readPublishedPackageCreatorIndex = (location)=>{
|
|
160
|
-
try {
|
|
161
|
-
const packageJsonPath = path.join(location.path, INDEX_FILE);
|
|
162
|
-
const packageJson = stripUtf8Bom(fs.readFileSync(packageJsonPath, {
|
|
163
|
-
encoding: "utf8"
|
|
164
|
-
}));
|
|
165
|
-
const result = JSON.parse(packageJson);
|
|
166
|
-
return result;
|
|
167
|
-
} catch (err) {
|
|
168
|
-
if (isErrorENOENT(err)) {
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
|
-
throw err;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const readWorkspaceNpmManifest = (workspace)=>{
|
|
176
|
-
try {
|
|
177
|
-
return readNpmManifest(workspace.path);
|
|
178
|
-
} catch (err) {
|
|
179
|
-
if (isErrorENOENT(err)) {
|
|
180
|
-
throw new Error(`Expected a package.json file to exist in ${workspace.path}. See packager readme for instructions on how to create the package.json.`);
|
|
181
|
-
}
|
|
182
|
-
throw err;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const getWorkspaceOutputPath = (workspace)=>path.join(workspace.path, "bin");
|
|
186
|
-
|
|
187
|
-
// /**
|
|
188
|
-
// * Determines the implicit dependencies of a an actual data workspace package.
|
|
189
|
-
// *
|
|
190
|
-
// * An implicit dependency is a dependency that is installed for the workspace and has the same runtime environment (evaluator, interactor) as the package.
|
|
191
|
-
// *
|
|
192
|
-
// * @param {WorkspaceLocation} workspace
|
|
193
|
-
// * @param {CreatorPackage} creatorPackage
|
|
194
|
-
// * @returns {PublishedPackageLocation[]}
|
|
195
|
-
// */
|
|
196
|
-
// export const determinePackageImplicitDependencies = (
|
|
197
|
-
// workspace: WorkspaceLocation,
|
|
198
|
-
// creatorPackage: CreatorPackage,
|
|
199
|
-
// ): PublishedPackageLocation[] => {
|
|
200
|
-
// const libraries = determineWorkspaceIGLibraries(workspace);
|
|
201
|
-
// const results: PublishedPackageLocation[] = [];
|
|
202
|
-
// for (const librarylocation of libraries) {
|
|
203
|
-
// const libraryManifest =
|
|
204
|
-
// readPublishedPackageCreatorManifest(librarylocation);
|
|
205
|
-
// if (
|
|
206
|
-
// libraryManifest !== undefined &&
|
|
207
|
-
// (libraryManifest.Type === "Mixed" ||
|
|
208
|
-
// libraryManifest.RunTime === creatorPackage.RunTime)
|
|
209
|
-
// ) {
|
|
210
|
-
// results.push(librarylocation);
|
|
211
|
-
// }
|
|
212
|
-
// }
|
|
213
|
-
// return results;
|
|
214
|
-
// };
|
|
215
|
-
/**
|
|
216
|
-
* Recursively determines all installed ig libraries for a workspace.
|
|
217
|
-
*
|
|
218
|
-
* @param {WorkspaceLocation} workspace
|
|
219
|
-
* @returns {PublishedPackageLocation[]}
|
|
220
|
-
*/ const determineWorkspaceIGLibraries = (workspace)=>{
|
|
221
|
-
const manifest = readWorkspaceNpmManifest(workspace);
|
|
222
|
-
const libraries = collectIGLibraries(workspace, manifest);
|
|
223
|
-
const results = new Map();
|
|
224
|
-
for (const location of libraries){
|
|
225
|
-
const manifest = readPublishedPackageNpmManifest(location);
|
|
226
|
-
if (!results.has(manifest.name)) {
|
|
227
|
-
results.set(manifest.name, location);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return Array.from(results.values());
|
|
231
|
-
};
|
|
232
|
-
const collectIGLibraries = (workspace, manifest)=>{
|
|
233
|
-
if (!manifest.dependencies) {
|
|
234
|
-
return [];
|
|
235
|
-
}
|
|
236
|
-
const runtimeDependencies = Object.getOwnPropertyNames(manifest.dependencies);
|
|
237
|
-
const result = [];
|
|
238
|
-
for (const runtimeDependency of runtimeDependencies){
|
|
239
|
-
var _runtimeManifest_ig;
|
|
240
|
-
const location = detectPublishedPackageFromPath(workspace.path, runtimeDependency);
|
|
241
|
-
if (location === undefined) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
const runtimeManifest = readPublishedPackageNpmManifest(location);
|
|
245
|
-
// packages need to explicitly be marked as ig scriptingLibraries
|
|
246
|
-
if ((_runtimeManifest_ig = runtimeManifest.ig) == null ? void 0 : _runtimeManifest_ig.scriptingLibrary) {
|
|
247
|
-
result.push(location);
|
|
248
|
-
result.push(...collectIGLibraries(workspace, runtimeManifest));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return result;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const readStringFromFile = (filePath)=>fs.readFileSync(filePath, {
|
|
255
|
-
encoding: "utf8"
|
|
256
|
-
});
|
|
257
|
-
const readStringFromFileOrUndefined = (filePath)=>{
|
|
258
|
-
try {
|
|
259
|
-
return readStringFromFile(filePath);
|
|
260
|
-
} catch (err) {
|
|
261
|
-
if (!isErrorENOENT(err)) {
|
|
262
|
-
throw err;
|
|
263
|
-
}
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
const logPackageMessage = (name, step, index, total, maxNameLength = 15)=>{
|
|
269
|
-
const numLength = total === undefined ? undefined : total.toString().length;
|
|
270
|
-
const indexString = total === undefined || total < 2 ? "" : `${index.toString().padStart(numLength, "0")}/${total} `;
|
|
271
|
-
const identifierString = `${indexString}${name.padEnd(maxNameLength)}`;
|
|
272
|
-
console.log(`${identifierString} >> ${step}`);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const getPackageTypescriptFiles = (location)=>glob.sync("**/*.ts", {
|
|
276
|
-
absolute: true,
|
|
277
|
-
cwd: location.scriptsDir,
|
|
278
|
-
ignore: "node_modules/**/*"
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
const PLUGIN_ID = "0feba3a0-b6d1-11e6-9598-0800200c9a66";
|
|
282
|
-
/**
|
|
283
|
-
* Starts an IG.Asset.Server session and returns the sessionId
|
|
284
|
-
*
|
|
285
|
-
* @param {SessionStartParams} params
|
|
286
|
-
* @returns
|
|
287
|
-
*/ const startSession = async ({ url , authentication , ...params })=>{
|
|
288
|
-
const payload = {
|
|
289
|
-
...params,
|
|
290
|
-
user: undefined,
|
|
291
|
-
password: undefined,
|
|
292
|
-
license: undefined,
|
|
293
|
-
plugin: PLUGIN_ID
|
|
294
|
-
};
|
|
295
|
-
if (authentication.type === "credentials") {
|
|
296
|
-
payload.user = authentication.username;
|
|
297
|
-
payload.password = authentication.password;
|
|
298
|
-
} else if (authentication.type === "license") {
|
|
299
|
-
payload.license = authentication.license;
|
|
300
|
-
}
|
|
301
|
-
const { data: { session: sessionId , state , response } } = await axios.post(`Session/Start2`, JSON.stringify(payload), {
|
|
302
|
-
baseURL: url
|
|
303
|
-
});
|
|
304
|
-
if (state !== "SUCCESS") {
|
|
305
|
-
let message = `Could not start session. IG.Asset.Server responded with ${state}`;
|
|
306
|
-
if (response) {
|
|
307
|
-
message += `: ${response}`;
|
|
308
|
-
}
|
|
309
|
-
throw new Error(message);
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
_kind: "AssetService",
|
|
313
|
-
url,
|
|
314
|
-
sessionId,
|
|
315
|
-
domain: params.domain,
|
|
316
|
-
subDomain: params.subDomain
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
const closeSession = async (session)=>{
|
|
320
|
-
await axios.get(`Session/Close/${session.sessionId}`, {
|
|
321
|
-
baseURL: session.url
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
const uploadPackageFromStream = async (session, { name , version }, stream)=>{
|
|
325
|
-
await uploadPackageToUrl(session.url, `UploadPackage/${session.sessionId}/${name}_${version}/`, stream);
|
|
326
|
-
};
|
|
327
|
-
const uploadPackageToUrl = async (url, path, stream)=>{
|
|
328
|
-
const { data , status } = await axios.post(path, stream, {
|
|
329
|
-
baseURL: url
|
|
330
|
-
});
|
|
331
|
-
let objectBody;
|
|
332
|
-
if (typeof data === "string") {
|
|
333
|
-
try {
|
|
334
|
-
objectBody = JSON.parse(data);
|
|
335
|
-
} catch (err) {}
|
|
336
|
-
} else if (typeof data === "object") {
|
|
337
|
-
objectBody = data;
|
|
338
|
-
}
|
|
339
|
-
if (objectBody !== undefined) {
|
|
340
|
-
if ("state" in objectBody && objectBody.state !== "SUCCESS") {
|
|
341
|
-
throw new Error(objectBody.response ?? objectBody.state);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (status >= 400) {
|
|
345
|
-
if (objectBody !== undefined) {
|
|
346
|
-
let text_1 = "";
|
|
347
|
-
for(const key in objectBody){
|
|
348
|
-
text_1 += key + ": \n";
|
|
349
|
-
if (typeof objectBody[key] === "object") {
|
|
350
|
-
text_1 += JSON.stringify(objectBody[key], undefined, 2);
|
|
351
|
-
} else {
|
|
352
|
-
text_1 += objectBody[key];
|
|
353
|
-
}
|
|
354
|
-
text_1 += "\n\n";
|
|
355
|
-
}
|
|
356
|
-
throw new Error(text_1);
|
|
357
|
-
}
|
|
358
|
-
throw new Error(data);
|
|
359
|
-
}
|
|
360
|
-
return data;
|
|
361
|
-
};
|
|
362
|
-
const getExistingPackages = async (session)=>{
|
|
363
|
-
const { data } = await axios.get(`Script/GetInformation/${session.sessionId}`, {
|
|
364
|
-
baseURL: session.url,
|
|
365
|
-
validateStatus: (status)=>status === 404 || status === 200
|
|
366
|
-
}).catch((err)=>{
|
|
367
|
-
throw new Error(`Failed to get existing packages: ${err.message}`);
|
|
368
|
-
});
|
|
369
|
-
return data;
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
const tryReadTsConfig = (location)=>{
|
|
373
|
-
const { config } = ts.readConfigFile(path.join(location.scriptsDir, "tsconfig.json"), (path)=>{
|
|
374
|
-
try {
|
|
375
|
-
return fs.readFileSync(path, "utf8");
|
|
376
|
-
} catch {
|
|
377
|
-
return undefined;
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
return config;
|
|
381
|
-
};
|
|
382
|
-
const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
|
|
383
|
-
const files = getPackageTypescriptFiles(location);
|
|
384
|
-
if (files.length === 0) {
|
|
385
|
-
env.onBuildStart();
|
|
386
|
-
env.onBuildEnd({
|
|
387
|
-
type: "success",
|
|
388
|
-
artefacts: {
|
|
389
|
-
js: "",
|
|
390
|
-
definitions: ""
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
return {
|
|
394
|
-
destroy: ()=>{}
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
env.onBuildStart();
|
|
399
|
-
const compilerOptions = getCompilerOptions(location, outputDir);
|
|
400
|
-
const host = ts.createCompilerHost(compilerOptions);
|
|
401
|
-
host.getCurrentDirectory = ()=>location.scriptsDir;
|
|
402
|
-
let js;
|
|
403
|
-
let definitions;
|
|
404
|
-
let sourceMap;
|
|
405
|
-
host.writeFile = (fileName, data, writeByteOrderMark)=>{
|
|
406
|
-
if (fileName.endsWith(".js")) {
|
|
407
|
-
js = data;
|
|
408
|
-
} else if (fileName.endsWith(".d.ts")) {
|
|
409
|
-
definitions = data;
|
|
410
|
-
} else if (fileName.endsWith(".js.map")) {
|
|
411
|
-
sourceMap = data;
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
const programOptions = {
|
|
415
|
-
rootNames: files,
|
|
416
|
-
options: compilerOptions,
|
|
417
|
-
host
|
|
418
|
-
};
|
|
419
|
-
const program = ts.createProgram(programOptions);
|
|
420
|
-
const emitResult = program.emit();
|
|
421
|
-
const allDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
422
|
-
if (!emitResult.emitSkipped) {
|
|
423
|
-
if (allDiagnostics.length > 0) {
|
|
424
|
-
console.log(allDiagnostics.map(createErrorMessage).join("\n"));
|
|
425
|
-
}
|
|
426
|
-
if (js === undefined || definitions === undefined) {
|
|
427
|
-
throw new Error(`Unexpected: no js or definitions were created`);
|
|
428
|
-
}
|
|
429
|
-
env.onBuildEnd({
|
|
430
|
-
type: "success",
|
|
431
|
-
artefacts: {
|
|
432
|
-
js: js.replace(`//# sourceMappingURL=out.js.map`, ""),
|
|
433
|
-
definitions,
|
|
434
|
-
sourceMap
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
} else {
|
|
438
|
-
const error = allDiagnostics.map(createErrorMessage).join("\n");
|
|
439
|
-
throw new Error(error);
|
|
440
|
-
}
|
|
441
|
-
} catch (err) {
|
|
442
|
-
env.onBuildEnd({
|
|
443
|
-
type: "error",
|
|
444
|
-
error: err.message
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
return {
|
|
448
|
-
destroy: ()=>{}
|
|
449
|
-
};
|
|
450
|
-
};
|
|
451
|
-
const createTSCWatchBuildParticipant = (location, outputDir)=>{
|
|
452
|
-
return ({ onBuildStart , onBuildEnd })=>{
|
|
453
|
-
let state = {
|
|
454
|
-
diagnostics: [],
|
|
455
|
-
js: undefined,
|
|
456
|
-
definitions: undefined,
|
|
457
|
-
sourceMap: undefined
|
|
458
|
-
};
|
|
459
|
-
const customSys = {
|
|
460
|
-
...ts.sys,
|
|
461
|
-
writeFile: (fileName, data, writeByteOrderMark)=>{
|
|
462
|
-
if (fileName.endsWith(".js")) {
|
|
463
|
-
state.js = data;
|
|
464
|
-
} else if (fileName.endsWith(".d.ts")) {
|
|
465
|
-
state.definitions = data;
|
|
466
|
-
} else if (fileName.endsWith(".js.map")) {
|
|
467
|
-
state.sourceMap = data;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
const reportDiagnostic = (diagnostic)=>{
|
|
472
|
-
switch(diagnostic.code){
|
|
473
|
-
// file not found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4640
|
|
474
|
-
// probably deleted -> ignore
|
|
475
|
-
case 6053:
|
|
476
|
-
return;
|
|
477
|
-
// no inputs were found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L6838
|
|
478
|
-
// we don't care about this error. a user might have temporarily deleted the last ts file and will readd one later.
|
|
479
|
-
case 18003:
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
state.diagnostics.push(diagnostic);
|
|
483
|
-
};
|
|
484
|
-
const reportWatchStatusChanged = (diagnostic)=>{
|
|
485
|
-
switch(diagnostic.code){
|
|
486
|
-
// regular watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4567
|
|
487
|
-
case 6031:
|
|
488
|
-
// incremental watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4571
|
|
489
|
-
case 6032:
|
|
490
|
-
// build start
|
|
491
|
-
onBuildStart();
|
|
492
|
-
break;
|
|
493
|
-
// found one error - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5119
|
|
494
|
-
case 6193:
|
|
495
|
-
// found n or 0 errors - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5123
|
|
496
|
-
case 6194:
|
|
497
|
-
// build end
|
|
498
|
-
const emitState = state;
|
|
499
|
-
state = {
|
|
500
|
-
diagnostics: [],
|
|
501
|
-
js: undefined,
|
|
502
|
-
definitions: undefined,
|
|
503
|
-
sourceMap: undefined
|
|
504
|
-
};
|
|
505
|
-
if (emitState.diagnostics.length > 0) {
|
|
506
|
-
const message = emitState.diagnostics.map(createErrorMessage).join("\n");
|
|
507
|
-
onBuildEnd({
|
|
508
|
-
type: "error",
|
|
509
|
-
error: message
|
|
510
|
-
});
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (emitState.js === undefined || emitState.definitions === undefined) {
|
|
514
|
-
onBuildEnd({
|
|
515
|
-
type: "success",
|
|
516
|
-
artefacts: {
|
|
517
|
-
js: ""
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
onBuildEnd({
|
|
523
|
-
type: "success",
|
|
524
|
-
artefacts: {
|
|
525
|
-
js: emitState.js.replace(`//# sourceMappingURL=out.js.map`, ""),
|
|
526
|
-
definitions: emitState.definitions,
|
|
527
|
-
sourceMap: emitState.sourceMap
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
break;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
const host = ts.createWatchCompilerHost(path.join(location.scriptsDir, "tsconfig.json"), getCompilerOptions(location, outputDir), customSys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
|
|
534
|
-
const watchProgram = ts.createWatchProgram(host);
|
|
535
|
-
const files = getPackageTypescriptFiles(location);
|
|
536
|
-
if (files.length === 0) {
|
|
537
|
-
onBuildStart();
|
|
538
|
-
onBuildEnd({
|
|
539
|
-
type: "success",
|
|
540
|
-
artefacts: {
|
|
541
|
-
js: "",
|
|
542
|
-
definitions: ""
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
return {
|
|
547
|
-
destroy: ()=>{
|
|
548
|
-
watchProgram.close();
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
};
|
|
552
|
-
};
|
|
553
|
-
const createErrorMessage = (diagnostic)=>{
|
|
554
|
-
if (!diagnostic.file) {
|
|
555
|
-
return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
|
|
556
|
-
}
|
|
557
|
-
const { line , character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
558
|
-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
559
|
-
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
|
|
560
|
-
};
|
|
561
|
-
const getCompilerOptions = (location, outputDir)=>{
|
|
562
|
-
const config = tryReadTsConfig(location);
|
|
563
|
-
config.compilerOptions.lib = [
|
|
564
|
-
"es5",
|
|
565
|
-
"dom"
|
|
566
|
-
];
|
|
567
|
-
const result = ts.convertCompilerOptionsFromJson(config.compilerOptions, location.scriptsDir);
|
|
568
|
-
const compilerOptions = {
|
|
569
|
-
...result.options,
|
|
570
|
-
removeComments: false,
|
|
571
|
-
declaration: true,
|
|
572
|
-
sourceMap: true,
|
|
573
|
-
inlineSources: false,
|
|
574
|
-
// We don't use tsc to actually emit the files, but we still need to set the correct
|
|
575
|
-
// output directory so the compiler can rewrite the `reference path` directives.
|
|
576
|
-
outFile: path.join(outputDir, "out.js"),
|
|
577
|
-
target: ts.ScriptTarget.ES5,
|
|
578
|
-
noEmitOnError: true
|
|
579
|
-
};
|
|
580
|
-
return compilerOptions;
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
const generateDocs = async (location, declarationFile, outFolder, name)=>{
|
|
584
|
-
const app = new typedoc.Application();
|
|
585
|
-
const mediaDir = path.join(location.manifestDir, "Media");
|
|
586
|
-
app.bootstrap({
|
|
587
|
-
entryPoints: [
|
|
588
|
-
declarationFile
|
|
589
|
-
],
|
|
590
|
-
media: mediaDir,
|
|
591
|
-
out: outFolder,
|
|
592
|
-
tsconfig: path.join(location.scriptsDir, "tsconfig.json"),
|
|
593
|
-
skipErrorChecking: true
|
|
594
|
-
});
|
|
595
|
-
app.options.setCompilerOptions([
|
|
596
|
-
declarationFile
|
|
597
|
-
], {
|
|
598
|
-
target: ts.ScriptTarget.ES5
|
|
599
|
-
}, undefined);
|
|
600
|
-
app.options.setValue("name", name);
|
|
601
|
-
const [readmePath] = glob.sync("**/readme.md", {
|
|
602
|
-
absolute: true,
|
|
603
|
-
cwd: location.manifestDir
|
|
604
|
-
});
|
|
605
|
-
if (readmePath) {
|
|
606
|
-
app.options.setValue("readme", readmePath);
|
|
607
|
-
}
|
|
608
|
-
const project = app.convert();
|
|
609
|
-
if (project) {
|
|
610
|
-
await app.generateDocs(project, outFolder);
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
// Stolen from ig.tools.core
|
|
615
|
-
const toposort = (packages)=>{
|
|
616
|
-
const queue = Object.getOwnPropertyNames(packages);
|
|
617
|
-
const result = [];
|
|
618
|
-
let index = 0;
|
|
619
|
-
while(queue.length > 0){
|
|
620
|
-
if (index >= queue.length) {
|
|
621
|
-
throw new Error("Packages can not have cyclic dependencies");
|
|
622
|
-
}
|
|
623
|
-
const queueEntry = queue[index];
|
|
624
|
-
const dependencies = packages[queueEntry];
|
|
625
|
-
const dependencyQueued = dependencies.some((dependency)=>queue.includes(dependency));
|
|
626
|
-
if (dependencyQueued) {
|
|
627
|
-
index++;
|
|
628
|
-
continue;
|
|
629
|
-
}
|
|
630
|
-
queue.splice(index, 1);
|
|
631
|
-
index = 0;
|
|
632
|
-
result.push(queueEntry);
|
|
633
|
-
}
|
|
634
|
-
return result;
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
class BuildManager extends EventEmitter {
|
|
638
|
-
constructor(manifest, writer, logStep){
|
|
639
|
-
super();
|
|
640
|
-
this.manifest = manifest;
|
|
641
|
-
this.writer = writer;
|
|
642
|
-
this.logStep = logStep;
|
|
643
|
-
this.participants = new Map();
|
|
644
|
-
this.states = new Map();
|
|
645
|
-
}
|
|
646
|
-
addParticipant(name, participant) {
|
|
647
|
-
this.participants.set(name, participant);
|
|
648
|
-
}
|
|
649
|
-
run() {
|
|
650
|
-
for (const [name] of this.participants){
|
|
651
|
-
this.states.set(name, {
|
|
652
|
-
type: "busy"
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
this.emit("start");
|
|
656
|
-
for (const [name, participant] of this.participants){
|
|
657
|
-
participant({
|
|
658
|
-
onBuildStart: ()=>{
|
|
659
|
-
let alreadyBusy = false;
|
|
660
|
-
for (const [name, state] of this.states){
|
|
661
|
-
if (state.type === "busy") {
|
|
662
|
-
alreadyBusy = true;
|
|
663
|
-
continue;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
this.states.set(name, {
|
|
667
|
-
type: "busy"
|
|
668
|
-
});
|
|
669
|
-
if (!alreadyBusy) {
|
|
670
|
-
this.emit("start");
|
|
671
|
-
}
|
|
672
|
-
},
|
|
673
|
-
onBuildEnd: (result)=>{
|
|
674
|
-
this.states.set(name, result);
|
|
675
|
-
this.maybeEmit();
|
|
676
|
-
},
|
|
677
|
-
log: this.logStep
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
maybeEmit() {
|
|
682
|
-
const errors = [];
|
|
683
|
-
const results = [];
|
|
684
|
-
for (const [_, state] of this.states){
|
|
685
|
-
if (state.type === "busy") {
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
if (state.type === "success") {
|
|
689
|
-
results.push(state);
|
|
690
|
-
} else if (state.type === "error") {
|
|
691
|
-
errors.push(state.error);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (errors.length > 0) {
|
|
695
|
-
this.emit("error", errors.join("\n"));
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
const completeResult = {
|
|
699
|
-
js: ""
|
|
700
|
-
};
|
|
701
|
-
const sourceMapGenerator = new SourceMapGenerator();
|
|
702
|
-
for (const result of results){
|
|
703
|
-
if (result.artefacts.js) {
|
|
704
|
-
if (completeResult.js) {
|
|
705
|
-
completeResult.js += "\n";
|
|
706
|
-
}
|
|
707
|
-
if (result.artefacts.sourceMap) {
|
|
708
|
-
const lines = completeResult.js.split("\n").length - 1;
|
|
709
|
-
const sourceMap = new SourceMapConsumer(JSON.parse(result.artefacts.sourceMap));
|
|
710
|
-
const sources = new Set();
|
|
711
|
-
sourceMap.eachMapping((mapping)=>{
|
|
712
|
-
sourceMapGenerator.addMapping({
|
|
713
|
-
generated: {
|
|
714
|
-
line: lines + mapping.generatedLine,
|
|
715
|
-
column: mapping.generatedColumn
|
|
716
|
-
},
|
|
717
|
-
original: {
|
|
718
|
-
line: mapping.originalLine,
|
|
719
|
-
column: mapping.originalColumn
|
|
720
|
-
},
|
|
721
|
-
source: mapping.source,
|
|
722
|
-
name: mapping.name
|
|
723
|
-
});
|
|
724
|
-
sources.add(mapping.source);
|
|
725
|
-
});
|
|
726
|
-
for (const source of sources){
|
|
727
|
-
const content = sourceMap.sourceContentFor(source);
|
|
728
|
-
if (content !== null) {
|
|
729
|
-
sourceMapGenerator.setSourceContent(source, content);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
completeResult.js += result.artefacts.js;
|
|
734
|
-
}
|
|
735
|
-
if (result.artefacts.definitions) {
|
|
736
|
-
if (completeResult.definitions) {
|
|
737
|
-
completeResult.definitions += "\n";
|
|
738
|
-
} else {
|
|
739
|
-
completeResult.definitions = "";
|
|
740
|
-
}
|
|
741
|
-
completeResult.definitions += result.artefacts.definitions;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
completeResult.sourceMap = sourceMapGenerator.toString();
|
|
745
|
-
this.writer(completeResult).then(()=>{
|
|
746
|
-
this.emit("build");
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
var animationSchema = {
|
|
752
|
-
$schema: "http://json-schema.org/draft-07/schema",
|
|
753
|
-
$id: "https://archive.intelligentgraphics.biz/schemas/gfx/animation.json",
|
|
754
|
-
$comment: "Version 2023-02-17, Source: ig.data.gfx/Specs/animation.json",
|
|
755
|
-
title: "Animation description format",
|
|
756
|
-
additionalProperties: false,
|
|
757
|
-
type: "object",
|
|
758
|
-
properties: {
|
|
759
|
-
$schema: {
|
|
760
|
-
type: "string"
|
|
761
|
-
},
|
|
762
|
-
Id: {
|
|
763
|
-
type: "string",
|
|
764
|
-
description: "Animation id, to be unique in the project scope. Needs to be a valid JavaScript identifier."
|
|
765
|
-
},
|
|
766
|
-
Animations: {
|
|
767
|
-
type: "array",
|
|
768
|
-
description: "Declaration of animation states for gfx objects",
|
|
769
|
-
items: {
|
|
770
|
-
type: "object",
|
|
771
|
-
additionalProperties: false,
|
|
772
|
-
properties: {
|
|
773
|
-
_: {
|
|
774
|
-
type: "string",
|
|
775
|
-
description: "Comment"
|
|
776
|
-
},
|
|
777
|
-
Path: {
|
|
778
|
-
$ref: "#/definitions/igxcPath"
|
|
779
|
-
},
|
|
780
|
-
States: {
|
|
781
|
-
type: "object",
|
|
782
|
-
additionalProperties: {
|
|
783
|
-
type: "object",
|
|
784
|
-
additionalProperties: false,
|
|
785
|
-
properties: {
|
|
786
|
-
Position: {
|
|
787
|
-
$ref: "#/definitions/vec3"
|
|
788
|
-
},
|
|
789
|
-
Rotation: {
|
|
790
|
-
$ref: "#/definitions/rotation"
|
|
791
|
-
},
|
|
792
|
-
Scaling: {
|
|
793
|
-
$ref: "#/definitions/vec3"
|
|
794
|
-
},
|
|
795
|
-
Visibility: {
|
|
796
|
-
type: "boolean"
|
|
797
|
-
},
|
|
798
|
-
Deformation: {
|
|
799
|
-
anyOf: [
|
|
800
|
-
{
|
|
801
|
-
type: "number"
|
|
802
|
-
},
|
|
803
|
-
{
|
|
804
|
-
type: "string"
|
|
805
|
-
}
|
|
806
|
-
]
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
},
|
|
814
|
-
Kinematics: {
|
|
815
|
-
oneOf: [
|
|
816
|
-
{
|
|
817
|
-
$ref: "#/definitions/kinematicChain"
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
type: "array",
|
|
821
|
-
items: {
|
|
822
|
-
$ref: "#/definitions/kinematicChain"
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
]
|
|
826
|
-
},
|
|
827
|
-
LinkedPoints: {
|
|
828
|
-
type: "object",
|
|
829
|
-
additionalProperties: {
|
|
830
|
-
type: "array",
|
|
831
|
-
items: {
|
|
832
|
-
type: "string"
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
_: {
|
|
837
|
-
type: "string",
|
|
838
|
-
description: "Comment"
|
|
839
|
-
}
|
|
840
|
-
},
|
|
841
|
-
definitions: {
|
|
842
|
-
vec3: {
|
|
843
|
-
type: "object",
|
|
844
|
-
additionalProperties: false,
|
|
845
|
-
properties: {
|
|
846
|
-
X: {
|
|
847
|
-
anyOf: [
|
|
848
|
-
{
|
|
849
|
-
type: "number"
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
type: "string"
|
|
853
|
-
}
|
|
854
|
-
]
|
|
855
|
-
},
|
|
856
|
-
Y: {
|
|
857
|
-
anyOf: [
|
|
858
|
-
{
|
|
859
|
-
type: "number"
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
type: "string"
|
|
863
|
-
}
|
|
864
|
-
]
|
|
865
|
-
},
|
|
866
|
-
Z: {
|
|
867
|
-
anyOf: [
|
|
868
|
-
{
|
|
869
|
-
type: "number"
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
type: "string"
|
|
873
|
-
}
|
|
874
|
-
]
|
|
875
|
-
},
|
|
876
|
-
_: {
|
|
877
|
-
type: "string",
|
|
878
|
-
description: "Comment"
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
},
|
|
882
|
-
rotation: {
|
|
883
|
-
type: "object",
|
|
884
|
-
additionalProperties: false,
|
|
885
|
-
properties: {
|
|
886
|
-
Q: {
|
|
887
|
-
description: "If true, the rotation is considered to be a Quaternion. Otherwise, it's interpreted as Euler arcs and W will be ignored.",
|
|
888
|
-
type: "boolean"
|
|
889
|
-
},
|
|
890
|
-
X: {
|
|
891
|
-
anyOf: [
|
|
892
|
-
{
|
|
893
|
-
type: "number"
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
type: "string"
|
|
897
|
-
}
|
|
898
|
-
]
|
|
899
|
-
},
|
|
900
|
-
Y: {
|
|
901
|
-
anyOf: [
|
|
902
|
-
{
|
|
903
|
-
type: "number"
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
type: "string"
|
|
907
|
-
}
|
|
908
|
-
]
|
|
909
|
-
},
|
|
910
|
-
Z: {
|
|
911
|
-
anyOf: [
|
|
912
|
-
{
|
|
913
|
-
type: "number"
|
|
914
|
-
},
|
|
915
|
-
{
|
|
916
|
-
type: "string"
|
|
917
|
-
}
|
|
918
|
-
]
|
|
919
|
-
},
|
|
920
|
-
W: {
|
|
921
|
-
anyOf: [
|
|
922
|
-
{
|
|
923
|
-
type: "number"
|
|
924
|
-
},
|
|
925
|
-
{
|
|
926
|
-
type: "string"
|
|
927
|
-
}
|
|
928
|
-
]
|
|
929
|
-
},
|
|
930
|
-
_: {
|
|
931
|
-
type: "string",
|
|
932
|
-
description: "Comment"
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
},
|
|
936
|
-
igxcPath: {
|
|
937
|
-
type: "string",
|
|
938
|
-
description: "Relative path of the target object",
|
|
939
|
-
pattern: "^((o|e)\\d+(\\.(o|e)\\d+)*|\\.)$"
|
|
940
|
-
},
|
|
941
|
-
param: {
|
|
942
|
-
type: "string",
|
|
943
|
-
pattern: "^Param\\d+$"
|
|
944
|
-
},
|
|
945
|
-
kinematicChain: {
|
|
946
|
-
type: "object",
|
|
947
|
-
additionalProperties: false,
|
|
948
|
-
properties: {
|
|
949
|
-
GeometryBase: {
|
|
950
|
-
type: "string"
|
|
951
|
-
},
|
|
952
|
-
Joints: {
|
|
953
|
-
type: "array",
|
|
954
|
-
items: {
|
|
955
|
-
type: "object",
|
|
956
|
-
additionalProperties: false,
|
|
957
|
-
properties: {
|
|
958
|
-
Name: {
|
|
959
|
-
oneOf: [
|
|
960
|
-
{
|
|
961
|
-
$ref: "#/definitions/param"
|
|
962
|
-
},
|
|
963
|
-
{
|
|
964
|
-
type: "string"
|
|
965
|
-
}
|
|
966
|
-
]
|
|
967
|
-
},
|
|
968
|
-
HeadX: {
|
|
969
|
-
oneOf: [
|
|
970
|
-
{
|
|
971
|
-
$ref: "#/definitions/param"
|
|
972
|
-
},
|
|
973
|
-
{
|
|
974
|
-
$ref: "#/definitions/igxcPath"
|
|
975
|
-
}
|
|
976
|
-
]
|
|
977
|
-
},
|
|
978
|
-
HeadY: {
|
|
979
|
-
oneOf: [
|
|
980
|
-
{
|
|
981
|
-
$ref: "#/definitions/param"
|
|
982
|
-
},
|
|
983
|
-
{
|
|
984
|
-
$ref: "#/definitions/igxcPath"
|
|
985
|
-
}
|
|
986
|
-
]
|
|
987
|
-
},
|
|
988
|
-
HeadZ: {
|
|
989
|
-
oneOf: [
|
|
990
|
-
{
|
|
991
|
-
$ref: "#/definitions/param"
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
$ref: "#/definitions/igxcPath"
|
|
995
|
-
}
|
|
996
|
-
]
|
|
997
|
-
},
|
|
998
|
-
Tail: {
|
|
999
|
-
oneOf: [
|
|
1000
|
-
{
|
|
1001
|
-
$ref: "#/definitions/param"
|
|
1002
|
-
},
|
|
1003
|
-
{
|
|
1004
|
-
$ref: "#/definitions/igxcPath"
|
|
1005
|
-
}
|
|
1006
|
-
]
|
|
1007
|
-
},
|
|
1008
|
-
LimitLeft: {
|
|
1009
|
-
type: "number"
|
|
1010
|
-
},
|
|
1011
|
-
LimitRight: {
|
|
1012
|
-
type: "number"
|
|
1013
|
-
},
|
|
1014
|
-
LimitUp: {
|
|
1015
|
-
type: "number"
|
|
1016
|
-
},
|
|
1017
|
-
LimitDown: {
|
|
1018
|
-
type: "number"
|
|
1019
|
-
},
|
|
1020
|
-
FollowJointNode: {
|
|
1021
|
-
$ref: "#/definitions/igxcPath"
|
|
1022
|
-
},
|
|
1023
|
-
_TargetNodeForFollow: {
|
|
1024
|
-
type: "string"
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
},
|
|
1029
|
-
Target: {
|
|
1030
|
-
oneOf: [
|
|
1031
|
-
{
|
|
1032
|
-
$ref: "#/definitions/igxcPath"
|
|
1033
|
-
},
|
|
1034
|
-
{
|
|
1035
|
-
$ref: "#/definitions/param"
|
|
1036
|
-
},
|
|
1037
|
-
{
|
|
1038
|
-
type: "string",
|
|
1039
|
-
enum: [
|
|
1040
|
-
"subbase"
|
|
1041
|
-
]
|
|
1042
|
-
}
|
|
1043
|
-
]
|
|
1044
|
-
},
|
|
1045
|
-
Parent: {
|
|
1046
|
-
oneOf: [
|
|
1047
|
-
{
|
|
1048
|
-
$ref: "#/definitions/igxcPath"
|
|
1049
|
-
},
|
|
1050
|
-
{
|
|
1051
|
-
type: "string",
|
|
1052
|
-
enum: [
|
|
1053
|
-
"root"
|
|
1054
|
-
]
|
|
1055
|
-
}
|
|
1056
|
-
]
|
|
1057
|
-
},
|
|
1058
|
-
Tolerance: {
|
|
1059
|
-
type: "number"
|
|
1060
|
-
},
|
|
1061
|
-
MaxIterations: {
|
|
1062
|
-
type: "integer"
|
|
1063
|
-
},
|
|
1064
|
-
_: {
|
|
1065
|
-
type: "string",
|
|
1066
|
-
description: "Comment"
|
|
1067
|
-
},
|
|
1068
|
-
__: {
|
|
1069
|
-
type: "string",
|
|
1070
|
-
description: "Super Comment"
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
|
-
const createAnimationBuildParticipant = (location, manifest)=>{
|
|
1078
|
-
return (env)=>{
|
|
1079
|
-
env.onBuildStart();
|
|
1080
|
-
bundleAnimations(location, manifest, env.log).then((result)=>{
|
|
1081
|
-
env.onBuildEnd({
|
|
1082
|
-
type: "success",
|
|
1083
|
-
artefacts: {
|
|
1084
|
-
js: (result == null ? void 0 : result.js) ?? ""
|
|
1085
|
-
}
|
|
1086
|
-
});
|
|
1087
|
-
}).catch((err)=>{
|
|
1088
|
-
env.onBuildEnd({
|
|
1089
|
-
type: "error",
|
|
1090
|
-
error: err.message
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
return {
|
|
1094
|
-
destroy: ()=>{}
|
|
1095
|
-
};
|
|
1096
|
-
};
|
|
1097
|
-
};
|
|
1098
|
-
const createAnimationWatchBuildParticipant = (location, manifest)=>{
|
|
1099
|
-
return (env)=>{
|
|
1100
|
-
env.onBuildStart();
|
|
1101
|
-
bundleAnimations(location, manifest, env.log).then((result)=>{
|
|
1102
|
-
env.onBuildEnd({
|
|
1103
|
-
type: "success",
|
|
1104
|
-
artefacts: {
|
|
1105
|
-
js: (result == null ? void 0 : result.js) ?? ""
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
}).catch((err)=>{
|
|
1109
|
-
env.onBuildEnd({
|
|
1110
|
-
type: "error",
|
|
1111
|
-
error: err.message
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
(async ()=>{
|
|
1115
|
-
for await (const event of fs$1.watch(location.scriptsDir)){
|
|
1116
|
-
if (event.filename.endsWith(".animation.json")) {
|
|
1117
|
-
env.onBuildStart();
|
|
1118
|
-
try {
|
|
1119
|
-
const result = await bundleAnimations(location, manifest, env.log);
|
|
1120
|
-
env.onBuildEnd({
|
|
1121
|
-
type: "success",
|
|
1122
|
-
artefacts: {
|
|
1123
|
-
js: (result == null ? void 0 : result.js) ?? ""
|
|
1124
|
-
}
|
|
1125
|
-
});
|
|
1126
|
-
} catch (err) {
|
|
1127
|
-
env.onBuildEnd({
|
|
1128
|
-
type: "error",
|
|
1129
|
-
error: err.message
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
})();
|
|
1135
|
-
return {
|
|
1136
|
-
destroy: ()=>{}
|
|
1137
|
-
};
|
|
1138
|
-
};
|
|
1139
|
-
};
|
|
1140
|
-
const bundleAnimations = async (location, manifest, logStep)=>{
|
|
1141
|
-
const animations = new Map();
|
|
1142
|
-
for (const scriptFilePath of readPackageAnimationList(location)){
|
|
1143
|
-
const content = await fs$1.readFile(scriptFilePath, {
|
|
1144
|
-
encoding: "utf8"
|
|
1145
|
-
});
|
|
1146
|
-
let data;
|
|
1147
|
-
try {
|
|
1148
|
-
data = JSON.parse(content);
|
|
1149
|
-
} catch (err) {
|
|
1150
|
-
const relativePath = path.relative(location.path, scriptFilePath);
|
|
1151
|
-
if (err instanceof SyntaxError) {
|
|
1152
|
-
throw new Error(`Encountered invalid syntax in file "${relativePath}": ${String(err)}`);
|
|
1153
|
-
}
|
|
1154
|
-
throw new Error(`Encountered an unexpected error while parsing animation json file at path "${relativePath}"`, {
|
|
1155
|
-
cause: err
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
if (!data.Id) {
|
|
1159
|
-
const fileName = path.basename(scriptFilePath, ".animation.json");
|
|
1160
|
-
data.Id = fileName;
|
|
1161
|
-
}
|
|
1162
|
-
(await getAnimationJsonValidation())(data);
|
|
1163
|
-
delete data.$schema;
|
|
1164
|
-
animations.set(data.Id, JSON.stringify(data));
|
|
1165
|
-
}
|
|
1166
|
-
if (animations.size > 0) {
|
|
1167
|
-
const scope = manifest.Scope ?? manifest.Package;
|
|
1168
|
-
const scopeParts = scope.split(".");
|
|
1169
|
-
let js = createNamespace(scopeParts);
|
|
1170
|
-
for (const [name, content] of animations){
|
|
1171
|
-
js += `${scope}["${name}"] = ` + content + ";";
|
|
1172
|
-
logStep(`Adding animation ${scope}.${name}`);
|
|
1173
|
-
}
|
|
1174
|
-
return {
|
|
1175
|
-
js
|
|
1176
|
-
};
|
|
1177
|
-
}
|
|
1178
|
-
return undefined;
|
|
1179
|
-
};
|
|
1180
|
-
const createNamespace = (parts)=>{
|
|
1181
|
-
let code = `var ${parts[0]};`;
|
|
1182
|
-
for(let index = 0; index < parts.length; index++){
|
|
1183
|
-
const path = parts.slice(0, index + 1).join(".");
|
|
1184
|
-
code += `\n(${path} = ${path} || {});`;
|
|
1185
|
-
}
|
|
1186
|
-
return code;
|
|
1187
|
-
};
|
|
1188
|
-
let validateAnimationJson;
|
|
1189
|
-
const getAnimationJsonValidation = async ()=>{
|
|
1190
|
-
if (validateAnimationJson === undefined) {
|
|
1191
|
-
validateAnimationJson = new Ajv({
|
|
1192
|
-
coerceTypes: true,
|
|
1193
|
-
allErrors: true,
|
|
1194
|
-
removeAdditional: true,
|
|
1195
|
-
useDefaults: "empty",
|
|
1196
|
-
validateSchema: "log"
|
|
1197
|
-
}).compile(animationSchema);
|
|
1198
|
-
}
|
|
1199
|
-
return validateAnimationJson;
|
|
1200
|
-
};
|
|
1201
|
-
|
|
1202
|
-
const buildFolders = async (options)=>{
|
|
1203
|
-
if (options.outDir !== undefined && options.clean) {
|
|
1204
|
-
await fs$1.rm(options.outDir, {
|
|
1205
|
-
recursive: true
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
const workspace = options.workspace;
|
|
1209
|
-
const folders = options.packages;
|
|
1210
|
-
let sortedPackages = sortPackagesByBuildOrder(folders);
|
|
1211
|
-
let index = 1;
|
|
1212
|
-
const manifests = new Map(sortedPackages.map((location)=>[
|
|
1213
|
-
location,
|
|
1214
|
-
readPackageCreatorManifest(location)
|
|
1215
|
-
]));
|
|
1216
|
-
const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
|
|
1217
|
-
for (const location of sortedPackages){
|
|
1218
|
-
await ensureTsConfig(location);
|
|
1219
|
-
const data = manifests.get(location);
|
|
1220
|
-
const logStep = (step)=>logPackageMessage(data.Package, step, index, folders.length, maxNameLength);
|
|
1221
|
-
const outputDirectory = options.outDir || location.scriptsDir;
|
|
1222
|
-
await fs$1.mkdir(outputDirectory, {
|
|
1223
|
-
recursive: true
|
|
1224
|
-
});
|
|
1225
|
-
const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
|
|
1226
|
-
if (options.banner) {
|
|
1227
|
-
manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
|
|
1228
|
-
}
|
|
1229
|
-
manager.addParticipant("tsc", createTSCBuildParticipant(location, outputDirectory));
|
|
1230
|
-
manager.addParticipant("animation", createAnimationBuildParticipant(location, data));
|
|
1231
|
-
await new Promise((resolve, reject)=>{
|
|
1232
|
-
manager.addListener("start", ()=>{
|
|
1233
|
-
logStep(`Build started`);
|
|
1234
|
-
});
|
|
1235
|
-
manager.addListener("error", (error)=>{
|
|
1236
|
-
reject(new Error(error));
|
|
1237
|
-
});
|
|
1238
|
-
manager.addListener("build", ()=>{
|
|
1239
|
-
logStep(`Build complete`);
|
|
1240
|
-
resolve();
|
|
1241
|
-
});
|
|
1242
|
-
manager.run();
|
|
1243
|
-
});
|
|
1244
|
-
if (options.docs) {
|
|
1245
|
-
logStep("Generating typedoc documentation");
|
|
1246
|
-
await generateDocs(location, path.join(outputDirectory, `${data.Package}.d.ts`), path.join(workspace.path, "docs", data.Package), data.Package);
|
|
1247
|
-
}
|
|
1248
|
-
index++;
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
const buildFoldersWatch = async (options)=>{
|
|
1252
|
-
if (options.outDir !== undefined && options.clean) {
|
|
1253
|
-
await fs$1.rm(options.outDir, {
|
|
1254
|
-
recursive: true
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
const workspace = options.workspace;
|
|
1258
|
-
const folders = options.packages;
|
|
1259
|
-
let sortedPackages = sortPackagesByBuildOrder(folders);
|
|
1260
|
-
let index = 1;
|
|
1261
|
-
const manifests = new Map(sortedPackages.map((location)=>[
|
|
1262
|
-
location,
|
|
1263
|
-
readPackageCreatorManifest(location)
|
|
1264
|
-
]));
|
|
1265
|
-
const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
|
|
1266
|
-
for (const location of sortedPackages){
|
|
1267
|
-
await ensureTsConfig(location);
|
|
1268
|
-
const data = manifests.get(location);
|
|
1269
|
-
const currentIndex = index;
|
|
1270
|
-
const logStep = (step)=>logPackageMessage(data.Package, step, currentIndex, folders.length, maxNameLength);
|
|
1271
|
-
const outputDirectory = options.outDir || location.scriptsDir;
|
|
1272
|
-
await fs$1.mkdir(outputDirectory, {
|
|
1273
|
-
recursive: true
|
|
1274
|
-
});
|
|
1275
|
-
const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
|
|
1276
|
-
if (options.banner) {
|
|
1277
|
-
manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
|
|
1278
|
-
}
|
|
1279
|
-
manager.addParticipant("tsc", createTSCWatchBuildParticipant(location, outputDirectory));
|
|
1280
|
-
manager.addParticipant("animation", createAnimationWatchBuildParticipant(location, data));
|
|
1281
|
-
await new Promise((resolve, reject)=>{
|
|
1282
|
-
manager.addListener("start", ()=>{
|
|
1283
|
-
logStep(`Build started`);
|
|
1284
|
-
});
|
|
1285
|
-
manager.addListener("error", (error)=>{
|
|
1286
|
-
logStep(`Build failed: ${error}`);
|
|
1287
|
-
resolve();
|
|
1288
|
-
});
|
|
1289
|
-
manager.addListener("build", ()=>{
|
|
1290
|
-
logStep(`Build complete`);
|
|
1291
|
-
resolve();
|
|
1292
|
-
});
|
|
1293
|
-
manager.run();
|
|
1294
|
-
});
|
|
1295
|
-
index++;
|
|
1296
|
-
}
|
|
1297
|
-
await new Promise(()=>{});
|
|
1298
|
-
};
|
|
1299
|
-
const writeBuildResult = async (buildResult, manifest, location, workspace, outputDirectory, minimize, logStep)=>{
|
|
1300
|
-
let js = buildResult.js;
|
|
1301
|
-
if (buildResult.sourceMap) {
|
|
1302
|
-
js += `\n//# sourceMappingURL=${manifest.Package}.js.map`;
|
|
1303
|
-
}
|
|
1304
|
-
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js`), js, {
|
|
1305
|
-
encoding: "utf8"
|
|
1306
|
-
});
|
|
1307
|
-
if (buildResult.definitions !== undefined) {
|
|
1308
|
-
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.d.ts`), buildResult.definitions, {
|
|
1309
|
-
encoding: "utf8"
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
if (buildResult.sourceMap !== undefined) {
|
|
1313
|
-
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js.map`), buildResult.sourceMap, {
|
|
1314
|
-
encoding: "utf8"
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
if (minimize) {
|
|
1318
|
-
const minifyResult = await terser.minify(js, {
|
|
1319
|
-
ecma: 5,
|
|
1320
|
-
sourceMap: {
|
|
1321
|
-
content: buildResult.sourceMap,
|
|
1322
|
-
includeSources: false
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
const minifiedPath = path.join(outputDirectory, `${manifest.Package}.min.js`);
|
|
1326
|
-
await fs$1.writeFile(minifiedPath, minifyResult.code, {
|
|
1327
|
-
encoding: "utf8"
|
|
1328
|
-
});
|
|
1329
|
-
if (minifyResult.map !== undefined) {
|
|
1330
|
-
await fs$1.writeFile(minifiedPath + ".map", typeof minifyResult.map === "string" ? minifyResult.map : JSON.stringify(minifyResult.map), {
|
|
1331
|
-
encoding: "utf8"
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
if (location.path.includes("Basics") && buildResult.definitions !== undefined) {
|
|
1336
|
-
await fs$1.mkdir(path.join(workspace.path, "lib"), {
|
|
1337
|
-
recursive: true
|
|
1338
|
-
});
|
|
1339
|
-
logStep("Copying basics definition file to the lib folder");
|
|
1340
|
-
await fs$1.writeFile(path.join(workspace.path, "lib", `${manifest.Package}.d.ts`), buildResult.definitions, {
|
|
1341
|
-
encoding: "utf8"
|
|
1342
|
-
});
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
const createBannerCommentBuildParticipant = (options)=>(env)=>{
|
|
1346
|
-
env.onBuildStart();
|
|
1347
|
-
const banner = createBannerComment(options);
|
|
1348
|
-
env.onBuildEnd({
|
|
1349
|
-
type: "success",
|
|
1350
|
-
artefacts: {
|
|
1351
|
-
js: banner ?? "",
|
|
1352
|
-
definitions: banner ?? ""
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1355
|
-
return {
|
|
1356
|
-
destroy: ()=>{}
|
|
1357
|
-
};
|
|
1358
|
-
};
|
|
1359
|
-
const ensureTsConfig = async (location)=>{
|
|
1360
|
-
const tsconfigPath = path.join(location.scriptsDir, "tsconfig.json");
|
|
1361
|
-
try {
|
|
1362
|
-
const content = JSON.parse(await fs$1.readFile(tsconfigPath, "utf8"));
|
|
1363
|
-
applyTsConfigOption(content);
|
|
1364
|
-
await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
1365
|
-
} catch (err) {
|
|
1366
|
-
if (!isErrorENOENT(err)) {
|
|
1367
|
-
throw err;
|
|
1368
|
-
}
|
|
1369
|
-
const content = {};
|
|
1370
|
-
applyTsConfigOption(content);
|
|
1371
|
-
await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
const applyTsConfigOption = (data)=>{
|
|
1375
|
-
data.compilerOptions = data.compilerOptions ?? {};
|
|
1376
|
-
data.compilerOptions.target = "es5";
|
|
1377
|
-
data.compilerOptions.lib = [
|
|
1378
|
-
"es5",
|
|
1379
|
-
"dom"
|
|
1380
|
-
];
|
|
1381
|
-
};
|
|
1382
|
-
const sortPackagesByBuildOrder = (folders)=>{
|
|
1383
|
-
const packages = Array.from(folders).reduce((acc, location)=>{
|
|
1384
|
-
const data = readPackageNpmManifest(location);
|
|
1385
|
-
if (data !== undefined) {
|
|
1386
|
-
acc[data.name] = {
|
|
1387
|
-
data,
|
|
1388
|
-
location
|
|
1389
|
-
};
|
|
1390
|
-
} else {
|
|
1391
|
-
acc[location.path] = {
|
|
1392
|
-
data: undefined,
|
|
1393
|
-
location
|
|
1394
|
-
};
|
|
1395
|
-
}
|
|
1396
|
-
return acc;
|
|
1397
|
-
}, {});
|
|
1398
|
-
const packageDependencies = Object.getOwnPropertyNames(packages).reduce((acc, packageName)=>{
|
|
1399
|
-
const packageData = packages[packageName];
|
|
1400
|
-
if (packageData.data === undefined) {
|
|
1401
|
-
acc[packageName] = [];
|
|
1402
|
-
} else {
|
|
1403
|
-
acc[packageName] = Object.getOwnPropertyNames({
|
|
1404
|
-
...packageData.data.devDependencies,
|
|
1405
|
-
...packageData.data.dependencies,
|
|
1406
|
-
...packageData.data.peerDependencies
|
|
1407
|
-
}).filter((packageName)=>packages[packageName] !== undefined);
|
|
1408
|
-
}
|
|
1409
|
-
return acc;
|
|
1410
|
-
}, {});
|
|
1411
|
-
const sortedPackages = toposort(packageDependencies);
|
|
1412
|
-
const result = [];
|
|
1413
|
-
for (const packageName of sortedPackages){
|
|
1414
|
-
const location = packages[packageName].location;
|
|
1415
|
-
if (readPackageCreatorManifest(location).Package.endsWith(".Basics")) {
|
|
1416
|
-
result.unshift(location);
|
|
1417
|
-
} else {
|
|
1418
|
-
result.push(location);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
return result;
|
|
1422
|
-
};
|
|
1423
|
-
const createBannerComment = (banner)=>{
|
|
1424
|
-
const bannerParts = [];
|
|
1425
|
-
if (banner.text) {
|
|
1426
|
-
bannerParts.push(" * " + banner.text);
|
|
1427
|
-
}
|
|
1428
|
-
{
|
|
1429
|
-
const details = [];
|
|
1430
|
-
if (banner.version) {
|
|
1431
|
-
details.push(`Version: ${banner.version}`);
|
|
1432
|
-
}
|
|
1433
|
-
if (banner.commit) {
|
|
1434
|
-
if (banner.commitDirty) {
|
|
1435
|
-
details.push(`Commit: ${banner.commit} (dirty)`);
|
|
1436
|
-
} else {
|
|
1437
|
-
details.push(`Commit: ${banner.commit}`);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
if (banner.date) {
|
|
1441
|
-
details.push(`Date: ${banner.date.toISOString()}`);
|
|
1442
|
-
}
|
|
1443
|
-
const detailsText = details.map((line)=>` * ${line}`).join("\n");
|
|
1444
|
-
if (detailsText) {
|
|
1445
|
-
bannerParts.push(detailsText);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
const bannerText = bannerParts.join("\n\n");
|
|
1449
|
-
if (bannerText) {
|
|
1450
|
-
return `/*
|
|
1451
|
-
${bannerText}
|
|
1452
|
-
*
|
|
1453
|
-
* @preserve
|
|
1454
|
-
*/`;
|
|
1455
|
-
}
|
|
1456
|
-
return undefined;
|
|
1457
|
-
};
|
|
1458
|
-
|
|
1459
|
-
const getVersionInformationFromGit = async (workspaceLocation, packageLocation)=>{
|
|
1460
|
-
try {
|
|
1461
|
-
var _log_latest, _log_latest1;
|
|
1462
|
-
const git = simpleGit({
|
|
1463
|
-
baseDir: workspaceLocation.path
|
|
1464
|
-
});
|
|
1465
|
-
// check wether the files for a folder are changed
|
|
1466
|
-
// if so, mark as dirty
|
|
1467
|
-
const diff = await git.diffSummary();
|
|
1468
|
-
const dirty = diff.files.some((file)=>{
|
|
1469
|
-
if (file.file.toLowerCase().includes("releases") || file.file.toLowerCase().endsWith("version.ts") || file.file.toLowerCase().endsWith("package.json")) {
|
|
1470
|
-
return false;
|
|
1471
|
-
}
|
|
1472
|
-
const fullPath = path.resolve(workspaceLocation.path, file.file);
|
|
1473
|
-
const relativePath = path.relative(packageLocation.path, fullPath);
|
|
1474
|
-
return !relativePath.startsWith("..");
|
|
1475
|
-
});
|
|
1476
|
-
const log = await git.log({
|
|
1477
|
-
maxCount: 1
|
|
1478
|
-
});
|
|
1479
|
-
const commit = !((_log_latest = log.latest) == null ? void 0 : _log_latest.hash) ? undefined : log.latest.hash.substring(0, 7);
|
|
1480
|
-
return {
|
|
1481
|
-
commit,
|
|
1482
|
-
dirty,
|
|
1483
|
-
commitDate: (_log_latest1 = log.latest) == null ? void 0 : _log_latest1.date
|
|
1484
|
-
};
|
|
1485
|
-
} catch (err) {
|
|
1486
|
-
return {};
|
|
1487
|
-
}
|
|
1488
|
-
};
|
|
1489
|
-
|
|
1490
|
-
const getWorkspaceBannerText = (manifest)=>{
|
|
1491
|
-
var _manifest_packager;
|
|
1492
|
-
let bannerText = manifest == null ? void 0 : (_manifest_packager = manifest.packager) == null ? void 0 : _manifest_packager.banner;
|
|
1493
|
-
if (bannerText) {
|
|
1494
|
-
const match = bannerText.match(/Copyright \(C\) (\d+)( ?- ?(\d+))?/);
|
|
1495
|
-
if (match !== null) {
|
|
1496
|
-
const startYear = parseInt(match[1]);
|
|
1497
|
-
const endYear = new Date().getFullYear();
|
|
1498
|
-
if (startYear !== endYear) {
|
|
1499
|
-
bannerText = bannerText.replace(match[0], `Copyright (C) ${startYear} - ${endYear}`);
|
|
1500
|
-
} else {
|
|
1501
|
-
bannerText = bannerText.replace(match[0], `Copyright (C) ${startYear}`);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
return bannerText;
|
|
1506
|
-
};
|
|
1507
|
-
|
|
1508
|
-
// Stolen from ig.tools.core
|
|
1509
|
-
class PackageVersion {
|
|
1510
|
-
static #_ = (()=>{
|
|
1511
|
-
// https://regex101.com/r/90PEY9/1
|
|
1512
|
-
this.fullTextMatcher = /(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?/;
|
|
1513
|
-
})();
|
|
1514
|
-
static #_1 = (()=>{
|
|
1515
|
-
this.lineMatcher = /^(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?$/;
|
|
1516
|
-
})();
|
|
1517
|
-
static extractFromText(input, description) {
|
|
1518
|
-
if (input === undefined) {
|
|
1519
|
-
throw new Error(`Can not parse version from undefined`);
|
|
1520
|
-
}
|
|
1521
|
-
const match = input.match(PackageVersion.fullTextMatcher);
|
|
1522
|
-
if (!match) {
|
|
1523
|
-
throw new Error(`Could not extract a version from input: ${input}`);
|
|
1524
|
-
}
|
|
1525
|
-
return PackageVersion.fromMatch(match, description);
|
|
1526
|
-
}
|
|
1527
|
-
static extractFromLine(input, description) {
|
|
1528
|
-
if (input === undefined) {
|
|
1529
|
-
throw new Error(`Can not parse version from undefined`);
|
|
1530
|
-
}
|
|
1531
|
-
const match = input.match(PackageVersion.lineMatcher);
|
|
1532
|
-
if (!match) {
|
|
1533
|
-
throw new Error(`Could not parse version from input: ${input}`);
|
|
1534
|
-
}
|
|
1535
|
-
return PackageVersion.fromMatch(match, description);
|
|
1536
|
-
}
|
|
1537
|
-
static equals(a, b, checkPrerelease = false) {
|
|
1538
|
-
if (a.major !== b.major || a.minor !== b.minor || a.patch !== b.patch) {
|
|
1539
|
-
return false;
|
|
1540
|
-
}
|
|
1541
|
-
if (checkPrerelease === false) {
|
|
1542
|
-
return true;
|
|
1543
|
-
}
|
|
1544
|
-
if (a.preRelease === b.preRelease) {
|
|
1545
|
-
return true;
|
|
1546
|
-
}
|
|
1547
|
-
if (a.preRelease === undefined || b.preRelease === undefined) {
|
|
1548
|
-
return false;
|
|
1549
|
-
}
|
|
1550
|
-
return a.preRelease.type === b.preRelease.type && a.preRelease.version === b.preRelease.version;
|
|
1551
|
-
}
|
|
1552
|
-
static fromMatch([, major, , minor = "0", , patch = "0", , build, , preReleaseType, preReleaseNumber], description) {
|
|
1553
|
-
let preRelease = undefined;
|
|
1554
|
-
let buildNumber = 100;
|
|
1555
|
-
if (preReleaseType && preReleaseNumber) {
|
|
1556
|
-
preRelease = {
|
|
1557
|
-
type: preReleaseType,
|
|
1558
|
-
version: parseInt(preReleaseNumber)
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
if (build) {
|
|
1562
|
-
buildNumber = Number(build);
|
|
1563
|
-
} else if (description) {
|
|
1564
|
-
const descriptionMatch = description.match(/(\d+)\)$/);
|
|
1565
|
-
if (descriptionMatch) {
|
|
1566
|
-
buildNumber = parseInt(descriptionMatch[1]);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
return new PackageVersion(parseInt(major), parseInt(minor), parseInt(patch), preRelease, buildNumber);
|
|
1570
|
-
}
|
|
1571
|
-
static sort(a, b, ascending = true) {
|
|
1572
|
-
const createSortResult = (a, b)=>ascending ? a - b : b - a;
|
|
1573
|
-
if (a.major !== b.major) {
|
|
1574
|
-
return createSortResult(a.major, b.major);
|
|
1575
|
-
}
|
|
1576
|
-
if (a.minor !== b.minor) {
|
|
1577
|
-
return createSortResult(a.minor, b.minor);
|
|
1578
|
-
}
|
|
1579
|
-
if (a.patch !== b.patch) {
|
|
1580
|
-
return createSortResult(a.patch, b.patch);
|
|
1581
|
-
}
|
|
1582
|
-
return createSortResult(a.preRelease ? a.preRelease.version : 0, b.preRelease ? b.preRelease.version : 0);
|
|
1583
|
-
}
|
|
1584
|
-
static toNumber(version) {
|
|
1585
|
-
return ((version.major * 1000 + version.minor) * 1000 + version.patch) * 1000 + version.buildNumber;
|
|
1586
|
-
}
|
|
1587
|
-
constructor(major, minor, patch, preRelease, buildNumber){
|
|
1588
|
-
this.major = major;
|
|
1589
|
-
this.minor = minor;
|
|
1590
|
-
this.patch = patch;
|
|
1591
|
-
this.preRelease = preRelease;
|
|
1592
|
-
this.buildNumber = buildNumber;
|
|
1593
|
-
}
|
|
1594
|
-
isPreRelease() {
|
|
1595
|
-
return this.preRelease !== undefined;
|
|
1596
|
-
}
|
|
1597
|
-
clone() {
|
|
1598
|
-
return new PackageVersion(this.major, this.minor, this.patch, this.preRelease ? {
|
|
1599
|
-
...this.preRelease
|
|
1600
|
-
} : undefined, this.buildNumber);
|
|
1601
|
-
}
|
|
1602
|
-
incrementMajor() {
|
|
1603
|
-
this.preRelease = undefined;
|
|
1604
|
-
this.patch = 0;
|
|
1605
|
-
this.minor = 0;
|
|
1606
|
-
this.major++;
|
|
1607
|
-
}
|
|
1608
|
-
incrementMinor() {
|
|
1609
|
-
this.preRelease = undefined;
|
|
1610
|
-
this.patch = 0;
|
|
1611
|
-
this.minor++;
|
|
1612
|
-
}
|
|
1613
|
-
incrementPatch() {
|
|
1614
|
-
this.preRelease = undefined;
|
|
1615
|
-
this.patch++;
|
|
1616
|
-
}
|
|
1617
|
-
createPreRelease(type) {
|
|
1618
|
-
if (!this.preRelease) {
|
|
1619
|
-
this.buildNumber = 1;
|
|
1620
|
-
} else {
|
|
1621
|
-
this.buildNumber++;
|
|
1622
|
-
}
|
|
1623
|
-
if (this.preRelease && type === this.preRelease.type) {
|
|
1624
|
-
this.preRelease.version++;
|
|
1625
|
-
return;
|
|
1626
|
-
}
|
|
1627
|
-
this.preRelease = {
|
|
1628
|
-
version: 0,
|
|
1629
|
-
type
|
|
1630
|
-
};
|
|
1631
|
-
}
|
|
1632
|
-
createRelease() {
|
|
1633
|
-
this.preRelease = undefined;
|
|
1634
|
-
this.buildNumber = 100;
|
|
1635
|
-
}
|
|
1636
|
-
toVersionString({ buildNumber } = {}) {
|
|
1637
|
-
let version = [
|
|
1638
|
-
this.major,
|
|
1639
|
-
this.minor,
|
|
1640
|
-
this.patch
|
|
1641
|
-
].join(".");
|
|
1642
|
-
if (buildNumber) {
|
|
1643
|
-
version += "." + this.buildNumber;
|
|
1644
|
-
}
|
|
1645
|
-
if (this.preRelease) {
|
|
1646
|
-
version += `-${this.preRelease.type}.${this.preRelease.version}`;
|
|
1647
|
-
}
|
|
1648
|
-
return version;
|
|
1649
|
-
}
|
|
1650
|
-
toDescriptionString(packageName) {
|
|
1651
|
-
const base = [
|
|
1652
|
-
this.major,
|
|
1653
|
-
this.minor,
|
|
1654
|
-
this.patch
|
|
1655
|
-
].join(".");
|
|
1656
|
-
const parts = [
|
|
1657
|
-
packageName,
|
|
1658
|
-
base
|
|
1659
|
-
];
|
|
1660
|
-
if (this.preRelease) {
|
|
1661
|
-
parts.push(upperCaseFirst(this.preRelease.type));
|
|
1662
|
-
parts.push(this.preRelease.version);
|
|
1663
|
-
}
|
|
1664
|
-
parts.push(`(${base}.${this.buildNumber})`);
|
|
1665
|
-
return parts.join(" ");
|
|
1666
|
-
}
|
|
1667
|
-
/**
|
|
1668
|
-
* Determines wether the version is lesser than the input version
|
|
1669
|
-
*
|
|
1670
|
-
* @param {PackageVersion} version
|
|
1671
|
-
* @returns
|
|
1672
|
-
*/ isLesserThan(version) {
|
|
1673
|
-
return PackageVersion.toNumber(this) < PackageVersion.toNumber(version);
|
|
1674
|
-
}
|
|
1675
|
-
/**
|
|
1676
|
-
* Determines wether the version is greater than the input version
|
|
1677
|
-
*
|
|
1678
|
-
* @param {PackageVersion} version
|
|
1679
|
-
* @returns
|
|
1680
|
-
*/ isGreaterThan(version) {
|
|
1681
|
-
return PackageVersion.toNumber(this) > PackageVersion.toNumber(version);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
const upperCaseFirst = (input)=>{
|
|
1685
|
-
return input.slice(0, 1).toUpperCase() + input.slice(1);
|
|
1686
|
-
};
|
|
1687
|
-
|
|
1688
|
-
const parseVersionFromString = (input)=>{
|
|
1689
|
-
if (input === undefined) {
|
|
1690
|
-
throw new Error(`Can not parse version from undefined`);
|
|
1691
|
-
}
|
|
1692
|
-
let match;
|
|
1693
|
-
let major;
|
|
1694
|
-
let minor;
|
|
1695
|
-
let patch;
|
|
1696
|
-
let build;
|
|
1697
|
-
let preReleaseType;
|
|
1698
|
-
let preReleaseNumber;
|
|
1699
|
-
if (// first try to find a full match with build number
|
|
1700
|
-
(match = input.match(/(\d+)\.(\d+)\.(\d+)\.(\d+)(-([^\.]+)\.(\d+))?/)) !== null) {
|
|
1701
|
-
[, major, minor, patch, build, preReleaseType, preReleaseNumber] = match;
|
|
1702
|
-
} else if ((match = input.match(/(\d+)\.(\d+)\.(\d+)(-([^\.]+)\.(\d+))?/)) !== null) {
|
|
1703
|
-
[, major, minor, patch, , preReleaseType, preReleaseNumber] = match;
|
|
1704
|
-
}
|
|
1705
|
-
if (match === null) {
|
|
1706
|
-
throw new Error(`Could not parse version from input: ${input}`);
|
|
1707
|
-
}
|
|
1708
|
-
let preRelease = undefined;
|
|
1709
|
-
let buildNumber = 100;
|
|
1710
|
-
if (preReleaseType && preReleaseNumber) {
|
|
1711
|
-
preRelease = {
|
|
1712
|
-
type: preReleaseType,
|
|
1713
|
-
version: parseInt(preReleaseNumber)
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
if (build) {
|
|
1717
|
-
buildNumber = Number(build);
|
|
1718
|
-
} else if (input) {
|
|
1719
|
-
const descriptionMatch = input.match(/(\d+)\)$/);
|
|
1720
|
-
if (descriptionMatch) {
|
|
1721
|
-
buildNumber = parseInt(descriptionMatch[1]);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
return new PackageVersion(parseInt(major), parseInt(minor), parseInt(patch), preRelease, buildNumber);
|
|
1725
|
-
};
|
|
1726
|
-
// 1000001001 -> 1.0.1.1
|
|
1727
|
-
// 1002017001 -> 1.2.17.1
|
|
1728
|
-
const parseVersionFromNumericVersion = (version)=>{
|
|
1729
|
-
const major = Math.floor(version / 1000000000);
|
|
1730
|
-
const minor = Math.floor(version % 1000000000 / 1000000);
|
|
1731
|
-
const patch = Math.floor(version % 1000000 / 1000);
|
|
1732
|
-
const buildNumber = version % 1000;
|
|
1733
|
-
return new PackageVersion(major, minor, patch, undefined, buildNumber);
|
|
1734
|
-
};
|
|
1735
|
-
|
|
1736
|
-
// https://regex101.com/r/LtGAu5/1
|
|
1737
|
-
const logRegex = /console\.log\(\s*"([\w\s\.\(\)]+)\ *Copyright[\w\s\(\)\.]+(\d{4}|\d{4} - \d{4})([\w\s\(\)\.]+)?",?\s*\)/i;
|
|
1738
|
-
const currentYear = new Date(Date.now()).getFullYear();
|
|
1739
|
-
const getVersionFileHandler = (location)=>{
|
|
1740
|
-
const filePath = path.join(location.scriptsDir, "Version.ts");
|
|
1741
|
-
const invalidVersionFile = (versionFile)=>({
|
|
1742
|
-
version: undefined,
|
|
1743
|
-
write: (name, newVersion)=>{
|
|
1744
|
-
const scriptsContent = fs.readdirSync(location.scriptsDir);
|
|
1745
|
-
const tsFiles = scriptsContent.filter((file)=>file.endsWith(".ts"));
|
|
1746
|
-
if (tsFiles.length > 0) {
|
|
1747
|
-
return createVersionFileWriter([
|
|
1748
|
-
currentYear
|
|
1749
|
-
], "")(name, newVersion);
|
|
1750
|
-
}
|
|
1751
|
-
},
|
|
1752
|
-
reset: ()=>{
|
|
1753
|
-
if (versionFile !== undefined) {
|
|
1754
|
-
fs.writeFileSync(filePath, versionFile, {
|
|
1755
|
-
encoding: "utf8"
|
|
1756
|
-
});
|
|
1757
|
-
} else {
|
|
1758
|
-
try {
|
|
1759
|
-
fs.rmSync(filePath);
|
|
1760
|
-
} catch (err) {
|
|
1761
|
-
if (!isErrorENOENT(err)) {
|
|
1762
|
-
throw err;
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
});
|
|
1768
|
-
const createVersionFileWriter = (copyright = [
|
|
1769
|
-
currentYear
|
|
1770
|
-
], copyrightStuff = "")=>(name, newVersion)=>{
|
|
1771
|
-
const descriptionText = newVersion.toDescriptionString(name);
|
|
1772
|
-
const copyrightText = createYearString(copyright);
|
|
1773
|
-
const result = `console.log("${descriptionText}. Copyright (C) ${copyrightText}${copyrightStuff}");`;
|
|
1774
|
-
fs.writeFileSync(filePath, result, {
|
|
1775
|
-
encoding: "utf-8"
|
|
1776
|
-
});
|
|
1777
|
-
};
|
|
1778
|
-
let rawVersionFile = readStringFromFileOrUndefined(filePath);
|
|
1779
|
-
if (rawVersionFile === undefined) {
|
|
1780
|
-
return invalidVersionFile(rawVersionFile);
|
|
1781
|
-
}
|
|
1782
|
-
const versionFile = rawVersionFile.replace(/\n/g, "");
|
|
1783
|
-
const match = versionFile.match(logRegex);
|
|
1784
|
-
if (!match) {
|
|
1785
|
-
return invalidVersionFile(versionFile);
|
|
1786
|
-
}
|
|
1787
|
-
const [_full, _description, copyright, copyrightStuff] = match;
|
|
1788
|
-
const copyrightYears = copyright.match(/^(\d+)( ?- ?(\d+))?$/);
|
|
1789
|
-
let years;
|
|
1790
|
-
if (copyrightYears === null) {
|
|
1791
|
-
years = [
|
|
1792
|
-
currentYear
|
|
1793
|
-
];
|
|
1794
|
-
} else {
|
|
1795
|
-
years = [
|
|
1796
|
-
Number(copyrightYears[1]),
|
|
1797
|
-
currentYear
|
|
1798
|
-
];
|
|
1799
|
-
}
|
|
1800
|
-
return {
|
|
1801
|
-
write: createVersionFileWriter(years, copyrightStuff),
|
|
1802
|
-
reset: ()=>{
|
|
1803
|
-
fs.writeFileSync(filePath, versionFile, {
|
|
1804
|
-
encoding: "utf8"
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
};
|
|
1809
|
-
const createYearString = (years)=>{
|
|
1810
|
-
if (years[1] === undefined || years[0] === years[1]) {
|
|
1811
|
-
return years[0].toString();
|
|
1812
|
-
}
|
|
1813
|
-
return `${years[0]} - ${years[1]}`;
|
|
1814
|
-
};
|
|
1815
|
-
|
|
1816
|
-
const buildArchiveFromPublishedPackage = (location, manifest, creatorPackage)=>{
|
|
1817
|
-
const archive = new JSZip();
|
|
1818
|
-
archive.file(PACKAGE_FILE, JSON.stringify(creatorPackage, null, 2));
|
|
1819
|
-
const index = readPublishedPackageCreatorIndex(location);
|
|
1820
|
-
if (index !== undefined) {
|
|
1821
|
-
archive.file(INDEX_FILE, JSON.stringify(index, null, 2));
|
|
1822
|
-
}
|
|
1823
|
-
archive.file(manifest.main, fs.createReadStream(path.join(location.path, manifest.main)));
|
|
1824
|
-
if (creatorPackage.Package === "IG.GFX.Standard") {
|
|
1825
|
-
const source = path.join(location.path, "Images");
|
|
1826
|
-
if (fs.existsSync(source)) {
|
|
1827
|
-
const images = fs.readdirSync(source);
|
|
1828
|
-
for (const file of images){
|
|
1829
|
-
const { ext } = path.parse(file);
|
|
1830
|
-
switch(ext){
|
|
1831
|
-
case ".png":
|
|
1832
|
-
case ".jpeg":
|
|
1833
|
-
case ".jpg":
|
|
1834
|
-
break;
|
|
1835
|
-
default:
|
|
1836
|
-
continue;
|
|
1837
|
-
}
|
|
1838
|
-
archive.file(file, fs.createReadStream(path.join(source, file)));
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
return archive;
|
|
1843
|
-
};
|
|
1844
|
-
const runtimeScripts = [
|
|
1845
|
-
"Interactor",
|
|
1846
|
-
"Core",
|
|
1847
|
-
"Mixed"
|
|
1848
|
-
];
|
|
1849
|
-
const notRuntimeScripts = [
|
|
1850
|
-
"Context",
|
|
1851
|
-
"Evaluator"
|
|
1852
|
-
];
|
|
1853
|
-
const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
|
|
1854
|
-
const { domain } = parseCreatorPackageName(data);
|
|
1855
|
-
const logStep = (step)=>logPackageMessage(data.Package, step);
|
|
1856
|
-
const libFilePath = path.join(binDir, `${data.Package}.min.js`);
|
|
1857
|
-
const scriptDirectories = [
|
|
1858
|
-
packageLocation.path,
|
|
1859
|
-
packageLocation.scriptsDir
|
|
1860
|
-
];
|
|
1861
|
-
if (data.Package === "IG.GFX.Standard") {
|
|
1862
|
-
logStep(`Including Images folder`);
|
|
1863
|
-
scriptDirectories.push(path.join(packageLocation.path, "Images"));
|
|
1864
|
-
}
|
|
1865
|
-
const manifest = readPackageCreatorManifest(packageLocation);
|
|
1866
|
-
if (manifest !== undefined) {
|
|
1867
|
-
if (manifest.RunTime && notRuntimeScripts.includes(manifest.Type)) {
|
|
1868
|
-
logStep("Setting script RunTime to false because of script type");
|
|
1869
|
-
writePackageCreatorManifest(packageLocation, {
|
|
1870
|
-
...manifest,
|
|
1871
|
-
RunTime: false
|
|
1872
|
-
});
|
|
1873
|
-
} else if (!manifest.RunTime && runtimeScripts.includes(manifest.Type)) {
|
|
1874
|
-
logStep("Setting script RunTime to true because of script type");
|
|
1875
|
-
writePackageCreatorManifest(packageLocation, {
|
|
1876
|
-
...manifest,
|
|
1877
|
-
RunTime: true
|
|
1878
|
-
});
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
let libFile;
|
|
1882
|
-
try {
|
|
1883
|
-
libFile = fs.readFileSync(libFilePath, {
|
|
1884
|
-
encoding: "utf8"
|
|
1885
|
-
});
|
|
1886
|
-
} catch (err) {
|
|
1887
|
-
if (!isErrorENOENT(err)) {
|
|
1888
|
-
throw err;
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
const archive = new JSZip();
|
|
1892
|
-
let library = "";
|
|
1893
|
-
if (libFile) {
|
|
1894
|
-
library = libFile;
|
|
1895
|
-
}
|
|
1896
|
-
if (!library) {
|
|
1897
|
-
const date = new Date(Date.now());
|
|
1898
|
-
library = `/* This file is part of the ${domain} Data Packages.
|
|
1899
|
-
* Copyright (C) ${date.getFullYear()} intelligentgraphics. All Rights Reserved. */`;
|
|
1900
|
-
}
|
|
1901
|
-
const minifyResult = await terser.minify(library, {
|
|
1902
|
-
ecma: 5
|
|
1903
|
-
});
|
|
1904
|
-
archive.file(`${data.Package}.js`, minifyResult.code);
|
|
1905
|
-
archive.file(PACKAGE_FILE, JSON.stringify(data, null, 2));
|
|
1906
|
-
const creatorIndex = readPackageCreatorIndex(packageLocation);
|
|
1907
|
-
if (creatorIndex !== undefined) {
|
|
1908
|
-
archive.file(INDEX_FILE, JSON.stringify(creatorIndex, null, 2));
|
|
1909
|
-
}
|
|
1910
|
-
for (const directory of scriptDirectories){
|
|
1911
|
-
try {
|
|
1912
|
-
for (const file of fs.readdirSync(directory)){
|
|
1913
|
-
const { ext } = path.parse(file);
|
|
1914
|
-
switch(ext){
|
|
1915
|
-
case ".png":
|
|
1916
|
-
case ".jpeg":
|
|
1917
|
-
case ".jpg":
|
|
1918
|
-
break;
|
|
1919
|
-
default:
|
|
1920
|
-
continue;
|
|
1921
|
-
}
|
|
1922
|
-
archive.file(file, fs.createReadStream(path.join(directory, file)));
|
|
1923
|
-
}
|
|
1924
|
-
} catch (err) {
|
|
1925
|
-
console.error(`Script directory "${directory}" does not exist`);
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
return archive;
|
|
1929
|
-
};
|
|
1930
|
-
|
|
1931
|
-
const execAsync = promisify(exec);
|
|
1932
|
-
const releaseFolder = async (options)=>{
|
|
1933
|
-
const workspace = options.workspace;
|
|
1934
|
-
const location = options.directory;
|
|
1935
|
-
const { write: writeVersionFile , reset: resetVersionFile } = getVersionFileHandler(location);
|
|
1936
|
-
const packageDescription = readPackageCreatorManifest(location);
|
|
1937
|
-
const fullPackageName = packageDescription.Package;
|
|
1938
|
-
const { domain , subdomain } = parseCreatorPackageName(packageDescription);
|
|
1939
|
-
const publishDomain = options.domain ?? domain;
|
|
1940
|
-
const publishSubdomain = options.subdomain ?? subdomain;
|
|
1941
|
-
const sharedPackageJson = readWorkspaceNpmManifest(workspace);
|
|
1942
|
-
let newVersion;
|
|
1943
|
-
try {
|
|
1944
|
-
newVersion = parseVersionFromString(options.newVersion);
|
|
1945
|
-
} catch (err) {
|
|
1946
|
-
throw new Error(`Please enter a version in this format 1.0.0.100`);
|
|
1947
|
-
}
|
|
1948
|
-
packageDescription.Version = newVersion.toVersionString({
|
|
1949
|
-
buildNumber: true
|
|
1950
|
-
});
|
|
1951
|
-
writePackageCreatorManifest(location, packageDescription);
|
|
1952
|
-
if (newVersion.buildNumber < 100) {
|
|
1953
|
-
newVersion.preRelease = {
|
|
1954
|
-
type: "beta",
|
|
1955
|
-
version: newVersion.buildNumber
|
|
1956
|
-
};
|
|
1957
|
-
} else if (newVersion.buildNumber > 100) {
|
|
1958
|
-
newVersion.preRelease = {
|
|
1959
|
-
type: "patch",
|
|
1960
|
-
version: newVersion.buildNumber - 100
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
if (sharedPackageJson !== undefined) {
|
|
1964
|
-
logPackageMessage(packageDescription.Package, `Running npm install to make sure all dependencies are up to date`);
|
|
1965
|
-
await execAsync(`npm install`, {
|
|
1966
|
-
encoding: "utf-8",
|
|
1967
|
-
cwd: workspace.path
|
|
1968
|
-
});
|
|
1969
|
-
}
|
|
1970
|
-
const binDir = options.outDir ?? getWorkspaceOutputPath(workspace);
|
|
1971
|
-
await fs$1.mkdir(binDir, {
|
|
1972
|
-
recursive: true
|
|
1973
|
-
});
|
|
1974
|
-
let assetServerPackageDetails;
|
|
1975
|
-
let packageNameWithVersion;
|
|
1976
|
-
{
|
|
1977
|
-
const versionWithoutPrelease = newVersion.clone();
|
|
1978
|
-
versionWithoutPrelease.preRelease = undefined;
|
|
1979
|
-
const newVersionString = versionWithoutPrelease.toVersionString({
|
|
1980
|
-
buildNumber: true
|
|
1981
|
-
});
|
|
1982
|
-
packageNameWithVersion = `${packageDescription.Package}_${newVersionString}`;
|
|
1983
|
-
assetServerPackageDetails = {
|
|
1984
|
-
name: packageDescription.Package,
|
|
1985
|
-
version: newVersionString
|
|
1986
|
-
};
|
|
1987
|
-
}
|
|
1988
|
-
let zipFilePath = path.join(binDir, packageNameWithVersion + ".zip");
|
|
1989
|
-
let uploadable = {
|
|
1990
|
-
getStream: ()=>createReadStream(zipFilePath)
|
|
1991
|
-
};
|
|
1992
|
-
try {
|
|
1993
|
-
if (options.pushOnly) {
|
|
1994
|
-
const zipFileExists = await fs$1.stat(zipFilePath).catch((err)=>{
|
|
1995
|
-
if (isErrorENOENT(err)) {
|
|
1996
|
-
return false;
|
|
1997
|
-
}
|
|
1998
|
-
return Promise.reject(err);
|
|
1999
|
-
});
|
|
2000
|
-
if (zipFileExists) {
|
|
2001
|
-
throw new Error(`Expected a zip file to exist at path ${zipFilePath} since pushOnly is specified`);
|
|
2002
|
-
}
|
|
2003
|
-
} else {
|
|
2004
|
-
const gitVersionInformation = await getVersionInformationFromGit(workspace, location);
|
|
2005
|
-
writeVersionFile(fullPackageName, newVersion);
|
|
2006
|
-
const bannerText = sharedPackageJson !== undefined ? getWorkspaceBannerText(sharedPackageJson) : undefined;
|
|
2007
|
-
await buildFolders({
|
|
2008
|
-
...options,
|
|
2009
|
-
packages: [
|
|
2010
|
-
location
|
|
2011
|
-
],
|
|
2012
|
-
banner: options.banner ? {
|
|
2013
|
-
text: bannerText,
|
|
2014
|
-
commit: gitVersionInformation.commit,
|
|
2015
|
-
commitDirty: gitVersionInformation.dirty,
|
|
2016
|
-
version: newVersion.toVersionString({
|
|
2017
|
-
buildNumber: true
|
|
2018
|
-
}),
|
|
2019
|
-
date: new Date(Date.now())
|
|
2020
|
-
} : undefined
|
|
2021
|
-
});
|
|
2022
|
-
newVersion.preRelease = undefined;
|
|
2023
|
-
try {
|
|
2024
|
-
await fs$1.rm(zipFilePath);
|
|
2025
|
-
} catch (err) {
|
|
2026
|
-
if (!isErrorENOENT(err)) {
|
|
2027
|
-
throw err;
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
if (readPackageAnimationList(location).length > 0) {
|
|
2031
|
-
var _workspaceManifest_dependencies;
|
|
2032
|
-
const workspaceManifest = readWorkspaceNpmManifest(workspace);
|
|
2033
|
-
if (!((_workspaceManifest_dependencies = workspaceManifest.dependencies) == null ? void 0 : _workspaceManifest_dependencies["@intelligentgraphics/3d.ig.gfx.standard"])) {
|
|
2034
|
-
const install = await options.prompter.confirm(`The IG.GFX.Standard package should be added as a dependency to provide the 'AnimationInteractor' used to display animations. Do you wish to add it now?`);
|
|
2035
|
-
if (install) {
|
|
2036
|
-
await execAsync(`npm install @intelligentgraphics/3d.ig.gfx.standard`, {
|
|
2037
|
-
encoding: "utf-8",
|
|
2038
|
-
cwd: workspace.path
|
|
2039
|
-
});
|
|
2040
|
-
await execAsync(`npm run postinstall`, {
|
|
2041
|
-
cwd: workspace.path
|
|
2042
|
-
});
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
const archive = await buildArchiveFromPackage(location, packageDescription, binDir);
|
|
2047
|
-
try {
|
|
2048
|
-
const zipOutputStream = createWriteStream(zipFilePath);
|
|
2049
|
-
await pipeline(archive.generateNodeStream(), zipOutputStream);
|
|
2050
|
-
} catch (err) {
|
|
2051
|
-
if (isErrorEACCES(err) || isErrorEPERM(err)) {
|
|
2052
|
-
logPackageMessage(packageDescription.Package, `Could not create zip file in the bin directory because of a permissions error. Only using it in-memory`);
|
|
2053
|
-
uploadable = {
|
|
2054
|
-
getStream: ()=>archive.generateNodeStream()
|
|
2055
|
-
};
|
|
2056
|
-
} else {
|
|
2057
|
-
throw err;
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
if (!options.noUpload) {
|
|
2062
|
-
if (!options.authentication) {
|
|
2063
|
-
throw new Error(`Expected authentication to be available`);
|
|
2064
|
-
}
|
|
2065
|
-
logPackageMessage(packageDescription.Package, `Opening connection to IG.Asset.Server`);
|
|
2066
|
-
const sessionManager = await createSessionManager({
|
|
2067
|
-
url: options.service,
|
|
2068
|
-
address: options.address,
|
|
2069
|
-
domain: publishDomain,
|
|
2070
|
-
subDomain: publishSubdomain,
|
|
2071
|
-
authentication: options.authentication
|
|
2072
|
-
});
|
|
2073
|
-
try {
|
|
2074
|
-
if (!options.skipDependencies) {
|
|
2075
|
-
await ensureRequiredVersions(workspace, packageDescription, sessionManager, options.prompter);
|
|
2076
|
-
}
|
|
2077
|
-
logPackageMessage(packageDescription.Package, `Uploading package to ${publishDomain}.${publishSubdomain}`);
|
|
2078
|
-
await uploadPackageFromStream(sessionManager.getTargetSession(), assetServerPackageDetails, uploadable.getStream());
|
|
2079
|
-
} finally{
|
|
2080
|
-
await sessionManager.destroy().catch((err)=>{
|
|
2081
|
-
logPackageMessage(packageDescription.Package, `Failed to close IG.Asset.Server session(s): ${err}`);
|
|
2082
|
-
});
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
} catch (err) {
|
|
2086
|
-
resetVersionFile();
|
|
2087
|
-
throw err;
|
|
2088
|
-
}
|
|
2089
|
-
if (newVersion.buildNumber >= 100 && !options.pushOnly) {
|
|
2090
|
-
logPackageMessage(fullPackageName, "Copying zip to releases folder");
|
|
2091
|
-
const zipFileName = `${packageNameWithVersion}.zip`;
|
|
2092
|
-
const releasesPath = getPackageReleasesDirectory(location);
|
|
2093
|
-
await fs$1.mkdir(releasesPath, {
|
|
2094
|
-
recursive: true
|
|
2095
|
-
});
|
|
2096
|
-
await pipeline(uploadable.getStream(), createWriteStream(path.join(releasesPath, zipFileName)));
|
|
2097
|
-
}
|
|
2098
|
-
};
|
|
2099
|
-
const ensureRequiredVersions = async (workspaceLocation, creatorPackage, sessionManager, prompter)=>{
|
|
2100
|
-
const libraries = determineWorkspaceIGLibraries(workspaceLocation);
|
|
2101
|
-
// If there are no libraries, we don't need to check for required versions
|
|
2102
|
-
if (libraries.length === 0) {
|
|
2103
|
-
return true;
|
|
2104
|
-
}
|
|
2105
|
-
const targetSession = sessionManager.getTargetSession();
|
|
2106
|
-
const rawUploadedPackages = await getExistingPackages(targetSession);
|
|
2107
|
-
const uploadedPackages = rawUploadedPackages.map((entry)=>{
|
|
2108
|
-
let version;
|
|
2109
|
-
try {
|
|
2110
|
-
version = parseVersionFromNumericVersion(entry.numericVersion);
|
|
2111
|
-
} catch (err) {
|
|
2112
|
-
throw new Error(`Encountered invalid format for version ${entry.numericVersion}`);
|
|
2113
|
-
}
|
|
2114
|
-
if (version.buildNumber < 100) {
|
|
2115
|
-
version.preRelease = {
|
|
2116
|
-
type: "beta",
|
|
2117
|
-
version: version.buildNumber
|
|
2118
|
-
};
|
|
2119
|
-
} else if (version.buildNumber > 100) {
|
|
2120
|
-
version.preRelease = {
|
|
2121
|
-
type: "patch",
|
|
2122
|
-
version: version.buildNumber - 100
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
return {
|
|
2126
|
-
...entry,
|
|
2127
|
-
version
|
|
2128
|
-
};
|
|
2129
|
-
});
|
|
2130
|
-
for (const libraryLocation of libraries){
|
|
2131
|
-
const libraryManifest = readPublishedPackageNpmManifest(libraryLocation);
|
|
2132
|
-
const libraryCreatorPackage = readPublishedPackageCreatorManifest(libraryLocation);
|
|
2133
|
-
if (libraryCreatorPackage === undefined || libraryManifest.main === undefined || libraryCreatorPackage.Package === creatorPackage.Package) {
|
|
2134
|
-
continue;
|
|
2135
|
-
}
|
|
2136
|
-
const libraryVersion = PackageVersion.extractFromLine(libraryManifest.version);
|
|
2137
|
-
if (libraryVersion.preRelease) {
|
|
2138
|
-
libraryVersion.buildNumber = libraryVersion.preRelease.version;
|
|
2139
|
-
libraryVersion.preRelease = undefined;
|
|
2140
|
-
} else {
|
|
2141
|
-
libraryVersion.buildNumber = 100;
|
|
2142
|
-
}
|
|
2143
|
-
let uploadedPackageInBasics;
|
|
2144
|
-
let uploadedPackageInTarget;
|
|
2145
|
-
for (const uploadedPackage of uploadedPackages){
|
|
2146
|
-
if (uploadedPackage.scope === libraryCreatorPackage.Package) {
|
|
2147
|
-
if (uploadedPackage.support) {
|
|
2148
|
-
uploadedPackageInBasics = uploadedPackage;
|
|
2149
|
-
} else {
|
|
2150
|
-
uploadedPackageInTarget = uploadedPackage;
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
const validInBasics = uploadedPackageInBasics !== undefined && !uploadedPackageInBasics.version.isLesserThan(libraryVersion);
|
|
2155
|
-
const validInTarget = uploadedPackageInTarget !== undefined && !uploadedPackageInTarget.version.isLesserThan(libraryVersion);
|
|
2156
|
-
if (validInBasics || validInTarget) {
|
|
2157
|
-
if (targetSession.subDomain !== "Basics" && uploadedPackageInBasics !== undefined && uploadedPackageInTarget !== undefined) {
|
|
2158
|
-
logPackageMessage(creatorPackage.Package, `Package ${libraryCreatorPackage.Package} is uploaded both for Basics and ${targetSession.subDomain}. The package within ${targetSession.subDomain} will be used.`);
|
|
2159
|
-
}
|
|
2160
|
-
continue;
|
|
2161
|
-
}
|
|
2162
|
-
const possibleTargets = [];
|
|
2163
|
-
if (uploadedPackageInBasics) {
|
|
2164
|
-
const version = uploadedPackageInBasics.version.toVersionString({
|
|
2165
|
-
buildNumber: true
|
|
2166
|
-
});
|
|
2167
|
-
possibleTargets.push({
|
|
2168
|
-
value: "Basics",
|
|
2169
|
-
name: `Basics (Current: ${version})`
|
|
2170
|
-
});
|
|
2171
|
-
} else {
|
|
2172
|
-
possibleTargets.push({
|
|
2173
|
-
value: "Basics",
|
|
2174
|
-
name: "Basics (Current: None)"
|
|
2175
|
-
});
|
|
2176
|
-
}
|
|
2177
|
-
if (targetSession.subDomain !== "Basics") {
|
|
2178
|
-
if (uploadedPackageInTarget) {
|
|
2179
|
-
const version = uploadedPackageInTarget.version.toVersionString({
|
|
2180
|
-
buildNumber: true
|
|
2181
|
-
});
|
|
2182
|
-
possibleTargets.push({
|
|
2183
|
-
value: targetSession.subDomain,
|
|
2184
|
-
name: `${targetSession.subDomain} (Current: ${version})`
|
|
2185
|
-
});
|
|
2186
|
-
} else {
|
|
2187
|
-
possibleTargets.push({
|
|
2188
|
-
value: targetSession.subDomain,
|
|
2189
|
-
name: `${targetSession.subDomain} (Current: None)`
|
|
2190
|
-
});
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
const libraryVersionString = libraryVersion.toVersionString({
|
|
2194
|
-
buildNumber: true
|
|
2195
|
-
});
|
|
2196
|
-
const uploadTargetScope = await prompter.ask({
|
|
2197
|
-
message: `Version ${libraryVersionString} of dependency ${libraryCreatorPackage.Package} is required but not available. Please select a subdomain to upload the correct dependency version to`,
|
|
2198
|
-
options: [
|
|
2199
|
-
...possibleTargets,
|
|
2200
|
-
{
|
|
2201
|
-
name: "Skip upload",
|
|
2202
|
-
value: "Skip"
|
|
2203
|
-
}
|
|
2204
|
-
],
|
|
2205
|
-
default: possibleTargets[0].value
|
|
2206
|
-
});
|
|
2207
|
-
if (uploadTargetScope === "Skip") {
|
|
2208
|
-
continue;
|
|
2209
|
-
}
|
|
2210
|
-
const archive = buildArchiveFromPublishedPackage(libraryLocation, libraryManifest, libraryCreatorPackage);
|
|
2211
|
-
const newVersionString = libraryVersion.toVersionString({
|
|
2212
|
-
buildNumber: true
|
|
2213
|
-
});
|
|
2214
|
-
const session = uploadTargetScope === "Basics" ? await sessionManager.getBasicsSession() : targetSession;
|
|
2215
|
-
logPackageMessage(creatorPackage.Package, `Uploading package ${libraryCreatorPackage.Package} with version ${newVersionString} to ${session.domain}.${session.subDomain}`);
|
|
2216
|
-
await uploadPackageFromStream(session, {
|
|
2217
|
-
name: libraryCreatorPackage.Package,
|
|
2218
|
-
version: newVersionString
|
|
2219
|
-
}, archive.generateNodeStream());
|
|
2220
|
-
}
|
|
2221
|
-
};
|
|
2222
|
-
const createSessionManager = async (params)=>{
|
|
2223
|
-
const targetSession = await startSession(params);
|
|
2224
|
-
let basicsSession;
|
|
2225
|
-
return {
|
|
2226
|
-
getBasicsSession: async ()=>{
|
|
2227
|
-
if (targetSession.subDomain === "Basics") {
|
|
2228
|
-
return targetSession;
|
|
2229
|
-
}
|
|
2230
|
-
if (basicsSession === undefined) {
|
|
2231
|
-
basicsSession = await startSession({
|
|
2232
|
-
...params,
|
|
2233
|
-
subDomain: "Basics"
|
|
2234
|
-
});
|
|
2235
|
-
}
|
|
2236
|
-
return basicsSession;
|
|
2237
|
-
},
|
|
2238
|
-
getTargetSession: ()=>targetSession,
|
|
2239
|
-
destroy: async ()=>{
|
|
2240
|
-
await closeSession(targetSession);
|
|
2241
|
-
if (basicsSession !== undefined) {
|
|
2242
|
-
await closeSession(basicsSession);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
};
|
|
2246
|
-
};
|
|
2247
|
-
|
|
2248
|
-
/**
|
|
2249
|
-
* Extracts and returns script array for _Index.json from a src folder
|
|
2250
|
-
*
|
|
2251
|
-
* @param folderPath path to a src folder
|
|
2252
|
-
*/ function generateIndex({ location , ignore =[] , strictOptional =false }) {
|
|
2253
|
-
const files = getPackageTypescriptFiles(location);
|
|
2254
|
-
const filtered = files.filter((path)=>{
|
|
2255
|
-
return !ignore.some((suffix)=>path.endsWith(suffix));
|
|
2256
|
-
});
|
|
2257
|
-
const arr = [];
|
|
2258
|
-
const existingIndex = readPackageCreatorIndex(location) ?? [];
|
|
2259
|
-
const program = ts.createProgram(filtered, {
|
|
2260
|
-
allowJs: true
|
|
2261
|
-
});
|
|
2262
|
-
const typeChecker = program.getTypeChecker();
|
|
2263
|
-
filtered.forEach((file)=>{
|
|
2264
|
-
// Create a Program to represent the project, then pull out the
|
|
2265
|
-
// source file to parse its AST.
|
|
2266
|
-
const sourceFile = program.getSourceFile(file);
|
|
2267
|
-
// Loop through the root AST nodes of the file
|
|
2268
|
-
ts.forEachChild(sourceFile, (node)=>{
|
|
2269
|
-
for (const scriptingClass of findScriptingClasses(node)){
|
|
2270
|
-
if (scriptingClass.node.name === undefined) {
|
|
2271
|
-
throw new Error(`Expected ${scriptingClass.type} class to have a name`);
|
|
2272
|
-
}
|
|
2273
|
-
const name = typeChecker.getFullyQualifiedName(typeChecker.getSymbolAtLocation(scriptingClass.node.name));
|
|
2274
|
-
if (name.length > 45) {
|
|
2275
|
-
throw new Error(`Package name length >45 '${name}'`);
|
|
2276
|
-
}
|
|
2277
|
-
const parameterDeclaration = getScriptingClassParameterdeclaration(scriptingClass);
|
|
2278
|
-
const parametersType = parameterDeclaration === undefined ? undefined : typeChecker.getTypeAtLocation(parameterDeclaration);
|
|
2279
|
-
if (parametersType === undefined) {
|
|
2280
|
-
console.log(`Failed to find parameters type declaration for ${scriptingClass.type} ${name}. Skipping parameter list generation`);
|
|
2281
|
-
}
|
|
2282
|
-
const existingIndexEntry = existingIndex.find((entry)=>entry.Name === name);
|
|
2283
|
-
const obj = {
|
|
2284
|
-
Name: name,
|
|
2285
|
-
Description: (existingIndexEntry == null ? void 0 : existingIndexEntry.Description) ?? name,
|
|
2286
|
-
Type: scriptingClass.type === "evaluator" ? "Evaluator" : "Interactor",
|
|
2287
|
-
Parameters: []
|
|
2288
|
-
};
|
|
2289
|
-
const rawDocTags = ts.getJSDocTags(scriptingClass.node);
|
|
2290
|
-
const dict = getTagDict(rawDocTags);
|
|
2291
|
-
if (dict.summary) {
|
|
2292
|
-
obj.Description = dict.summary;
|
|
2293
|
-
} else {
|
|
2294
|
-
const comment = typeChecker.getTypeAtLocation(scriptingClass.node).symbol.getDocumentationComment(typeChecker).map((comment)=>comment.text).join(" ");
|
|
2295
|
-
if (comment) {
|
|
2296
|
-
obj.Description = comment;
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
if (parametersType !== undefined) {
|
|
2300
|
-
obj.Parameters = parseParametersList(typeChecker.getPropertiesOfType(parametersType), strictOptional);
|
|
2301
|
-
if (obj.Parameters.length === 0 && parametersType.getStringIndexType() !== undefined) {
|
|
2302
|
-
obj.Parameters = (existingIndexEntry == null ? void 0 : existingIndexEntry.Parameters) ?? [];
|
|
2303
|
-
}
|
|
2304
|
-
} else if (existingIndexEntry !== undefined) {
|
|
2305
|
-
obj.Parameters = existingIndexEntry.Parameters;
|
|
2306
|
-
}
|
|
2307
|
-
arr.push(obj);
|
|
2308
|
-
}
|
|
2309
|
-
});
|
|
2310
|
-
});
|
|
2311
|
-
arr.sort((a, b)=>a.Name.localeCompare(b.Name));
|
|
2312
|
-
writePackageCreatorIndex(location, arr);
|
|
2313
|
-
}
|
|
2314
|
-
function capitalizeFirstLetter(string) {
|
|
2315
|
-
return (string == null ? void 0 : string.charAt(0).toUpperCase()) + (string == null ? void 0 : string.slice(1));
|
|
2316
|
-
}
|
|
2317
|
-
const parseDefault = (value, type)=>{
|
|
2318
|
-
const uType = capitalizeFirstLetter(type);
|
|
2319
|
-
if (value === "null") return null;
|
|
2320
|
-
switch(uType){
|
|
2321
|
-
case "LengthM":
|
|
2322
|
-
case "ArcDEG":
|
|
2323
|
-
case "Float":
|
|
2324
|
-
return parseFloat(value);
|
|
2325
|
-
case "Integer":
|
|
2326
|
-
case "Int":
|
|
2327
|
-
return parseInt(value);
|
|
2328
|
-
case "Boolean":
|
|
2329
|
-
case "Bool":
|
|
2330
|
-
return value === "true";
|
|
2331
|
-
case "Material":
|
|
2332
|
-
case "String":
|
|
2333
|
-
case "Geometry":
|
|
2334
|
-
default:
|
|
2335
|
-
return value.replace(/^"/, "").replace(/"$/, "");
|
|
2336
|
-
}
|
|
2337
|
-
};
|
|
2338
|
-
const parseTypeFromName = (name)=>{
|
|
2339
|
-
const parts = name.split(".");
|
|
2340
|
-
const identifier = parts[parts.length - 1];
|
|
2341
|
-
switch(identifier){
|
|
2342
|
-
case "LengthM":
|
|
2343
|
-
case "ArcDEG":
|
|
2344
|
-
case "Float":
|
|
2345
|
-
case "Integer":
|
|
2346
|
-
return identifier;
|
|
2347
|
-
case "GeometryReference":
|
|
2348
|
-
return "Geometry";
|
|
2349
|
-
case "MaterialReference":
|
|
2350
|
-
return "Material";
|
|
2351
|
-
case "AnimationReference":
|
|
2352
|
-
return "Animation";
|
|
2353
|
-
case "InteractorReference":
|
|
2354
|
-
return "Interactor";
|
|
2355
|
-
case "EvaluatorReference":
|
|
2356
|
-
return "Evaluator";
|
|
2357
|
-
case "String":
|
|
2358
|
-
case "string":
|
|
2359
|
-
return "String";
|
|
2360
|
-
case "number":
|
|
2361
|
-
case "Number":
|
|
2362
|
-
return "Float";
|
|
2363
|
-
case "boolean":
|
|
2364
|
-
case "Boolean":
|
|
2365
|
-
return "Boolean";
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
const parseParametersList = (properties, strictOptional)=>{
|
|
2369
|
-
return properties.map((symbol, i)=>{
|
|
2370
|
-
var _symbol_getDeclarations;
|
|
2371
|
-
const parameter = {
|
|
2372
|
-
Name: symbol.name,
|
|
2373
|
-
Description: undefined,
|
|
2374
|
-
Type: "String",
|
|
2375
|
-
Default: undefined,
|
|
2376
|
-
DisplayIndex: i + 1
|
|
2377
|
-
};
|
|
2378
|
-
if (parameter.Name.length > 45) {
|
|
2379
|
-
throw new Error(`Parameter name length >45 '${parameter.Name}'`);
|
|
2380
|
-
}
|
|
2381
|
-
let declaration = (_symbol_getDeclarations = symbol.getDeclarations()) == null ? void 0 : _symbol_getDeclarations[0];
|
|
2382
|
-
let documentationComment = symbol.getDocumentationComment(undefined);
|
|
2383
|
-
let checkLinksSymbol = symbol;
|
|
2384
|
-
while(checkLinksSymbol !== undefined && declaration === undefined){
|
|
2385
|
-
const links = checkLinksSymbol.links;
|
|
2386
|
-
if (links == null ? void 0 : links.syntheticOrigin) {
|
|
2387
|
-
var _links_syntheticOrigin_getDeclarations;
|
|
2388
|
-
declaration = (_links_syntheticOrigin_getDeclarations = links.syntheticOrigin.getDeclarations()) == null ? void 0 : _links_syntheticOrigin_getDeclarations[0];
|
|
2389
|
-
if (documentationComment.length === 0) {
|
|
2390
|
-
documentationComment = links.syntheticOrigin.getDocumentationComment(undefined);
|
|
2391
|
-
}
|
|
2392
|
-
checkLinksSymbol = links.syntheticOrigin;
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
if (declaration !== undefined) {
|
|
2396
|
-
const rawDocTags = ts.getJSDocTags(declaration);
|
|
2397
|
-
const dict = getTagDict(rawDocTags);
|
|
2398
|
-
if (dict.summary) {
|
|
2399
|
-
parameter.Description = dict.summary;
|
|
2400
|
-
} else {
|
|
2401
|
-
const comment = documentationComment.map((comment)=>comment.text).join(" ");
|
|
2402
|
-
if (comment) {
|
|
2403
|
-
parameter.Description = comment;
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
if (dict.creatorType) {
|
|
2407
|
-
parameter.Type = dict.creatorType;
|
|
2408
|
-
} else {
|
|
2409
|
-
const propertySignature = declaration;
|
|
2410
|
-
if (propertySignature.type !== undefined) {
|
|
2411
|
-
const parsedType = parseTypeFromName(propertySignature.type.getText());
|
|
2412
|
-
if (parsedType !== undefined) {
|
|
2413
|
-
parameter.Type = parsedType;
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
if (dict.default) {
|
|
2418
|
-
parameter.Default = parseDefault(dict.default, parameter.Type);
|
|
2419
|
-
}
|
|
2420
|
-
if (strictOptional && declaration.kind === ts.SyntaxKind.PropertySignature) {
|
|
2421
|
-
const propertySignature = declaration;
|
|
2422
|
-
if (propertySignature.questionToken === undefined) {
|
|
2423
|
-
parameter.Required = true;
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
return parameter;
|
|
2428
|
-
});
|
|
2429
|
-
};
|
|
2430
|
-
function getTagDict(tags) {
|
|
2431
|
-
const dict = {};
|
|
2432
|
-
for (const tag of tags){
|
|
2433
|
-
dict[tag.tagName.text] = tag.comment;
|
|
2434
|
-
}
|
|
2435
|
-
return dict;
|
|
2436
|
-
}
|
|
2437
|
-
const getScriptingClassParameterdeclaration = (scriptingClass)=>{
|
|
2438
|
-
for (const member of scriptingClass.node.members){
|
|
2439
|
-
if (ts.isMethodDeclaration(member)) {
|
|
2440
|
-
for(let index = 0; index < member.parameters.length; index++){
|
|
2441
|
-
const parameter = member.parameters[index];
|
|
2442
|
-
if (isScriptingClassParameterDeclaration(scriptingClass, member, index)) {
|
|
2443
|
-
return parameter;
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
if (ts.isConstructorDeclaration(member)) {
|
|
2448
|
-
for(let index = 0; index < member.parameters.length; index++){
|
|
2449
|
-
const parameter = member.parameters[index];
|
|
2450
|
-
if (isScriptingClassParameterDeclaration(scriptingClass, member, index)) {
|
|
2451
|
-
return parameter;
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
};
|
|
2457
|
-
const isScriptingClassParameterDeclaration = (scriptingClass, memberNode, parameterIndex)=>{
|
|
2458
|
-
if (scriptingClass.type === "evaluator") {
|
|
2459
|
-
var _memberNode_name;
|
|
2460
|
-
return (memberNode == null ? void 0 : (_memberNode_name = memberNode.name) == null ? void 0 : _memberNode_name.getText()) == "Create" && parameterIndex === 2;
|
|
2461
|
-
}
|
|
2462
|
-
if (scriptingClass.type === "interactor") {
|
|
2463
|
-
return memberNode.kind === ts.SyntaxKind.Constructor && parameterIndex === 0;
|
|
2464
|
-
}
|
|
2465
|
-
return false;
|
|
2466
|
-
};
|
|
2467
|
-
/**
|
|
2468
|
-
* Finds interactors and evaluators within a script file
|
|
2469
|
-
*
|
|
2470
|
-
* @param {ts.Node} node
|
|
2471
|
-
* @return {*}
|
|
2472
|
-
*/ const findScriptingClasses = (node)=>{
|
|
2473
|
-
let body;
|
|
2474
|
-
if (ts.isModuleDeclaration(node)) {
|
|
2475
|
-
body = node.body;
|
|
2476
|
-
}
|
|
2477
|
-
if (body !== undefined && ts.isModuleDeclaration(body)) {
|
|
2478
|
-
body = body.body;
|
|
2479
|
-
}
|
|
2480
|
-
const classes = [];
|
|
2481
|
-
if (body !== undefined) {
|
|
2482
|
-
ts.forEachChild(body, (child)=>{
|
|
2483
|
-
if (!ts.isClassDeclaration(child)) {
|
|
2484
|
-
return;
|
|
2485
|
-
}
|
|
2486
|
-
const scriptingClass = detectScriptingClass(child);
|
|
2487
|
-
if (scriptingClass !== undefined) {
|
|
2488
|
-
classes.push(scriptingClass);
|
|
2489
|
-
}
|
|
2490
|
-
});
|
|
2491
|
-
}
|
|
2492
|
-
return classes;
|
|
2493
|
-
};
|
|
2494
|
-
const detectScriptingClass = (node)=>{
|
|
2495
|
-
var _node_heritageClauses, _node_heritageClauses1;
|
|
2496
|
-
const isEvaluator = (_node_heritageClauses = node.heritageClauses) == null ? void 0 : _node_heritageClauses.some((clause)=>{
|
|
2497
|
-
if (clause.token !== ts.SyntaxKind.ExtendsKeyword && clause.token !== ts.SyntaxKind.ImplementsKeyword) {
|
|
2498
|
-
return false;
|
|
2499
|
-
}
|
|
2500
|
-
return clause.types.some((type)=>type.getText().includes("Evaluator"));
|
|
2501
|
-
});
|
|
2502
|
-
if (isEvaluator) {
|
|
2503
|
-
return {
|
|
2504
|
-
node,
|
|
2505
|
-
type: "evaluator"
|
|
2506
|
-
};
|
|
2507
|
-
}
|
|
2508
|
-
const isInteractor = (_node_heritageClauses1 = node.heritageClauses) == null ? void 0 : _node_heritageClauses1.some((clause)=>{
|
|
2509
|
-
if (clause.token !== ts.SyntaxKind.ExtendsKeyword) {
|
|
2510
|
-
return false;
|
|
2511
|
-
}
|
|
2512
|
-
return clause.types.some((type)=>type.getText().includes("Interactor"));
|
|
2513
|
-
});
|
|
2514
|
-
if (isInteractor) {
|
|
2515
|
-
return {
|
|
2516
|
-
node,
|
|
2517
|
-
type: "interactor"
|
|
2518
|
-
};
|
|
2519
|
-
}
|
|
2520
|
-
};
|
|
2521
|
-
|
|
2522
|
-
export { buildFolders, buildFoldersWatch, generateIndex, releaseFolder };
|
|
10
|
+
import 'axios';
|
|
11
|
+
import 'typescript';
|
|
12
|
+
import 'typedoc';
|
|
13
|
+
import 'events';
|
|
14
|
+
import 'source-map-js';
|
|
15
|
+
import 'ajv';
|
|
16
|
+
import 'stream/promises';
|
|
17
|
+
import 'child_process';
|
|
18
|
+
import 'util';
|
|
19
|
+
import 'simple-git';
|
|
20
|
+
import 'jszip';
|
|
2523
21
|
//# sourceMappingURL=lib.mjs.map
|