@nova-ui/bits
Version:
SolarWinds Nova Framework
135 lines • 6.95 kB
JavaScript
;
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const find_module_1 = require("@schematics/angular/utility/find-module");
const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
const parse_name_1 = require("@schematics/angular/utility/parse-name");
const validation_1 = require("@schematics/angular/utility/validation");
const project_1 = require("../utility/project");
const project_targets_1 = require("../utility/project-targets");
const schematics_helper_1 = require("../utility/schematics-helper");
const workspace_1 = require("../utility/workspace");
function getBrowserProjectTargets(host, options) {
const workspace = (0, workspace_1.getWorkspace)(host);
const clientProject = (0, project_1.getProject)(workspace, options.project);
return (0, project_targets_1.getProjectTargets)(clientProject)["build"];
}
function addDeclarationToNgModule(options) {
return (host) => {
if (options.skipImport || !options.module) {
return host;
}
const projectTargets = getBrowserProjectTargets(host, options);
const mainPath = projectTargets.options.main;
const appModulePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainPath);
const moduleSource = (0, schematics_helper_1.readIntoSourceFile)(host, appModulePath);
const modulePath = options.module;
const importedModulePath = `/${options.path}/` +
(options.flat ? "" : core_1.strings.dasherize(options.name) + "/") +
core_1.strings.dasherize(options.name) +
".module";
const relativePath = (0, find_module_1.buildRelativePath)(modulePath, importedModulePath);
(0, schematics_helper_1.updateModuleChanges)(host, options, moduleSource, [
{
item: `${core_1.strings.classify(options.name)}Module`,
path: relativePath,
},
{
item: "BrowserAnimationsModule",
path: "@angular/platform-browser/animations",
},
], [{ item: "DatePipe", path: "@angular/common" }]);
return host;
};
}
function default_1(options) {
return (host) => {
if (!options.project) {
throw new schematics_1.SchematicsException("Option (project) is required.");
}
const project = (0, project_1.getProject)(host, options.project);
if (options.path === undefined) {
options.path = (0, project_1.buildDefaultPath)(project);
}
options.module = (0, find_module_1.findModuleFromOptions)(host, options);
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
const targetFolder = core_1.strings.dasherize(options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector =
options.selector || (0, schematics_helper_1.buildSelector)(options, project.prefix);
addDeclarationToNgModule(options);
(0, validation_1.validateHtmlSelector)(options.selector);
const filterGroupOptions = { ...options };
filterGroupOptions.name = "filter-group";
filterGroupOptions.selector = `${options.prefix || project.prefix}-filter-group`;
filterGroupOptions.path = `${options.path}/${targetFolder}`;
filterGroupOptions.module = `${options.name}.module.ts`;
filterGroupOptions.skipImport = true;
const listOptions = { ...options };
listOptions.name = "filtered-view-list";
listOptions.selector = `${options.selector}-list`;
listOptions.path = `${options.path}/${targetFolder}`;
listOptions.skipImport = true;
listOptions.dataSourceName = options.name;
// TODO: validate after creating proper schematic for table
const tableOptions = { ...options };
tableOptions.name = "filtered-view-table";
tableOptions.selector = `${options.selector}-table`;
tableOptions.path = `${options.path}/${targetFolder}`;
tableOptions.skipImport = true;
tableOptions.dataSourceName = options.name;
options.childSelector =
options.presentationType === "table"
? tableOptions.selector
: listOptions.selector;
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)("./files"), [
(0, schematics_1.template)({
...core_1.strings,
"if-flat": (s) => (options.flat ? "" : s),
...options,
}),
(0, schematics_1.filter)((path) => {
if (options.dataSource === "none" &&
path.endsWith("data-source.service.ts")) {
return false;
}
return (options.dataSource !== "custom" ||
(options.dataSource === "custom" &&
!path.endsWith("data-source.service.ts") &&
!path.endsWith("data.ts") &&
!path.endsWith("types.ts")));
}),
(0, schematics_1.move)(parsedPath.path),
]);
return (0, schematics_1.chain)([
(0, schematics_1.mergeWith)(templateSource),
(0, schematics_1.branchAndMerge)((0, schematics_1.schematic)("filter-group", filterGroupOptions)),
options.presentationType === "table"
? (0, schematics_1.branchAndMerge)((0, schematics_1.schematic)("table", tableOptions))
: (0, schematics_1.branchAndMerge)((0, schematics_1.schematic)("list", listOptions)),
]);
};
}
exports.default = default_1;
//# sourceMappingURL=index.js.map