ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
60 lines • 3.34 kB
JavaScript
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addDeclaration = exports.addModule = void 0;
const schematics_1 = require("@angular/cdk/schematics");
const schematics_2 = require("@angular-devkit/schematics");
const change_1 = require("@schematics/angular/utility/change");
const find_module_1 = require("@schematics/angular/utility/find-module");
const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
const workspace_1 = require("@schematics/angular/utility/workspace");
const ts = require("typescript");
function readIntoSourceFile(host, modulePath) {
const text = host.read(modulePath);
if (text === null) {
throw new schematics_2.SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
return ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
}
function addModule(moduleName, modulePath) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, workspace_1.getWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace);
(0, schematics_1.addModuleImportToRootModule)(host, moduleName, modulePath, project);
return (0, schematics_2.noop)();
});
}
exports.addModule = addModule;
function addDeclaration(componentName, componentPath) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, workspace_1.getWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace);
const appModulePath = (0, ng_ast_utils_1.getAppModulePath)(host, (0, schematics_1.getProjectMainFile)(project));
const source = readIntoSourceFile(host, appModulePath);
const relativePath = (0, find_module_1.buildRelativePath)(appModulePath, componentPath);
const declarationChanges = (0, schematics_1.addDeclarationToModule)(source, appModulePath, componentName, relativePath);
const declarationRecorder = host.beginUpdate(appModulePath);
for (const change of declarationChanges) {
if (change instanceof change_1.InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
return (0, schematics_2.noop)();
});
}
exports.addDeclaration = addDeclaration;
//# sourceMappingURL=root-module.js.map
;