Skip to content

Commit

Permalink
refactor: move core to brain (#548)
Browse files Browse the repository at this point in the history
* refactor: move core to brain

* refactor: migrating core imports

* refactor: updating deps

* refactor: updating generator

* refactor: fixing import

* refactor: updating cli

* refactor: updating templates

* fix: merge latest changes

* fix: tests
  • Loading branch information
ashley-hunter authored Jan 8, 2025
1 parent 2856e31 commit 74d4016
Show file tree
Hide file tree
Showing 395 changed files with 924 additions and 914 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@ export const routeMeta: RouteMeta = {
also builds on top of angular/cdk. To install it run the following command:
</p>
<spartan-code class="mt-4" code="npm i @angular/cdk" />
<spartan-section-sub-heading id="installing-ui-core">Installing ui-core</spartan-section-sub-heading>
<p class="${hlmP}">
<code class="${hlmCode}">spartan/ui</code>
comes with a core package. To get started install this package with the command below:
</p>
<spartan-code class="mt-4" code="npm i @spartan-ng/ui-core" />
<spartan-section-sub-heading id="setting-up-tailwind">Setting up tailwind.config.js</spartan-section-sub-heading>
<p class="${hlmP}">
You now have to add our spartan-specific configuration to your TailwindCSS setup. To make the setup of your
<code class="${hlmCode}">tailwind.config.js</code>
as easy as possible, the
<code class="${hlmCode}">&#64;spartan-ng/ui-core</code>
<code class="${hlmCode}">&#64;spartan-ng/brain</code>
package comes with it own preset.
</p>
<p class="${hlmP}">Simply add it to the presets array of your config file:</p>
Expand All @@ -86,7 +80,7 @@ const { join } = require('path');
/** @type {import('tailwindcss').Config} */
module.exports = {
presets: [require('@spartan-ng/ui-core/hlm-tailwind-preset')],
presets: [require('@spartan-ng/brain/hlm-tailwind-preset')],
content: [
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
...createGlobPatternsForDependencies(__dirname),
Expand All @@ -100,7 +94,7 @@ module.exports = {
ngCode="
/** @type {import('tailwindcss').Config} */
module.exports = {
presets: [require('@spartan-ng/ui-core/hlm-tailwind-preset')],
presets: [require('@spartan-ng/brain/hlm-tailwind-preset')],
content: [
'./src/**/*.{html,ts}',
'./REPLACE_WITH_PATH_TO_YOUR_COMPONENTS_DIRECTORY/**/*.{html,ts}',
Expand Down
2 changes: 1 addition & 1 deletion apps/app/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { join } = require('node:path');
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: 'class',
presets: [require('../../libs/ui/core/hlm-tailwind-preset.js')],
presets: [require('../../libs/brain/hlm-tailwind-preset.js')],
content: [
join(__dirname, 'index.html'),
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, ViewEncapsulation, computed, inject, signal } from '@angular/core';
import type { CustomElementClassSettable } from '@spartan-ng/ui-core';
import type { CustomElementClassSettable } from '@spartan-ng/brain/core';
import type { ClassValue } from 'clsx';
import { BrnAccordionItemDirective } from './brn-accordion.directive';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive } from '@angular/core';
import { provideExposesStateProviderExisting } from '@spartan-ng/brain/core';
import { BrnDialogContentDirective } from '@spartan-ng/brain/dialog';
import { provideExposesStateProviderExisting } from '@spartan-ng/ui-core';

@Directive({
selector: '[brnAlertDialogContent]',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { provideCustomClassSettableExisting } from '@spartan-ng/brain/core';
import { BrnDialogOverlayComponent } from '@spartan-ng/brain/dialog';
import { provideCustomClassSettableExisting } from '@spartan-ng/ui-core';

@Component({
selector: 'brn-alert-dialog-overlay',
Expand Down
3 changes: 3 additions & 0 deletions libs/brain/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @spartan-ng/brain/core

Secondary entry point of `@spartan-ng/brain`. It can be used by importing from `@spartan-ng/brain/core`.
5 changes: 5 additions & 0 deletions libs/brain/core/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lib": {
"entryFile": "src/index.ts"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions libs/brain/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './helpers/custom-element-class-settable';
export * from './helpers/dev-mode';
export * from './helpers/exposes-side';
export * from './helpers/exposes-state';
export * from './helpers/hlm';
export * from './helpers/table-classes-settable';
export * from './helpers/zone-free';
2 changes: 1 addition & 1 deletion libs/brain/dialog/src/lib/brn-dialog-content.directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Directive, Input, TemplateRef, computed, inject } from '@angular/core';
import { provideExposesStateProviderExisting } from '@spartan-ng/ui-core';
import { provideExposesStateProviderExisting } from '@spartan-ng/brain/core';
import { BrnDialogRef } from './brn-dialog-ref';
import { BrnDialogComponent } from './brn-dialog.component';

Expand Down
2 changes: 1 addition & 1 deletion libs/brain/dialog/src/lib/brn-dialog-overlay.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation, inject } from '@angular/core';
import { provideCustomClassSettableExisting } from '@spartan-ng/ui-core';
import { provideCustomClassSettableExisting } from '@spartan-ng/brain/core';
import { BrnDialogComponent } from './brn-dialog.component';

@Component({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
type ExposesState,
provideExposedSideProviderExisting,
provideExposesStateProviderExisting,
} from '@spartan-ng/ui-core';
} from '@spartan-ng/brain/core';
import { BehaviorSubject, fromEvent, merge, Observable, of, Subject } from 'rxjs';
import { delay, distinctUntilChanged, filter, map, share, switchMap, takeUntil, tap } from 'rxjs/operators';
import { createHoverObservable } from './createHoverObservable';
Expand Down
2 changes: 1 addition & 1 deletion libs/brain/hover-card/src/lib/createHoverObservable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NgZone } from '@angular/core';
import { brnZoneOptimized } from '@spartan-ng/ui-core';
import { brnZoneOptimized } from '@spartan-ng/brain/core';
import { Observable, Subject, fromEvent, merge } from 'rxjs';
import { distinctUntilChanged, filter, map, takeUntil } from 'rxjs/operators';

Expand Down
3 changes: 2 additions & 1 deletion libs/brain/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"dest": "../../dist/libs/brain",
"lib": {
"entryFile": "src/index.ts"
}
},
"assets": ["hlm-tailwind-preset.js"]
}
11 changes: 9 additions & 2 deletions libs/brain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"name": "@spartan-ng/brain",
"version": "0.0.1-alpha.357",
"sideEffects": false,
"exports": {
"./hlm-tailwind-preset": {
"default": "./hlm-tailwind-preset.js"
}
},
"peerDependencies": {
"@angular/cdk": ">=18.0.0",
"@angular/common": ">=18.0.0",
Expand All @@ -10,10 +15,12 @@
"@ngneat/overview": "^5.1.1",
"@ngneat/until-destroy": "^10.0.0",
"@ngxpert/cmdk": "^1.0.0",
"@spartan-ng/ui-core": "0.0.1-alpha.357",
"clsx": ">=2.0.0",
"luxon": ">=3.0.0",
"rxjs": ">=6.6.0"
"rxjs": ">=6.6.0",
"tailwind-merge": ">=2.5.0",
"tailwindcss": ">=3.3.0",
"tailwindcss-animate": ">=1.0.7"
},
"peerDependenciesMeta": {
"@ngneat/overview": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive } from '@angular/core';
import { provideExposesStateProviderExisting } from '@spartan-ng/brain/core';
import { BrnDialogContentDirective } from '@spartan-ng/brain/dialog';
import { provideExposesStateProviderExisting } from '@spartan-ng/ui-core';

@Directive({
selector: '[brnPopoverContent]',
Expand Down
8 changes: 4 additions & 4 deletions libs/brain/select/src/lib/brn-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import {
} from '@angular/core';
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
import { type ControlValueAccessor, FormGroupDirective, NgControl, NgForm } from '@angular/forms';
import { BrnFormFieldControl } from '@spartan-ng/brain/form-field';
import { ChangeFn, ErrorStateMatcher, ErrorStateTracker, TouchFn } from '@spartan-ng/brain/forms';
import { BrnLabelDirective } from '@spartan-ng/brain/label';
import {
type ExposesSide,
type ExposesState,
provideExposedSideProviderExisting,
provideExposesStateProviderExisting,
} from '@spartan-ng/ui-core';
} from '@spartan-ng/brain/core';
import { BrnFormFieldControl } from '@spartan-ng/brain/form-field';
import { ChangeFn, ErrorStateMatcher, ErrorStateTracker, TouchFn } from '@spartan-ng/brain/forms';
import { BrnLabelDirective } from '@spartan-ng/brain/label';
import { Subject, combineLatest, of } from 'rxjs';
import { delay, map, switchMap } from 'rxjs/operators';
import { BrnSelectContentComponent } from './brn-select-content.component';
Expand Down
4 changes: 2 additions & 2 deletions libs/brain/sheet/src/lib/brn-sheet-content.directive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Directive, inject } from '@angular/core';
import { BrnDialogContentDirective } from '@spartan-ng/brain/dialog';
import {
type ExposesSide,
provideExposedSideProviderExisting,
provideExposesStateProviderExisting,
} from '@spartan-ng/ui-core';
} from '@spartan-ng/brain/core';
import { BrnDialogContentDirective } from '@spartan-ng/brain/dialog';
import { BrnSheetComponent } from './brn-sheet.component';

@Directive({
Expand Down
2 changes: 1 addition & 1 deletion libs/brain/sheet/src/lib/brn-sheet-overlay.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { provideCustomClassSettableExisting } from '@spartan-ng/brain/core';
import { BrnDialogOverlayComponent } from '@spartan-ng/brain/dialog';
import { provideCustomClassSettableExisting } from '@spartan-ng/ui-core';

@Component({
selector: 'brn-sheet-overlay',
Expand Down
2 changes: 1 addition & 1 deletion libs/brain/table/src/lib/brn-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ViewEncapsulation,
booleanAttribute,
} from '@angular/core';
import { type TableClassesSettable, provideTableClassesSettableExisting } from '@spartan-ng/ui-core';
import { type TableClassesSettable, provideTableClassesSettableExisting } from '@spartan-ng/brain/core';
import { BrnColumnDefComponent } from './brn-column-def.component';

export type BrnTableDataSourceInput<T> = CdkTableDataSourceInput<T>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
untracked,
ViewContainerRef,
} from '@angular/core';
import { brnDevMode } from '@spartan-ng/ui-core';
import { brnDevMode } from '@spartan-ng/brain/core';
import { Subject } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { BrnTooltipContentComponent } from './brn-tooltip-content.component';
Expand Down
10 changes: 10 additions & 0 deletions libs/cli/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"factory": "./src/generators/migrate-icon/generator",
"schema": "./src/generators/migrate-icon/schema.json",
"description": "Migrate hlm-icon to ng-icon"
},
"migrate-core": {
"factory": "./src/generators/migrate-core/generator",
"schema": "./src/generators/migrate-core/schema.json",
"description": "Migrate core library to brain core entrypoing"
}
},
"schematics": {
Expand Down Expand Up @@ -51,6 +56,11 @@
"factory": "./src/generators/migrate-icon/compat",
"schema": "./src/generators/migrate-icon/schema.json",
"description": "Migrate hlm-icon to ng-icon"
},
"migrate-core": {
"factory": "./src/generators/migrate-scroll-area/compat",
"schema": "./src/generators/migrate-core/schema.json",
"description": "Migrate core library to brain core entrypoing"
}
}
}
57 changes: 3 additions & 54 deletions libs/cli/src/generators/base/lib/build-dependency-array.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,26 @@
import type { HlmBaseGeneratorSchema } from '../schema';
import {
NG_ICONS_VERSION,
SPARTAN_ACCORDION_BRAIN_VERSION,
SPARTAN_ALERT_DIALOG_BRAIN_VERSION,
SPARTAN_AVATAR_BRAIN_VERSION,
SPARTAN_COMMAND_BRAIN_VERSION,
SPARTAN_CORE_VERSION,
SPARTAN_DIALOG_BRAIN_VERSION,
SPARTAN_FORMFIELD_VERSION,
SPARTAN_HOVERCARD_BRAIN_VERSION,
SPARTAN_LABEL_BRAIN_VERSION,
SPARTAN_MENU_BRAIN_VERSION,
SPARTAN_POPOVER_BRAIN_VERSION,
SPARTAN_PROGRESS_BRAIN_VERSION,
SPARTAN_RADIO_GROUP_BRAIN_VERSION,
SPARTAN_SELECT_BRAIN_VERSION,
SPARTAN_SEPARATOR_BRAIN_VERSION,
SPARTAN_SHEET_BRAIN_VERSION,
SPARTAN_SWITCH_VERSION,
SPARTAN_TABLE_VERSION,
SPARTAN_TABS_VERSION,
SPARTAN_TOGGLE_VERSION,
SPARTAN_BRAIN_VERSION,
TAILWINDCSS_VERSION,
TAILWIND_ANIMATE_VERSION,
TAILWIND_MERGE_VERSION,
} from '../versions';

const BRAIN_DEPENDENCY_MAP = {
accordion: SPARTAN_ACCORDION_BRAIN_VERSION,
alertdialog: SPARTAN_ALERT_DIALOG_BRAIN_VERSION,
avatar: SPARTAN_AVATAR_BRAIN_VERSION,
command: SPARTAN_COMMAND_BRAIN_VERSION,
dialog: SPARTAN_DIALOG_BRAIN_VERSION,
hovercard: SPARTAN_HOVERCARD_BRAIN_VERSION,
label: SPARTAN_LABEL_BRAIN_VERSION,
menu: SPARTAN_MENU_BRAIN_VERSION,
popover: SPARTAN_POPOVER_BRAIN_VERSION,
progress: SPARTAN_PROGRESS_BRAIN_VERSION,
radiogroup: SPARTAN_RADIO_GROUP_BRAIN_VERSION,
select: SPARTAN_SELECT_BRAIN_VERSION,
separator: SPARTAN_SEPARATOR_BRAIN_VERSION,
sheet: SPARTAN_SHEET_BRAIN_VERSION,
switch: SPARTAN_SWITCH_VERSION,
tabs: SPARTAN_TABS_VERSION,
table: SPARTAN_TABLE_VERSION,
toggle: SPARTAN_TOGGLE_VERSION,
formfield: SPARTAN_FORMFIELD_VERSION,
};

// TODO: can we combine this with primitive-deps.ts
const DEPENDENT_ON_DIALOG = ['alertdialog', 'sheet', 'popover'];
const DEPENDENT_ON_FORMS = ['input', 'select'];

export function buildDependencyArray(
options: HlmBaseGeneratorSchema,
angularVersion: string,
existingCdkVersion: string,
) {
let dependencies: Record<string, string> = {
'@spartan-ng/ui-core': SPARTAN_CORE_VERSION,
'@angular/cdk': existingCdkVersion ?? angularVersion,
'@spartan-ng/brain': SPARTAN_BRAIN_VERSION,
};

if (options.peerDependencies) {
dependencies = { ...dependencies, ...options.peerDependencies };
}
const brainDependencyVersion = BRAIN_DEPENDENCY_MAP[options.primitiveName];
if (brainDependencyVersion && DEPENDENT_ON_DIALOG.includes(options.primitiveName)) {
dependencies = { ...dependencies, '@spartan-ng/brain/dialog': brainDependencyVersion };
}
if (brainDependencyVersion && DEPENDENT_ON_FORMS.includes(options.primitiveName)) {
dependencies = { ...dependencies, '@spartan-ng/brain/forms': brainDependencyVersion };
}

if (options.primitiveName === 'icon') {
dependencies = { ...dependencies, '@ng-icons/core': NG_ICONS_VERSION };
}
Expand Down
1 change: 0 additions & 1 deletion libs/cli/src/generators/base/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export interface HlmBaseGeneratorSchema {
rootProject?: boolean;
tags?: string;
peerDependencies?: Record<string, string>;
skipBrainDependencies?: boolean;
angularCli?: boolean;
}
22 changes: 1 addition & 21 deletions libs/cli/src/generators/base/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,7 @@ export const FALLBACK_ANGULAR_VERSION = '^18.0.0';
// ng-icon dependency
export const NG_ICONS_VERSION = '^29.10.0';
// spartan dependencies
export const SPARTAN_ACCORDION_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_ALERT_DIALOG_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_AVATAR_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_COMMAND_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_COLLAPSIBLE_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_CORE_VERSION = '0.0.1-alpha.357';
export const SPARTAN_DIALOG_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_FORMFIELD_VERSION = '0.0.1-alpha.357';
export const SPARTAN_HOVERCARD_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_LABEL_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_MENU_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_POPOVER_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_PROGRESS_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_RADIO_GROUP_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_SELECT_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_SEPARATOR_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_SHEET_BRAIN_VERSION = '0.0.1-alpha.357';
export const SPARTAN_SWITCH_VERSION = '0.0.1-alpha.357';
export const SPARTAN_TABS_VERSION = '0.0.1-alpha.357';
export const SPARTAN_TABLE_VERSION = '0.0.1-alpha.357';
export const SPARTAN_TOGGLE_VERSION = '0.0.1-alpha.357';
export const SPARTAN_BRAIN_VERSION = '0.0.1-alpha.357';
// dev dependencies
export const TAILWIND_MERGE_VERSION = '^2.2.0';
export const TAILWINDCSS_VERSION = '^3.0.2';
Expand Down
4 changes: 4 additions & 0 deletions libs/cli/src/generators/migrate-core/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { convertNxGenerator } from '@nx/devkit';
import { migrateCoreGenerator } from './generator';

export default convertNxGenerator(migrateCoreGenerator);
Loading

0 comments on commit 74d4016

Please sign in to comment.