@styloviz/schematics 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Styloviz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @styloviz/schematics
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Angular schematics for the [Styloviz](https://styloviz.dev) Angular + Tailwind CSS 4
4
+ component kit.
5
+
6
+ ## `ng add @styloviz/core`
7
+
8
+ Sets up an Angular app (21 or 22) to render Styloviz, in one command:
9
+
10
+ ```sh
11
+ ng add @styloviz/core
12
+ ```
13
+
14
+ - adds `@styloviz/core`, `@styloviz/icons`, `@styloviz/button` and Tailwind 4
15
+ (`tailwindcss`, `@tailwindcss/postcss`, `postcss`), keeping any version you
16
+ already have;
17
+ - creates `.postcssrc.json` for the Tailwind 4 PostCSS plugin, unless you have a
18
+ PostCSS config;
19
+ - prepends `@import "tailwindcss"`, the kit stylesheet and an `@source` for the
20
+ kit's templates to your global stylesheet;
21
+ - adds `provideStyloviz()` to `app.config.ts`;
22
+ - adds a demo page at `/styloviz` (pass `--demo=false` to skip it).
23
+
24
+ Running it again changes nothing. The same schematic is `ng add @styloviz/schematics`.
25
+
26
+ ## `ng g @styloviz/schematics:migrate-primeng`
27
+
28
+ Moves a PrimeNG 21 app onto Styloviz, applying the selector map that
29
+ [styloviz.dev/primeng-alternative](https://styloviz.dev/primeng-alternative)
30
+ shows:
31
+
32
+ ```sh
33
+ npm i -D @styloviz/schematics
34
+ ng g @styloviz/schematics:migrate-primeng # the whole workspace
35
+ ng g @styloviz/schematics:migrate-primeng --path src/app/admin
36
+ ```
37
+
38
+ - renames every mapped PrimeNG element (`<p-table>` → `<sv-data-table>`) in
39
+ `.html` files and inline templates;
40
+ - in each component that now uses Styloviz, imports the Styloviz classes and
41
+ removes the PrimeNG modules it no longer needs;
42
+ - adds the Styloviz packages now in use to `package.json`.
43
+
44
+ It does not translate inputs — PrimeNG's `[value]` on a table is Styloviz's
45
+ `[rows]` — so it lists every migrated selector with its docs page, and reports
46
+ everything it left alone: attribute directives such as `pTooltip`, and the
47
+ PrimeNG components Styloviz has no equivalent for, with the reason.
48
+
49
+ ## `ng update`
50
+
51
+ Every Styloviz package names the whole kit as its `packageGroup`, so
52
+ `ng update @styloviz/core` moves every installed Styloviz package together and
53
+ runs the kit's migrations once:
54
+
55
+ - **2.0.0** — icons are registered per glyph. An upgraded app is opted into the
56
+ full glyph set (`provideSvIcons(svAllIcons)`, plus `svAllProIcons` with the Pro
57
+ icons), so every icon keeps rendering. Trim it to the glyphs you use
58
+ afterwards.
59
+ - **2.0.0** — one pie family. `sv-default-pie-chart(-pro)` becomes
60
+ `sv-pie-chart(-pro)` and `sv-donut-chart` becomes
61
+ `sv-pie-chart-pro variant="donut"` (keeping its 1.x size), with the classes and
62
+ the option and slice types renamed.
63
+ - **2.0.0** — the data table's phone layout is one input: `[cardOnMobile]="true"`
64
+ becomes `responsive="cards"`. Each file that uses `sv-record-grid` is listed for
65
+ you to fold into the table's `responsive="records"` by hand.
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "ng-add": {
5
+ "description": "Set up Styloviz: Tailwind CSS 4, the kit stylesheet and tokens, provideStyloviz(), and one demo page.",
6
+ "factory": "./ng-add/index#ngAdd",
7
+ "schema": "./ng-add/schema.json"
8
+ },
9
+ "migrate-primeng": {
10
+ "description": "Rewrite PrimeNG 21 component selectors and imports to their Styloviz equivalents, and report what could not be mapped.",
11
+ "factory": "./migrate-primeng/index#migratePrimeng",
12
+ "schema": "./migrate-primeng/schema.json"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+ /**
3
+ * `ng g @styloviz/schematics:migrate-primeng` — PrimeNG 21 → Styloviz (FL-B7).
4
+ *
5
+ * Applies the selector map styloviz.dev/primeng-alternative renders (map.json,
6
+ * generated from the same source by scripts/generate-primeng-map.mjs):
7
+ *
8
+ * • templates `<p-table …>` → `<sv-data-table …>` and its closing tag, in
9
+ * .html files and inline `template:` literals;
10
+ * • components a component whose template now uses Styloviz selectors
11
+ * imports their classes from their packages, and drops the
12
+ * PrimeNG modules and components it imported;
13
+ * • package.json the Styloviz packages now used are added.
14
+ *
15
+ * It does NOT translate inputs — `[value]` on p-table is `[rows]` on
16
+ * sv-data-table — and says so: every migrated selector is listed with its docs
17
+ * page, and every PrimeNG selector it could not map (attribute directives, and
18
+ * components with no equivalent) is reported with the reason, so nothing is
19
+ * changed silently and nothing is left unexplained.
20
+ */
21
+ const { posix } = require('node:path');
22
+ const MAP = require('./map.json');
23
+
24
+ const KIT_VERSION = require('../package.json').version;
25
+ const ELEMENT_ROWS = MAP.rows.filter((r) => r.kind === 'element');
26
+ const ATTRIBUTE_ROWS = MAP.rows.filter((r) => r.kind === 'attribute');
27
+ const BY_SELECTOR = new Map(ELEMENT_ROWS.map((r) => [r.primeng, r]));
28
+ const GAPS = new Map(MAP.gaps.map((g) => [g.primeng, g.note]));
29
+
30
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
31
+
32
+ /** Rename every mapped PrimeNG element in a template; returns the rows it used. */
33
+ function migrateTemplate(text) {
34
+ const used = new Set();
35
+ let out = text.replace(/<(\/?)(p-[a-z][a-z0-9-]*)(?=[\s/>])/g, (whole, close, tag) => {
36
+ const row = BY_SELECTOR.get(tag);
37
+ if (!row) return whole;
38
+ used.add(row);
39
+ return `<${close}${row.selector}`;
40
+ });
41
+ const leftovers = [...new Set([...out.matchAll(/<(p-[a-z][a-z0-9-]*)(?=[\s/>])/g)].map((m) => m[1]))];
42
+ const attributes = ATTRIBUTE_ROWS.filter((r) => new RegExp(`\\s\\[?${esc(r.primeng.slice(1, -1))}\\]?[\\s=>/]`).test(out));
43
+ return { out, used, leftovers, attributes };
44
+ }
45
+
46
+ /** Add `import { X } from 'pkg';` once, merging into an existing import from the same package. */
47
+ function addImport(src, className, pkg) {
48
+ if (new RegExp(`\\b${className}\\b`).test(src.split('@Component')[0])) return src;
49
+ const existing = src.match(new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*['"]${esc(pkg)}['"];`));
50
+ if (existing) return src.replace(existing[0], `import {${existing[1].replace(/\s*$/, '')}, ${className} } from '${pkg}';`);
51
+ const imports = [...src.matchAll(/^import[\s\S]*?;\s*$/gm)];
52
+ const at = imports.length ? imports[imports.length - 1].index + imports[imports.length - 1][0].length : 0;
53
+ return `${src.slice(0, at)}${at ? '\n' : ''}import { ${className} } from '${pkg}';${at ? '' : '\n'}${src.slice(at)}`;
54
+ }
55
+
56
+ /**
57
+ * Remove the PrimeNG imports of the components this file no longer uses —
58
+ * `primeng/table` once its `p-table` became `sv-data-table` — and their names
59
+ * from `imports: [...]`. A module the template still needs (a directive it could
60
+ * not migrate, like `pTooltip`) stays.
61
+ */
62
+ function dropPrimeng(src, removed, migrated) {
63
+ const names = [];
64
+ src = src.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]primeng\/([\w-]+)['"];\s*\n?/gm, (whole, list, mod) => {
65
+ if (!migrated.has(mod)) return whole;
66
+ for (const n of list.split(',').map((s) => s.trim().split(/\s+as\s+/).pop()).filter(Boolean)) names.push(n);
67
+ return '';
68
+ });
69
+ for (const n of names) {
70
+ removed.add(n);
71
+ src = src.replace(new RegExp(`(imports\\s*:\\s*\\[[^\\]]*?)\\b${esc(n)}\\b\\s*,?\\s*`, 'g'), '$1');
72
+ }
73
+ return src.replace(/imports\s*:\s*\[\s*,/g, 'imports: [');
74
+ }
75
+
76
+ /** Add classes to the first `imports: [...]` of the @Component, creating it if absent. */
77
+ function addToComponentImports(src, classNames) {
78
+ if (!classNames.length) return src;
79
+ const decorator = src.match(/@Component\(\s*\{/);
80
+ if (!decorator) return src;
81
+ const after = src.slice(decorator.index);
82
+ const list = after.match(/imports\s*:\s*\[([\s\S]*?)\]/);
83
+ const missing = classNames.filter((c) => !(list && new RegExp(`\\b${c}\\b`).test(list[1])));
84
+ if (!missing.length) return src;
85
+ if (list) {
86
+ const at = decorator.index + list.index + list[0].length - 1;
87
+ const body = list[1].trim();
88
+ return `${src.slice(0, at)}${body && !body.endsWith(',') ? ', ' : body ? ' ' : ''}${missing.join(', ')}${src.slice(at)}`;
89
+ }
90
+ const at = decorator.index + decorator[0].length;
91
+ return `${src.slice(0, at)}\n imports: [${missing.join(', ')}],${src.slice(at)}`;
92
+ }
93
+
94
+ /** @param {{ path?: string, addDependencies?: boolean }} options */
95
+ function migratePrimeng(options = {}) {
96
+ return (tree, context) => {
97
+ const root = posix.join('/', options.path ?? '/');
98
+ const report = { files: 0, used: new Map(), leftovers: new Map(), attributes: new Map(), removed: new Set() };
99
+ const templateUse = new Map(); // .html path → rows used
100
+ const note = (map, key, file) => map.set(key, [...(map.get(key) ?? []), file]);
101
+
102
+ // Templates in .html files first, so a component can learn what its templateUrl now uses.
103
+ tree.getDir(root).visit((path) => {
104
+ if (/node_modules|\/dist\//.test(path) || !path.endsWith('.html')) return;
105
+ const text = tree.read(path).toString('utf8');
106
+ const { out, used, leftovers, attributes } = migrateTemplate(text);
107
+ for (const l of leftovers) note(report.leftovers, l, path);
108
+ for (const a of attributes) note(report.attributes, a.primeng, path);
109
+ if (!used.size) return;
110
+ tree.overwrite(path, out);
111
+ report.files++;
112
+ templateUse.set(path, used);
113
+ for (const r of used) note(report.used, r.primeng, path);
114
+ });
115
+
116
+ tree.getDir(root).visit((path) => {
117
+ if (/node_modules|\/dist\//.test(path) || !path.endsWith('.ts') || path.endsWith('.spec.ts')) return;
118
+ let src = tree.read(path).toString('utf8');
119
+ if (!/@Component\(/.test(src) && !/from\s*['"]primeng\//.test(src)) return;
120
+ const used = new Set();
121
+ // Inline template.
122
+ src = src.replace(/(template\s*:\s*`)([\s\S]*?)(`)/, (whole, open, body, close) => {
123
+ const r = migrateTemplate(body);
124
+ for (const row of r.used) used.add(row);
125
+ for (const l of r.leftovers) note(report.leftovers, l, path);
126
+ for (const a of r.attributes) note(report.attributes, a.primeng, path);
127
+ for (const row of r.used) note(report.used, row.primeng, path);
128
+ return `${open}${r.out}${close}`;
129
+ });
130
+ // External template.
131
+ const url = src.match(/templateUrl\s*:\s*['"]([^'"]+)['"]/)?.[1];
132
+ if (url) for (const row of templateUse.get(posix.join(posix.dirname(path), url)) ?? []) used.add(row);
133
+
134
+ const before = src;
135
+ if (used.size) {
136
+ src = dropPrimeng(src, report.removed, new Set([...used].map((r) => r.primeng.slice(2))));
137
+ const rows = [...used];
138
+ for (const r of rows) src = addImport(src, r.className, r.package);
139
+ src = addToComponentImports(src, [...new Set(rows.map((r) => r.className))]);
140
+ }
141
+ if (src !== before || used.size) {
142
+ tree.overwrite(path, src);
143
+ report.files++;
144
+ }
145
+ });
146
+
147
+ // package.json: the Styloviz packages now in use.
148
+ const packages = new Set([...report.used.keys()].map((sel) => BY_SELECTOR.get(sel).package));
149
+ if (options.addDependencies !== false && packages.size && tree.exists('/package.json')) {
150
+ const pkg = JSON.parse(tree.read('/package.json').toString('utf8'));
151
+ pkg.dependencies = pkg.dependencies ?? {};
152
+ for (const p of ['@styloviz/core', ...packages]) if (!pkg.dependencies[p]) pkg.dependencies[p] = `^${KIT_VERSION}`;
153
+ pkg.dependencies = Object.fromEntries(Object.entries(pkg.dependencies).sort(([a], [b]) => a.localeCompare(b)));
154
+ tree.overwrite('/package.json', `${JSON.stringify(pkg, null, 2)}\n`);
155
+ }
156
+
157
+ // ── Report ──
158
+ const log = context.logger;
159
+ log.info(`Styloviz migrate-primeng — ${report.used.size} PrimeNG selector(s) migrated in ${report.files} file(s).`);
160
+ for (const [sel, files] of report.used) {
161
+ const r = BY_SELECTOR.get(sel);
162
+ log.info(` ✔ ${sel} → ${r.selector} (${r.package}${r.tier === 'pro' ? ', Pro' : ''}) in ${new Set(files).size} file(s). Check its inputs: ${r.docsUrl}${r.note ? ` — ${r.note}` : ''}`);
163
+ }
164
+ if (report.removed.size) log.info(` ✔ Removed PrimeNG imports: ${[...report.removed].sort().join(', ')}`);
165
+ for (const [sel, files] of report.attributes) {
166
+ const r = ATTRIBUTE_ROWS.find((x) => x.primeng === sel);
167
+ log.warn(` ! ${sel} is a directive; move it to ${r.selector} by hand (${r.docsUrl}) — ${[...new Set(files)].join(', ')}`);
168
+ }
169
+ for (const [sel, files] of report.leftovers) {
170
+ const why = GAPS.get(sel);
171
+ log.warn(` ! ${sel} was not migrated: ${why ?? 'it is not in the Styloviz map'} — ${[...new Set(files)].join(', ')}`);
172
+ }
173
+ if (packages.size) log.info(' Run your package manager to install the Styloviz packages, then build and fix the inputs the docs links above describe.');
174
+ return tree;
175
+ };
176
+ }
177
+
178
+ module.exports = { migratePrimeng, migrateTemplate };