@androbinco/library-cli 0.1.0 → 0.2.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.
@@ -21,7 +21,48 @@ export function isWithinProjectRoot(targetPath) {
21
21
  return !relative.startsWith('..') && !path.isAbsolute(relative);
22
22
  }
23
23
 
24
- export async function copyComponent(component, templatesDir) {
24
+ export async function checkComponentExists(componentName, filename) {
25
+ const componentPath = path.resolve(process.cwd(), 'src', 'components', componentName, filename);
26
+ return await fs.pathExists(componentPath);
27
+ }
28
+
29
+ export async function copyExamples(component, templatesDir, examplesToCopy) {
30
+ if (!examplesToCopy || examplesToCopy.length === 0) {
31
+ return true;
32
+ }
33
+
34
+ const examplesSourcePath = path.join(templatesDir, component.sourceDir, 'examples');
35
+ const examplesDestPath = path.resolve(process.cwd(), 'src', 'components', component.name, 'examples');
36
+
37
+ if (!(await fs.pathExists(examplesSourcePath))) {
38
+ p.log.warn(`Examples directory not found at ${examplesSourcePath}. Skipping examples.`);
39
+ return true;
40
+ }
41
+
42
+ try {
43
+ // Ensure destination directory exists
44
+ await fs.ensureDir(examplesDestPath);
45
+
46
+ // Copy selected example files
47
+ for (const exampleFile of examplesToCopy) {
48
+ const sourceFile = path.join(examplesSourcePath, exampleFile);
49
+ const destFile = path.join(examplesDestPath, exampleFile);
50
+
51
+ if (await fs.pathExists(sourceFile)) {
52
+ await fs.copy(sourceFile, destFile, { overwrite: true });
53
+ } else {
54
+ p.log.warn(`Example file "${exampleFile}" not found. Skipping.`);
55
+ }
56
+ }
57
+
58
+ return true;
59
+ } catch (error) {
60
+ p.log.error(`Failed to copy examples: ${error.message}`);
61
+ return false;
62
+ }
63
+ }
64
+
65
+ export async function copyComponent(component, templatesDir, examplesToCopy = null, componentsToCopy = null) {
25
66
  const sourcePath = path.join(templatesDir, component.sourceDir);
26
67
  const destBasePath = path.resolve(process.cwd(), 'src', 'components', component.name);
27
68
 
@@ -35,8 +76,8 @@ export async function copyComponent(component, templatesDir) {
35
76
  return false;
36
77
  }
37
78
 
38
- // Check if destination exists and is not empty
39
- if (await fs.pathExists(destBasePath)) {
79
+ // Check if destination exists and is not empty (only if copying all files)
80
+ if (!componentsToCopy && await fs.pathExists(destBasePath)) {
40
81
  const isEmpty = await isDirectoryEmpty(destBasePath);
41
82
 
42
83
  if (!isEmpty) {
@@ -56,8 +97,50 @@ export async function copyComponent(component, templatesDir) {
56
97
  // Ensure destination directory exists
57
98
  await fs.ensureDir(destBasePath);
58
99
 
59
- // Copy all files from source to destination
60
- await fs.copy(sourcePath, destBasePath, { overwrite: true });
100
+ if (componentsToCopy && componentsToCopy.length > 0) {
101
+ // Copy only selected component files
102
+ for (const filename of componentsToCopy) {
103
+ const sourceFile = path.join(sourcePath, filename);
104
+ const destFile = path.join(destBasePath, filename);
105
+
106
+ if (!(await fs.pathExists(sourceFile))) {
107
+ p.log.warn(`Component file "${filename}" not found. Skipping.`);
108
+ continue;
109
+ }
110
+
111
+ // Check if it's a directory and if it already exists
112
+ const sourceStat = await fs.stat(sourceFile);
113
+ if (sourceStat.isDirectory()) {
114
+ // If directory already exists, skip copying it (allows sharing between variants)
115
+ if (await fs.pathExists(destFile)) {
116
+ p.log.info(`Directory "${filename}" already exists. Skipping to allow sharing.`);
117
+ continue;
118
+ }
119
+ }
120
+
121
+ await fs.copy(sourceFile, destFile, { overwrite: true });
122
+ }
123
+ } else {
124
+ // Copy all files from source to destination, excluding examples folder
125
+ const files = await fs.readdir(sourcePath);
126
+ for (const file of files) {
127
+ const sourceFile = path.join(sourcePath, file);
128
+ const destFile = path.join(destBasePath, file);
129
+ const stat = await fs.stat(sourceFile);
130
+
131
+ // Skip examples directory - we'll handle it separately
132
+ if (stat.isDirectory() && file === 'examples') {
133
+ continue;
134
+ }
135
+
136
+ await fs.copy(sourceFile, destFile, { overwrite: true });
137
+ }
138
+ }
139
+
140
+ // Copy selected examples if provided
141
+ if (examplesToCopy && examplesToCopy.length > 0) {
142
+ await copyExamples(component, templatesDir, examplesToCopy);
143
+ }
61
144
 
62
145
  return true;
63
146
  } catch (error) {
@@ -1,5 +0,0 @@
1
- // @ts-nocheck
2
-
3
- export default function Button() {
4
- return <button>Click me</button>;
5
- }
@@ -1,5 +0,0 @@
1
- // @ts-nocheck
2
-
3
- export default function Card() {
4
- return <div>Card content</div>;
5
- }
@@ -1,5 +0,0 @@
1
- // @ts-nocheck
2
-
3
- export default function Example() {
4
- return <div>Hello World</div>;
5
- }
@@ -1,5 +0,0 @@
1
- // @ts-nocheck
2
-
3
- export default function Hero() {
4
- return <section>Hero section</section>;
5
- }