@spartacus/smartedit
Version:
Smart Edit feature library for Spartacus
65 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSmartEditFeatures = void 0;
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@spartacus/schematics");
const package_json_1 = require("../../package.json");
const constants_1 = require("../constants");
function addSmartEditFeatures(options) {
return (tree, _context) => {
const packageJson = schematics_2.readPackageJson(tree);
schematics_2.validateSpartacusInstallation(packageJson);
return schematics_1.chain([
schematics_2.addPackageJsonDependenciesForLibrary(package_json_1.peerDependencies, options),
schematics_2.shouldAddFeature(schematics_2.CLI_SMARTEDIT_FEATURE, options.features)
? addSmartEditFeature(options)
: schematics_1.noop(),
]);
};
}
exports.addSmartEditFeatures = addSmartEditFeatures;
function addSmartEditFeature(options) {
const customConfig = [];
if (options.storefrontPreviewRoute || options.allowOrigin) {
let content = `<${schematics_2.SMART_EDIT_CONFIG}>{
smartEdit: {\n`;
if (options.storefrontPreviewRoute) {
content += `storefrontPreviewRoute: '${options.storefrontPreviewRoute}',\n`;
}
if (options.allowOrigin) {
content += `allowOrigin: '${options.allowOrigin}',\n`;
}
content += `},\n}`;
customConfig.push({
import: [
{
moduleSpecifier: constants_1.SPARTACUS_SMARTEDIT_ROOT,
namedImports: [schematics_2.SMART_EDIT_CONFIG],
},
],
content,
});
}
return schematics_2.addLibraryFeature(options, {
folderName: constants_1.SMARTEDIT_FOLDER_NAME,
moduleName: constants_1.SMARTEDIT_MODULE_NAME,
featureModule: {
name: constants_1.SMARTEDIT_MODULE,
importPath: schematics_2.SPARTACUS_SMARTEDIT,
},
rootModule: {
name: constants_1.SMARTEDIT_ROOT_MODULE,
importPath: constants_1.SPARTACUS_SMARTEDIT_ROOT,
},
lazyLoadingChunk: {
moduleSpecifier: constants_1.SPARTACUS_SMARTEDIT_ROOT,
namedImports: [constants_1.SMARTEDIT_FEATURE_NAME_CONSTANT],
},
customConfig,
assets: {
input: constants_1.SPARTACUS_SMARTEDIT_ASSETS,
glob: '**/*',
},
});
}
//# sourceMappingURL=index.js.map