@styloviz/schematics 0.0.0-stage → 2.0.1

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/migration.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "v2-register-icons": {
5
+ "version": "2.0.0",
6
+ "description": "2.0 registers icons per glyph. Opt an existing app into the full glyph set (provideSvIcons(svAllIcons)) so every name it draws keeps rendering; trim it to the glyphs you use afterwards.",
7
+ "factory": "./migrations/v2-register-icons/index#registerIcons"
8
+ },
9
+ "v2-pie-family": {
10
+ "version": "2.0.0",
11
+ "description": "2.0 has one pie family: sv-default-pie-chart becomes sv-pie-chart, sv-default-pie-chart-pro becomes sv-pie-chart-pro, and sv-donut-chart becomes sv-pie-chart-pro variant=\"donut\" (with its 1.x size kept). Renames the elements, the classes and the option and slice types.",
12
+ "factory": "./migrations/v2-pie-family/index#pieFamily"
13
+ },
14
+ "v2-data-table-responsive": {
15
+ "version": "2.0.0",
16
+ "description": "2.0 names what the data table does on a phone with one input: [cardOnMobile]=\"true\" becomes responsive=\"cards\". sv-record-grid became responsive=\"records\" on the table; files that use it are listed for you to fold by hand.",
17
+ "factory": "./migrations/v2-data-table-responsive/index#dataTableResponsive"
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+ /**
3
+ * ng update → 2.0: one name for "what the table does on a phone" (FL-C13).
4
+ *
5
+ * <sv-data-table [cardOnMobile]="true"> → <sv-data-table responsive="cards">
6
+ * <sv-data-table cardOnMobile> → <sv-data-table responsive="cards">
7
+ * <sv-data-table [cardOnMobile]="false"> → <sv-data-table>
8
+ * <sv-data-table [cardOnMobile]="expr"> → <sv-data-table [responsive]="(expr) ? 'cards' : 'none'">
9
+ *
10
+ * (and the same on `sv-data-table-pro`) — those are renames, so they are done
11
+ * for you, in `.html` files and inline templates.
12
+ *
13
+ * `sv-record-grid` / `sv-record-grid-pro` became `responsive="records"` on the
14
+ * table itself. That is NOT a rename: the grid wrapped a table you configured
15
+ * inside an `ng-template`, and the two elements have to become one, with
16
+ * `[(sort)]` (one sort) turning into the table's own sort (`sortChange`, a
17
+ * list). Folding two configured elements together by regex would guess, so
18
+ * this migration lists every file that uses one and leaves it to you — the
19
+ * CHANGELOG has the mapping.
20
+ *
21
+ * Idempotent.
22
+ */
23
+
24
+ const SKIP = /node_modules|\/dist\/|\/\.angular\//;
25
+ const TABLE_TAG = /<sv-data-table(?:-pro)?(?=[\s/>])[^>]*>/g;
26
+
27
+ function migrateTag(tag) {
28
+ let out = tag.replace(/\s\[cardOnMobile\]\s*=\s*"\s*true\s*"/, ' responsive="cards"');
29
+ out = out.replace(/\s\[cardOnMobile\]\s*=\s*"\s*false\s*"/, '');
30
+ out = out.replace(/\s\[cardOnMobile\]\s*=\s*"([^"]*)"/, (_m, expr) => ` [responsive]="(${expr.trim()}) ? 'cards' : 'none'"`);
31
+ out = out.replace(/\scardOnMobile(?=[\s/>])(?!\s*=)/, ' responsive="cards"');
32
+ out = out.replace(/\scardOnMobile\s*=\s*"(?:true)?"/, ' responsive="cards"');
33
+ return out;
34
+ }
35
+
36
+ function migrateTemplate(text) {
37
+ let changed = 0;
38
+ const out = text.replace(TABLE_TAG, (tag) => {
39
+ const next = migrateTag(tag);
40
+ if (next !== tag) changed++;
41
+ return next;
42
+ });
43
+ return { out, changed, recordGrid: /<sv-record-grid(?:-pro)?(?=[\s/>])/.test(text) };
44
+ }
45
+
46
+ function dataTableResponsive() {
47
+ return (tree, context) => {
48
+ let files = 0;
49
+ const recordGrid = [];
50
+ tree.getDir('/').visit((path) => {
51
+ if (SKIP.test(path)) return;
52
+ const isHtml = path.endsWith('.html');
53
+ const isTs = path.endsWith('.ts');
54
+ if (!isHtml && !isTs) return;
55
+ const before = tree.read(path).toString('utf8');
56
+ let src = before;
57
+ let usesGrid = false;
58
+ if (isHtml) {
59
+ const r = migrateTemplate(src);
60
+ src = r.out;
61
+ usesGrid = r.recordGrid;
62
+ } else {
63
+ src = src.replace(/(template\s*:\s*`)([\s\S]*?)(`)/g, (_w, open, body, close) => {
64
+ const r = migrateTemplate(body);
65
+ usesGrid = usesGrid || r.recordGrid;
66
+ return `${open}${r.out}${close}`;
67
+ });
68
+ usesGrid = usesGrid || /\bSvRecordGrid(?:Pro)?Component\b/.test(src);
69
+ }
70
+ if (usesGrid) recordGrid.push(path);
71
+ if (src !== before) {
72
+ tree.overwrite(path, src);
73
+ files++;
74
+ }
75
+ });
76
+ context.logger.info(
77
+ files
78
+ ? `✔ Styloviz 2.0: cardOnMobile → responsive="cards" in ${files} file(s).`
79
+ : 'Styloviz 2.0: no cardOnMobile to rename.',
80
+ );
81
+ for (const path of recordGrid) {
82
+ context.logger.warn(
83
+ `! ${path}: sv-record-grid is now responsive="records" on sv-data-table / sv-data-table-pro. ` +
84
+ 'Move the grid\'s inputs onto the table it wrapped (titleKey → recordTitleKey, breakpoint → recordBreakpoint, ' +
85
+ 'mode="cards" → recordView="always", [(expandedIds)] → [(recordExpandedIds)], [(selected)] → [(selectedIds)], ' +
86
+ 'rowActions → actions) and drop the wrapper — see the 2.0 CHANGELOG.',
87
+ );
88
+ }
89
+ return tree;
90
+ };
91
+ }
92
+
93
+ module.exports = { dataTableResponsive, migrateTemplate };
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+ /**
3
+ * ng update → 2.0: one pie family (FL-C2).
4
+ *
5
+ * 2.0 renames the pie chart and folds the donut into it:
6
+ *
7
+ * <sv-default-pie-chart> → <sv-pie-chart> (SvPieChartComponent)
8
+ * <sv-default-pie-chart-pro> → <sv-pie-chart-pro> (SvPieChartProComponent)
9
+ * <sv-donut-chart> → <sv-pie-chart-pro variant="donut"> (SvPieChartProComponent)
10
+ * DefaultPieChartOptions, DonutChartOptions → PieChartOptions
11
+ * DonutSlice → PieSlice
12
+ *
13
+ * Every one of those is a rename, so it is done for you, in templates (`.html`
14
+ * and inline `template:`) and in TypeScript. A migrated donut also gets
15
+ * `[size]="220"` when it set no size, because the pie's default is 260 and the
16
+ * 1.x donut's was 220. `sv-gradient-donut-chart` is unchanged.
17
+ *
18
+ * Idempotent: nothing it writes matches what it looks for.
19
+ */
20
+
21
+ const SKIP = /node_modules|\/dist\/|\/\.angular\//;
22
+
23
+ /** Templates: element names, plus the donut's `variant` and its old default size. */
24
+ function migrateTemplate(text) {
25
+ let changed = 0;
26
+ let out = text.replace(/<(\/?)sv-default-pie-chart-pro(?=[\s/>])/g, (_m, slash) => {
27
+ changed++;
28
+ return `<${slash}sv-pie-chart-pro`;
29
+ });
30
+ out = out.replace(/<(\/?)sv-default-pie-chart(?=[\s/>])/g, (_m, slash) => {
31
+ changed++;
32
+ return `<${slash}sv-pie-chart`;
33
+ });
34
+ out = out.replace(/<\/sv-donut-chart\s*>/g, () => {
35
+ changed++;
36
+ return '</sv-pie-chart-pro>';
37
+ });
38
+ // The opening tag up to its end. Attribute values with a bare `>` in them
39
+ // (rare in a chart's bindings) end the match early, which only means the
40
+ // size check below looks at fewer attributes.
41
+ out = out.replace(/<sv-donut-chart(?=[\s/>])([^>]*)>/g, (_m, attrs) => {
42
+ changed++;
43
+ const hasSize = /(^|\s)(\[size\]|size)\s*=/.test(attrs);
44
+ return `<sv-pie-chart-pro variant="donut"${hasSize ? '' : ' [size]="220"'}${attrs}>`;
45
+ });
46
+ return { out, changed };
47
+ }
48
+
49
+ const IDENTIFIERS = [
50
+ [/\bSvDefaultPieChartProComponent\b/g, 'SvPieChartProComponent'],
51
+ [/\bSvDefaultPieChartComponent\b/g, 'SvPieChartComponent'],
52
+ [/\bSvDonutChartComponent\b/g, 'SvPieChartProComponent'],
53
+ [/\bDefaultPieChartOptions\b/g, 'PieChartOptions'],
54
+ [/\bDonutChartOptions\b/g, 'PieChartOptions'],
55
+ [/\bDonutSlice\b/g, 'PieSlice'],
56
+ ];
57
+
58
+ /** `import { A, B, A } from '…'` → `import { A, B } from '…'` — two renames can land on one name. */
59
+ function dedupeImports(src) {
60
+ return src.replace(/import\s*(type\s*)?\{([^}]*)\}\s*from\s*(['"][^'"]+['"])/g, (whole, typeKw, list, from) => {
61
+ const seen = new Set();
62
+ const kept = [];
63
+ for (const raw of list.split(',')) {
64
+ const spec = raw.trim();
65
+ if (!spec) continue;
66
+ const name = spec.replace(/^type\s+/, '').split(/\s+as\s+/).pop().trim();
67
+ if (seen.has(name)) continue;
68
+ seen.add(name);
69
+ kept.push(spec);
70
+ }
71
+ const rebuilt = `import ${typeKw ?? ''}{ ${kept.join(', ')} } from ${from}`;
72
+ return kept.length === list.split(',').map((s) => s.trim()).filter(Boolean).length ? whole : rebuilt;
73
+ });
74
+ }
75
+
76
+ /** `imports: [A, B, A]` → `imports: [A, B]`, for a standalone component's metadata. */
77
+ function dedupeImportsArray(src) {
78
+ return src.replace(/(\bimports\s*:\s*\[)([^\]]*)(\])/g, (whole, open, list, close) => {
79
+ const items = list.split(',');
80
+ const seen = new Set();
81
+ const kept = items.filter((item) => {
82
+ const name = item.trim();
83
+ if (!name) return true;
84
+ if (seen.has(name)) return false;
85
+ seen.add(name);
86
+ return true;
87
+ });
88
+ return kept.length === items.length ? whole : `${open}${kept.join(',')}${close}`;
89
+ });
90
+ }
91
+
92
+ function pieFamily() {
93
+ return (tree, context) => {
94
+ let files = 0;
95
+ let edits = 0;
96
+ tree.getDir('/').visit((path) => {
97
+ if (SKIP.test(path)) return;
98
+ const isHtml = path.endsWith('.html');
99
+ const isTs = path.endsWith('.ts');
100
+ if (!isHtml && !isTs) return;
101
+ const before = tree.read(path).toString('utf8');
102
+ let src = before;
103
+ if (isHtml) {
104
+ const r = migrateTemplate(src);
105
+ src = r.out;
106
+ edits += r.changed;
107
+ } else {
108
+ src = src.replace(/(template\s*:\s*`)([\s\S]*?)(`)/g, (_w, open, body, close) => {
109
+ const r = migrateTemplate(body);
110
+ edits += r.changed;
111
+ return `${open}${r.out}${close}`;
112
+ });
113
+ for (const [re, to] of IDENTIFIERS) {
114
+ src = src.replace(re, () => {
115
+ edits++;
116
+ return to;
117
+ });
118
+ }
119
+ src = dedupeImportsArray(dedupeImports(src));
120
+ }
121
+ if (src !== before) {
122
+ tree.overwrite(path, src);
123
+ files++;
124
+ }
125
+ });
126
+ context.logger.info(
127
+ files
128
+ ? `✔ Styloviz 2.0: moved ${files} file(s) to the pie family (${edits} edit(s)): sv-default-pie-chart → sv-pie-chart, sv-donut-chart → sv-pie-chart-pro variant="donut". The donut now uses the pie's palette and 10px margin; see the CHANGELOG.`
129
+ : 'Styloviz 2.0: no pie or donut chart to rename.',
130
+ );
131
+ return tree;
132
+ };
133
+ }
134
+
135
+ module.exports = { pieFamily, migrateTemplate };
@@ -0,0 +1,5 @@
1
+ {
2
+ "$comment": "The import lines the 2.0 icon migration writes. Data, not code: the free and Pro registries live in different packages.",
3
+ "free": { "import": "import { provideSvIcons, svAllIcons } from '@styloviz/icons';", "names": ["svAllIcons"] },
4
+ "pro": { "package": "@styloviz-pro/icons", "import": "import { svAllProIcons } from '@styloviz-pro/icons/registry';", "names": ["svAllProIcons"] }
5
+ }
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+ /**
3
+ * ng update → 2.0: icons are registered per glyph (FL-B4).
4
+ *
5
+ * In 1.x `<sv-icon name="bell">` resolved against the whole bundled registry;
6
+ * in 2.0 a name nobody registered renders nothing. The kit's own components
7
+ * register what they draw, but names an APP passes in (a button's `icon`, nav
8
+ * items, its own `<sv-icon>`s) are the app's to register. So an upgraded app is
9
+ * opted into the full set — exactly the 1.x behaviour, nothing disappears — and
10
+ * told how to trim it to the glyphs it uses:
11
+ *
12
+ * providers: [provideSvIcons(svAllIcons /*, svAllProIcons *\/), …]
13
+ *
14
+ * Idempotent; an app that already calls provideSvIcons is left alone.
15
+ */
16
+ const { posix } = require('node:path');
17
+ const IMPORTS = require('./imports.json');
18
+
19
+ function registerIcons() {
20
+ return (tree, context) => {
21
+ const workspace = tree.exists('/angular.json') ? JSON.parse(tree.read('/angular.json').toString('utf8')) : { projects: {} };
22
+ const pkg = tree.exists('/package.json') ? JSON.parse(tree.read('/package.json').toString('utf8')) : {};
23
+ const hasPro = !!(pkg.dependencies?.[IMPORTS.pro.package] || pkg.devDependencies?.[IMPORTS.pro.package]);
24
+ let touched = 0;
25
+ for (const project of Object.values(workspace.projects ?? {})) {
26
+ if (project.projectType !== 'application') continue;
27
+ const config = posix.join('/', project.sourceRoot || posix.join(project.root || '', 'src'), 'app/app.config.ts');
28
+ if (!tree.exists(config)) continue;
29
+ let src = tree.read(config).toString('utf8');
30
+ if (src.includes('provideSvIcons(')) continue;
31
+ const providers = src.match(/providers\s*:\s*\[/);
32
+ if (!providers) {
33
+ context.logger.warn(`! ${config}: add provideSvIcons(svAllIcons) from '@styloviz/icons' to your providers (2.0 registers icons per glyph).`);
34
+ continue;
35
+ }
36
+ const sets = [...IMPORTS.free.names, ...(hasPro ? IMPORTS.pro.names : [])].join(', ');
37
+ const at = providers.index + providers[0].length;
38
+ src = `${src.slice(0, at)}\n // Styloviz 2.0: the full glyph set, as 1.x had. Trim to the glyphs you use: provideSvIcons([bellIcon, …]).\n provideSvIcons(${sets}),${src.slice(at)}`;
39
+ src = `${IMPORTS.free.import}\n${hasPro ? `${IMPORTS.pro.import}\n` : ''}${src}`;
40
+ tree.overwrite(config, src);
41
+ touched++;
42
+ }
43
+ context.logger.info(
44
+ touched
45
+ ? `✔ Styloviz 2.0: registered the full glyph set in ${touched} app config(s). Every icon keeps rendering; see https://styloviz.dev/docs/icon-library to register only what you use.`
46
+ : 'Styloviz 2.0: no app config needed the icon registration.',
47
+ );
48
+ return tree;
49
+ };
50
+ }
51
+
52
+ module.exports = { registerIcons };
@@ -0,0 +1,217 @@
1
+ 'use strict';
2
+ /**
3
+ * `ng add @styloviz/core` — make a fresh Angular app render Styloviz (FL-B7).
4
+ *
5
+ * 1. dependencies @styloviz/core, @styloviz/icons, @styloviz/button (the demo)
6
+ * and Tailwind 4 (tailwindcss, @tailwindcss/postcss, postcss).
7
+ * Only what is MISSING is added: a version the app already
8
+ * pins — or a local tarball it installed from — is kept.
9
+ * 2. .postcssrc.json the Tailwind 4 PostCSS plugin, when the app has no PostCSS config.
10
+ * 3. global styles `@import "tailwindcss"`, the kit stylesheet (tokens, the
11
+ * class-based dark variant, component CSS) and an `@source`
12
+ * for the kit's templates, prepended once.
13
+ * 4. app.config.ts `provideStyloviz()` in the providers.
14
+ * 5. demo page /styloviz, a standalone page with a few buttons, routed
15
+ * lazily — the proof the setup works, and a thing to delete.
16
+ * 6. angular.json `allowedCommonJsDependencies` gains the CommonJS modules
17
+ * jspdf pulls in (the kit's PDF/PNG export loads it lazily).
18
+ * Without them the first production build after adding an
19
+ * export feature prints ~18 warnings the app cannot act on
20
+ * (FL-L2). The templates ship the same list.
21
+ *
22
+ * Every step is idempotent: running it twice changes nothing the second time.
23
+ */
24
+ const { SchematicsException } = require('@angular-devkit/schematics');
25
+ const { NodePackageInstallTask } = require('@angular-devkit/schematics/tasks');
26
+ const { posix } = require('node:path');
27
+
28
+ const KIT_VERSION = require('../package.json').version;
29
+
30
+ const DEPENDENCIES = {
31
+ '@styloviz/core': `^${KIT_VERSION}`,
32
+ '@styloviz/icons': `^${KIT_VERSION}`,
33
+ '@styloviz/button': `^${KIT_VERSION}`,
34
+ };
35
+ const DEV_DEPENDENCIES = {
36
+ tailwindcss: '^4.1.0',
37
+ '@tailwindcss/postcss': '^4.1.0',
38
+ postcss: '^8.5.0',
39
+ };
40
+
41
+ /** jspdf's CommonJS modules — the same list scripts/lib/template-project.mjs gives the templates. */
42
+ const EXPORT_COMMONJS = ['html2canvas', 'canvg', 'raf', 'rgbcolor', 'core-js'];
43
+
44
+ function readJson(tree, path) {
45
+ const buf = tree.read(path);
46
+ if (!buf) return null;
47
+ try {
48
+ return JSON.parse(buf.toString('utf8'));
49
+ } catch {
50
+ throw new SchematicsException(`${path} is not valid JSON.`);
51
+ }
52
+ }
53
+
54
+ function addDependencies(tree, context) {
55
+ const pkg = readJson(tree, '/package.json');
56
+ if (!pkg) throw new SchematicsException('No package.json at the workspace root.');
57
+ const added = [];
58
+ for (const [section, wanted] of [['dependencies', DEPENDENCIES], ['devDependencies', DEV_DEPENDENCIES]]) {
59
+ pkg[section] = pkg[section] ?? {};
60
+ for (const [name, range] of Object.entries(wanted)) {
61
+ if (pkg.dependencies?.[name] || pkg.devDependencies?.[name]) continue;
62
+ pkg[section][name] = range;
63
+ added.push(name);
64
+ }
65
+ pkg[section] = Object.fromEntries(Object.entries(pkg[section]).sort(([a], [b]) => a.localeCompare(b)));
66
+ }
67
+ tree.overwrite('/package.json', `${JSON.stringify(pkg, null, 2)}\n`);
68
+ if (added.length) context.logger.info(`✔ Added ${added.join(', ')}`);
69
+ return added.length > 0;
70
+ }
71
+
72
+ /** The app to set up, and where its files are. */
73
+ function resolveProject(tree, options) {
74
+ const workspace = readJson(tree, '/angular.json');
75
+ if (!workspace) throw new SchematicsException('No angular.json — run this inside an Angular workspace.');
76
+ const name =
77
+ options.project ||
78
+ Object.keys(workspace.projects).find((p) => workspace.projects[p].projectType === 'application');
79
+ const project = name && workspace.projects[name];
80
+ if (!project) throw new SchematicsException(`No application project ${options.project ? `"${options.project}" ` : ''}in angular.json.`);
81
+ const root = project.root || '';
82
+ const sourceRoot = project.sourceRoot || posix.join(root, 'src');
83
+ const build = project.architect?.build ?? project.targets?.build;
84
+ const styles = (build?.options?.styles ?? [])
85
+ .map((s) => (typeof s === 'string' ? s : s.input))
86
+ .find((s) => /\.css$/.test(s));
87
+ return { name, root, sourceRoot, styles: styles ?? posix.join(sourceRoot, 'styles.css') };
88
+ }
89
+
90
+ function addPostcssConfig(tree, context, root) {
91
+ const has = ['.postcssrc.json', 'postcss.config.js', 'postcss.config.mjs', 'postcss.config.cjs'].some((f) => tree.exists(posix.join('/', root, f)) || tree.exists(`/${f}`));
92
+ if (has) return;
93
+ tree.create(posix.join('/', root, '.postcssrc.json'), `${JSON.stringify({ plugins: { '@tailwindcss/postcss': {} } }, null, 2)}\n`);
94
+ context.logger.info('✔ Created .postcssrc.json (Tailwind 4 PostCSS plugin)');
95
+ }
96
+
97
+ function addStyles(tree, context, stylesPath) {
98
+ const path = `/${stylesPath.replace(/^\/+/, '')}`;
99
+ const current = tree.exists(path) ? tree.read(path).toString('utf8') : '';
100
+ const toNodeModules = posix.relative(posix.dirname(path), '/node_modules') || 'node_modules';
101
+ // Quote-agnostic: the CLI may reformat what this wrote with single quotes.
102
+ const lines = [
103
+ [/@import\s+['"]tailwindcss['"]/, `@import "tailwindcss";`],
104
+ [/@styloviz\/core\/styles\/styloviz\.css/, `@import "@styloviz/core/styles/styloviz.css";`],
105
+ [/@source\s+['"][^'"]*node_modules\/@styloviz['"]/, `@source "${toNodeModules}/@styloviz";`],
106
+ ].filter(([marker]) => !marker.test(current)).map(([, line]) => line);
107
+ if (!lines.length) return;
108
+ const next = `${lines.join('\n')}\n${current ? `\n${current}` : ''}`;
109
+ if (tree.exists(path)) tree.overwrite(path, next);
110
+ else tree.create(path, next);
111
+ context.logger.info(`✔ ${posix.basename(path)}: Tailwind 4, the Styloviz stylesheet and @source`);
112
+ }
113
+
114
+ function addProvider(tree, context, sourceRoot) {
115
+ const path = posix.join('/', sourceRoot, 'app/app.config.ts');
116
+ if (!tree.exists(path)) {
117
+ context.logger.warn(`! No ${path}: add provideStyloviz() from '@styloviz/core' to your application providers.`);
118
+ return;
119
+ }
120
+ let src = tree.read(path).toString('utf8');
121
+ if (src.includes('provideStyloviz(')) return;
122
+ const providers = src.match(/providers\s*:\s*\[/);
123
+ if (!providers) {
124
+ context.logger.warn(`! ${path} has no providers array: add provideStyloviz() from '@styloviz/core' yourself.`);
125
+ return;
126
+ }
127
+ const at = providers.index + providers[0].length;
128
+ src = `${src.slice(0, at)}\n provideStyloviz(),${src.slice(at)}`;
129
+ src = `import { provideStyloviz } from '@styloviz/core';\n${src}`;
130
+ tree.overwrite(path, src);
131
+ context.logger.info('✔ app.config.ts: provideStyloviz()');
132
+ }
133
+
134
+ const DEMO = `import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
135
+ import { SvButtonComponent } from '@styloviz/button';
136
+
137
+ /**
138
+ * Added by \`ng add @styloviz/core\` to prove the setup renders. Delete it — and
139
+ * its route in app.routes.ts — once you have your own pages.
140
+ */
141
+ @Component({
142
+ selector: 'app-styloviz-demo',
143
+ imports: [SvButtonComponent],
144
+ changeDetection: ChangeDetectionStrategy.OnPush,
145
+ template: \`
146
+ <main class="mx-auto max-w-2xl space-y-6 p-8">
147
+ <h1 class="text-2xl font-bold text-gray-900 dark:text-white">Styloviz is set up</h1>
148
+ <p class="text-gray-600 dark:text-gray-300">
149
+ Tailwind 4, the Styloviz tokens and the kit stylesheet are loaded. Browse the components at
150
+ <a class="font-semibold text-primary-600 underline" href="https://styloviz.dev/components">styloviz.dev</a>.
151
+ </p>
152
+ <div class="flex flex-wrap gap-3">
153
+ <sv-button label="Primary" (clicked)="clicks.set(clicks() + 1)" />
154
+ <sv-button label="Secondary" variant="secondary" />
155
+ <sv-button label="Outline" btnStyle="outline" />
156
+ </div>
157
+ <p class="text-sm text-gray-500" aria-live="polite">Clicked {{ clicks() }} time(s).</p>
158
+ </main>
159
+ \`,
160
+ })
161
+ export class StylovizDemoComponent {
162
+ protected readonly clicks = signal(0);
163
+ }
164
+ `;
165
+
166
+ function addDemo(tree, context, sourceRoot) {
167
+ const file = posix.join('/', sourceRoot, 'app/styloviz-demo/styloviz-demo.component.ts');
168
+ if (!tree.exists(file)) tree.create(file, DEMO);
169
+ const routes = posix.join('/', sourceRoot, 'app/app.routes.ts');
170
+ if (!tree.exists(routes)) {
171
+ context.logger.warn(`! No ${routes}: route StylovizDemoComponent yourself to see the demo page.`);
172
+ return;
173
+ }
174
+ let src = tree.read(routes).toString('utf8');
175
+ if (src.includes('styloviz-demo')) return;
176
+ const list = src.match(/:\s*Routes\s*=\s*\[/);
177
+ if (!list) {
178
+ context.logger.warn(`! ${routes} has no Routes array: route StylovizDemoComponent yourself.`);
179
+ return;
180
+ }
181
+ const at = list.index + list[0].length;
182
+ src = `${src.slice(0, at)}\n {\n path: 'styloviz',\n loadComponent: () => import('./styloviz-demo/styloviz-demo.component').then((m) => m.StylovizDemoComponent),\n },${src.slice(at)}`;
183
+ tree.overwrite(routes, src);
184
+ context.logger.info('✔ Demo page at /styloviz');
185
+ }
186
+
187
+ function allowExportCommonJs(tree, context, projectName) {
188
+ const workspace = readJson(tree, '/angular.json');
189
+ const project = workspace?.projects?.[projectName];
190
+ const build = project?.architect?.build ?? project?.targets?.build;
191
+ if (!build) return;
192
+ build.options = build.options ?? {};
193
+ const allowed = build.options.allowedCommonJsDependencies ?? [];
194
+ const missing = EXPORT_COMMONJS.filter((m) => !allowed.includes(m));
195
+ if (!missing.length) return;
196
+ build.options.allowedCommonJsDependencies = [...allowed, ...missing];
197
+ tree.overwrite('/angular.json', `${JSON.stringify(workspace, null, 2)}\n`);
198
+ context.logger.info(`✔ angular.json: allowed jspdf's CommonJS modules (${missing.join(', ')})`);
199
+ }
200
+
201
+ /** @param {{ project?: string, demo?: boolean, skipInstall?: boolean }} options */
202
+ function ngAdd(options = {}) {
203
+ return (tree, context) => {
204
+ const project = resolveProject(tree, options);
205
+ const changed = addDependencies(tree, context);
206
+ addPostcssConfig(tree, context, project.root);
207
+ addStyles(tree, context, project.styles);
208
+ addProvider(tree, context, project.sourceRoot);
209
+ if (options.demo !== false) addDemo(tree, context, project.sourceRoot);
210
+ allowExportCommonJs(tree, context, project.name);
211
+ if (changed && !options.skipInstall) context.addTask(new NodePackageInstallTask());
212
+ context.logger.info('Styloviz is set up. Docs: https://styloviz.dev/docs — or connect the MCP server: npx -y @styloviz/mcp');
213
+ return tree;
214
+ };
215
+ }
216
+
217
+ module.exports = { ngAdd };
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "StylovizNgAdd",
4
+ "title": "Styloviz ng add",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": { "type": "string", "description": "The application to set up. Defaults to the first application in angular.json.", "$default": { "$source": "projectName" } },
8
+ "demo": { "type": "boolean", "default": true, "description": "Add a demo page at /styloviz." },
9
+ "skipInstall": { "type": "boolean", "default": false, "description": "Do not run the package manager." }
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@styloviz/schematics",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.1",
4
+ "description": "Angular schematics for the Styloviz UI kit — ng add (Tailwind 4, tokens, a demo page), migrate-primeng (PrimeNG 21 selectors to Styloviz) and the kit's ng update migrations.",
5
+ "keywords": [
6
+ "angular",
7
+ "schematics",
8
+ "ng-add",
9
+ "ng-update",
10
+ "tailwind",
11
+ "styloviz",
12
+ "primeng",
13
+ "migration"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "sazzad-bs23",
17
+ "homepage": "https://styloviz.dev/docs",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/styloviz/styloviz.git",
21
+ "directory": "tools/schematics"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/styloviz/community/discussions"
25
+ },
26
+ "type": "commonjs",
27
+ "schematics": "./collection.json",
28
+ "ng-update": {
29
+ "migrations": "./migration.json"
30
+ },
31
+ "files": [
32
+ "collection.json",
33
+ "migration.json",
34
+ "ng-add",
35
+ "migrate-primeng",
36
+ "migrations",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "peerDependencies": {
41
+ "@angular-devkit/schematics": ">=21.0.0 <23.0.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }