@blackbaud/skyux-lib-stache
Version:
This library was generated with [Nx](https://nx.dev).
61 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ngAdd;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const json_file_1 = require("../utility/json-file");
const GOOGLE_ANALYTICS_URL = 'www.google-analytics.com';
function installEssentialSkyUxPackages(skyuxVersion) {
return async (tree) => {
const packageNames = [
'@skyux/config',
'@skyux/core',
'@skyux/forms',
'@skyux/help-inline',
'@skyux/i18n',
'@skyux/icon',
'@skyux/indicators',
'@skyux/inline-form',
'@skyux/lists',
'@skyux/layout',
'@skyux/lookup',
'@skyux/modals',
];
for (const packageName of packageNames) {
(0, dependencies_1.addPackageJsonDependency)(tree, {
type: dependencies_1.NodeDependencyType.Default,
name: packageName,
version: skyuxVersion,
overwrite: true,
});
}
};
}
function tryConfigureCsp() {
return (tree) => {
const skyuxConfigPath = '/skyuxconfig.json';
if (!tree.exists(skyuxConfigPath)) {
return;
}
try {
const skyuxConfig = new json_file_1.JSONFile(tree, skyuxConfigPath);
const connectSrcJsonPath = ['host', 'csp', 'directives', 'connect-src'];
const connectSrc = skyuxConfig.get(connectSrcJsonPath) ?? [];
if (!connectSrc.includes(GOOGLE_ANALYTICS_URL)) {
connectSrc.push(GOOGLE_ANALYTICS_URL);
}
skyuxConfig.modify(connectSrcJsonPath, connectSrc);
}
catch (err) {
throw new Error('Failed to parse skyuxconfig.json.', { cause: err });
}
};
}
function ngAdd() {
return async (_tree, context) => {
context.addTask(new tasks_1.NodePackageInstallTask());
return (0, schematics_1.chain)([installEssentialSkyUxPackages('^12.0.0'), tryConfigureCsp()]);
};
}
//# sourceMappingURL=ng-add.schematic.js.map