Created
August 1, 2022 11:33
-
-
Save muhammedaltug/ee9293b765fdb60a9fd7a37e87505159 to your computer and use it in GitHub Desktop.
Suite modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
Object.defineProperty(exports, '__esModule', { value: true }); | |
const core_1 = require('@angular-devkit/core'); | |
const schematics_1 = require('@angular-devkit/schematics'); | |
const constants_1 = require('../../constants'); | |
const paths = require('../../utils/path'); | |
const cases = require('../../utils/text'); | |
const templateUtils = require('../../utils/template'); | |
const utils_1 = require('../../utils'); | |
function default_1(params) { | |
return schematics_1.chain([ | |
async (tree, _context) => { | |
const entity = utils_1.readSourceJson(params.source); | |
const solution = params.target; | |
const projectName = solution.split('.').pop(); // BookStore in Acme.BookStore | |
const name = entity.Name; | |
const namespace = entity.Namespace; | |
const { options, project } = await utils_1.resolveModuleOptions(tree, { | |
project: projectName, | |
name: entity.Name, | |
route: core_1.strings.dasherize(entity.NamePlural), | |
selector: params.selector, | |
}); | |
if (namespace) options.path = `${options.path}/${cases.dir(namespace)}`; | |
const isMS = utils_1.checkIsMS(params.template); | |
const isModule = utils_1.checkIsModule(params.template, project); | |
const createEntityRoute = utils_1.addRoutingToModule(options, isModule || isMS); | |
const providerPath = | |
isModule || isMS | |
? '.' | |
: namespace | |
? `./${cases.dir(namespace)}/${cases.kebab(name)}` | |
: `./${cases.kebab(name)}`; | |
const injectProvider = | |
isModule || isMS ? utils_1.addProviderToModuleWithProvider : utils_1.addProviderToNgModule; | |
const addRouteProvider = injectProvider( | |
utils_1.findModule( | |
tree, | |
core_1.normalize( | |
isModule || isMS ? utils_1.buildConfigPath(project) : utils_1.buildDefaultPath(project) | |
) | |
), | |
`${cases.macro(namespace)}_${cases.macro(name)}_ROUTE_PROVIDER`, | |
`${providerPath}/providers/${cases.kebab(name)}-route.provider` | |
); | |
const resourceName = isModule || isMS ? projectName : ''; | |
const enums = utils_1.getEnumsFromEntity(solution, entity); | |
const targetPath = core_1.normalize(options.path + paths.relativePathToSrcRoot(namespace)); | |
const entityTemplateOptions = new EntityTemplateOptions({ | |
solution, | |
project: projectName, | |
resourceName, | |
selector: options.selector, | |
entity, | |
enums, | |
projectTemplate: params.template, | |
projectDefinition: project, | |
}); | |
const createEntityFiles = schematics_1.chain([ | |
utils_1.applyWithOverwrite(schematics_1.url('./files'), [ | |
schematics_1.applyTemplates(entityTemplateOptions), | |
schematics_1.move(targetPath), | |
]), | |
]); | |
const apiName = isModule || isMS ? projectName : 'default'; | |
const moduleName = isModule || isMS ? cases.camel(projectName) : 'app'; | |
const generateProxyJson = utils_1.createProxyJsonGenerator( | |
new utils_1.ProxyJsonParams({ project, solution, moduleName, apiName, entity }) | |
); | |
const sourceName = isModule ? 'dev-app' : isMS ? solution.split('.')[0] : options.project; | |
const abpSchematics = './node_modules/@abp/ng.schematics/collection.json'; | |
const generateProxy = schematics_1.externalSchematic(abpSchematics, 'api', { | |
module: moduleName, | |
'api-name': apiName, | |
source: sourceName, | |
target: options.project, | |
}); | |
const generateIndex = schematics_1.externalSchematic(abpSchematics, 'proxy-index', { | |
target: options.project, | |
}); | |
const formatFilesFn = _tree => utils_1.formatFiles(_tree); | |
return schematics_1.branchAndMerge( | |
schematics_1.chain([ | |
createEntityRoute, | |
addRouteProvider, | |
createEntityFiles, | |
formatFilesFn, | |
generateProxyJson, | |
generateProxy, | |
generateIndex, | |
]) | |
); | |
}, | |
]); | |
} | |
exports.default = default_1; | |
class EntityTemplateOptions { | |
constructor(options) { | |
var _a, _b; | |
Object.assign(this, cases, core_1.strings, paths, templateUtils, options); | |
this.isModule = utils_1.checkIsModule(this.projectTemplate, this.projectDefinition); | |
this.isMS = utils_1.checkIsMS(this.projectTemplate); | |
// resourceName can only have value when template is module-pro or microservice-pro | |
this.scope = | |
this.resourceName && !this.isModule ? cases.kebab(this.project) : constants_1.DEFAULT_SCOPE; | |
this.namespace = this.entity.Namespace; | |
this.name = this.entity.Name; | |
this.namePlural = this.entity.NamePlural; | |
this.requiredPolicy = this.project + '.' + this.namePlural; | |
this.navPropsSuffix = | |
((_a = this.entity.NavigationProperties) === null || _a === void 0 ? void 0 : _a.length) || | |
((_b = this.entity.NavigationConnections) === null || _b === void 0 ? void 0 : _b.length) | |
? constants_1.NAVIGATION_PROPERTY_SUFFIX | |
: ''; | |
this.entityNamePrefix = this.navPropsSuffix ? cases.camel(this.name) + '.' : ''; | |
const namespacePath = cases.dir(this.namespace); | |
const relativePath = `${namespacePath}/${cases.kebab(this.name)}`; | |
if (this.isModule || this.isMS) { | |
this.modulePath = `src/lib/${relativePath}`; | |
this.configPath = 'config/src'; | |
} else { | |
this.modulePath = `src/app/${relativePath}`; | |
this.configPath = this.modulePath; | |
} | |
this.props = utils_1.getPropsFromEntity(this.solution, this.entity); | |
this.navProps = utils_1.getNavPropsFromEntity(this.solution, this.entity); | |
this.navConnections = utils_1.getNavConnectionsFromEntity(this.solution, this.entity); | |
this.navEntities = utils_1.getEntityRefsFromProps(this.navProps); | |
this.isModule = this.isModule || this.isMS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment