@promptbook/core 0.52.0-16 → 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 +103 -43
- 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 -2
- package/umd/index.umd.js +107 -48
- 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,7 +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
|
|
4
|
+
import { join } from 'path';
|
|
5
5
|
import moment from 'moment';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
@@ -448,7 +448,7 @@ function union() {
|
|
|
448
448
|
/**
|
|
449
449
|
* The version of the Promptbook library
|
|
450
450
|
*/
|
|
451
|
-
var PROMPTBOOK_VERSION = '0.52.0-
|
|
451
|
+
var PROMPTBOOK_VERSION = '0.52.0-17';
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
454
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3169,6 +3169,23 @@ var isRunningInNode = new Function("\n try {\n return this === global;
|
|
|
3169
3169
|
*/
|
|
3170
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");
|
|
3171
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
|
+
|
|
3172
3189
|
/**
|
|
3173
3190
|
* This error indicates that promptbook not found in the library
|
|
3174
3191
|
*/
|
|
@@ -3252,6 +3269,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
3252
3269
|
var _this = this;
|
|
3253
3270
|
var promptbook = this.library.get(url);
|
|
3254
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
|
+
}
|
|
3255
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()
|
|
3256
3276
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
3257
3277
|
.join('\n')), "\n\n "); }));
|
|
@@ -3412,34 +3432,91 @@ function createPromptbookLibraryFromDirectory(path, options) {
|
|
|
3412
3432
|
if (!isRunningInNode()) {
|
|
3413
3433
|
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3414
3434
|
}
|
|
3415
|
-
var _a =
|
|
3435
|
+
var _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c;
|
|
3416
3436
|
return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
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
|
+
}
|
|
3438
3515
|
});
|
|
3439
3516
|
}); });
|
|
3440
3517
|
}
|
|
3441
3518
|
/***
|
|
3442
|
-
* Note: [1] Fixing the dynamic import issue in Webpack
|
|
3519
|
+
* Note: [1] Fixing the dynamic import issue in Webpack (! Not working !)
|
|
3443
3520
|
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
3444
3521
|
* > Critical dependency: the request of a dependency is an expression
|
|
3445
3522
|
*
|
|
@@ -3558,7 +3635,7 @@ function justTestFsImport() {
|
|
|
3558
3635
|
if (!isRunningInNode()) {
|
|
3559
3636
|
throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
|
|
3560
3637
|
}
|
|
3561
|
-
return [4 /*yield*/, glob('/**/*')];
|
|
3638
|
+
return [4 /*yield*/, require(just('glob-promise'))('/**/*')];
|
|
3562
3639
|
case 1:
|
|
3563
3640
|
files = _a.sent();
|
|
3564
3641
|
console.info('testFiles', { files: files });
|
|
@@ -3588,23 +3665,6 @@ function formatNumber(value) {
|
|
|
3588
3665
|
return value.toString();
|
|
3589
3666
|
}
|
|
3590
3667
|
|
|
3591
|
-
/**
|
|
3592
|
-
* Returns the same value that is passed as argument.
|
|
3593
|
-
* No side effects.
|
|
3594
|
-
*
|
|
3595
|
-
* Note: It can be usefull for leveling indentation
|
|
3596
|
-
*
|
|
3597
|
-
* @param value any values
|
|
3598
|
-
* @returns the same values
|
|
3599
|
-
*/
|
|
3600
|
-
function just(value) {
|
|
3601
|
-
if (value === undefined) {
|
|
3602
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3603
|
-
return undefined;
|
|
3604
|
-
}
|
|
3605
|
-
return value;
|
|
3606
|
-
}
|
|
3607
|
-
|
|
3608
3668
|
/**
|
|
3609
3669
|
* Create a markdown table from a 2D array of strings
|
|
3610
3670
|
*
|