@solercia/ui 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +150 -0
- package/README.md +38 -9
- package/fesm2022/solercia-ui.mjs +6669 -2596
- package/fesm2022/solercia-ui.mjs.map +1 -1
- package/package.json +2 -1
- package/schematics/ng-add/index.js +128 -42
- package/types/solercia-ui.d.ts +1641 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solercia/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Design system Solercia (componentes sol-*, theming agnóstico por puertos, contrato i18n y schematics ng add/ng generate) para proyectos Angular del ecosistema Solercia.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Solercia Solutions SAS",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"migrations": "./schematics/migrations.json"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
+
"@angular/cdk": "^22.0.0",
|
|
21
22
|
"@angular/common": "^22.0.0",
|
|
22
23
|
"@angular/core": "^22.0.0",
|
|
23
24
|
"@angular/forms": "^22.0.0",
|
|
@@ -5,32 +5,39 @@ const schematics_1 = require("@angular-devkit/schematics");
|
|
|
5
5
|
const utility_1 = require("@schematics/angular/utility");
|
|
6
6
|
const json_file_1 = require("@schematics/angular/utility/json-file");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
/** Alias FSD fijos del ecosistema Solercia (CONVENCIONES-FRONT-SOLERCIA.md).
|
|
8
|
+
/** Alias FSD fijos del ecosistema Solercia (CONVENCIONES-FRONT-SOLERCIA.md).
|
|
9
|
+
* Prefijo `./` explícito (fix TS5090): un `tsconfig.json` de `ng new` NO
|
|
10
|
+
* define `baseUrl`, así que una entrada de `paths` sin `./` (p. ej.
|
|
11
|
+
* `"src/pages/*"`) queda ambigua para el compilador y falla con
|
|
12
|
+
* `TS5090 (non-relative paths are not allowed when 'baseUrl' is not set)`. */
|
|
9
13
|
function fsdPathAliases(sourceRoot) {
|
|
10
14
|
return {
|
|
11
|
-
'@app/*': [
|
|
12
|
-
'@pages/*': [
|
|
13
|
-
'@widgets/*': [
|
|
14
|
-
'@features/*': [
|
|
15
|
-
'@entities/*': [
|
|
16
|
-
'@shared/*': [
|
|
15
|
+
'@app/*': [`./${sourceRoot}/app/*`],
|
|
16
|
+
'@pages/*': [`./${sourceRoot}/pages/*`],
|
|
17
|
+
'@widgets/*': [`./${sourceRoot}/widgets/*`],
|
|
18
|
+
'@features/*': [`./${sourceRoot}/features/*`],
|
|
19
|
+
'@entities/*': [`./${sourceRoot}/entities/*`],
|
|
20
|
+
'@shared/*': [`./${sourceRoot}/shared/*`],
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* `ng add @solercia/ui` — scaffoldea el andamiaje FSD en un proyecto Angular
|
|
21
25
|
* standalone recién creado (`ng new`): carpetas `pages/widgets/features/entities`
|
|
22
26
|
* (con sus `index.ts` agregadores) + `shared/tokens` (adaptadores de los
|
|
23
|
-
* puertos de `@solercia/ui`)
|
|
24
|
-
*
|
|
27
|
+
* puertos de theming/tenant de `@solercia/ui`) + `shared/i18n` (adaptador del
|
|
28
|
+
* puerto `SOL_I18N`, consumido también por los schematics `page/feature/widget`),
|
|
29
|
+
* path aliases en `tsconfig.json`, `provideTheme()` cableado real en
|
|
30
|
+
* `app.config.ts`, `@solercia/eslint-config` instalada como `devDependency` y
|
|
25
31
|
* Husky + lint-staged + commitlint.
|
|
26
32
|
*
|
|
27
33
|
* Alcance deliberado (ver `openspec/07-e9-extraccion-solercia-ui/design.md`,
|
|
28
34
|
* Decisión A): `@solercia/ui` expone puertos (`THEME_SOURCE`, `SOL_TENANT_RESOLVER`,
|
|
29
35
|
* `SOL_I18N`) con defaults null-object `providedIn: 'root'` — un proyecto recién
|
|
30
36
|
* scaffoldeado YA renderiza con el tema por defecto de la librería sin wiring
|
|
31
|
-
* adicional. `ng-add` deja los ADAPTADORES listos en `shared/tokens/`
|
|
32
|
-
* para cuando el consumidor tenga backend/tenant
|
|
33
|
-
* llamada HTTP falsa que rompería un `ng new`
|
|
37
|
+
* adicional. `ng-add` deja los ADAPTADORES listos en `shared/tokens/` y
|
|
38
|
+
* `shared/i18n/` (con TODO) para cuando el consumidor tenga backend/tenant/motor
|
|
39
|
+
* i18n real, en vez de inventar una llamada HTTP falsa que rompería un `ng new`
|
|
40
|
+
* limpio.
|
|
34
41
|
*/
|
|
35
42
|
function ngAdd(options) {
|
|
36
43
|
return async (tree, context) => {
|
|
@@ -39,6 +46,7 @@ function ngAdd(options) {
|
|
|
39
46
|
const rules = [
|
|
40
47
|
scaffoldFsdLayers(sourceRoot),
|
|
41
48
|
scaffoldThemeAdapters(sourceRoot),
|
|
49
|
+
scaffoldI18nAdapter(sourceRoot),
|
|
42
50
|
wireTsconfigPaths(sourceRoot),
|
|
43
51
|
appendGlobalStyles(sourceRoot, context),
|
|
44
52
|
scaffoldEslintConfig(context),
|
|
@@ -57,13 +65,18 @@ function ngAdd(options) {
|
|
|
57
65
|
context.logger.warn('[@solercia/ui] No se encontró angular.json — se omite el cableado automático de ' +
|
|
58
66
|
'provideTheme() en app.config.ts. Agrégalo a mano: providers: [provideTheme(), ...].');
|
|
59
67
|
}
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
68
|
+
// devDependencies que SÍ existen en un registry público — `addDependency`
|
|
69
|
+
// ya agenda su propia NodePackageInstallTask (una sola, deduplicada) salvo
|
|
70
|
+
// `skipInstall`. `@solercia/eslint-config` está publicado desde 0.1.1 (npm
|
|
71
|
+
// público) y es el preset que referencia el `eslint.config.{js,mjs}`
|
|
72
|
+
// scaffoldeado por `scaffoldEslintConfig`.
|
|
64
73
|
const installBehavior = options.skipInstall ? utility_1.InstallBehavior.None : utility_1.InstallBehavior.Auto;
|
|
65
74
|
return (0, schematics_1.chain)([
|
|
66
75
|
...rules,
|
|
76
|
+
(0, utility_1.addDependency)('@solercia/eslint-config', '^0.1.1', {
|
|
77
|
+
type: utility_1.DependencyType.Dev,
|
|
78
|
+
install: installBehavior,
|
|
79
|
+
}),
|
|
67
80
|
(0, utility_1.addDependency)('husky', '^9.1.7', { type: utility_1.DependencyType.Dev, install: installBehavior }),
|
|
68
81
|
(0, utility_1.addDependency)('lint-staged', '^17.0.8', { type: utility_1.DependencyType.Dev, install: installBehavior }),
|
|
69
82
|
(0, utility_1.addDependency)('@commitlint/cli', '^21.2.1', { type: utility_1.DependencyType.Dev, install: installBehavior }),
|
|
@@ -71,15 +84,6 @@ function ngAdd(options) {
|
|
|
71
84
|
type: utility_1.DependencyType.Dev,
|
|
72
85
|
install: installBehavior,
|
|
73
86
|
}),
|
|
74
|
-
// @solercia/eslint-config aún no está publicado (07-e9 PR4, bloqueado por
|
|
75
|
-
// D1 del openspec madre): se documenta como pendiente en vez de forzar un
|
|
76
|
-
// `npm install` que fallaría contra un paquete inexistente en el registry.
|
|
77
|
-
(host, ctx) => {
|
|
78
|
-
ctx.logger.info('[@solercia/ui] @solercia/eslint-config todavía no está publicado (PR4 pendiente). ' +
|
|
79
|
-
'eslint.config.js quedó listo esperándolo — mientras tanto, referencia el preset por ' +
|
|
80
|
-
'ruta relativa si tienes el monorepo clonado (ver packages/eslint-config/README.md).');
|
|
81
|
-
return host;
|
|
82
|
-
},
|
|
83
87
|
]);
|
|
84
88
|
};
|
|
85
89
|
}
|
|
@@ -151,6 +155,53 @@ function scaffoldThemeAdapters(sourceRoot) {
|
|
|
151
155
|
return tree;
|
|
152
156
|
};
|
|
153
157
|
}
|
|
158
|
+
/** Adaptador mínimo de `SOL_I18N` (puerto de `@solercia/ui`) en `shared/i18n/`.
|
|
159
|
+
* Fix TS2571: los schematics `page`/`feature`/`widget` de esta misma colección
|
|
160
|
+
* generan código que importa `I18nService` desde `@shared/i18n` — sin esta capa
|
|
161
|
+
* el proyecto horneado por el starter no compila. Por defecto es una identidad
|
|
162
|
+
* (retorna la clave sin traducir), igual que `createIdentitySolI18n()` de la
|
|
163
|
+
* librería; el consumidor reemplaza el cuerpo por su motor real (Transloco,
|
|
164
|
+
* ngx-translate, `@angular/localize`) cuando lo tenga — ver
|
|
165
|
+
* projects/solercia/ui/docs/I18N.md. */
|
|
166
|
+
function scaffoldI18nAdapter(sourceRoot) {
|
|
167
|
+
return (tree) => {
|
|
168
|
+
const dir = `/${sourceRoot}/shared/i18n`;
|
|
169
|
+
const servicePath = `${dir}/i18n.service.ts`;
|
|
170
|
+
if (!tree.exists(servicePath)) {
|
|
171
|
+
tree.create(servicePath, `import { Injectable, Signal, signal } from '@angular/core';\n` +
|
|
172
|
+
`import type { SolI18n } from '@solercia/ui';\n\n` +
|
|
173
|
+
`/**\n` +
|
|
174
|
+
` * Adaptador de SOL_I18N (puerto de @solercia/ui), consumido también por los\n` +
|
|
175
|
+
` * componentes que generan los schematics \`page\`/\`feature\`/\`widget\` de esta\n` +
|
|
176
|
+
` * misma colección (\`inject(I18nService)\`). Por defecto es una identidad\n` +
|
|
177
|
+
` * (retorna la clave sin traducir) — reemplaza el cuerpo por tu motor real\n` +
|
|
178
|
+
` * (Transloco, ngx-translate, @angular/localize) cuando el proyecto lo tenga.\n` +
|
|
179
|
+
` * Para que los propios componentes de @solercia/ui usen el mismo motor,\n` +
|
|
180
|
+
` * cablea en app.config.ts:\n` +
|
|
181
|
+
` * { provide: SOL_I18N, useExisting: I18nService }\n` +
|
|
182
|
+
` * (ver projects/solercia/ui/docs/I18N.md del monorepo).\n` +
|
|
183
|
+
` */\n` +
|
|
184
|
+
`@Injectable({ providedIn: 'root' })\n` +
|
|
185
|
+
`export class I18nService implements SolI18n {\n` +
|
|
186
|
+
` readonly activeLang: Signal<string> = signal('es-CO');\n\n` +
|
|
187
|
+
` translate(key: string, _params?: Record<string, unknown>): string {\n` +
|
|
188
|
+
` return key;\n` +
|
|
189
|
+
` }\n\n` +
|
|
190
|
+
` t(key: string, _params?: Record<string, unknown>): Signal<string> {\n` +
|
|
191
|
+
` return signal(key);\n` +
|
|
192
|
+
` }\n\n` +
|
|
193
|
+
` tMany(keys: string[]): Signal<string[]> {\n` +
|
|
194
|
+
` return signal(keys);\n` +
|
|
195
|
+
` }\n` +
|
|
196
|
+
`}\n`);
|
|
197
|
+
}
|
|
198
|
+
const indexPath = `${dir}/index.ts`;
|
|
199
|
+
if (!tree.exists(indexPath)) {
|
|
200
|
+
tree.create(indexPath, `export { I18nService } from './i18n.service';\n`);
|
|
201
|
+
}
|
|
202
|
+
return tree;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
154
205
|
/** Path aliases FSD en `tsconfig.json` (edición segura vía JSONC AST — tolera
|
|
155
206
|
* comentarios/trailing commas, igual que el resto del tooling oficial Angular). */
|
|
156
207
|
function wireTsconfigPaths(sourceRoot) {
|
|
@@ -168,14 +219,19 @@ function wireTsconfigPaths(sourceRoot) {
|
|
|
168
219
|
}
|
|
169
220
|
/** Snippet de estilos globales que demuestra el consumo de los tokens `--sol-*`
|
|
170
221
|
* (el resto de las 95 variables las emite ThemeService en runtime — ver
|
|
171
|
-
* projects/solercia/ui/docs/THEMING.md).
|
|
172
|
-
* `styles.
|
|
222
|
+
* projects/solercia/ui/docs/THEMING.md). Detecta tanto `styles.css` como
|
|
223
|
+
* `styles.scss` (fix: `ng new --style=scss` dejaba los tokens sin inyectar
|
|
224
|
+
* porque solo se comprobaba `styles.css`); el snippet usa comentarios estilo
|
|
225
|
+
* CSS de bloque, válidos también en SCSS. Si el proyecto no tiene ninguno de
|
|
226
|
+
* los dos archivos, solo avisa. */
|
|
173
227
|
function appendGlobalStyles(sourceRoot, context) {
|
|
174
228
|
return (tree) => {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
229
|
+
const candidates = [`/${sourceRoot}/styles.css`, `/${sourceRoot}/styles.scss`];
|
|
230
|
+
const stylesPath = candidates.find((candidate) => tree.exists(candidate));
|
|
231
|
+
if (!stylesPath) {
|
|
232
|
+
context.logger.warn(`[@solercia/ui] No se encontró "${candidates[0]}" ni "${candidates[1]}" — agrega ` +
|
|
233
|
+
'manualmente el snippet de tokens --sol-* a tu hoja de estilos global (ver ' +
|
|
234
|
+
'projects/solercia/ui/docs/THEMING.md).');
|
|
179
235
|
return tree;
|
|
180
236
|
}
|
|
181
237
|
const marker = '/* @solercia/ui — tokens base */';
|
|
@@ -193,19 +249,37 @@ function appendGlobalStyles(sourceRoot, context) {
|
|
|
193
249
|
return tree;
|
|
194
250
|
};
|
|
195
251
|
}
|
|
196
|
-
/** `
|
|
252
|
+
/** `true` cuando el `package.json` del anfitrión declara `"type": "module"`. */
|
|
253
|
+
function packageDeclaresEsm(tree) {
|
|
254
|
+
if (!tree.exists('/package.json')) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const pkg = new json_file_1.JSONFile(tree, '/package.json');
|
|
258
|
+
return pkg.get(['type']) === 'module';
|
|
259
|
+
}
|
|
260
|
+
/** `eslint.config.{js,mjs}` del consumidor, referenciando `@solercia/eslint-config`
|
|
197
261
|
* (preset compartido — fronteras FSD, smart/dumb, Chart.js, naming-convention).
|
|
198
262
|
* El `srcDir` por defecto del preset (`'src'`) ya coincide con el scaffold FSD
|
|
199
263
|
* de este schematic. No sobrescribe uno existente (proyecto que ya trae su
|
|
200
|
-
* propio lint).
|
|
264
|
+
* propio lint, en cualquiera de las dos extensiones).
|
|
265
|
+
*
|
|
266
|
+
* Fix ESM: el preset se importa con `import ... from` (sintaxis ESM). Un
|
|
267
|
+
* `package.json` de `ng new` NO declara `"type": "module"` por defecto, así
|
|
268
|
+
* que Node interpreta `eslint.config.js` como CommonJS y falla con
|
|
269
|
+
* `ERR_REQUIRE_ESM` al resolver el `import`. En vez de forzar `type: module`
|
|
270
|
+
* en `package.json` (rompería los `module.exports` de `commitlint.config.js`/
|
|
271
|
+
* `lint-staged.config.js` que scaffoldea `scaffoldHusky`), se emite el archivo
|
|
272
|
+
* como `.mjs` cuando el proyecto no es ya ESM. */
|
|
201
273
|
function scaffoldEslintConfig(context) {
|
|
202
274
|
return (tree) => {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
275
|
+
const jsPath = '/eslint.config.js';
|
|
276
|
+
const mjsPath = '/eslint.config.mjs';
|
|
277
|
+
if (tree.exists(jsPath) || tree.exists(mjsPath)) {
|
|
278
|
+
context.logger.info('[@solercia/ui] Ya existe un "eslint.config.{js,mjs}" — se deja intacto.');
|
|
206
279
|
return tree;
|
|
207
280
|
}
|
|
208
|
-
tree
|
|
281
|
+
const targetPath = packageDeclaresEsm(tree) ? jsPath : mjsPath;
|
|
282
|
+
tree.create(targetPath, `// @ts-check\n` +
|
|
209
283
|
`// Generado por \`ng add @solercia/ui\`. @solercia/eslint-config trae las fronteras FSD\n` +
|
|
210
284
|
`// (app → pages → widgets → features → entities → shared), la regla smart/dumb de\n` +
|
|
211
285
|
`// shared/ui, la restricción de Chart.js y naming-convention/filename-case.\n` +
|
|
@@ -219,20 +293,32 @@ function scaffoldEslintConfig(context) {
|
|
|
219
293
|
}
|
|
220
294
|
/** Husky + lint-staged + commitlint, calcados 1:1 del cableado real de
|
|
221
295
|
* `boki-front` (07-e9 PR2, T21): `pre-commit` → lint-staged (eslint --fix +
|
|
222
|
-
* tsc --noEmit sobre staged); `commit-msg` → commitlint (conventional commits).
|
|
296
|
+
* tsc --noEmit sobre staged); `commit-msg` → commitlint (conventional commits).
|
|
297
|
+
*
|
|
298
|
+
* Fix ESM (coherente con `scaffoldEslintConfig`): ambos configs usan sintaxis
|
|
299
|
+
* CommonJS (`module.exports`). Si el `package.json` anfitrión declara
|
|
300
|
+
* `"type": "module"`, Node interpreta cualquier `.js` como ESM y `module` deja
|
|
301
|
+
* de existir en ese scope (`ReferenceError: module is not defined in ES
|
|
302
|
+
* module scope`), reventando los hooks de Husky. commitlint y lint-staged
|
|
303
|
+
* soportan `.cjs` explícito para forzar CommonJS sin tocar el contenido — se
|
|
304
|
+
* usa esa extensión cuando el host ya es ESM; en caso contrario se mantiene
|
|
305
|
+
* `.js` (comportamiento previo, sin cambios para el caso por defecto). */
|
|
223
306
|
function scaffoldHusky(context) {
|
|
224
307
|
return (tree) => {
|
|
308
|
+
const commonJsExt = packageDeclaresEsm(tree) ? 'cjs' : 'js';
|
|
225
309
|
if (!tree.exists('/.husky/pre-commit')) {
|
|
226
310
|
tree.create('/.husky/pre-commit', 'npx lint-staged\n');
|
|
227
311
|
}
|
|
228
312
|
if (!tree.exists('/.husky/commit-msg')) {
|
|
229
313
|
tree.create('/.husky/commit-msg', 'npx --no -- commitlint --edit "$1"\n');
|
|
230
314
|
}
|
|
231
|
-
|
|
232
|
-
|
|
315
|
+
const commitlintPath = `/commitlint.config.${commonJsExt}`;
|
|
316
|
+
if (!tree.exists('/commitlint.config.js') && !tree.exists('/commitlint.config.cjs')) {
|
|
317
|
+
tree.create(commitlintPath, `module.exports = {\n extends: ['@commitlint/config-conventional'],\n};\n`);
|
|
233
318
|
}
|
|
234
|
-
|
|
235
|
-
|
|
319
|
+
const lintStagedPath = `/lint-staged.config.${commonJsExt}`;
|
|
320
|
+
if (!tree.exists('/lint-staged.config.js') && !tree.exists('/lint-staged.config.cjs')) {
|
|
321
|
+
tree.create(lintStagedPath, `// tsc --noEmit corre UNA vez contra todo el proyecto (no archivo por archivo):\n` +
|
|
236
322
|
`// TypeScript necesita el grafo completo para chequear tipos correctamente.\n` +
|
|
237
323
|
`module.exports = {\n` +
|
|
238
324
|
` '*.ts': [\n` +
|