@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/umd/index.umd.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('path'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'path', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.path, global.moment));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, path, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
10
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
11
|
-
var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
|
|
12
11
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
13
12
|
|
|
14
13
|
/*! *****************************************************************************
|
|
@@ -455,7 +454,7 @@
|
|
|
455
454
|
/**
|
|
456
455
|
* The version of the Promptbook library
|
|
457
456
|
*/
|
|
458
|
-
var PROMPTBOOK_VERSION = '0.52.0-
|
|
457
|
+
var PROMPTBOOK_VERSION = '0.52.0-17';
|
|
459
458
|
|
|
460
459
|
/**
|
|
461
460
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3176,6 +3175,23 @@
|
|
|
3176
3175
|
*/
|
|
3177
3176
|
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");
|
|
3178
3177
|
|
|
3178
|
+
/**
|
|
3179
|
+
* Returns the same value that is passed as argument.
|
|
3180
|
+
* No side effects.
|
|
3181
|
+
*
|
|
3182
|
+
* Note: It can be usefull for leveling indentation
|
|
3183
|
+
*
|
|
3184
|
+
* @param value any values
|
|
3185
|
+
* @returns the same values
|
|
3186
|
+
*/
|
|
3187
|
+
function just(value) {
|
|
3188
|
+
if (value === undefined) {
|
|
3189
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3190
|
+
return undefined;
|
|
3191
|
+
}
|
|
3192
|
+
return value;
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3179
3195
|
/**
|
|
3180
3196
|
* This error indicates that promptbook not found in the library
|
|
3181
3197
|
*/
|
|
@@ -3259,6 +3275,9 @@
|
|
|
3259
3275
|
var _this = this;
|
|
3260
3276
|
var promptbook = this.library.get(url);
|
|
3261
3277
|
if (!promptbook) {
|
|
3278
|
+
if (this.listPromptbooks().length === 0) {
|
|
3279
|
+
throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
3280
|
+
}
|
|
3262
3281
|
throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
3263
3282
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
3264
3283
|
.join('\n')), "\n\n "); }));
|
|
@@ -3414,39 +3433,96 @@
|
|
|
3414
3433
|
* @param options - Misc options for the library
|
|
3415
3434
|
* @returns PromptbookLibrary
|
|
3416
3435
|
*/
|
|
3417
|
-
function createPromptbookLibraryFromDirectory(path, options) {
|
|
3436
|
+
function createPromptbookLibraryFromDirectory(path$1, options) {
|
|
3418
3437
|
var _this = this;
|
|
3419
3438
|
if (!isRunningInNode()) {
|
|
3420
3439
|
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3421
3440
|
}
|
|
3422
|
-
var _a =
|
|
3441
|
+
var _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c;
|
|
3423
3442
|
return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3443
|
+
var justR_equire, fsPromises, readdir, readFile, dirents, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbookString, promptbook, e_1_1;
|
|
3444
|
+
var e_1, _a;
|
|
3445
|
+
return __generator(this, function (_b) {
|
|
3446
|
+
switch (_b.label) {
|
|
3447
|
+
case 0:
|
|
3448
|
+
justR_equire = require;
|
|
3449
|
+
fsPromises = justR_equire(just('fs/promises') /* <- Note: [2] */);
|
|
3450
|
+
readdir = fsPromises.readdir;
|
|
3451
|
+
readFile = fsPromises.readFile;
|
|
3452
|
+
return [4 /*yield*/, readdir(path$1, {
|
|
3453
|
+
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
3454
|
+
})];
|
|
3455
|
+
case 1:
|
|
3456
|
+
dirents = _b.sent();
|
|
3457
|
+
fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
|
|
3458
|
+
var name = _a.name;
|
|
3459
|
+
return path.join(path$1, name);
|
|
3460
|
+
});
|
|
3461
|
+
if (isVerbose) {
|
|
3462
|
+
console.info('createPromptbookLibraryFromDirectory', { path: path$1, isRecursive: isRecursive, dirents: dirents, fileNames: fileNames });
|
|
3463
|
+
}
|
|
3464
|
+
promptbooks = [];
|
|
3465
|
+
_b.label = 2;
|
|
3466
|
+
case 2:
|
|
3467
|
+
_b.trys.push([2, 8, 9, 10]);
|
|
3468
|
+
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3469
|
+
_b.label = 3;
|
|
3470
|
+
case 3:
|
|
3471
|
+
if (!!fileNames_1_1.done) return [3 /*break*/, 7];
|
|
3472
|
+
fileName = fileNames_1_1.value;
|
|
3473
|
+
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3474
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3475
|
+
case 4:
|
|
3476
|
+
promptbookString = (_b.sent());
|
|
3477
|
+
promptbook = promptbookStringToJson(promptbookString);
|
|
3478
|
+
if (!promptbook.promptbookUrl) {
|
|
3479
|
+
if (isVerbose) {
|
|
3480
|
+
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
else {
|
|
3484
|
+
if (isVerbose) {
|
|
3485
|
+
console.info("Loading ".concat(fileName));
|
|
3486
|
+
}
|
|
3487
|
+
// TODO: !!!! Chack url uniqueness and collisions
|
|
3488
|
+
promptbooks.push(promptbook);
|
|
3489
|
+
}
|
|
3490
|
+
return [3 /*break*/, 6];
|
|
3491
|
+
case 5:
|
|
3492
|
+
if (fileName.endsWith('.ptbk.json')) {
|
|
3493
|
+
if (isVerbose) {
|
|
3494
|
+
console.info("Loading ".concat(fileName));
|
|
3495
|
+
}
|
|
3496
|
+
// TODO: !!!! Implement JSON loading
|
|
3497
|
+
// TODO: !!!! Chack url uniqueness and collisions
|
|
3498
|
+
}
|
|
3499
|
+
else {
|
|
3500
|
+
if (isVerbose) {
|
|
3501
|
+
console.info("Skipping file ".concat(fileName));
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
_b.label = 6;
|
|
3505
|
+
case 6:
|
|
3506
|
+
fileNames_1_1 = fileNames_1.next();
|
|
3507
|
+
return [3 /*break*/, 3];
|
|
3508
|
+
case 7: return [3 /*break*/, 10];
|
|
3509
|
+
case 8:
|
|
3510
|
+
e_1_1 = _b.sent();
|
|
3511
|
+
e_1 = { error: e_1_1 };
|
|
3512
|
+
return [3 /*break*/, 10];
|
|
3513
|
+
case 9:
|
|
3514
|
+
try {
|
|
3515
|
+
if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
|
|
3516
|
+
}
|
|
3517
|
+
finally { if (e_1) throw e_1.error; }
|
|
3518
|
+
return [7 /*endfinally*/];
|
|
3519
|
+
case 10: return [2 /*return*/, promptbooks];
|
|
3520
|
+
}
|
|
3445
3521
|
});
|
|
3446
3522
|
}); });
|
|
3447
3523
|
}
|
|
3448
3524
|
/***
|
|
3449
|
-
* Note: [1] Fixing the dynamic import issue in Webpack
|
|
3525
|
+
* Note: [1] Fixing the dynamic import issue in Webpack (! Not working !)
|
|
3450
3526
|
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
3451
3527
|
* > Critical dependency: the request of a dependency is an expression
|
|
3452
3528
|
*
|
|
@@ -3565,7 +3641,7 @@
|
|
|
3565
3641
|
if (!isRunningInNode()) {
|
|
3566
3642
|
throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
|
|
3567
3643
|
}
|
|
3568
|
-
return [4 /*yield*/,
|
|
3644
|
+
return [4 /*yield*/, require(just('glob-promise'))('/**/*')];
|
|
3569
3645
|
case 1:
|
|
3570
3646
|
files = _a.sent();
|
|
3571
3647
|
console.info('testFiles', { files: files });
|
|
@@ -3595,23 +3671,6 @@
|
|
|
3595
3671
|
return value.toString();
|
|
3596
3672
|
}
|
|
3597
3673
|
|
|
3598
|
-
/**
|
|
3599
|
-
* Returns the same value that is passed as argument.
|
|
3600
|
-
* No side effects.
|
|
3601
|
-
*
|
|
3602
|
-
* Note: It can be usefull for leveling indentation
|
|
3603
|
-
*
|
|
3604
|
-
* @param value any values
|
|
3605
|
-
* @returns the same values
|
|
3606
|
-
*/
|
|
3607
|
-
function just(value) {
|
|
3608
|
-
if (value === undefined) {
|
|
3609
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3610
|
-
return undefined;
|
|
3611
|
-
}
|
|
3612
|
-
return value;
|
|
3613
|
-
}
|
|
3614
|
-
|
|
3615
3674
|
/**
|
|
3616
3675
|
* Create a markdown table from a 2D array of strings
|
|
3617
3676
|
*
|