@gilav21/shadcn-angular 0.0.4 → 0.0.5

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.
@@ -138,7 +138,11 @@ export async function add(components, options) {
138
138
  for (const file of component.files) {
139
139
  const targetPath = path.join(targetDir, file);
140
140
  try {
141
- const content = await fetchComponentContent(file, options);
141
+ let content = await fetchComponentContent(file, options);
142
+ // Transform imports
143
+ // Replace ../lib/utils (or similar relative paths) with the configured alias
144
+ const utilsAlias = config.aliases.utils;
145
+ content = content.replace(/(\.\.\/)+lib\/utils/g, utilsAlias);
142
146
  await fs.ensureDir(path.dirname(targetPath));
143
147
  await fs.writeFile(targetPath, content);
144
148
  spinner.text = `Added ${file}`;
@@ -88,9 +88,9 @@ export async function init(options) {
88
88
  cssVariables: true,
89
89
  },
90
90
  aliases: {
91
- components: '@/components',
92
- utils: '@/lib/utils',
93
- ui: '@/components/ui',
91
+ components: responses.componentsPath.replace('src/', '@/'), // Basic heuristic
92
+ utils: responses.utilsPath.replace('src/', '@/').replace('.ts', ''),
93
+ ui: responses.componentsPath.replace('src/', '@/'),
94
94
  },
95
95
  iconLibrary: 'lucide-angular',
96
96
  };
@@ -101,9 +101,15 @@ export async function init(options) {
101
101
  await fs.writeJson(componentsJsonPath, config, { spaces: 2 });
102
102
  spinner.text = 'Created components.json';
103
103
  // Create utils directory and file
104
- const utilsDir = path.join(cwd, config.aliases.utils.replace('@/', 'src/').replace('/utils', ''));
104
+ // Resolve path from the config alias, assuming @/ maps to src/ logic for file creation if not provided directly
105
+ // But we have the 'responses' object from CLI prompt only in the else block above!
106
+ // So we should rely on config to reconstruct the path, or better yet, if we are in 'defaults' mode, check what config is.
107
+ // If config came from defaults, aliases are set.
108
+ // We can reverse-map alias to path: @/ -> src/
109
+ const utilsPathResolved = config.aliases.utils.replace('@/', 'src/');
110
+ const utilsDir = path.dirname(path.join(cwd, utilsPathResolved + '.ts')); // utils usually ends in path/to/utils
105
111
  await fs.ensureDir(utilsDir);
106
- await fs.writeFile(path.join(utilsDir, 'utils.ts'), getUtilsTemplate());
112
+ await fs.writeFile(path.join(cwd, utilsPathResolved + '.ts'), getUtilsTemplate());
107
113
  spinner.text = 'Created utils.ts';
108
114
  // Create/update styles file
109
115
  const stylesPath = path.join(cwd, config.tailwind.css);
@@ -115,7 +121,8 @@ export async function init(options) {
115
121
  spinner.text = 'Updated styles with theme variables';
116
122
  }
117
123
  // Create components/ui directory
118
- const uiDir = path.join(cwd, 'src/components/ui');
124
+ const uiPathResolved = config.aliases.ui.replace('@/', 'src/');
125
+ const uiDir = path.join(cwd, uiPathResolved);
119
126
  await fs.ensureDir(uiDir);
120
127
  spinner.text = 'Created components directory';
121
128
  // Install dependencies
@@ -173,6 +180,13 @@ export async function init(options) {
173
180
  console.log('\n' + chalk.bold('Next steps:'));
174
181
  console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx shadcn-angular add button'));
175
182
  console.log(chalk.dim(' 2. Import and use in your templates'));
183
+ console.log(chalk.dim(' 3. Update your ') + chalk.bold('tsconfig.json') + chalk.dim(' paths:'));
184
+ console.log(chalk.dim(' "compilerOptions": {'));
185
+ console.log(chalk.dim(' "baseUrl": ".",'));
186
+ console.log(chalk.dim(' "paths": {'));
187
+ console.log(chalk.dim(' "@/*": ["./src/*"]'));
188
+ console.log(chalk.dim(' }'));
189
+ console.log(chalk.dim(' }'));
176
190
  console.log('');
177
191
  }
178
192
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gilav21/shadcn-angular",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "CLI for adding shadcn-angular components to your project",
5
5
  "bin": {
6
6
  "shadcn-angular": "./dist/index.js"
@@ -32,4 +32,4 @@
32
32
  "@types/prompts": "^2.4.9",
33
33
  "typescript": "^5.5.0"
34
34
  }
35
- }
35
+ }
@@ -163,7 +163,12 @@ export async function add(components: string[], options: AddOptions) {
163
163
  const targetPath = path.join(targetDir, file);
164
164
 
165
165
  try {
166
- const content = await fetchComponentContent(file, options);
166
+ let content = await fetchComponentContent(file, options);
167
+
168
+ // Transform imports
169
+ // Replace ../lib/utils (or similar relative paths) with the configured alias
170
+ const utilsAlias = config.aliases.utils;
171
+ content = content.replace(/(\.\.\/)+lib\/utils/g, utilsAlias);
167
172
  await fs.ensureDir(path.dirname(targetPath));
168
173
  await fs.writeFile(targetPath, content);
169
174
  spinner.text = `Added ${file}`;
@@ -99,9 +99,9 @@ export async function init(options: InitOptions) {
99
99
  cssVariables: true,
100
100
  },
101
101
  aliases: {
102
- components: '@/components',
103
- utils: '@/lib/utils',
104
- ui: '@/components/ui',
102
+ components: responses.componentsPath.replace('src/', '@/'), // Basic heuristic
103
+ utils: responses.utilsPath.replace('src/', '@/').replace('.ts', ''),
104
+ ui: responses.componentsPath.replace('src/', '@/'),
105
105
  },
106
106
  iconLibrary: 'lucide-angular',
107
107
  };
@@ -115,9 +115,17 @@ export async function init(options: InitOptions) {
115
115
  spinner.text = 'Created components.json';
116
116
 
117
117
  // Create utils directory and file
118
- const utilsDir = path.join(cwd, config.aliases.utils.replace('@/', 'src/').replace('/utils', ''));
118
+ // Resolve path from the config alias, assuming @/ maps to src/ logic for file creation if not provided directly
119
+ // But we have the 'responses' object from CLI prompt only in the else block above!
120
+ // So we should rely on config to reconstruct the path, or better yet, if we are in 'defaults' mode, check what config is.
121
+ // If config came from defaults, aliases are set.
122
+ // We can reverse-map alias to path: @/ -> src/
123
+
124
+ const utilsPathResolved = config.aliases.utils.replace('@/', 'src/');
125
+ const utilsDir = path.dirname(path.join(cwd, utilsPathResolved + '.ts')); // utils usually ends in path/to/utils
126
+
119
127
  await fs.ensureDir(utilsDir);
120
- await fs.writeFile(path.join(utilsDir, 'utils.ts'), getUtilsTemplate());
128
+ await fs.writeFile(path.join(cwd, utilsPathResolved + '.ts'), getUtilsTemplate());
121
129
  spinner.text = 'Created utils.ts';
122
130
 
123
131
  // Create/update styles file
@@ -132,7 +140,8 @@ export async function init(options: InitOptions) {
132
140
  }
133
141
 
134
142
  // Create components/ui directory
135
- const uiDir = path.join(cwd, 'src/components/ui');
143
+ const uiPathResolved = config.aliases.ui.replace('@/', 'src/');
144
+ const uiDir = path.join(cwd, uiPathResolved);
136
145
  await fs.ensureDir(uiDir);
137
146
  spinner.text = 'Created components directory';
138
147
 
@@ -192,6 +201,13 @@ export async function init(options: InitOptions) {
192
201
  console.log('\n' + chalk.bold('Next steps:'));
193
202
  console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx shadcn-angular add button'));
194
203
  console.log(chalk.dim(' 2. Import and use in your templates'));
204
+ console.log(chalk.dim(' 3. Update your ') + chalk.bold('tsconfig.json') + chalk.dim(' paths:'));
205
+ console.log(chalk.dim(' "compilerOptions": {'));
206
+ console.log(chalk.dim(' "baseUrl": ".",'));
207
+ console.log(chalk.dim(' "paths": {'));
208
+ console.log(chalk.dim(' "@/*": ["./src/*"]'));
209
+ console.log(chalk.dim(' }'));
210
+ console.log(chalk.dim(' }'));
195
211
  console.log('');
196
212
 
197
213
  } catch (error) {