[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
| 10 | if (k2 === undefined) k2 = k;
|
---|
| 11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
| 12 | }) : (function(o, m, k, k2) {
|
---|
| 13 | if (k2 === undefined) k2 = k;
|
---|
| 14 | o[k2] = m[k];
|
---|
| 15 | }));
|
---|
| 16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
| 17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
| 18 | }) : function(o, v) {
|
---|
| 19 | o["default"] = v;
|
---|
| 20 | });
|
---|
| 21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
| 22 | if (mod && mod.__esModule) return mod;
|
---|
| 23 | var result = {};
|
---|
| 24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
| 25 | __setModuleDefault(result, mod);
|
---|
| 26 | return result;
|
---|
| 27 | };
|
---|
| 28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 29 | exports.FileSystemEngineHost = void 0;
|
---|
| 30 | const fs_1 = require("fs");
|
---|
| 31 | const path_1 = require("path");
|
---|
| 32 | const rxjs_1 = require("rxjs");
|
---|
| 33 | const operators_1 = require("rxjs/operators");
|
---|
| 34 | const src_1 = require("../src");
|
---|
| 35 | const export_ref_1 = require("./export-ref");
|
---|
| 36 | const file_system_engine_host_base_1 = require("./file-system-engine-host-base");
|
---|
| 37 | /**
|
---|
| 38 | * A simple EngineHost that uses a root with one directory per collection inside of it. The
|
---|
| 39 | * collection declaration follows the same rules as the regular FileSystemEngineHostBase.
|
---|
| 40 | */
|
---|
| 41 | class FileSystemEngineHost extends file_system_engine_host_base_1.FileSystemEngineHostBase {
|
---|
| 42 | constructor(_root) {
|
---|
| 43 | super();
|
---|
| 44 | this._root = _root;
|
---|
| 45 | }
|
---|
| 46 | _resolveCollectionPath(name) {
|
---|
| 47 | try {
|
---|
| 48 | // Allow `${_root}/${name}.json` as a collection.
|
---|
| 49 | const maybePath = require.resolve(path_1.join(this._root, name + '.json'));
|
---|
| 50 | if (fs_1.existsSync(maybePath)) {
|
---|
| 51 | return maybePath;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | catch (error) { }
|
---|
| 55 | try {
|
---|
| 56 | // Allow `${_root}/${name}/collection.json.
|
---|
| 57 | const maybePath = require.resolve(path_1.join(this._root, name, 'collection.json'));
|
---|
| 58 | if (fs_1.existsSync(maybePath)) {
|
---|
| 59 | return maybePath;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | catch (error) { }
|
---|
| 63 | throw new file_system_engine_host_base_1.CollectionCannotBeResolvedException(name);
|
---|
| 64 | }
|
---|
| 65 | _resolveReferenceString(refString, parentPath) {
|
---|
| 66 | // Use the same kind of export strings as NodeModule.
|
---|
| 67 | const ref = new export_ref_1.ExportStringRef(refString, parentPath);
|
---|
| 68 | if (!ref.ref) {
|
---|
| 69 | return null;
|
---|
| 70 | }
|
---|
| 71 | return { ref: ref.ref, path: ref.module };
|
---|
| 72 | }
|
---|
| 73 | _transformCollectionDescription(name, desc) {
|
---|
| 74 | if (!desc.schematics || typeof desc.schematics != 'object') {
|
---|
| 75 | throw new file_system_engine_host_base_1.CollectionMissingSchematicsMapException(name);
|
---|
| 76 | }
|
---|
| 77 | return {
|
---|
| 78 | ...desc,
|
---|
| 79 | name,
|
---|
| 80 | };
|
---|
| 81 | }
|
---|
| 82 | _transformSchematicDescription(name, _collection, desc) {
|
---|
| 83 | if (!desc.factoryFn || !desc.path || !desc.description) {
|
---|
| 84 | throw new file_system_engine_host_base_1.SchematicMissingFieldsException(name);
|
---|
| 85 | }
|
---|
| 86 | return desc;
|
---|
| 87 | }
|
---|
| 88 | hasTaskExecutor(name) {
|
---|
| 89 | if (super.hasTaskExecutor(name)) {
|
---|
| 90 | return true;
|
---|
| 91 | }
|
---|
| 92 | try {
|
---|
| 93 | const maybePath = require.resolve(path_1.join(this._root, name));
|
---|
| 94 | if (fs_1.existsSync(maybePath)) {
|
---|
| 95 | return true;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | catch { }
|
---|
| 99 | return false;
|
---|
| 100 | }
|
---|
| 101 | createTaskExecutor(name) {
|
---|
| 102 | if (!super.hasTaskExecutor(name)) {
|
---|
| 103 | try {
|
---|
| 104 | const path = require.resolve(path_1.join(this._root, name));
|
---|
| 105 | // Default handling code is for old tasks that incorrectly export `default` with non-ESM module
|
---|
| 106 | return rxjs_1.from(Promise.resolve().then(() => __importStar(require(path))).then((mod) => { var _a; return (((_a = mod.default) === null || _a === void 0 ? void 0 : _a.default) || mod.default)(); })).pipe(operators_1.catchError(() => rxjs_1.throwError(new src_1.UnregisteredTaskException(name))));
|
---|
| 107 | }
|
---|
| 108 | catch { }
|
---|
| 109 | }
|
---|
| 110 | return super.createTaskExecutor(name);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | exports.FileSystemEngineHost = FileSystemEngineHost;
|
---|