tailjng 0.0.13 → 0.0.14
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/cli/tailjng.js +40 -3
- package/package.json +1 -1
package/cli/tailjng.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
@@ -27,6 +27,8 @@ const componentsPath = path.join(packageRoot, 'src', 'lib', 'components');
|
|
|
27
27
|
const args = process.argv.slice(2);
|
|
28
28
|
const command = args[0];
|
|
29
29
|
|
|
30
|
+
const installedComponents = new Set();
|
|
31
|
+
|
|
30
32
|
if (command === 'add') {
|
|
31
33
|
const componentName = args[1];
|
|
32
34
|
checkTailwindInstalled();
|
|
@@ -38,6 +40,12 @@ Usage:
|
|
|
38
40
|
${COLORS.reset}`);
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if TailwindCSS is installed in the project.
|
|
47
|
+
* If not, display a warning message with installation instructions.
|
|
48
|
+
*/
|
|
41
49
|
function checkTailwindInstalled() {
|
|
42
50
|
try {
|
|
43
51
|
require.resolve('tailwindcss');
|
|
@@ -60,9 +68,26 @@ ${COLORS.reset}`);
|
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Add a component to the project.
|
|
75
|
+
* @param {string} componentName
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
63
78
|
function addComponent(componentName) {
|
|
79
|
+
|
|
80
|
+
if (installedComponents.has(componentName)) {
|
|
81
|
+
// If the component is already installed, skip it
|
|
82
|
+
console.log(`${COLORS.dim}[tailjng CLI] Component "${componentName}" already installed, skipping.${COLORS.reset}`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
installedComponents.add(componentName);
|
|
87
|
+
|
|
64
88
|
const sourcePath = path.join(componentsPath, componentName);
|
|
65
89
|
|
|
90
|
+
// Check if the component exists in the source path
|
|
66
91
|
if (!fs.existsSync(sourcePath)) {
|
|
67
92
|
console.error(`${COLORS.red}[tailjng CLI] ERROR: Component "${componentName}" does not exist at path: ${sourcePath}${COLORS.reset}`);
|
|
68
93
|
process.exit(1);
|
|
@@ -83,20 +108,32 @@ function addComponent(componentName) {
|
|
|
83
108
|
|
|
84
109
|
let content = fs.readFileSync(srcFile, 'utf8');
|
|
85
110
|
|
|
86
|
-
//
|
|
111
|
+
// Analize if it imports any service from the library
|
|
87
112
|
const serviceMatches = [...content.matchAll(/import\s+\{\s*(\w+)\s*\}\s+from\s+['"]\.\.\/\.\.\/services\/(.*?)['"]/g)];
|
|
88
113
|
|
|
89
114
|
for (const match of serviceMatches) {
|
|
90
115
|
const serviceName = match[1];
|
|
91
116
|
console.log(`${COLORS.yellow}[tailjng CLI] Updating import of service "${serviceName}" to tailjng.${COLORS.reset}`);
|
|
92
117
|
|
|
93
|
-
//
|
|
118
|
+
// Rewrite the import statement to use the tailjng library
|
|
94
119
|
content = content.replace(
|
|
95
120
|
match[0],
|
|
96
121
|
`import { ${serviceName} } from 'tailjng'`
|
|
97
122
|
);
|
|
98
123
|
}
|
|
99
124
|
|
|
125
|
+
// Analize if it imports another component from the same library
|
|
126
|
+
const componentMatches = [...content.matchAll(/import\s+.*\s+from\s+['"]\.\.\/(\w+)\/.*['"]/g)];
|
|
127
|
+
|
|
128
|
+
for (const match of componentMatches) {
|
|
129
|
+
const dependentComponent = match[1];
|
|
130
|
+
|
|
131
|
+
if (!installedComponents.has(dependentComponent)) {
|
|
132
|
+
console.log(`${COLORS.magenta}[tailjng CLI] Detected dependency on component "${dependentComponent}". Installing it...${COLORS.reset}`);
|
|
133
|
+
addComponent(dependentComponent);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
100
137
|
fs.writeFileSync(destFile, content);
|
|
101
138
|
console.log(`${COLORS.green}[tailjng CLI] Copied file: ${file}${COLORS.reset}`);
|
|
102
139
|
}
|