69 lines
8.0 KiB
JavaScript
69 lines
8.0 KiB
JavaScript
"use strict";
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.addDeclarationToNgModule = void 0;
|
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
const ast_utils_1 = require("./ast-utils");
|
|
const change_1 = require("./change");
|
|
const find_module_1 = require("./find-module");
|
|
function addDeclarationToNgModule(options) {
|
|
return (host) => {
|
|
const modulePath = options.module;
|
|
if (options.skipImport || options.standalone || !modulePath) {
|
|
return host;
|
|
}
|
|
const sourceText = host.readText(modulePath);
|
|
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
const filePath = `/${options.path}/` +
|
|
(options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
|
|
schematics_1.strings.dasherize(options.name) +
|
|
(options.type ? '.' : '') +
|
|
schematics_1.strings.dasherize(options.type);
|
|
const importPath = (0, find_module_1.buildRelativePath)(modulePath, filePath);
|
|
const classifiedName = schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type);
|
|
const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, importPath);
|
|
if (options.export) {
|
|
changes.push(...(0, ast_utils_1.addSymbolToNgModuleMetadata)(source, modulePath, 'exports', classifiedName));
|
|
}
|
|
const recorder = host.beginUpdate(modulePath);
|
|
for (const change of changes) {
|
|
if (change instanceof change_1.InsertChange) {
|
|
recorder.insertLeft(change.pos, change.toAdd);
|
|
}
|
|
}
|
|
host.commitUpdate(recorder);
|
|
return host;
|
|
};
|
|
}
|
|
exports.addDeclarationToNgModule = addDeclarationToNgModule;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkLWRlY2xhcmF0aW9uLXRvLW5nLW1vZHVsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3NjaGVtYXRpY3MvYW5ndWxhci91dGlsaXR5L2FkZC1kZWNsYXJhdGlvbi10by1uZy1tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFFSCwyREFBaUU7QUFDakUsa0dBQW9GO0FBQ3BGLDJDQUFrRjtBQUNsRixxQ0FBd0M7QUFDeEMsK0NBQWtEO0FBYWxELFNBQWdCLHdCQUF3QixDQUFDLE9BQXFDO0lBQzVFLE9BQU8sQ0FBQyxJQUFVLEVBQUUsRUFBRTtRQUNwQixNQUFNLFVBQVUsR0FBRyxPQUF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