@gilav21/shadcn-angular 0.0.3 → 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.
- package/dist/commands/add.js +5 -1
- package/dist/commands/init.js +69 -7
- package/dist/registry/index.js +1 -1
- package/package.json +2 -2
- package/src/commands/add.ts +6 -1
- package/src/commands/init.ts +70 -7
- package/src/registry/index.ts +1 -1
package/dist/commands/add.js
CHANGED
|
@@ -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
|
-
|
|
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}`;
|
package/dist/commands/init.js
CHANGED
|
@@ -88,9 +88,9 @@ export async function init(options) {
|
|
|
88
88
|
cssVariables: true,
|
|
89
89
|
},
|
|
90
90
|
aliases: {
|
|
91
|
-
components: '@/
|
|
92
|
-
utils: '
|
|
93
|
-
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
|
-
|
|
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(
|
|
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,16 +121,72 @@ export async function init(options) {
|
|
|
115
121
|
spinner.text = 'Updated styles with theme variables';
|
|
116
122
|
}
|
|
117
123
|
// Create components/ui directory
|
|
118
|
-
const
|
|
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
|
|
122
129
|
spinner.text = 'Installing dependencies...';
|
|
123
|
-
|
|
130
|
+
const dependencies = [
|
|
131
|
+
'clsx',
|
|
132
|
+
'tailwind-merge',
|
|
133
|
+
'class-variance-authority',
|
|
134
|
+
'@angular/cdk',
|
|
135
|
+
'lucide-angular',
|
|
136
|
+
'tailwindcss',
|
|
137
|
+
'postcss',
|
|
138
|
+
'@tailwindcss/postcss'
|
|
139
|
+
];
|
|
140
|
+
await execa('npm', ['install', ...dependencies], { cwd });
|
|
141
|
+
// Setup PostCSS
|
|
142
|
+
spinner.text = 'Configuring PostCSS...';
|
|
143
|
+
const postcssConfigPath = path.join(cwd, 'postcss.config.js');
|
|
144
|
+
const postcssConfigMjsPath = path.join(cwd, 'postcss.config.mjs');
|
|
145
|
+
if (await fs.pathExists(postcssConfigMjsPath)) {
|
|
146
|
+
// Check mjs config
|
|
147
|
+
const content = await fs.readFile(postcssConfigMjsPath, 'utf-8');
|
|
148
|
+
if (!content.includes('@tailwindcss/postcss')) {
|
|
149
|
+
// Very basic append attempt for mjs, safest is to warn or skip complex types
|
|
150
|
+
// But user asked to try.
|
|
151
|
+
// If it's a simple export default { plugins: {} }, we can try to inject.
|
|
152
|
+
// For now, let's just log a warning if we can't safely inject
|
|
153
|
+
console.log(chalk.yellow('\nComputed postcss.config.mjs found. Please manually add "@tailwindcss/postcss" to your plugins.'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (await fs.pathExists(postcssConfigPath)) {
|
|
157
|
+
let content = await fs.readFile(postcssConfigPath, 'utf-8');
|
|
158
|
+
if (!content.includes('@tailwindcss/postcss')) {
|
|
159
|
+
// Try to inject into plugins object
|
|
160
|
+
if (content.includes('plugins: {')) {
|
|
161
|
+
content = content.replace('plugins: {', 'plugins: {\n \'@tailwindcss/postcss\': {},');
|
|
162
|
+
await fs.writeFile(postcssConfigPath, content);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
console.log(chalk.yellow('\nExisting postcss.config.js found but structure not recognized. Please manually add "@tailwindcss/postcss" to your plugins.'));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// Create new config
|
|
171
|
+
const configContent = `module.exports = {
|
|
172
|
+
plugins: {
|
|
173
|
+
'@tailwindcss/postcss': {},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
await fs.writeFile(postcssConfigPath, configContent);
|
|
178
|
+
}
|
|
124
179
|
spinner.succeed(chalk.green('Project initialized successfully!'));
|
|
125
180
|
console.log('\n' + chalk.bold('Next steps:'));
|
|
126
181
|
console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx shadcn-angular add button'));
|
|
127
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(' }'));
|
|
128
190
|
console.log('');
|
|
129
191
|
}
|
|
130
192
|
catch (error) {
|
package/dist/registry/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gilav21/shadcn-angular",
|
|
3
|
-
"version": "0.0.
|
|
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
|
+
}
|
package/src/commands/add.ts
CHANGED
|
@@ -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
|
-
|
|
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}`;
|
package/src/commands/init.ts
CHANGED
|
@@ -99,9 +99,9 @@ export async function init(options: InitOptions) {
|
|
|
99
99
|
cssVariables: true,
|
|
100
100
|
},
|
|
101
101
|
aliases: {
|
|
102
|
-
components: '@/
|
|
103
|
-
utils: '
|
|
104
|
-
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
|
-
|
|
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(
|
|
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,19 +140,74 @@ export async function init(options: InitOptions) {
|
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
// Create components/ui directory
|
|
135
|
-
const
|
|
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
|
|
|
139
148
|
// Install dependencies
|
|
140
149
|
spinner.text = 'Installing dependencies...';
|
|
141
|
-
|
|
150
|
+
const dependencies = [
|
|
151
|
+
'clsx',
|
|
152
|
+
'tailwind-merge',
|
|
153
|
+
'class-variance-authority',
|
|
154
|
+
'@angular/cdk',
|
|
155
|
+
'lucide-angular',
|
|
156
|
+
'tailwindcss',
|
|
157
|
+
'postcss',
|
|
158
|
+
'@tailwindcss/postcss'
|
|
159
|
+
];
|
|
160
|
+
await execa('npm', ['install', ...dependencies], { cwd });
|
|
161
|
+
|
|
162
|
+
// Setup PostCSS
|
|
163
|
+
spinner.text = 'Configuring PostCSS...';
|
|
164
|
+
const postcssConfigPath = path.join(cwd, 'postcss.config.js');
|
|
165
|
+
const postcssConfigMjsPath = path.join(cwd, 'postcss.config.mjs');
|
|
166
|
+
|
|
167
|
+
if (await fs.pathExists(postcssConfigMjsPath)) {
|
|
168
|
+
// Check mjs config
|
|
169
|
+
const content = await fs.readFile(postcssConfigMjsPath, 'utf-8');
|
|
170
|
+
if (!content.includes('@tailwindcss/postcss')) {
|
|
171
|
+
// Very basic append attempt for mjs, safest is to warn or skip complex types
|
|
172
|
+
// But user asked to try.
|
|
173
|
+
// If it's a simple export default { plugins: {} }, we can try to inject.
|
|
174
|
+
// For now, let's just log a warning if we can't safely inject
|
|
175
|
+
console.log(chalk.yellow('\nComputed postcss.config.mjs found. Please manually add "@tailwindcss/postcss" to your plugins.'));
|
|
176
|
+
}
|
|
177
|
+
} else if (await fs.pathExists(postcssConfigPath)) {
|
|
178
|
+
let content = await fs.readFile(postcssConfigPath, 'utf-8');
|
|
179
|
+
if (!content.includes('@tailwindcss/postcss')) {
|
|
180
|
+
// Try to inject into plugins object
|
|
181
|
+
if (content.includes('plugins: {')) {
|
|
182
|
+
content = content.replace('plugins: {', 'plugins: {\n \'@tailwindcss/postcss\': {},');
|
|
183
|
+
await fs.writeFile(postcssConfigPath, content);
|
|
184
|
+
} else {
|
|
185
|
+
console.log(chalk.yellow('\nExisting postcss.config.js found but structure not recognized. Please manually add "@tailwindcss/postcss" to your plugins.'));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
// Create new config
|
|
190
|
+
const configContent = `module.exports = {
|
|
191
|
+
plugins: {
|
|
192
|
+
'@tailwindcss/postcss': {},
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
await fs.writeFile(postcssConfigPath, configContent);
|
|
197
|
+
}
|
|
142
198
|
|
|
143
199
|
spinner.succeed(chalk.green('Project initialized successfully!'));
|
|
144
200
|
|
|
145
201
|
console.log('\n' + chalk.bold('Next steps:'));
|
|
146
202
|
console.log(chalk.dim(' 1. Add components: ') + chalk.cyan('npx shadcn-angular add button'));
|
|
147
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(' }'));
|
|
148
211
|
console.log('');
|
|
149
212
|
|
|
150
213
|
} catch (error) {
|
package/src/registry/index.ts
CHANGED