@foblex/flow
Version:
Angular-native node-based UI library for building node editors, workflow builders, and interactive graph interfaces.
84 lines • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = ngAdd;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const utility_1 = require("@schematics/angular/utility");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const foblex_dependencies_1 = require("../shared/foblex-dependencies");
const DEFAULT_THEME_STYLE_PATH = 'node_modules/@foblex/flow/styles/default.scss';
const KNOWN_THEME_STYLE_PATHS = new Set([
DEFAULT_THEME_STYLE_PATH,
'@foblex/flow/styles/default.scss',
]);
function ngAdd() {
return (0, schematics_1.chain)([addDependencies(), addDefaultTheme(), installDependencies()]);
}
function addDependencies() {
return (tree, context) => {
context.logger.info('⚡ Installing @foblex/flow dependencies...');
foblex_dependencies_1.FoblexDependencies.forEach((dependency) => {
(0, dependencies_1.addPackageJsonDependency)(tree, {
type: dependencies_1.NodeDependencyType.Default,
name: dependency.name,
version: dependency.version,
});
context.logger.info(`✅ Added "${dependency.name}" to package.json`);
});
return tree;
};
}
function addDefaultTheme() {
return (0, utility_1.updateWorkspace)((workspace) => {
for (const [, project] of workspace.projects) {
if (project.extensions['projectType'] !== 'application') {
continue;
}
addStyleToTarget(project.targets.get('build'));
addStyleToTarget(project.targets.get('test'));
}
});
}
function addStyleToTarget(target) {
var _a;
if (!target) {
return;
}
ensureThemeInStyles(((_a = target.options) !== null && _a !== void 0 ? _a : (target.options = {})));
if (!target.configurations) {
return;
}
Object.values(target.configurations).forEach((configuration) => {
if (!configuration) {
return;
}
ensureThemeInStyles(configuration);
});
}
function ensureThemeInStyles(options) {
const styles = Array.isArray(options['styles']) ? [...options['styles']] : [];
if (styles.some(isThemeStyleEntry)) {
return;
}
styles.push(DEFAULT_THEME_STYLE_PATH);
options['styles'] = styles;
}
function isThemeStyleEntry(entry) {
if (typeof entry === 'string') {
return KNOWN_THEME_STYLE_PATHS.has(entry);
}
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
return false;
}
const input = entry['input'];
return typeof input === 'string' && KNOWN_THEME_STYLE_PATHS.has(input);
}
function installDependencies() {
return (_tree, context) => {
context.addTask(new tasks_1.NodePackageInstallTask());
context.logger.info(`✅ Added "${DEFAULT_THEME_STYLE_PATH}" to application styles.`);
context.logger.info('✅ All dependencies installed successfully.');
return _tree;
};
}
//# sourceMappingURL=index.js.map