UNPKG

@nstudio/angular

Version:

Angular Plugin for xplat

52 lines (51 loc) 2.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const schematics_1 = require("@angular-devkit/schematics"); const xplat_1 = require("@nstudio/xplat"); const xplat_utils_1 = require("@nstudio/xplat-utils"); const angular_1 = require("@nstudio/angular"); let componentSettings; function default_1(options) { componentSettings = xplat_1.XplatComponentHelpers.prepare(options); const externalChains = []; for (const platform of componentSettings.platforms) { if (xplat_utils_1.supportedPlatforms.includes(platform)) { externalChains.push((tree, context) => (0, schematics_1.externalSchematic)(`@nstudio/${platform}-angular`, 'component', options, { interactive: false, })); } else { throw new Error((0, xplat_1.unsupportedPlatformError)(platform)); } } // if (externalChains.length === 0) { // // none specified, insert noop // externalChains.push(noop()); // } return (0, schematics_1.chain)([ (0, xplat_utils_1.prerun)(), // add component for base libs feature (tree, context) => !options.onlyProject && options.createBase ? (0, angular_1.addToFeature)('', 'component', options, 'libs/xplat', tree, '_base', true)(tree, context) : (0, schematics_1.noop)()(tree, context), // adjust libs barrel for subFolder (tree, context) => options.subFolder && !options.onlyProject && options.createBase ? (0, angular_1.adjustBarrelIndex)('component', options, `libs/xplat/features/src/lib/${componentSettings.featureName}/base/${options.subFolder}/index.ts`, false, true)(tree, context) : (0, schematics_1.noop)()(tree, context), // add index barrel if needed for subFolder (tree, context) => options.needsIndex ? (0, angular_1.addToFeature)('', 'component', options, 'libs/xplat', tree, '_base_index', true)(tree, context) : (0, schematics_1.noop)()(tree, context), // adjust libs barrel (tree, context) => !options.onlyProject && options.createBase ? (0, angular_1.adjustBarrelIndex)('component', options, `libs/xplat/features/src/lib/${componentSettings.featureName}/base/index.ts`, false, true)(tree, context) : (0, schematics_1.noop)()(tree, context), // add index barrel if needed (tree, context) => options.needsIndex ? (0, angular_1.addToFeature)('', 'component', options, 'libs/xplat', tree, '_base_index')(tree, context) : (0, schematics_1.noop)()(tree, context), // add platform chains (tree, context) => (0, schematics_1.chain)(externalChains), ]); }