@promptbook/core 0.52.0-17 → 0.52.0-18
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/esm/index.es.js +102 -41
- package/esm/index.es.js.map +1 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +106 -46
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
package/esm/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
2
2
|
import { format } from 'prettier';
|
|
3
3
|
import parserHtml from 'prettier/parser-html';
|
|
4
|
+
import { join } from 'path';
|
|
4
5
|
import moment from 'moment';
|
|
5
6
|
|
|
6
7
|
/*! *****************************************************************************
|
|
@@ -447,7 +448,7 @@ function union() {
|
|
|
447
448
|
/**
|
|
448
449
|
* The version of the Promptbook library
|
|
449
450
|
*/
|
|
450
|
-
var PROMPTBOOK_VERSION = '0.52.0-
|
|
451
|
+
var PROMPTBOOK_VERSION = '0.52.0-17';
|
|
451
452
|
|
|
452
453
|
/**
|
|
453
454
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3168,6 +3169,23 @@ var isRunningInNode = new Function("\n try {\n return this === global;
|
|
|
3168
3169
|
*/
|
|
3169
3170
|
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
3170
3171
|
|
|
3172
|
+
/**
|
|
3173
|
+
* Returns the same value that is passed as argument.
|
|
3174
|
+
* No side effects.
|
|
3175
|
+
*
|
|
3176
|
+
* Note: It can be usefull for leveling indentation
|
|
3177
|
+
*
|
|
3178
|
+
* @param value any values
|
|
3179
|
+
* @returns the same values
|
|
3180
|
+
*/
|
|
3181
|
+
function just(value) {
|
|
3182
|
+
if (value === undefined) {
|
|
3183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3184
|
+
return undefined;
|
|
3185
|
+
}
|
|
3186
|
+
return value;
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3171
3189
|
/**
|
|
3172
3190
|
* This error indicates that promptbook not found in the library
|
|
3173
3191
|
*/
|
|
@@ -3251,6 +3269,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
3251
3269
|
var _this = this;
|
|
3252
3270
|
var promptbook = this.library.get(url);
|
|
3253
3271
|
if (!promptbook) {
|
|
3272
|
+
if (this.listPromptbooks().length === 0) {
|
|
3273
|
+
throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
3274
|
+
}
|
|
3254
3275
|
throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
3255
3276
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
3256
3277
|
.join('\n')), "\n\n "); }));
|
|
@@ -3411,34 +3432,91 @@ function createPromptbookLibraryFromDirectory(path, options) {
|
|
|
3411
3432
|
if (!isRunningInNode()) {
|
|
3412
3433
|
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3413
3434
|
}
|
|
3414
|
-
var _a =
|
|
3435
|
+
var _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c;
|
|
3415
3436
|
return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
+
var justR_equire, fsPromises, readdir, readFile, dirents, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbookString, promptbook, e_1_1;
|
|
3438
|
+
var e_1, _a;
|
|
3439
|
+
return __generator(this, function (_b) {
|
|
3440
|
+
switch (_b.label) {
|
|
3441
|
+
case 0:
|
|
3442
|
+
justR_equire = require;
|
|
3443
|
+
fsPromises = justR_equire(just('fs/promises') /* <- Note: [2] */);
|
|
3444
|
+
readdir = fsPromises.readdir;
|
|
3445
|
+
readFile = fsPromises.readFile;
|
|
3446
|
+
return [4 /*yield*/, readdir(path, {
|
|
3447
|
+
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
3448
|
+
})];
|
|
3449
|
+
case 1:
|
|
3450
|
+
dirents = _b.sent();
|
|
3451
|
+
fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
|
|
3452
|
+
var name = _a.name;
|
|
3453
|
+
return join(path, name);
|
|
3454
|
+
});
|
|
3455
|
+
if (isVerbose) {
|
|
3456
|
+
console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, dirents: dirents, fileNames: fileNames });
|
|
3457
|
+
}
|
|
3458
|
+
promptbooks = [];
|
|
3459
|
+
_b.label = 2;
|
|
3460
|
+
case 2:
|
|
3461
|
+
_b.trys.push([2, 8, 9, 10]);
|
|
3462
|
+
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3463
|
+
_b.label = 3;
|
|
3464
|
+
case 3:
|
|
3465
|
+
if (!!fileNames_1_1.done) return [3 /*break*/, 7];
|
|
3466
|
+
fileName = fileNames_1_1.value;
|
|
3467
|
+
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3468
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3469
|
+
case 4:
|
|
3470
|
+
promptbookString = (_b.sent());
|
|
3471
|
+
promptbook = promptbookStringToJson(promptbookString);
|
|
3472
|
+
if (!promptbook.promptbookUrl) {
|
|
3473
|
+
if (isVerbose) {
|
|
3474
|
+
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
else {
|
|
3478
|
+
if (isVerbose) {
|
|
3479
|
+
console.info("Loading ".concat(fileName));
|
|
3480
|
+
}
|
|
3481
|
+
// TODO: !!!! Chack url uniqueness and collisions
|
|
3482
|
+
promptbooks.push(promptbook);
|
|
3483
|
+
}
|
|
3484
|
+
return [3 /*break*/, 6];
|
|
3485
|
+
case 5:
|
|
3486
|
+
if (fileName.endsWith('.ptbk.json')) {
|
|
3487
|
+
if (isVerbose) {
|
|
3488
|
+
console.info("Loading ".concat(fileName));
|
|
3489
|
+
}
|
|
3490
|
+
// TODO: !!!! Implement JSON loading
|
|
3491
|
+
// TODO: !!!! Chack url uniqueness and collisions
|
|
3492
|
+
}
|
|
3493
|
+
else {
|
|
3494
|
+
if (isVerbose) {
|
|
3495
|
+
console.info("Skipping file ".concat(fileName));
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
_b.label = 6;
|
|
3499
|
+
case 6:
|
|
3500
|
+
fileNames_1_1 = fileNames_1.next();
|
|
3501
|
+
return [3 /*break*/, 3];
|
|
3502
|
+
case 7: return [3 /*break*/, 10];
|
|
3503
|
+
case 8:
|
|
3504
|
+
e_1_1 = _b.sent();
|
|
3505
|
+
e_1 = { error: e_1_1 };
|
|
3506
|
+
return [3 /*break*/, 10];
|
|
3507
|
+
case 9:
|
|
3508
|
+
try {
|
|
3509
|
+
if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
|
|
3510
|
+
}
|
|
3511
|
+
finally { if (e_1) throw e_1.error; }
|
|
3512
|
+
return [7 /*endfinally*/];
|
|
3513
|
+
case 10: return [2 /*return*/, promptbooks];
|
|
3514
|
+
}
|
|
3437
3515
|
});
|
|
3438
3516
|
}); });
|
|
3439
3517
|
}
|
|
3440
3518
|
/***
|
|
3441
|
-
* Note: [1] Fixing the dynamic import issue in Webpack
|
|
3519
|
+
* Note: [1] Fixing the dynamic import issue in Webpack (! Not working !)
|
|
3442
3520
|
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
3443
3521
|
* > Critical dependency: the request of a dependency is an expression
|
|
3444
3522
|
*
|
|
@@ -3545,23 +3623,6 @@ function createPromptbookSublibrary(library, predicate) {
|
|
|
3545
3623
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
3546
3624
|
*/
|
|
3547
3625
|
|
|
3548
|
-
/**
|
|
3549
|
-
* Returns the same value that is passed as argument.
|
|
3550
|
-
* No side effects.
|
|
3551
|
-
*
|
|
3552
|
-
* Note: It can be usefull for leveling indentation
|
|
3553
|
-
*
|
|
3554
|
-
* @param value any values
|
|
3555
|
-
* @returns the same values
|
|
3556
|
-
*/
|
|
3557
|
-
function just(value) {
|
|
3558
|
-
if (value === undefined) {
|
|
3559
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3560
|
-
return undefined;
|
|
3561
|
-
}
|
|
3562
|
-
return value;
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
3626
|
/**
|
|
3566
3627
|
* Just testing imports and compatibility
|
|
3567
3628
|
*/
|