@gilav21/shadcn-angular 0.0.17 → 0.0.18
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/dist/commands/add.js +6 -10
- package/dist/commands/init.js +4 -5
- package/dist/utils/config.js +1 -1
- package/dist/utils/shortcut-registry.js +3 -7
- package/package.json +1 -1
- package/src/commands/add.ts +6 -10
- package/src/commands/init.ts +173 -174
- package/src/utils/config.ts +1 -1
- package/src/utils/shortcut-registry.ts +3 -7
package/dist/commands/add.js
CHANGED
|
@@ -174,8 +174,7 @@ export async function add(components, options) {
|
|
|
174
174
|
try {
|
|
175
175
|
let remoteContent = await fetchComponentContent(file, options);
|
|
176
176
|
// Transform all lib/ imports for comparison
|
|
177
|
-
|
|
178
|
-
remoteContent = remoteContent.replace(/(\.\.\/)+lib\//g, libAlias + '/');
|
|
177
|
+
remoteContent = remoteContent.replace(/(\.\.\/)+lib\//g, config.aliases.utils + '/');
|
|
179
178
|
const normalize = (str) => str.replace(/\r\n/g, '\n').trim();
|
|
180
179
|
if (normalize(localContent) !== normalize(remoteContent)) {
|
|
181
180
|
hasChanges = true;
|
|
@@ -256,8 +255,7 @@ export async function add(components, options) {
|
|
|
256
255
|
if (!content) {
|
|
257
256
|
content = await fetchComponentContent(file, options);
|
|
258
257
|
// Transform all lib/ imports if not already transformed (cached is transformed)
|
|
259
|
-
|
|
260
|
-
content = content.replace(/(\.\.\/)+lib\//g, libAlias + '/');
|
|
258
|
+
content = content.replace(/(\.\.\/)+lib\//g, config.aliases.utils + '/');
|
|
261
259
|
}
|
|
262
260
|
await fs.ensureDir(path.dirname(targetPath));
|
|
263
261
|
await fs.writeFile(targetPath, content);
|
|
@@ -293,8 +291,7 @@ export async function add(components, options) {
|
|
|
293
291
|
}
|
|
294
292
|
}
|
|
295
293
|
if (requiredLibFiles.size > 0) {
|
|
296
|
-
const
|
|
297
|
-
const libDir = path.dirname(utilsPathResolved);
|
|
294
|
+
const libDir = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
298
295
|
await fs.ensureDir(libDir);
|
|
299
296
|
for (const libFile of requiredLibFiles) {
|
|
300
297
|
const libTargetPath = path.join(libDir, libFile);
|
|
@@ -332,12 +329,11 @@ export async function add(components, options) {
|
|
|
332
329
|
}
|
|
333
330
|
const shortcutEntries = collectInstalledShortcutEntries(targetDir);
|
|
334
331
|
if (shortcutEntries.length > 0) {
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const shortcutServicePath = path.join(utilsDir, 'shortcut-binding.service.ts');
|
|
332
|
+
const libDir2 = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
333
|
+
const shortcutServicePath = path.join(libDir2, 'shortcut-binding.service.ts');
|
|
338
334
|
if (!await fs.pathExists(shortcutServicePath)) {
|
|
339
335
|
const shortcutServiceContent = await fetchLibContent('shortcut-binding.service.ts', options);
|
|
340
|
-
await fs.ensureDir(
|
|
336
|
+
await fs.ensureDir(libDir2);
|
|
341
337
|
await fs.writeFile(shortcutServicePath, shortcutServiceContent);
|
|
342
338
|
}
|
|
343
339
|
}
|
package/dist/commands/init.js
CHANGED
|
@@ -195,12 +195,11 @@ export async function init(options) {
|
|
|
195
195
|
// So we should rely on config to reconstruct the path, or better yet, if we are in 'defaults' mode, check what config is.
|
|
196
196
|
// If config came from defaults, aliases are set.
|
|
197
197
|
// We can reverse-map alias to path: @/ -> src/
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
await fs.
|
|
201
|
-
await fs.writeFile(utilsPathResolved, getUtilsTemplate());
|
|
198
|
+
const libDir = resolveAliasOrPath(cwd, config.aliases.utils);
|
|
199
|
+
await fs.ensureDir(libDir);
|
|
200
|
+
await fs.writeFile(path.join(libDir, 'utils.ts'), getUtilsTemplate());
|
|
202
201
|
spinner.text = 'Created utils.ts';
|
|
203
|
-
const shortcutServicePath = path.join(
|
|
202
|
+
const shortcutServicePath = path.join(libDir, 'shortcut-binding.service.ts');
|
|
204
203
|
const shortcutServiceContent = await fetchLibFileContent('shortcut-binding.service.ts');
|
|
205
204
|
await fs.writeFile(shortcutServicePath, shortcutServiceContent);
|
|
206
205
|
spinner.text = 'Created shortcut-binding.service.ts';
|
package/dist/utils/config.js
CHANGED
|
@@ -14,9 +14,8 @@ function resolveProjectPath(cwd, inputPath) {
|
|
|
14
14
|
return resolved;
|
|
15
15
|
}
|
|
16
16
|
function getShortcutRegistryIndexPath(cwd, config) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
return path.join(utilsDir, 'shortcut-registry.index.ts');
|
|
17
|
+
const libDir = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
18
|
+
return path.join(libDir, 'shortcut-registry.index.ts');
|
|
20
19
|
}
|
|
21
20
|
export async function writeShortcutRegistryIndex(cwd, config, entries) {
|
|
22
21
|
const registryPath = getShortcutRegistryIndexPath(cwd, config);
|
|
@@ -24,10 +23,7 @@ export async function writeShortcutRegistryIndex(cwd, config, entries) {
|
|
|
24
23
|
const uniqueEntries = Array.from(new Map(entries.map(entry => [entry.exportName, entry])).values())
|
|
25
24
|
.sort((a, b) => a.exportName.localeCompare(b.exportName));
|
|
26
25
|
const uiAlias = config.aliases.ui;
|
|
27
|
-
const
|
|
28
|
-
? config.aliases.utils.slice(0, config.aliases.utils.lastIndexOf('/'))
|
|
29
|
-
: config.aliases.utils;
|
|
30
|
-
const shortcutServiceImport = `${utilsAliasDir}/shortcut-binding.service`;
|
|
26
|
+
const shortcutServiceImport = `${config.aliases.utils}/shortcut-binding.service`;
|
|
31
27
|
const imports = uniqueEntries
|
|
32
28
|
.map(entry => {
|
|
33
29
|
const importPath = `${uiAlias}/${entry.sourceFile.replace(/\.ts$/, '')}`;
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -204,8 +204,7 @@ export async function add(components: string[], options: AddOptions) {
|
|
|
204
204
|
try {
|
|
205
205
|
let remoteContent = await fetchComponentContent(file, options);
|
|
206
206
|
// Transform all lib/ imports for comparison
|
|
207
|
-
|
|
208
|
-
remoteContent = remoteContent.replace(/(\.\.\/)+lib\//g, libAlias + '/');
|
|
207
|
+
remoteContent = remoteContent.replace(/(\.\.\/)+lib\//g, config.aliases.utils + '/');
|
|
209
208
|
|
|
210
209
|
const normalize = (str: string) => str.replace(/\r\n/g, '\n').trim();
|
|
211
210
|
if (normalize(localContent) !== normalize(remoteContent)) {
|
|
@@ -294,8 +293,7 @@ export async function add(components: string[], options: AddOptions) {
|
|
|
294
293
|
if (!content) {
|
|
295
294
|
content = await fetchComponentContent(file, options);
|
|
296
295
|
// Transform all lib/ imports if not already transformed (cached is transformed)
|
|
297
|
-
|
|
298
|
-
content = content.replace(/(\.\.\/)+lib\//g, libAlias + '/');
|
|
296
|
+
content = content.replace(/(\.\.\/)+lib\//g, config.aliases.utils + '/');
|
|
299
297
|
}
|
|
300
298
|
|
|
301
299
|
await fs.ensureDir(path.dirname(targetPath));
|
|
@@ -334,8 +332,7 @@ export async function add(components: string[], options: AddOptions) {
|
|
|
334
332
|
}
|
|
335
333
|
|
|
336
334
|
if (requiredLibFiles.size > 0) {
|
|
337
|
-
const
|
|
338
|
-
const libDir = path.dirname(utilsPathResolved);
|
|
335
|
+
const libDir = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
339
336
|
await fs.ensureDir(libDir);
|
|
340
337
|
|
|
341
338
|
for (const libFile of requiredLibFiles) {
|
|
@@ -375,13 +372,12 @@ export async function add(components: string[], options: AddOptions) {
|
|
|
375
372
|
|
|
376
373
|
const shortcutEntries = collectInstalledShortcutEntries(targetDir);
|
|
377
374
|
if (shortcutEntries.length > 0) {
|
|
378
|
-
const
|
|
379
|
-
const
|
|
380
|
-
const shortcutServicePath = path.join(utilsDir, 'shortcut-binding.service.ts');
|
|
375
|
+
const libDir2 = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
376
|
+
const shortcutServicePath = path.join(libDir2, 'shortcut-binding.service.ts');
|
|
381
377
|
|
|
382
378
|
if (!await fs.pathExists(shortcutServicePath)) {
|
|
383
379
|
const shortcutServiceContent = await fetchLibContent('shortcut-binding.service.ts', options);
|
|
384
|
-
await fs.ensureDir(
|
|
380
|
+
await fs.ensureDir(libDir2);
|
|
385
381
|
await fs.writeFile(shortcutServicePath, shortcutServiceContent);
|
|
386
382
|
}
|
|
387
383
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -38,7 +38,7 @@ async function fetchLibFileContent(file: string): Promise<string> {
|
|
|
38
38
|
}
|
|
39
39
|
return response.text();
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
interface InitOptions {
|
|
43
43
|
yes?: boolean;
|
|
44
44
|
defaults?: boolean;
|
|
@@ -61,18 +61,18 @@ function resolveAliasOrPath(cwd: string, aliasOrPath: string): string {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export async function init(options: InitOptions) {
|
|
64
|
-
console.log(chalk.bold('\n🎨 Welcome to shadcn-angular!\n'));
|
|
65
|
-
|
|
66
|
-
const cwd = process.cwd();
|
|
67
|
-
|
|
68
|
-
// Check if this is an Angular project
|
|
69
|
-
const angularJsonPath = path.join(cwd, 'angular.json');
|
|
70
|
-
if (!await fs.pathExists(angularJsonPath)) {
|
|
71
|
-
console.log(chalk.red('Error: This does not appear to be an Angular project.'));
|
|
72
|
-
console.log(chalk.dim('Please run this command in the root of your Angular project.'));
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
64
|
+
console.log(chalk.bold('\n🎨 Welcome to shadcn-angular!\n'));
|
|
65
|
+
|
|
66
|
+
const cwd = process.cwd();
|
|
67
|
+
|
|
68
|
+
// Check if this is an Angular project
|
|
69
|
+
const angularJsonPath = path.join(cwd, 'angular.json');
|
|
70
|
+
if (!await fs.pathExists(angularJsonPath)) {
|
|
71
|
+
console.log(chalk.red('Error: This does not appear to be an Angular project.'));
|
|
72
|
+
console.log(chalk.dim('Please run this command in the root of your Angular project.'));
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
76
|
// Check if already initialized
|
|
77
77
|
const componentsJsonPath = path.join(cwd, 'components.json');
|
|
78
78
|
if (await fs.pathExists(componentsJsonPath)) {
|
|
@@ -87,93 +87,93 @@ export async function init(options: InitOptions) {
|
|
|
87
87
|
if (!overwrite) {
|
|
88
88
|
console.log(chalk.dim('Initialization cancelled.'));
|
|
89
89
|
return;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
93
|
let config: Config;
|
|
94
94
|
let createShortcutRegistry = true;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
if (options.defaults || options.yes) {
|
|
97
97
|
config = getDefaultConfig();
|
|
98
98
|
createShortcutRegistry = true;
|
|
99
99
|
} else {
|
|
100
|
-
const THEME_COLORS: Record<string, string> = {
|
|
101
|
-
zinc: '#71717a',
|
|
102
|
-
slate: '#64748b',
|
|
103
|
-
stone: '#78716c',
|
|
104
|
-
gray: '#6b7280',
|
|
105
|
-
neutral: '#737373',
|
|
106
|
-
red: '#ef4444',
|
|
107
|
-
rose: '#f43f5e',
|
|
108
|
-
orange: '#f97316', // bright orange
|
|
109
|
-
green: '#22c55e',
|
|
110
|
-
blue: '#3b82f6',
|
|
111
|
-
yellow: '#eab308',
|
|
112
|
-
violet: '#8b5cf6',
|
|
113
|
-
amber: '#d97706', // warm amber for preview
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const themeChoices = [
|
|
117
|
-
{ title: 'Zinc', value: 'zinc' },
|
|
118
|
-
{ title: 'Slate', value: 'slate' },
|
|
119
|
-
{ title: 'Stone', value: 'stone' },
|
|
120
|
-
{ title: 'Gray', value: 'gray' },
|
|
121
|
-
{ title: 'Neutral', value: 'neutral' },
|
|
122
|
-
{ title: 'Red', value: 'red' },
|
|
123
|
-
{ title: 'Rose', value: 'rose' },
|
|
124
|
-
{ title: 'Orange', value: 'orange' },
|
|
125
|
-
{ title: 'Green', value: 'green' },
|
|
126
|
-
{ title: 'Blue', value: 'blue' },
|
|
127
|
-
{ title: 'Yellow', value: 'yellow' },
|
|
128
|
-
{ title: 'Violet', value: 'violet' },
|
|
129
|
-
{ title: 'Amber', value: 'amber' },
|
|
130
|
-
].map(c => ({
|
|
131
|
-
...c,
|
|
132
|
-
title: `${chalk.hex(THEME_COLORS[c.value])('██')} ${c.title}`
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
const baseColorChoices = [
|
|
136
|
-
{ title: 'Neutral', value: 'neutral' },
|
|
137
|
-
{ title: 'Slate', value: 'slate' },
|
|
138
|
-
{ title: 'Stone', value: 'stone' },
|
|
139
|
-
{ title: 'Gray', value: 'gray' },
|
|
140
|
-
{ title: 'Zinc', value: 'zinc' },
|
|
141
|
-
].map(c => ({
|
|
142
|
-
...c,
|
|
143
|
-
title: `${chalk.hex(THEME_COLORS[c.value])('██')} ${c.title}`
|
|
144
|
-
}));
|
|
145
|
-
|
|
146
|
-
const responses = await prompts([
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
type: 'select',
|
|
150
|
-
name: 'baseColor',
|
|
151
|
-
message: 'Which color would you like to use as base color?',
|
|
152
|
-
choices: baseColorChoices,
|
|
153
|
-
initial: 0,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
type: 'select',
|
|
157
|
-
name: 'theme',
|
|
158
|
-
message: 'Which color would you like to use for the main theme?',
|
|
159
|
-
choices: themeChoices,
|
|
160
|
-
initial: (prev: string) => {
|
|
161
|
-
const index = themeChoices.findIndex(c => c.value === prev);
|
|
162
|
-
return index === -1 ? 0 : index;
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
type: 'text',
|
|
167
|
-
name: 'componentsPath',
|
|
168
|
-
message: 'Where would you like to install components?',
|
|
169
|
-
initial: 'src/components/ui',
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
type: 'text',
|
|
173
|
-
name: 'utilsPath',
|
|
174
|
-
message: 'Where would you like to install utils?',
|
|
175
|
-
initial: 'src/components/lib',
|
|
176
|
-
},
|
|
100
|
+
const THEME_COLORS: Record<string, string> = {
|
|
101
|
+
zinc: '#71717a',
|
|
102
|
+
slate: '#64748b',
|
|
103
|
+
stone: '#78716c',
|
|
104
|
+
gray: '#6b7280',
|
|
105
|
+
neutral: '#737373',
|
|
106
|
+
red: '#ef4444',
|
|
107
|
+
rose: '#f43f5e',
|
|
108
|
+
orange: '#f97316', // bright orange
|
|
109
|
+
green: '#22c55e',
|
|
110
|
+
blue: '#3b82f6',
|
|
111
|
+
yellow: '#eab308',
|
|
112
|
+
violet: '#8b5cf6',
|
|
113
|
+
amber: '#d97706', // warm amber for preview
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const themeChoices = [
|
|
117
|
+
{ title: 'Zinc', value: 'zinc' },
|
|
118
|
+
{ title: 'Slate', value: 'slate' },
|
|
119
|
+
{ title: 'Stone', value: 'stone' },
|
|
120
|
+
{ title: 'Gray', value: 'gray' },
|
|
121
|
+
{ title: 'Neutral', value: 'neutral' },
|
|
122
|
+
{ title: 'Red', value: 'red' },
|
|
123
|
+
{ title: 'Rose', value: 'rose' },
|
|
124
|
+
{ title: 'Orange', value: 'orange' },
|
|
125
|
+
{ title: 'Green', value: 'green' },
|
|
126
|
+
{ title: 'Blue', value: 'blue' },
|
|
127
|
+
{ title: 'Yellow', value: 'yellow' },
|
|
128
|
+
{ title: 'Violet', value: 'violet' },
|
|
129
|
+
{ title: 'Amber', value: 'amber' },
|
|
130
|
+
].map(c => ({
|
|
131
|
+
...c,
|
|
132
|
+
title: `${chalk.hex(THEME_COLORS[c.value])('██')} ${c.title}`
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
const baseColorChoices = [
|
|
136
|
+
{ title: 'Neutral', value: 'neutral' },
|
|
137
|
+
{ title: 'Slate', value: 'slate' },
|
|
138
|
+
{ title: 'Stone', value: 'stone' },
|
|
139
|
+
{ title: 'Gray', value: 'gray' },
|
|
140
|
+
{ title: 'Zinc', value: 'zinc' },
|
|
141
|
+
].map(c => ({
|
|
142
|
+
...c,
|
|
143
|
+
title: `${chalk.hex(THEME_COLORS[c.value])('██')} ${c.title}`
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
const responses = await prompts([
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
type: 'select',
|
|
150
|
+
name: 'baseColor',
|
|
151
|
+
message: 'Which color would you like to use as base color?',
|
|
152
|
+
choices: baseColorChoices,
|
|
153
|
+
initial: 0,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: 'select',
|
|
157
|
+
name: 'theme',
|
|
158
|
+
message: 'Which color would you like to use for the main theme?',
|
|
159
|
+
choices: themeChoices,
|
|
160
|
+
initial: (prev: string) => {
|
|
161
|
+
const index = themeChoices.findIndex(c => c.value === prev);
|
|
162
|
+
return index === -1 ? 0 : index;
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: 'text',
|
|
167
|
+
name: 'componentsPath',
|
|
168
|
+
message: 'Where would you like to install components?',
|
|
169
|
+
initial: 'src/components/ui',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'text',
|
|
173
|
+
name: 'utilsPath',
|
|
174
|
+
message: 'Where would you like to install utils?',
|
|
175
|
+
initial: 'src/components/lib',
|
|
176
|
+
},
|
|
177
177
|
{
|
|
178
178
|
type: 'text',
|
|
179
179
|
name: 'globalCss',
|
|
@@ -187,47 +187,46 @@ export async function init(options: InitOptions) {
|
|
|
187
187
|
initial: true,
|
|
188
188
|
},
|
|
189
189
|
]);
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
config = {
|
|
192
192
|
$schema: 'https://shadcn-angular.dev/schema.json',
|
|
193
|
-
style: 'default',
|
|
194
|
-
tailwind: {
|
|
195
|
-
css: responses.globalCss,
|
|
196
|
-
baseColor: responses.baseColor,
|
|
197
|
-
theme: responses.theme,
|
|
198
|
-
cssVariables: true,
|
|
199
|
-
},
|
|
200
|
-
aliases: {
|
|
201
|
-
components: responses.componentsPath.replace('src/', '@/'), // Basic heuristic
|
|
202
|
-
utils: responses.utilsPath.replace('src/', '@/').replace('.ts', ''),
|
|
203
|
-
ui: responses.componentsPath.replace('src/', '@/'),
|
|
193
|
+
style: 'default',
|
|
194
|
+
tailwind: {
|
|
195
|
+
css: responses.globalCss,
|
|
196
|
+
baseColor: responses.baseColor,
|
|
197
|
+
theme: responses.theme,
|
|
198
|
+
cssVariables: true,
|
|
199
|
+
},
|
|
200
|
+
aliases: {
|
|
201
|
+
components: responses.componentsPath.replace('src/', '@/'), // Basic heuristic
|
|
202
|
+
utils: responses.utilsPath.replace('src/', '@/').replace('.ts', ''),
|
|
203
|
+
ui: responses.componentsPath.replace('src/', '@/'),
|
|
204
204
|
},
|
|
205
205
|
};
|
|
206
206
|
createShortcutRegistry = responses.createShortcutRegistry ?? true;
|
|
207
207
|
}
|
|
208
|
-
|
|
209
|
-
const spinner = ora('Initializing project...').start();
|
|
210
|
-
|
|
211
|
-
try {
|
|
212
|
-
// Write components.json
|
|
213
|
-
await fs.writeJson(componentsJsonPath, config, { spaces: 2 });
|
|
214
|
-
spinner.text = 'Created components.json';
|
|
215
|
-
|
|
216
|
-
// Create utils directory and file
|
|
217
|
-
// Resolve path from the config alias, assuming @/ maps to src/ logic for file creation if not provided directly
|
|
218
|
-
// But we have the 'responses' object from CLI prompt only in the else block above!
|
|
219
|
-
// So we should rely on config to reconstruct the path, or better yet, if we are in 'defaults' mode, check what config is.
|
|
220
|
-
// If config came from defaults, aliases are set.
|
|
221
|
-
// We can reverse-map alias to path: @/ -> src/
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
await fs.
|
|
227
|
-
await fs.writeFile(utilsPathResolved, getUtilsTemplate());
|
|
208
|
+
|
|
209
|
+
const spinner = ora('Initializing project...').start();
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
// Write components.json
|
|
213
|
+
await fs.writeJson(componentsJsonPath, config, { spaces: 2 });
|
|
214
|
+
spinner.text = 'Created components.json';
|
|
215
|
+
|
|
216
|
+
// Create utils directory and file
|
|
217
|
+
// Resolve path from the config alias, assuming @/ maps to src/ logic for file creation if not provided directly
|
|
218
|
+
// But we have the 'responses' object from CLI prompt only in the else block above!
|
|
219
|
+
// So we should rely on config to reconstruct the path, or better yet, if we are in 'defaults' mode, check what config is.
|
|
220
|
+
// If config came from defaults, aliases are set.
|
|
221
|
+
// We can reverse-map alias to path: @/ -> src/
|
|
222
|
+
|
|
223
|
+
const libDir = resolveAliasOrPath(cwd, config.aliases.utils);
|
|
224
|
+
|
|
225
|
+
await fs.ensureDir(libDir);
|
|
226
|
+
await fs.writeFile(path.join(libDir, 'utils.ts'), getUtilsTemplate());
|
|
228
227
|
spinner.text = 'Created utils.ts';
|
|
229
228
|
|
|
230
|
-
const shortcutServicePath = path.join(
|
|
229
|
+
const shortcutServicePath = path.join(libDir, 'shortcut-binding.service.ts');
|
|
231
230
|
const shortcutServiceContent = await fetchLibFileContent('shortcut-binding.service.ts');
|
|
232
231
|
await fs.writeFile(shortcutServicePath, shortcutServiceContent);
|
|
233
232
|
spinner.text = 'Created shortcut-binding.service.ts';
|
|
@@ -251,63 +250,63 @@ export async function init(options: InitOptions) {
|
|
|
251
250
|
let userStyles = await fs.pathExists(userStylesPath)
|
|
252
251
|
? await fs.readFile(userStylesPath, 'utf-8')
|
|
253
252
|
: '';
|
|
254
|
-
|
|
255
|
-
const tailwindImport = '@import "./tailwind.css";';
|
|
256
|
-
if (!userStyles.includes('tailwind.css')) {
|
|
257
|
-
// Add import at the top of the file
|
|
258
|
-
userStyles = tailwindImport + '\n\n' + userStyles;
|
|
259
|
-
await fs.writeFile(userStylesPath, userStyles);
|
|
260
|
-
spinner.text = 'Added tailwind.css import to styles';
|
|
253
|
+
|
|
254
|
+
const tailwindImport = '@import "./tailwind.css";';
|
|
255
|
+
if (!userStyles.includes('tailwind.css')) {
|
|
256
|
+
// Add import at the top of the file
|
|
257
|
+
userStyles = tailwindImport + '\n\n' + userStyles;
|
|
258
|
+
await fs.writeFile(userStylesPath, userStyles);
|
|
259
|
+
spinner.text = 'Added tailwind.css import to styles';
|
|
261
260
|
}
|
|
262
261
|
|
|
263
262
|
// Create components/ui directory
|
|
264
263
|
const uiDir = resolveAliasOrPath(cwd, config.aliases.ui);
|
|
265
264
|
await fs.ensureDir(uiDir);
|
|
266
265
|
spinner.text = 'Created components directory';
|
|
267
|
-
|
|
268
|
-
// Install dependencies
|
|
269
|
-
spinner.text = 'Installing dependencies...';
|
|
266
|
+
|
|
267
|
+
// Install dependencies
|
|
268
|
+
spinner.text = 'Installing dependencies...';
|
|
270
269
|
const dependencies = [
|
|
271
270
|
'clsx',
|
|
272
271
|
'tailwind-merge',
|
|
273
|
-
'class-variance-authority',
|
|
274
|
-
'tailwindcss',
|
|
272
|
+
'class-variance-authority',
|
|
273
|
+
'tailwindcss',
|
|
275
274
|
'postcss',
|
|
276
275
|
'@tailwindcss/postcss'
|
|
277
276
|
];
|
|
278
277
|
await installPackages(dependencies, { cwd });
|
|
279
|
-
|
|
280
|
-
// Setup PostCSS - create .postcssrc.json which is the preferred format for Angular
|
|
281
|
-
spinner.text = 'Configuring PostCSS...';
|
|
282
|
-
const postcssrcPath = path.join(cwd, '.postcssrc.json');
|
|
283
|
-
|
|
284
|
-
if (!await fs.pathExists(postcssrcPath)) {
|
|
285
|
-
const configContent = {
|
|
286
|
-
plugins: {
|
|
287
|
-
'@tailwindcss/postcss': {}
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
await fs.writeJson(postcssrcPath, configContent, { spaces: 4 });
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
spinner.succeed(chalk.green('Project initialized successfully!'));
|
|
295
|
-
|
|
296
|
-
console.log('\n' + chalk.bold('Next steps:'));
|
|
297
|
-
console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx @gilav21/shadcn-angular add button'));
|
|
298
|
-
console.log(chalk.dim(' 2. Import and use in your templates'));
|
|
299
|
-
console.log(chalk.dim(' 3. Update your ') + chalk.bold('tsconfig.json') + chalk.dim(' paths:'));
|
|
300
|
-
console.log(chalk.dim(' "compilerOptions": {'));
|
|
301
|
-
console.log(chalk.dim(' "baseUrl": ".",'));
|
|
302
|
-
console.log(chalk.dim(' "paths": {'));
|
|
303
|
-
console.log(chalk.dim(' "@/*": ["./src/*"]'));
|
|
304
|
-
console.log(chalk.dim(' }'));
|
|
305
|
-
console.log(chalk.dim(' }'));
|
|
306
|
-
console.log('');
|
|
307
|
-
|
|
308
|
-
} catch (error) {
|
|
309
|
-
spinner.fail('Failed to initialize project');
|
|
310
|
-
console.error(error);
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
278
|
+
|
|
279
|
+
// Setup PostCSS - create .postcssrc.json which is the preferred format for Angular
|
|
280
|
+
spinner.text = 'Configuring PostCSS...';
|
|
281
|
+
const postcssrcPath = path.join(cwd, '.postcssrc.json');
|
|
282
|
+
|
|
283
|
+
if (!await fs.pathExists(postcssrcPath)) {
|
|
284
|
+
const configContent = {
|
|
285
|
+
plugins: {
|
|
286
|
+
'@tailwindcss/postcss': {}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
await fs.writeJson(postcssrcPath, configContent, { spaces: 4 });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
spinner.succeed(chalk.green('Project initialized successfully!'));
|
|
294
|
+
|
|
295
|
+
console.log('\n' + chalk.bold('Next steps:'));
|
|
296
|
+
console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx @gilav21/shadcn-angular add button'));
|
|
297
|
+
console.log(chalk.dim(' 2. Import and use in your templates'));
|
|
298
|
+
console.log(chalk.dim(' 3. Update your ') + chalk.bold('tsconfig.json') + chalk.dim(' paths:'));
|
|
299
|
+
console.log(chalk.dim(' "compilerOptions": {'));
|
|
300
|
+
console.log(chalk.dim(' "baseUrl": ".",'));
|
|
301
|
+
console.log(chalk.dim(' "paths": {'));
|
|
302
|
+
console.log(chalk.dim(' "@/*": ["./src/*"]'));
|
|
303
|
+
console.log(chalk.dim(' }'));
|
|
304
|
+
console.log(chalk.dim(' }'));
|
|
305
|
+
console.log('');
|
|
306
|
+
|
|
307
|
+
} catch (error) {
|
|
308
|
+
spinner.fail('Failed to initialize project');
|
|
309
|
+
console.error(error);
|
|
310
|
+
process.exit(1);
|
|
311
|
+
}
|
|
312
|
+
}
|
package/src/utils/config.ts
CHANGED
|
@@ -24,9 +24,8 @@ function resolveProjectPath(cwd: string, inputPath: string): string {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function getShortcutRegistryIndexPath(cwd: string, config: Config): string {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
return path.join(utilsDir, 'shortcut-registry.index.ts');
|
|
27
|
+
const libDir = resolveProjectPath(cwd, aliasToProjectPath(config.aliases.utils));
|
|
28
|
+
return path.join(libDir, 'shortcut-registry.index.ts');
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export async function writeShortcutRegistryIndex(
|
|
@@ -41,10 +40,7 @@ export async function writeShortcutRegistryIndex(
|
|
|
41
40
|
.sort((a, b) => a.exportName.localeCompare(b.exportName));
|
|
42
41
|
|
|
43
42
|
const uiAlias = config.aliases.ui;
|
|
44
|
-
const
|
|
45
|
-
? config.aliases.utils.slice(0, config.aliases.utils.lastIndexOf('/'))
|
|
46
|
-
: config.aliases.utils;
|
|
47
|
-
const shortcutServiceImport = `${utilsAliasDir}/shortcut-binding.service`;
|
|
43
|
+
const shortcutServiceImport = `${config.aliases.utils}/shortcut-binding.service`;
|
|
48
44
|
|
|
49
45
|
const imports = uniqueEntries
|
|
50
46
|
.map(entry => {
|